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