81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* @package Joomla.Component.Builder
|
|
*
|
|
* @created 4th September 2022
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
*/
|
|
|
|
// No direct access to this JCB template file (EVER)
|
|
defined('_JCB_TEMPLATE') or die;
|
|
?>
|
|
###BOM###
|
|
namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Api\View\###ApiName###;
|
|
|
|
###API_DYNAMIC_VIEW_JSON_HEADER###
|
|
|
|
// No direct access to this file
|
|
\defined('_JEXEC') or die;
|
|
|
|
/**
|
|
* ###Component### Json View class for the ###ApiName### resource
|
|
*
|
|
* The attributes are whatever the model of the ###sview### view returns.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
class JsonapiView extends BaseApiView
|
|
{
|
|
/**
|
|
* The fields to render item in the documents, taken from the item
|
|
*
|
|
* @var array
|
|
* @since 4.0.0
|
|
*/
|
|
protected $fieldsToRenderItem = [];
|
|
|
|
/**
|
|
* Execute and display a template script.
|
|
*
|
|
* @param object $item Item
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
public function displayItem($item = null)
|
|
{
|
|
if ($item === null)
|
|
{
|
|
$item = $this->prepareItem($this->getModel()->getItem());
|
|
}
|
|
|
|
// The attributes are the keys the model returned (a field selection may follow later).
|
|
$this->fieldsToRenderItem = is_object($item) ? array_keys(get_object_vars($item)) : [];
|
|
|
|
return parent::displayItem($item);
|
|
}
|
|
|
|
/**
|
|
* Prepare item before render.
|
|
*
|
|
* @param object $item The model item
|
|
*
|
|
* @return object
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
protected function prepareItem($item)
|
|
{
|
|
if (!is_object($item))
|
|
{
|
|
return $item;
|
|
}###API_DYNAMIC_VIEW_JSON_PREPAREITEM###
|
|
|
|
return parent::prepareItem($item);
|
|
}
|
|
}
|