[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_newsfeeds/src/Controller/ -> NewsfeedController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_newsfeeds
   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\Newsfeeds\Administrator\Controller;
  12  
  13  use Joomla\CMS\MVC\Controller\FormController;
  14  use Joomla\CMS\Router\Route;
  15  use Joomla\CMS\Versioning\VersionableControllerTrait;
  16  use Joomla\Utilities\ArrayHelper;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Newsfeed controller class.
  24   *
  25   * @since  1.6
  26   */
  27  class NewsfeedController extends FormController
  28  {
  29      use VersionableControllerTrait;
  30  
  31      /**
  32       * Method override to check if you can add a new record.
  33       *
  34       * @param   array  $data  An array of input data.
  35       *
  36       * @return  boolean
  37       *
  38       * @since   1.6
  39       */
  40      protected function allowAdd($data = array())
  41      {
  42          $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
  43          $allow = null;
  44  
  45          if ($categoryId) {
  46              // If the category has been passed in the URL check it.
  47              $allow = $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
  48          }
  49  
  50          if ($allow === null) {
  51              // In the absence of better information, revert to the component permissions.
  52              return parent::allowAdd($data);
  53          } else {
  54              return $allow;
  55          }
  56      }
  57  
  58      /**
  59       * Method to check if you can edit a record.
  60       *
  61       * @param   array   $data  An array of input data.
  62       * @param   string  $key   The name of the key for the primary key.
  63       *
  64       * @return  boolean
  65       *
  66       * @since   1.6
  67       */
  68      protected function allowEdit($data = array(), $key = 'id')
  69      {
  70          $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
  71  
  72          // Since there is no asset tracking, fallback to the component permissions.
  73          if (!$recordId) {
  74              return parent::allowEdit($data, $key);
  75          }
  76  
  77          // Get the item.
  78          $item = $this->getModel()->getItem($recordId);
  79  
  80          // Since there is no item, return false.
  81          if (empty($item)) {
  82              return false;
  83          }
  84  
  85          $user = $this->app->getIdentity();
  86  
  87          // Check if can edit own core.edit.own.
  88          $canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id;
  89  
  90          // Check the category core.edit permissions.
  91          return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $item->catid);
  92      }
  93  
  94      /**
  95       * Method to run batch operations.
  96       *
  97       * @param   object  $model  The model.
  98       *
  99       * @return  boolean   True if successful, false otherwise and internal error is set.
 100       *
 101       * @since   2.5
 102       */
 103      public function batch($model = null)
 104      {
 105          $this->checkToken();
 106  
 107          // Set the model
 108          $model = $this->getModel('Newsfeed', '', array());
 109  
 110          // Preset the redirect
 111          $this->setRedirect(Route::_('index.php?option=com_newsfeeds&view=newsfeeds' . $this->getRedirectToListAppend(), false));
 112  
 113          return parent::batch($model);
 114      }
 115  }


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