[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.API 5 * @subpackage com_privacy 6 * 7 * @copyright (C) 2019 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\Privacy\Api\View\Consents; 12 13 use Joomla\CMS\Language\Text; 14 use Joomla\CMS\MVC\View\GenericDataException; 15 use Joomla\CMS\MVC\View\JsonApiView as BaseApiView; 16 use Joomla\CMS\Router\Exception\RouteNotFoundException; 17 use Joomla\CMS\Serializer\JoomlaSerializer; 18 use Joomla\CMS\Uri\Uri; 19 use Tobscure\JsonApi\Resource; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * The consents view 27 * 28 * @since 4.0.0 29 */ 30 class JsonapiView extends BaseApiView 31 { 32 /** 33 * The fields to render item in the documents 34 * 35 * @var array 36 * @since 4.0.0 37 */ 38 protected $fieldsToRenderItem = [ 39 'id', 40 'user_id', 41 'state', 42 'created', 43 'subject', 44 'body', 45 'remind', 46 'token', 47 'username', 48 ]; 49 50 /** 51 * The fields to render items in the documents 52 * 53 * @var array 54 * @since 4.0.0 55 */ 56 protected $fieldsToRenderList = [ 57 'id', 58 'user_id', 59 'state', 60 'created', 61 'subject', 62 'body', 63 'remind', 64 'token', 65 'username', 66 ]; 67 68 /** 69 * Execute and display a template script. 70 * 71 * @param object $item Item 72 * 73 * @return string 74 * 75 * @since 4.0.0 76 */ 77 public function displayItem($item = null) 78 { 79 $id = $this->get('state')->get($this->getName() . '.id'); 80 81 if ($id === null) { 82 throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ITEMID_MISSING')); 83 } 84 85 /** @var \Joomla\CMS\MVC\Model\ListModel $model */ 86 $model = $this->getModel(); 87 $displayItem = null; 88 89 foreach ($model->getItems() as $item) { 90 $item = $this->prepareItem($item); 91 92 if ($item->id === $id) { 93 $displayItem = $item; 94 break; 95 } 96 } 97 98 if ($displayItem === null) { 99 throw new RouteNotFoundException('Item does not exist'); 100 } 101 102 // Check for errors. 103 if (\count($errors = $this->get('Errors'))) { 104 throw new GenericDataException(implode("\n", $errors), 500); 105 } 106 107 if ($this->type === null) { 108 throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_CONTENT_TYPE_MISSING')); 109 } 110 111 $serializer = new JoomlaSerializer($this->type); 112 $element = (new Resource($displayItem, $serializer)) 113 ->fields([$this->type => $this->fieldsToRenderItem]); 114 115 $this->document->setData($element); 116 $this->document->addLink('self', Uri::current()); 117 118 return $this->document->render(); 119 } 120 }
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 |