[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_scheduler 6 * 7 * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Scheduler\Administrator\Controller; 12 13 use Joomla\CMS\Application\AdministratorApplication; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\Controller\FormController; 16 use Joomla\CMS\Router\Route; 17 use Joomla\Component\Scheduler\Administrator\Helper\SchedulerHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * MVC Controller for the item configuration page (TaskView). 25 * 26 * @since 4.1.0 27 */ 28 class TaskController extends FormController 29 { 30 /** 31 * Add a new record 32 * 33 * @return boolean 34 * @since 4.1.0 35 * @throws \Exception 36 */ 37 public function add(): bool 38 { 39 /** @var AdministratorApplication $app */ 40 $app = $this->app; 41 $input = $app->getInput(); 42 $validTaskOptions = SchedulerHelper::getTaskOptions(); 43 44 $canAdd = parent::add(); 45 46 if ($canAdd !== true) { 47 return false; 48 } 49 50 $taskType = $input->get('type'); 51 $taskOption = $validTaskOptions->findOption($taskType) ?: null; 52 53 if (!$taskOption) { 54 // ? : Is this the right redirect [review] 55 $redirectUrl = 'index.php?option=' . $this->option . '&view=select&layout=edit'; 56 $this->setRedirect(Route::_($redirectUrl, false)); 57 $app->enqueueMessage(Text::_('COM_SCHEDULER_ERROR_INVALID_TASK_TYPE'), 'warning'); 58 $canAdd = false; 59 } 60 61 $app->setUserState('com_scheduler.add.task.task_type', $taskType); 62 $app->setUserState('com_scheduler.add.task.task_option', $taskOption); 63 64 // @todo : Parameter array handling below? 65 66 return $canAdd; 67 } 68 69 /** 70 * Override parent cancel method to reset the add task state 71 * 72 * @param ?string $key Primary key from the URL param 73 * 74 * @return boolean True if access level checks pass 75 * 76 * @since 4.1.0 77 */ 78 public function cancel($key = null): bool 79 { 80 $result = parent::cancel($key); 81 82 $this->app->setUserState('com_scheduler.add.task.task_type', null); 83 $this->app->setUserState('com_scheduler.add.task.task_option', null); 84 85 // ? Do we need to redirect based on URL's 'return' param? {@see ModuleController} 86 87 return $result; 88 } 89 90 /** 91 * Check if user has the authority to edit an asset 92 * 93 * @param array $data Array of input data 94 * @param string $key Name of key for primary key, defaults to 'id' 95 * 96 * @return boolean True if user is allowed to edit record 97 * 98 * @since 4.1.0 99 */ 100 protected function allowEdit($data = array(), $key = 'id'): bool 101 { 102 // Extract the recordId from $data, will come in handy 103 $recordId = (int) $data[$key] ?? 0; 104 105 /** 106 * Zero record (id:0), return component edit permission by calling parent controller method 107 * ?: Is this the right way to do this? 108 */ 109 if ($recordId === 0) { 110 return parent::allowEdit($data, $key); 111 } 112 113 // @todo : Check if this works as expected 114 return $this->app->getIdentity()->authorise('core.edit', 'com_scheduler.task.' . $recordId); 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |