- md5
- 283bf9fd78a695a714bd4b029d457240
- sha1
- a532ab7a0b793172139959b618333c103b0d6017
- sha256
- 137bf38585e9005b56137b718fc551a4362ae21dbfbdec218e4f5cd0bd8f655e
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
<?php
/**
* @package Joomla.Administrator
* @subpackage com_csp
*
* @copyright Copyright (C) 2005 - 2018 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;
/**
* 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',
);
}
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('#__csp AS a');
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published))
{
$query->where('a.published = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.published IN (0, 1))');
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
$query->where('(a.document_uri LIKE ' . $search . ' OR a.blocked_uri LIKE ' . $search . ' OR a.directive LIKE ' . $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 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.