[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_content/src/Helper/ -> AssociationsHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_content
   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\Content\Administrator\Helper;
  12  
  13  use Joomla\CMS\Association\AssociationExtensionHelper;
  14  use Joomla\CMS\Language\Associations;
  15  use Joomla\CMS\Table\Table;
  16  use Joomla\Component\Content\Site\Helper\AssociationHelper;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Content associations helper.
  24   *
  25   * @since  3.7.0
  26   */
  27  class AssociationsHelper extends AssociationExtensionHelper
  28  {
  29      /**
  30       * The extension name
  31       *
  32       * @var     array   $extension
  33       *
  34       * @since   3.7.0
  35       */
  36      protected $extension = 'com_content';
  37  
  38      /**
  39       * Array of item types
  40       *
  41       * @var     array   $itemTypes
  42       *
  43       * @since   3.7.0
  44       */
  45      protected $itemTypes = array('article', 'category');
  46  
  47      /**
  48       * Has the extension association support
  49       *
  50       * @var     boolean   $associationsSupport
  51       *
  52       * @since   3.7.0
  53       */
  54      protected $associationsSupport = true;
  55  
  56      /**
  57       * Method to get the associations for a given item.
  58       *
  59       * @param   integer  $id    Id of the item
  60       * @param   string   $view  Name of the view
  61       *
  62       * @return  array   Array of associations for the item
  63       *
  64       * @since  4.0.0
  65       */
  66      public function getAssociationsForItem($id = 0, $view = null)
  67      {
  68          return AssociationHelper::getAssociations($id, $view);
  69      }
  70  
  71      /**
  72       * Get the associated items for an item
  73       *
  74       * @param   string  $typeName  The item type
  75       * @param   int     $id        The id of item for which we need the associated items
  76       *
  77       * @return  array
  78       *
  79       * @since   3.7.0
  80       */
  81      public function getAssociations($typeName, $id)
  82      {
  83          $type = $this->getType($typeName);
  84  
  85          $context    = $this->extension . '.item';
  86          $catidField = 'catid';
  87  
  88          if ($typeName === 'category') {
  89              $context    = 'com_categories.item';
  90              $catidField = '';
  91          }
  92  
  93          // Get the associations.
  94          $associations = Associations::getAssociations(
  95              $this->extension,
  96              $type['tables']['a'],
  97              $context,
  98              $id,
  99              'id',
 100              'alias',
 101              $catidField
 102          );
 103  
 104          return $associations;
 105      }
 106  
 107      /**
 108       * Get item information
 109       *
 110       * @param   string  $typeName  The item type
 111       * @param   int     $id        The id of item for which we need the associated items
 112       *
 113       * @return  Table|null
 114       *
 115       * @since   3.7.0
 116       */
 117      public function getItem($typeName, $id)
 118      {
 119          if (empty($id)) {
 120              return null;
 121          }
 122  
 123          $table = null;
 124  
 125          switch ($typeName) {
 126              case 'article':
 127                  $table = Table::getInstance('Content');
 128                  break;
 129  
 130              case 'category':
 131                  $table = Table::getInstance('Category');
 132                  break;
 133          }
 134  
 135          if (is_null($table)) {
 136              return null;
 137          }
 138  
 139          $table->load($id);
 140  
 141          return $table;
 142      }
 143  
 144      /**
 145       * Get information about the type
 146       *
 147       * @param   string  $typeName  The item type
 148       *
 149       * @return  array  Array of item types
 150       *
 151       * @since   3.7.0
 152       */
 153      public function getType($typeName = '')
 154      {
 155          $fields  = $this->getFieldsTemplate();
 156          $tables  = array();
 157          $joins   = array();
 158          $support = $this->getSupportTemplate();
 159          $title   = '';
 160  
 161          if (in_array($typeName, $this->itemTypes)) {
 162              switch ($typeName) {
 163                  case 'article':
 164                      $support['state'] = true;
 165                      $support['acl'] = true;
 166                      $support['checkout'] = true;
 167                      $support['category'] = true;
 168                      $support['save2copy'] = true;
 169  
 170                      $tables = array(
 171                          'a' => '#__content'
 172                      );
 173  
 174                      $title = 'article';
 175                      break;
 176  
 177                  case 'category':
 178                      $fields['created_user_id'] = 'a.created_user_id';
 179                      $fields['ordering'] = 'a.lft';
 180                      $fields['level'] = 'a.level';
 181                      $fields['catid'] = '';
 182                      $fields['state'] = 'a.published';
 183  
 184                      $support['state'] = true;
 185                      $support['acl'] = true;
 186                      $support['checkout'] = true;
 187                      $support['level'] = true;
 188  
 189                      $tables = array(
 190                          'a' => '#__categories'
 191                      );
 192  
 193                      $title = 'category';
 194                      break;
 195              }
 196          }
 197  
 198          return array(
 199              'fields'  => $fields,
 200              'support' => $support,
 201              'tables'  => $tables,
 202              'joins'   => $joins,
 203              'title'   => $title
 204          );
 205      }
 206  }


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