[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_categories/src/Controller/ -> CategoriesController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_categories
   6   *
   7   * @copyright   (C) 2017 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\Categories\Administrator\Controller;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\MVC\Controller\AdminController;
  15  use Joomla\CMS\Response\JsonResponse;
  16  use Joomla\CMS\Router\Route;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * The Categories List Controller
  24   *
  25   * @since  1.6
  26   */
  27  class CategoriesController extends AdminController
  28  {
  29      /**
  30       * Proxy for getModel
  31       *
  32       * @param   string  $name    The model name. Optional.
  33       * @param   string  $prefix  The class prefix. Optional.
  34       * @param   array   $config  The array of possible config values. Optional.
  35       *
  36       * @return  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model.
  37       *
  38       * @since   1.6
  39       */
  40      public function getModel($name = 'Category', $prefix = 'Administrator', $config = array('ignore_request' => true))
  41      {
  42          return parent::getModel($name, $prefix, $config);
  43      }
  44  
  45      /**
  46       * Outputs the JSON-encoded amount of published content categories
  47       *
  48       * @return  void
  49       *
  50       * @since   4.0.0
  51       */
  52      public function getQuickiconContent()
  53      {
  54          $model = $this->getModel('Categories');
  55          $model->setState('filter.published', 1);
  56          $model->setState('filter.extension', 'com_content');
  57  
  58          $amount = (int) $model->getTotal();
  59  
  60          $result = [];
  61  
  62          $result['amount'] = $amount;
  63          $result['sronly'] = Text::plural('COM_CATEGORIES_N_QUICKICON_SRONLY', $amount);
  64          $result['name'] = Text::plural('COM_CATEGORIES_N_QUICKICON', $amount);
  65  
  66          echo new JsonResponse($result);
  67      }
  68  
  69      /**
  70       * Rebuild the nested set tree.
  71       *
  72       * @return  boolean  False on failure or error, true on success.
  73       *
  74       * @since   1.6
  75       */
  76      public function rebuild()
  77      {
  78          $this->checkToken();
  79  
  80          $extension = $this->input->get('extension');
  81          $this->setRedirect(Route::_('index.php?option=com_categories&view=categories&extension=' . $extension, false));
  82  
  83          /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $model */
  84          $model = $this->getModel();
  85  
  86          if ($model->rebuild()) {
  87              // Rebuild succeeded.
  88              $this->setMessage(Text::_('COM_CATEGORIES_REBUILD_SUCCESS'));
  89  
  90              return true;
  91          }
  92  
  93          // Rebuild failed.
  94          $this->setMessage(Text::_('COM_CATEGORIES_REBUILD_FAILURE'));
  95  
  96          return false;
  97      }
  98  
  99      /**
 100       * Gets the URL arguments to append to a list redirect.
 101       *
 102       * @return  string  The arguments to append to the redirect URL.
 103       *
 104       * @since   4.0.0
 105       */
 106      protected function getRedirectToListAppend()
 107      {
 108          $extension = $this->input->getCmd('extension', null);
 109  
 110          return '&extension=' . $extension;
 111      }
 112  }


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