[ 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_categories 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\Categories\Api\View\Categories; 12 13 use Joomla\CMS\MVC\View\JsonApiView as BaseApiView; 14 use Joomla\CMS\Router\Exception\RouteNotFoundException; 15 use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * The categories view 23 * 24 * @since 4.0.0 25 */ 26 class JsonapiView extends BaseApiView 27 { 28 /** 29 * The fields to render item in the documents 30 * 31 * @var array 32 * @since 4.0.0 33 */ 34 protected $fieldsToRenderItem = [ 35 'id', 36 'title', 37 'alias', 38 'note', 39 'published', 40 'access', 41 'checked_out', 42 'checked_out_time', 43 'created_user_id', 44 'parent_id', 45 'level', 46 'extension', 47 'lft', 48 'rgt', 49 'language', 50 'language_title', 51 'language_image', 52 'editor', 53 'access_level', 54 'author_name', 55 'count_trashed', 56 'count_unpublished', 57 'count_published', 58 'count_archived', 59 'params', 60 ]; 61 62 /** 63 * The fields to render items in the documents 64 * 65 * @var array 66 * @since 4.0.0 67 */ 68 protected $fieldsToRenderList = [ 69 'id', 70 'title', 71 'alias', 72 'note', 73 'published', 74 'access', 75 'checked_out', 76 'checked_out_time', 77 'created_user_id', 78 'parent_id', 79 'level', 80 'lft', 81 'rgt', 82 'language', 83 'language_title', 84 'language_image', 85 'editor', 86 'access_level', 87 'author_name', 88 'count_trashed', 89 'count_unpublished', 90 'count_published', 91 'count_archived', 92 'params', 93 ]; 94 95 /** 96 * Execute and display a template script. 97 * 98 * @param array|null $items Array of items 99 * 100 * @return string 101 * 102 * @since 4.0.0 103 */ 104 public function displayList(array $items = null) 105 { 106 foreach (FieldsHelper::getFields('com_content.categories') as $field) { 107 $this->fieldsToRenderList[] = $field->name; 108 } 109 110 return parent::displayList(); 111 } 112 113 /** 114 * Execute and display a template script. 115 * 116 * @param object $item Item 117 * 118 * @return string 119 * 120 * @since 4.0.0 121 */ 122 public function displayItem($item = null) 123 { 124 foreach (FieldsHelper::getFields('com_content.categories') as $field) { 125 $this->fieldsToRenderItem[] = $field->name; 126 } 127 128 if ($item === null) { 129 /** @var \Joomla\CMS\MVC\Model\AdminModel $model */ 130 $model = $this->getModel(); 131 $item = $this->prepareItem($model->getItem()); 132 } 133 134 if ($item->id === null) { 135 throw new RouteNotFoundException('Item does not exist'); 136 } 137 138 if ($item->extension != $this->getModel()->getState('filter.extension')) { 139 throw new RouteNotFoundException('Item does not exist'); 140 } 141 142 return parent::displayItem($item); 143 } 144 145 /** 146 * Prepare item before render. 147 * 148 * @param object $item The model item 149 * 150 * @return object 151 * 152 * @since 4.0.0 153 */ 154 protected function prepareItem($item) 155 { 156 foreach (FieldsHelper::getFields('com_content.categories', $item, true) as $field) { 157 $item->{$field->name} = $field->apivalue ?? $field->rawvalue; 158 } 159 160 return parent::prepareItem($item); 161 } 162 }
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 |