[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/api/components/com_content/src/Serializer/ -> ContentSerializer.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\Component\Content\Api\Serializer;
  11  
  12  use Joomla\CMS\Router\Route;
  13  use Joomla\CMS\Serializer\JoomlaSerializer;
  14  use Joomla\CMS\Uri\Uri;
  15  use Tobscure\JsonApi\Collection;
  16  use Tobscure\JsonApi\Relationship;
  17  use Tobscure\JsonApi\Resource;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Temporary serializer
  25   *
  26   * @since  4.0.0
  27   */
  28  class ContentSerializer extends JoomlaSerializer
  29  {
  30      /**
  31       * Build content relationships by associations
  32       *
  33       * @param   \stdClass  $model  Item model
  34       *
  35       * @return  Relationship
  36       *
  37       * @since 4.0.0
  38       */
  39      public function languageAssociations($model)
  40      {
  41          $resources = [];
  42  
  43          // @todo: This can't be hardcoded in the future?
  44          $serializer = new JoomlaSerializer($this->type);
  45  
  46          foreach ($model->associations as $association) {
  47              $resources[] = (new Resource($association, $serializer))
  48                  ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/content/articles/' . $association->id));
  49          }
  50  
  51          $collection = new Collection($resources, $serializer);
  52  
  53          return new Relationship($collection);
  54      }
  55  
  56      /**
  57       * Build category relationship
  58       *
  59       * @param   \stdClass  $model  Item model
  60       *
  61       * @return  Relationship
  62       *
  63       * @since 4.0.0
  64       */
  65      public function category($model)
  66      {
  67          $serializer = new JoomlaSerializer('categories');
  68  
  69          $resource = (new Resource($model->catid, $serializer))
  70              ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/content/categories/' . $model->catid));
  71  
  72          return new Relationship($resource);
  73      }
  74  
  75      /**
  76       * Build category relationship
  77       *
  78       * @param   \stdClass  $model  Item model
  79       *
  80       * @return  Relationship
  81       *
  82       * @since 4.0.0
  83       */
  84      public function createdBy($model)
  85      {
  86          $serializer = new JoomlaSerializer('users');
  87  
  88          $resource = (new Resource($model->created_by, $serializer))
  89              ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/users/' . $model->created_by));
  90  
  91          return new Relationship($resource);
  92      }
  93  
  94      /**
  95       * Build editor relationship
  96       *
  97       * @param   \stdClass  $model  Item model
  98       *
  99       * @return  Relationship
 100       *
 101       * @since 4.0.0
 102       */
 103      public function modifiedBy($model)
 104      {
 105          $serializer = new JoomlaSerializer('users');
 106  
 107          $resource = (new Resource($model->modified_by, $serializer))
 108              ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/users/' . $model->modified_by));
 109  
 110          return new Relationship($resource);
 111      }
 112  }


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