[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/api/components/com_contenthistory/src/Controller/ -> HistoryController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.API
   5   * @subpackage  com_contenthistory
   6   *
   7   * @copyright   (C) 2019 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\Contenthistory\Api\Controller;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\MVC\Controller\ApiController;
  15  use Joomla\CMS\MVC\Controller\Exception;
  16  use Joomla\Component\Contenthistory\Administrator\Model\HistoryModel;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * The history controller
  24   *
  25   * @since  4.0.0
  26   */
  27  class HistoryController extends ApiController
  28  {
  29      /**
  30       * The content type of the item.
  31       *
  32       * @var    string
  33       * @since  4.0.0
  34       */
  35      protected $contentType = 'history';
  36  
  37      /**
  38       * The default view for the display method.
  39       *
  40       * @var    string
  41       * @since  3.0
  42       */
  43      protected $default_view = 'history';
  44  
  45      /**
  46       * Basic display of a list view
  47       *
  48       * @return  static  A \JControllerLegacy object to support chaining.
  49       *
  50       * @since   4.0.0
  51       */
  52      public function displayList()
  53      {
  54          $this->modelState->set('type_alias', $this->getTypeAliasFromInput());
  55          $this->modelState->set('type_id', $this->getTypeIdFromInput());
  56          $this->modelState->set('item_id', $this->getTypeAliasFromInput() . '.' . $this->getItemIdFromInput());
  57          $this->modelState->set('list.ordering', 'h.save_date');
  58          $this->modelState->set('list.direction', 'DESC');
  59  
  60          return parent::displayList();
  61      }
  62  
  63      /**
  64       * Method to edit an existing record.
  65       *
  66       * @return  static  A \JControllerLegacy object to support chaining.
  67       *
  68       * @since   4.0.0
  69       */
  70      public function keep()
  71      {
  72          /** @var HistoryModel $model */
  73          $model = $this->getModel($this->contentType);
  74  
  75          if (!$model) {
  76              throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
  77          }
  78  
  79          $recordId = $this->input->getInt('id');
  80  
  81          if (!$recordId) {
  82              throw new Exception\ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
  83          }
  84  
  85          $cid = [$recordId];
  86  
  87          if (!$model->keep($cid)) {
  88              throw new Exception\Save(Text::plural('COM_CONTENTHISTORY_N_ITEMS_KEEP_TOGGLE', \count($cid)));
  89          }
  90  
  91          return $this;
  92      }
  93  
  94      /**
  95       * Get item id from input
  96       *
  97       * @return string
  98       *
  99       * @since 4.0.0
 100       */
 101      private function getItemIdFromInput()
 102      {
 103          return $this->input->exists('id') ?
 104              $this->input->get('id') : $this->input->post->get('id');
 105      }
 106  
 107      /**
 108       * Get type id from input
 109       *
 110       * @return string
 111       *
 112       * @since 4.0.0
 113       */
 114      private function getTypeIdFromInput()
 115      {
 116          return $this->input->exists('type_id') ?
 117              $this->input->get('type_id') : $this->input->post->get('type_id');
 118      }
 119  
 120      /**
 121       * Get type alias from input
 122       *
 123       * @return string
 124       *
 125       * @since 4.0.0
 126       */
 127      private function getTypeAliasFromInput()
 128      {
 129          return $this->input->exists('type_alias') ?
 130              $this->input->get('type_alias') : $this->input->post->get('type_alias');
 131      }
 132  }


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