- md5
- cad57822441800b218d36c1c800b398b
- sha1
- b84a3e7c2fe99f71fd79ef423b1eaf50674c8a2c
- sha256
- be3ceaf10d44ec39d06b114763f20ac806b520190db4d9fab2979be0f3d75e40
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
/**
* @package Joomla.API
* @subpackage com_banners
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Banners\Api\Controller;
use Joomla\CMS\Categories\CategoryChangeTrait;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\MVC\Controller\ApiController;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* The banners controller
*
* @since 4.0.0
*/
class BannersController extends ApiController
{
use CategoryChangeTrait;
/**
* The content type of the item.
*
* @var string
* @since 4.0.0
*/
protected $contentType = 'banners';
/**
* The default view for the display method.
*
* @var string
* @since 3.0
*/
protected $default_view = 'banners';
/**
* Banner list view amended to add filtering of data
*
* @return static A BaseController object to support chaining.
*
* @since 6.1.0
*/
public function displayList()
{
$apiFilterInfo = $this->input->get('filter', [], 'array');
$filter = InputFilter::getInstance();
if (\array_key_exists('state', $apiFilterInfo)) {
$this->modelState->set('filter.published', $filter->clean($apiFilterInfo['state'], 'INT'));
}
return parent::displayList();
}
/**
* Method to check if you can add a new record.
*
* Like in the administrator, the create permission is checked in the target category.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 6.2.1
*/
protected function allowAdd($data = [])
{
if (!$this->allowCategoryAdd($data)) {
return false;
}
return parent::allowAdd($data);
}
/**
* Method to check if you can edit an existing record.
*
* Like in the administrator, the edit permission is checked in the category of the record, because there is no
* asset tracking. Moving the record to another category requires the create permission in the target category.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key; default is id.
*
* @return boolean
*
* @since 6.2.1
*/
protected function allowEdit($data = [], $key = 'id')
{
if (!parent::allowEdit($data, $key)) {
return false;
}
$recordId = isset($data[$key]) ? (int) $data[$key] : 0;
if (!$recordId) {
return true;
}
$table = $this->getModel('banner')->getTable();
if (!$table->load($recordId)) {
return false;
}
$user = $this->app->getIdentity();
$category = $this->option . '.category.' . (int) $table->catid;
if (!$user->authorise('core.edit', $category)) {
return false;
}
return $this->allowCategoryChange(
$table,
$recordId,
$this->input->get('data', json_decode($this->input->json->getRaw(), true), 'array')
);
}
}
The same content is in 2 releases, Joomla 6.2.1 to 6.3.0-alpha1. See them all, or every version of this file.