[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_workflow/src/Controller/ -> StageController.php (source)

   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   * The stage controller
  25   *
  26   * @since  4.0.0
  27   */
  28  class StageController extends FormController
  29  {
  30      /**
  31       * The workflow in where the stage belongs to
  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          $record = $this->getModel()->getItem($recordId);
 126  
 127          if (empty($record->id)) {
 128              return false;
 129          }
 130  
 131          // Check "edit" permission on record asset (explicit or inherited)
 132          if ($user->authorise('core.edit', $this->extension . '.stage.' . $recordId)) {
 133              return true;
 134          }
 135  
 136          // Check "edit own" permission on record asset (explicit or inherited)
 137          if ($user->authorise('core.edit.own', $this->extension . '.stage.' . $recordId)) {
 138              return !empty($record) && $record->created_by == $user->id;
 139          }
 140  
 141          return false;
 142      }
 143  
 144      /**
 145       * Gets the URL arguments to append to an item redirect.
 146       *
 147       * @param   integer  $recordId  The primary key id for the item.
 148       * @param   string   $urlVar    The name of the URL variable for the id.
 149       *
 150       * @return  string  The arguments to append to the redirect URL.
 151       *
 152       * @since  4.0.0
 153       */
 154      protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
 155      {
 156          $append = parent::getRedirectToItemAppend($recordId);
 157  
 158          $append .= '&workflow_id=' . $this->workflowId . '&extension=' . $this->extension . ($this->section ? '.' . $this->section : '');
 159  
 160          return $append;
 161      }
 162  
 163      /**
 164       * Gets the URL arguments to append to a list redirect.
 165       *
 166       * @return  string  The arguments to append to the redirect URL.
 167       *
 168       * @since  4.0.0
 169       */
 170      protected function getRedirectToListAppend()
 171      {
 172          $append = parent::getRedirectToListAppend();
 173          $append .= '&workflow_id=' . $this->workflowId . '&extension=' . $this->extension . ($this->section ? '.' . $this->section : '');
 174  
 175          return $append;
 176      }
 177  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer