[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Categories/ -> CategoryServiceTrait.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\Categories;
  11  
  12  use Joomla\CMS\Form\Form;
  13  use Joomla\CMS\Helper\ContentHelper;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Trait for component categories service.
  21   *
  22   * @since  4.0.0
  23   */
  24  trait CategoryServiceTrait
  25  {
  26      /**
  27       * The categories factory
  28       *
  29       * @var  CategoryFactoryInterface
  30       *
  31       * @since  4.0.0
  32       */
  33      private $categoryFactory;
  34  
  35      /**
  36       * Returns the category service.
  37       *
  38       * @param   array   $options  The options
  39       * @param   string  $section  The section
  40       *
  41       * @return  CategoryInterface
  42       *
  43       * @since   4.0.0
  44       * @throws  SectionNotFoundException
  45       */
  46      public function getCategory(array $options = [], $section = ''): CategoryInterface
  47      {
  48          return $this->categoryFactory->createCategory($options, $section);
  49      }
  50  
  51      /**
  52       * Sets the internal category factory.
  53       *
  54       * @param   CategoryFactoryInterface  $categoryFactory  The categories factory
  55       *
  56       * @return  void
  57       *
  58       * @since  4.0.0
  59       */
  60      public function setCategoryFactory(CategoryFactoryInterface $categoryFactory)
  61      {
  62          $this->categoryFactory = $categoryFactory;
  63      }
  64  
  65      /**
  66       * Adds Count Items for Category Manager.
  67       *
  68       * @param   \stdClass[]  $items    The category objects
  69       * @param   string       $section  The section
  70       *
  71       * @return  void
  72       *
  73       * @since   4.0.0
  74       * @throws  \Exception
  75       */
  76      public function countItems(array $items, string $section)
  77      {
  78          $config = (object) array(
  79              'related_tbl'   => $this->getTableNameForSection($section),
  80              'state_col'     => $this->getStateColumnForSection($section),
  81              'group_col'     => 'catid',
  82              'relation_type' => 'category_or_group',
  83          );
  84  
  85          ContentHelper::countRelations($items, $config);
  86      }
  87  
  88      /**
  89       * Prepares the category form
  90       *
  91       * @param   Form          $form  The form to change
  92       * @param   array|object  $data  The form data
  93       *
  94       * @return void
  95       */
  96      public function prepareForm(Form $form, $data)
  97      {
  98      }
  99  
 100      /**
 101       * Returns the table for the count items functions for the given section.
 102       *
 103       * @param   string  $section  The section
 104       *
 105       * @return  string|null
 106       *
 107       * @since   4.0.0
 108       */
 109      protected function getTableNameForSection(string $section = null)
 110      {
 111          return null;
 112      }
 113  
 114      /**
 115       * Returns the state column for the count items functions for the given section.
 116       *
 117       * @param   string  $section  The section
 118       *
 119       * @return  string|null
 120       *
 121       * @since   4.0.0
 122       */
 123      protected function getStateColumnForSection(string $section = null)
 124      {
 125          return 'state';
 126      }
 127  }


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