[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2021 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\Contact\Api\Serializer; 11 12 use Joomla\CMS\Router\Route; 13 use Joomla\CMS\Serializer\JoomlaSerializer; 14 use Joomla\CMS\Tag\TagApiSerializerTrait; 15 use Joomla\CMS\Uri\Uri; 16 use Tobscure\JsonApi\Collection; 17 use Tobscure\JsonApi\Relationship; 18 use Tobscure\JsonApi\Resource; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Temporary serializer 26 * 27 * @since 4.0.0 28 */ 29 class ContactSerializer extends JoomlaSerializer 30 { 31 use TagApiSerializerTrait; 32 33 /** 34 * Build content relationships by associations 35 * 36 * @param \stdClass $model Item model 37 * 38 * @return Relationship 39 * 40 * @since 4.0.0 41 */ 42 public function languageAssociations($model) 43 { 44 $resources = []; 45 46 // @todo: This can't be hardcoded in the future? 47 $serializer = new JoomlaSerializer($this->type); 48 49 foreach ($model->associations as $association) { 50 $resources[] = (new Resource($association, $serializer)) 51 ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/contact/' . $association->id)); 52 } 53 54 $collection = new Collection($resources, $serializer); 55 56 return new Relationship($collection); 57 } 58 59 /** 60 * Build category relationship 61 * 62 * @param \stdClass $model Item model 63 * 64 * @return Relationship 65 * 66 * @since 4.0.0 67 */ 68 public function category($model) 69 { 70 $serializer = new JoomlaSerializer('categories'); 71 72 $resource = (new Resource($model->catid, $serializer)) 73 ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/content/categories/' . $model->catid)); 74 75 return new Relationship($resource); 76 } 77 78 /** 79 * Build category relationship 80 * 81 * @param \stdClass $model Item model 82 * 83 * @return Relationship 84 * 85 * @since 4.0.0 86 */ 87 public function createdBy($model) 88 { 89 $serializer = new JoomlaSerializer('users'); 90 91 $resource = (new Resource($model->created_by, $serializer)) 92 ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/users/' . $model->created_by)); 93 94 return new Relationship($resource); 95 } 96 97 /** 98 * Build editor relationship 99 * 100 * @param \stdClass $model Item model 101 * 102 * @return Relationship 103 * 104 * @since 4.0.0 105 */ 106 public function modifiedBy($model) 107 { 108 $serializer = new JoomlaSerializer('users'); 109 110 $resource = (new Resource($model->modified_by, $serializer)) 111 ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/users/' . $model->modified_by)); 112 113 return new Relationship($resource); 114 } 115 116 /** 117 * Build contact user relationship 118 * 119 * @param \stdClass $model Item model 120 * 121 * @return Relationship 122 * 123 * @since 4.0.0 124 */ 125 public function userId($model) 126 { 127 $serializer = new JoomlaSerializer('users'); 128 129 $resource = (new Resource($model->user_id, $serializer)) 130 ->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/users/' . $model->user_id)); 131 132 return new Relationship($resource); 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |