[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_newsfeeds
   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\Newsfeeds\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\Newsfeeds\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_newsfeeds';
  37  
  38      /**
  39       * Array of item types
  40       *
  41       * @var       array   $itemTypes
  42       *
  43       * @since    3.7.0
  44       */
  45      protected $itemTypes = array('newsfeed', '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 'newsfeed':
 127                  $table = Table::getInstance('NewsfeedTable', 'Joomla\\Component\\Newsfeeds\\Administrator\\Table\\');
 128                  break;
 129  
 130              case 'category':
 131                  $table = Table::getInstance('Category');
 132                  break;
 133          }
 134  
 135          if (empty($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 'newsfeed':
 164                      $fields['title'] = 'a.name';
 165                      $fields['state'] = 'a.published';
 166  
 167                      $support['state'] = true;
 168                      $support['acl'] = true;
 169                      $support['checkout'] = true;
 170                      $support['category'] = true;
 171                      $support['save2copy'] = true;
 172  
 173                      $tables = array(
 174                          'a' => '#__newsfeeds'
 175                      );
 176                      $title = 'newsfeed';
 177                      break;
 178  
 179                  case 'category':
 180                      $fields['created_user_id'] = 'a.created_user_id';
 181                      $fields['ordering'] = 'a.lft';
 182                      $fields['level'] = 'a.level';
 183                      $fields['catid'] = '';
 184                      $fields['state'] = 'a.published';
 185  
 186                      $support['state'] = true;
 187                      $support['acl'] = true;
 188                      $support['checkout'] = true;
 189                      $support['level'] = true;
 190  
 191                      $tables = array(
 192                          'a' => '#__categories'
 193                      );
 194  
 195                      $title = 'category';
 196                      break;
 197              }
 198          }
 199  
 200          return array(
 201              'fields'  => $fields,
 202              'support' => $support,
 203              'tables'  => $tables,
 204              'joins'   => $joins,
 205              'title'   => $title
 206          );
 207      }
 208  }


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