[ 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\AdminController; 16 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 17 use Joomla\CMS\Router\Route; 18 use Joomla\Input\Input; 19 use Joomla\Utilities\ArrayHelper; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * The workflow stages controller 27 * 28 * @since 4.0.0 29 */ 30 class StagesController extends AdminController 31 { 32 /** 33 * The workflow in where the stage belongs to 34 * 35 * @var integer 36 * @since 4.0.0 37 */ 38 protected $workflowId; 39 40 /** 41 * The extension 42 * 43 * @var string 44 * @since 4.0.0 45 */ 46 protected $extension; 47 48 /** 49 * The section of the current extension 50 * 51 * @var string 52 * @since 4.0.0 53 */ 54 protected $section; 55 56 /** 57 * The prefix to use with controller messages. 58 * 59 * @var string 60 * @since 4.0.0 61 */ 62 protected $text_prefix = 'COM_WORKFLOW_STAGES'; 63 64 /** 65 * Constructor. 66 * 67 * @param array $config An optional associative array of configuration settings. 68 * @param MVCFactoryInterface $factory The factory. 69 * @param CMSApplication $app The Application for the dispatcher 70 * @param Input $input Input 71 * 72 * @since 4.0.0 73 * @throws \InvalidArgumentException when no extension or workflow id is set 74 */ 75 public function __construct(array $config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) 76 { 77 parent::__construct($config, $factory, $app, $input); 78 79 // If workflow id is not set try to get it from input or throw an exception 80 if (empty($this->workflowId)) { 81 $this->workflowId = $this->input->getInt('workflow_id'); 82 83 if (empty($this->workflowId)) { 84 throw new \InvalidArgumentException(Text::_('COM_WORKFLOW_ERROR_WORKFLOW_ID_NOT_SET')); 85 } 86 } 87 88 // If extension is not set try to get it from input or throw an exception 89 if (empty($this->extension)) { 90 $extension = $this->input->getCmd('extension'); 91 92 $parts = explode('.', $extension); 93 94 $this->extension = array_shift($parts); 95 96 if (!empty($parts)) { 97 $this->section = array_shift($parts); 98 } 99 100 if (empty($this->extension)) { 101 throw new \InvalidArgumentException(Text::_('COM_WORKFLOW_ERROR_EXTENSION_NOT_SET')); 102 } 103 } 104 105 $this->registerTask('unsetDefault', 'setDefault'); 106 } 107 108 /** 109 * Proxy for getModel 110 * 111 * @param string $name The model name. Optional. 112 * @param string $prefix The class prefix. Optional. 113 * @param array $config The array of possible config values. Optional. 114 * 115 * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. 116 * 117 * @since 4.0.0 118 */ 119 public function getModel($name = 'Stage', $prefix = 'Administrator', $config = array('ignore_request' => true)) 120 { 121 return parent::getModel($name, $prefix, $config); 122 } 123 124 /** 125 * Method to set the home property for a list of items 126 * 127 * @return void 128 * 129 * @since 4.0.0 130 */ 131 public function setDefault() 132 { 133 // Check for request forgeries 134 $this->checkToken(); 135 136 // Get items to publish from the request. 137 $cid = (array) $this->input->get('cid', array(), 'int'); 138 $data = array('setDefault' => 1, 'unsetDefault' => 0); 139 $task = $this->getTask(); 140 $value = ArrayHelper::getValue($data, $task, 0, 'int'); 141 142 if (!$value) { 143 $this->setMessage(Text::_('COM_WORKFLOW_DISABLE_DEFAULT'), 'warning'); 144 $this->setRedirect( 145 Route::_( 146 'index.php?option=' . $this->option . '&view=' . $this->view_list 147 . '&extension=' . $this->extension, 148 false 149 ) 150 ); 151 152 return; 153 } 154 155 // Remove zero values resulting from input filter 156 $cid = array_filter($cid); 157 158 if (empty($cid)) { 159 $this->setMessage(Text::_('COM_WORKFLOW_NO_ITEM_SELECTED'), 'warning'); 160 } elseif (count($cid) > 1) { 161 $this->setMessage(Text::_('COM_WORKFLOW_TOO_MANY_STAGES'), 'error'); 162 } else { 163 // Get the model. 164 $model = $this->getModel(); 165 166 // Make sure the item ids are integers 167 $id = reset($cid); 168 169 // Publish the items. 170 if (!$model->setDefault($id, $value)) { 171 $this->setMessage($model->getError(), 'warning'); 172 } else { 173 $this->setMessage(Text::_('COM_WORKFLOW_STAGE_SET_DEFAULT')); 174 } 175 } 176 177 $this->setRedirect( 178 Route::_( 179 'index.php?option=' . $this->option . '&view=' . $this->view_list 180 . '&extension=' . $this->extension 181 . '&workflow_id=' . $this->workflowId, 182 false 183 ) 184 ); 185 } 186 187 /** 188 * Gets the URL arguments to append to a list redirect. 189 * 190 * @return string The arguments to append to the redirect URL. 191 * 192 * @since 4.0.0 193 */ 194 protected function getRedirectToListAppend() 195 { 196 return '&extension=' . $this->extension . ($this->section ? '.' . $this->section : '') . '&workflow_id=' . $this->workflowId; 197 } 198 }
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 |