- md5
- f8c06226055d9585c0cfb34a8a5c75bc
- sha1
- ca00ed030312b3c5e461be82d89d79658ffd9e50
- sha256
- 7ebc71c7550a7f8afc9aaa4b51f19e5dcc57c50a3d13b720eacfbcf3bc9b5b2c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
<?php
/**
* @package Joomla.Administrator
* @subpackage com_csp
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Csp\Administrator\Model;
\defined('_JEXEC') or die;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
/**
* CSP Component Reports Model
*
* @since 4.0.0
*/
class ReportsModel extends ListModel
{
/**
* Constructor
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param MVCFactoryInterface $factory The factory.
*
* @since 4.0.0
* @throws \Exception
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'document_uri', 'a.document_uri',
'blocked_uri', 'a.blocked_uri',
'directive', 'a.directive',
'client', 'a.client',
'published', 'a.published',
'created', 'a.created',
);
}
parent::__construct($config, $factory);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 4.0.0
*/
protected function populateState($ordering = 'a.id', $direction = 'asc')
{
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 4.0.0
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.published');
return parent::getStoreId($id);
}
/**
* Method to create a query for a list of items.
*
* @return string
*
* @since 4.0.0
*/
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query
->select('*')
->from($db->quoteName('#__csp', 'a'));
// Filter by client
$client = (string) $this->getState('filter.client');
if (!empty($client))
{
$query->where($db->quoteName('a.client') . ' = :client')
->bind(':client', $client);
}
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published))
{
$published = (int) $published;
$query->where($db->quoteName('a.published') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
}
elseif ($published === '')
{
$query->whereIn($db->quoteName('a.published'), [0, 1]);
}
// Filter by directive
$directive = (string) $this->getState('filter.directive');
if (!empty($directive))
{
$query->where($db->quoteName('a.directive') . ' = :directive')
->bind(':directive', $directive);
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$ids = (int) substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id');
$query->bind(':id', $ids, ParameterType::INTEGER);
}
else
{
$search = '%' . trim($search) . '%';
$query->where(
'(' . $db->quoteName('a.document_uri') . ' LIKE :documenturi'
. ' OR ' . $db->quoteName('a.blocked_uri') . ' LIKE :blockeduri'
. ' OR ' . $db->quoteName('a.directive') . ' LIKE :directive)'
)
->bind(':documenturi', $search)
->bind(':blockeduri', $search)
->bind(':directive', $search);
}
}
// Add the list ordering clause
$listOrdering = $this->getState('list.ordering', 'a.id');
$listDirn = $db->escape($this->getState('list.direction', 'ASC'));
$query->order($db->escape($listOrdering) . ' ' . $listDirn);
return $query;
}
}
The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.