[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_fields/src/Controller/ -> GroupController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_fields
   6   *
   7   * @copyright   (C) 2016 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\Fields\Administrator\Controller;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\MVC\Controller\FormController;
  15  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  16  use Joomla\CMS\MVC\Model\BaseDatabaseModel;
  17  use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
  18  use Joomla\Input\Input;
  19  use Joomla\Registry\Registry;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * The Group controller
  27   *
  28   * @since  3.7.0
  29   */
  30  class GroupController extends FormController
  31  {
  32      /**
  33       * The prefix to use with controller messages.
  34       *
  35       * @var    string
  36  
  37       * @since   3.7.0
  38       */
  39      protected $text_prefix = 'COM_FIELDS_GROUP';
  40  
  41      /**
  42       * The component for which the group applies.
  43       *
  44       * @var    string
  45       * @since   3.7.0
  46       */
  47      private $component = '';
  48  
  49      /**
  50       * Constructor.
  51       *
  52       * @param   array                $config   An optional associative array of configuration settings.
  53       * Recognized key values include 'name', 'default_task', 'model_path', and
  54       * 'view_path' (this list is not meant to be comprehensive).
  55       * @param   MVCFactoryInterface  $factory  The factory.
  56       * @param   CMSApplication       $app      The Application for the dispatcher
  57       * @param   Input                $input    Input
  58       *
  59       * @since   3.7.0
  60       */
  61      public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
  62      {
  63          parent::__construct($config, $factory, $app, $input);
  64  
  65          $parts = FieldsHelper::extract($this->input->getCmd('context'));
  66  
  67          if ($parts) {
  68              $this->component = $parts[0];
  69          }
  70      }
  71  
  72      /**
  73       * Method to run batch operations.
  74       *
  75       * @param   object  $model  The model.
  76       *
  77       * @return  boolean   True if successful, false otherwise and internal error is set.
  78       *
  79       * @since   3.7.0
  80       */
  81      public function batch($model = null)
  82      {
  83          $this->checkToken();
  84  
  85          // Set the model
  86          $model = $this->getModel('Group');
  87  
  88          // Preset the redirect
  89          $this->setRedirect('index.php?option=com_fields&view=groups');
  90  
  91          return parent::batch($model);
  92      }
  93  
  94      /**
  95       * Method override to check if you can add a new record.
  96       *
  97       * @param   array  $data  An array of input data.
  98       *
  99       * @return  boolean
 100       *
 101       * @since   3.7.0
 102       */
 103      protected function allowAdd($data = array())
 104      {
 105          return $this->app->getIdentity()->authorise('core.create', $this->component);
 106      }
 107  
 108      /**
 109       * Method override to check if you can edit an existing record.
 110       *
 111       * @param   array   $data  An array of input data.
 112       * @param   string  $key   The name of the key for the primary key.
 113       *
 114       * @return  boolean
 115       *
 116       * @since   3.7.0
 117       */
 118      protected function allowEdit($data = array(), $key = 'parent_id')
 119      {
 120          $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
 121          $user = $this->app->getIdentity();
 122  
 123          // Zero record (parent_id:0), return component edit permission by calling parent controller method
 124          if (!$recordId) {
 125              return parent::allowEdit($data, $key);
 126          }
 127  
 128          // Check edit on the record asset (explicit or inherited)
 129          if ($user->authorise('core.edit', $this->component . '.fieldgroup.' . $recordId)) {
 130              return true;
 131          }
 132  
 133          // Check edit own on the record asset (explicit or inherited)
 134          if ($user->authorise('core.edit.own', $this->component . '.fieldgroup.' . $recordId) || $user->authorise('core.edit.own', $this->component)) {
 135              // Existing record already has an owner, get it
 136              $record = $this->getModel()->getItem($recordId);
 137  
 138              if (empty($record)) {
 139                  return false;
 140              }
 141  
 142              // Grant if current user is owner of the record
 143              return $user->id == $record->created_by;
 144          }
 145  
 146          return false;
 147      }
 148  
 149      /**
 150       * Function that allows child controller access to model data after the data has been saved.
 151       *
 152       * @param   BaseDatabaseModel  $model      The data model object.
 153       * @param   array              $validData  The validated data.
 154       *
 155       * @return  void
 156       *
 157       * @since   3.7.0
 158       */
 159      protected function postSaveHook(BaseDatabaseModel $model, $validData = array())
 160      {
 161          $item = $model->getItem();
 162  
 163          if (isset($item->params) && is_array($item->params)) {
 164              $registry = new Registry();
 165              $registry->loadArray($item->params);
 166              $item->params = (string) $registry;
 167          }
 168      }
 169  
 170      /**
 171       * Gets the URL arguments to append to an item redirect.
 172       *
 173       * @param   integer  $recordId  The primary key id for the item.
 174       * @param   string   $urlVar    The name of the URL variable for the id.
 175       *
 176       * @return  string  The arguments to append to the redirect URL.
 177       *
 178       * @since  4.0.0
 179       */
 180      protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
 181      {
 182          $append = parent::getRedirectToItemAppend($recordId);
 183          $append .= '&context=' . $this->input->get('context');
 184  
 185          return $append;
 186      }
 187  
 188      /**
 189       * Gets the URL arguments to append to a list redirect.
 190       *
 191       * @return  string  The arguments to append to the redirect URL.
 192       *
 193       * @since  4.0.0
 194       */
 195      protected function getRedirectToListAppend()
 196      {
 197          $append = parent::getRedirectToListAppend();
 198          $append .= '&context=' . $this->input->get('context');
 199  
 200          return $append;
 201      }
 202  }


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