[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_content/src/Controller/ -> ArticleController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_content
   6   *
   7   * @copyright   (C) 2009 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\Content\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\CMS\Router\Route;
  18  use Joomla\CMS\Versioning\VersionableControllerTrait;
  19  use Joomla\Input\Input;
  20  use Joomla\Utilities\ArrayHelper;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * The article controller
  28   *
  29   * @since  1.6
  30   */
  31  class ArticleController extends FormController
  32  {
  33      use VersionableControllerTrait;
  34  
  35      /**
  36       * Constructor.
  37       *
  38       * @param   array                $config   An optional associative array of configuration settings.
  39       * Recognized key values include 'name', 'default_task', 'model_path', and
  40       * 'view_path' (this list is not meant to be comprehensive).
  41       * @param   MVCFactoryInterface  $factory  The factory.
  42       * @param   CMSApplication       $app      The Application for the dispatcher
  43       * @param   Input                $input    Input
  44       *
  45       * @since   3.0
  46       */
  47      public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
  48      {
  49          parent::__construct($config, $factory, $app, $input);
  50  
  51          // An article edit form can come from the articles or featured view.
  52          // Adjust the redirect view on the value of 'return' in the request.
  53          if ($this->input->get('return') == 'featured') {
  54              $this->view_list = 'featured';
  55              $this->view_item = 'article&return=featured';
  56          }
  57      }
  58  
  59      /**
  60       * Function that allows child controller access to model data
  61       * after the data has been saved.
  62       *
  63       * @param   BaseDatabaseModel  $model      The data model object.
  64       * @param   array              $validData  The validated data.
  65       *
  66       * @return  void
  67       *
  68       * @since   4.0.0
  69       */
  70      protected function postSaveHook(BaseDatabaseModel $model, $validData = array())
  71      {
  72          if ($this->getTask() === 'save2menu') {
  73              $editState = [];
  74  
  75              $id = $model->getState('article.id');
  76  
  77              $link = 'index.php?option=com_content&view=article';
  78              $type = 'component';
  79  
  80              $editState['id'] = $id;
  81              $editState['link']  = $link;
  82              $editState['title'] = $model->getItem($id)->title;
  83              $editState['type']  = $type;
  84              $editState['request']['id'] = $id;
  85  
  86              $this->app->setUserState('com_menus.edit.item', array(
  87                  'data' => $editState,
  88                  'type' => $type,
  89                  'link' => $link));
  90  
  91              $this->setRedirect(Route::_('index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit', false));
  92          }
  93      }
  94  
  95      /**
  96       * Method override to check if you can add a new record.
  97       *
  98       * @param   array  $data  An array of input data.
  99       *
 100       * @return  boolean
 101       *
 102       * @since   1.6
 103       */
 104      protected function allowAdd($data = array())
 105      {
 106          $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
 107  
 108          if ($categoryId) {
 109              // If the category has been passed in the data or URL check it.
 110              return $this->app->getIdentity()->authorise('core.create', 'com_content.category.' . $categoryId);
 111          }
 112  
 113          // In the absence of better information, revert to the component permissions.
 114          return parent::allowAdd();
 115      }
 116  
 117      /**
 118       * Method override to check if you can edit an existing record.
 119       *
 120       * @param   array   $data  An array of input data.
 121       * @param   string  $key   The name of the key for the primary key.
 122       *
 123       * @return  boolean
 124       *
 125       * @since   1.6
 126       */
 127      protected function allowEdit($data = array(), $key = 'id')
 128      {
 129          $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
 130          $user = $this->app->getIdentity();
 131  
 132          // Zero record (id:0), return component edit permission by calling parent controller method
 133          if (!$recordId) {
 134              return parent::allowEdit($data, $key);
 135          }
 136  
 137          // Check edit on the record asset (explicit or inherited)
 138          if ($user->authorise('core.edit', 'com_content.article.' . $recordId)) {
 139              return true;
 140          }
 141  
 142          // Check edit own on the record asset (explicit or inherited)
 143          if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId)) {
 144              // Existing record already has an owner, get it
 145              $record = $this->getModel()->getItem($recordId);
 146  
 147              if (empty($record)) {
 148                  return false;
 149              }
 150  
 151              // Grant if current user is owner of the record
 152              return $user->id == $record->created_by;
 153          }
 154  
 155          return false;
 156      }
 157  
 158      /**
 159       * Method to run batch operations.
 160       *
 161       * @param   object  $model  The model.
 162       *
 163       * @return  boolean   True if successful, false otherwise and internal error is set.
 164       *
 165       * @since   1.6
 166       */
 167      public function batch($model = null)
 168      {
 169          $this->checkToken();
 170  
 171          // Set the model
 172          /** @var \Joomla\Component\Content\Administrator\Model\ArticleModel $model */
 173          $model = $this->getModel('Article', 'Administrator', array());
 174  
 175          // Preset the redirect
 176          $this->setRedirect(Route::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
 177  
 178          return parent::batch($model);
 179      }
 180  }


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