[ 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_workflow 6 * 7 * @copyright (C) 2018 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\Workflow\Administrator\Controller; 12 13 use Joomla\CMS\Application\CMSApplication; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\Controller\FormController; 16 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 17 use Joomla\Input\Input; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Transition controller 25 * 26 * @since 4.0.0 27 */ 28 class TransitionController extends FormController 29 { 30 /** 31 * The workflow where the transition takes place 32 * 33 * @var integer 34 * @since 4.0.0 35 */ 36 protected $workflowId; 37 38 /** 39 * The extension 40 * 41 * @var string 42 * @since 4.0.0 43 */ 44 protected $extension; 45 46 /** 47 * The section of the current extension 48 * 49 * @var string 50 * @since 4.0.0 51 */ 52 protected $section; 53 54 /** 55 * Constructor. 56 * 57 * @param array $config An optional associative array of configuration settings. 58 * @param MVCFactoryInterface $factory The factory. 59 * @param CMSApplication $app The Application for the dispatcher 60 * @param Input $input Input 61 * 62 * @since 4.0.0 63 * @throws \InvalidArgumentException when no extension or workflow id is set 64 */ 65 public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) 66 { 67 parent::__construct($config, $factory, $app, $input); 68 69 // If workflow id is not set try to get it from input or throw an exception 70 if (empty($this->workflowId)) { 71 $this->workflowId = $this->input->getInt('workflow_id'); 72 73 if (empty($this->workflowId)) { 74 throw new \InvalidArgumentException(Text::_('COM_WORKFLOW_ERROR_WORKFLOW_ID_NOT_SET')); 75 } 76 } 77 78 // If extension is not set try to get it from input or throw an exception 79 if (empty($this->extension)) { 80 $extension = $this->input->getCmd('extension'); 81 82 $parts = explode('.', $extension); 83 84 $this->extension = array_shift($parts); 85 86 if (!empty($parts)) { 87 $this->section = array_shift($parts); 88 } 89 90 if (empty($this->extension)) { 91 throw new \InvalidArgumentException(Text::_('COM_WORKFLOW_ERROR_EXTENSION_NOT_SET')); 92 } 93 } 94 } 95 96 /** 97 * Method to check if you can add a new record. 98 * 99 * @param array $data An array of input data. 100 * 101 * @return boolean 102 * 103 * @since 4.0.0 104 */ 105 protected function allowAdd($data = array()) 106 { 107 return $this->app->getIdentity()->authorise('core.create', $this->extension . '.workflow.' . (int) $this->workflowId); 108 } 109 110 /** 111 * Method to check if you can edit a record. 112 * 113 * @param array $data An array of input data. 114 * @param string $key The name of the key for the primary key. 115 * 116 * @return boolean 117 * 118 * @since 4.0.0 119 */ 120 protected function allowEdit($data = array(), $key = 'id') 121 { 122 $recordId = isset($data[$key]) ? (int) $data[$key] : 0; 123 $user = $this->app->getIdentity(); 124 125 $model = $this->getModel(); 126 127 $item = $model->getItem($recordId); 128 129 if (empty($item->id)) { 130 return false; 131 } 132 133 // Check "edit" permission on record asset (explicit or inherited) 134 if ($user->authorise('core.edit', $this->extension . '.transition.' . $recordId)) { 135 return true; 136 } 137 138 // Check "edit own" permission on record asset (explicit or inherited) 139 if ($user->authorise('core.edit.own', $this->extension . '.transition.' . $recordId)) { 140 return !empty($item) && $item->created_by == $user->id; 141 } 142 143 return false; 144 } 145 146 /** 147 * Gets the URL arguments to append to an item redirect. 148 * 149 * @param integer $recordId The primary key id for the item. 150 * @param string $urlVar The name of the URL variable for the id. 151 * 152 * @return string The arguments to append to the redirect URL. 153 * 154 * @since 4.0.0 155 */ 156 protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') 157 { 158 $append = parent::getRedirectToItemAppend($recordId); 159 $append .= '&workflow_id=' . $this->workflowId . '&extension=' . $this->extension; 160 161 return $append; 162 } 163 164 /** 165 * Gets the URL arguments to append to a list redirect. 166 * 167 * @return string The arguments to append to the redirect URL. 168 * 169 * @since 4.0.0 170 */ 171 protected function getRedirectToListAppend() 172 { 173 $append = parent::getRedirectToListAppend(); 174 $append .= '&workflow_id=' . $this->workflowId . '&extension=' . $this->extension; 175 176 return $append; 177 } 178 }
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 |