Skip to content

Commit

Permalink
Merge pull request #5 from bembelimen/Tiny_Textfilter
Browse files Browse the repository at this point in the history
Tiny textfilter
  • Loading branch information
chmst committed May 2, 2016
2 parents 522a585 + 743ab0a commit 67ee733
Show file tree
Hide file tree
Showing 499 changed files with 9,022 additions and 4,085 deletions.
5 changes: 3 additions & 2 deletions administrator/components/com_admin/models/sysinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,11 @@ public function getExtensions()
$installed[$extension->name] = array(
'name' => $extension->name,
'type' => $extension->type,
'state' => $extension->enabled ? JText::_('JENABLED') : JText::_('JDISABLED'),
'author' => 'unknown',
'version' => 'unknown',
'creationDate' => 'unknown',
'authorUrl' => 'unknown'
'authorUrl' => 'unknown',
);

$manifest = json_decode($extension->manifest_cache);
Expand All @@ -481,7 +482,7 @@ public function getExtensions()
'author' => $manifest->author,
'version' => $manifest->version,
'creationDate' => $manifest->creationDate,
'authorUrl' => $manifest->authorUrl
'authorUrl' => $manifest->authorUrl,
);

$installed[$extension->name] = array_merge($installed[$extension->name], $extraData);
Expand Down
1 change: 1 addition & 0 deletions administrator/components/com_banners/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
label="JGLOBAL_HISTORY_LIMIT_OPTIONS_LABEL"
description="JGLOBAL_HISTORY_LIMIT_OPTIONS_DESC"
default="5"
showon="save_history:1"
/>
</fieldset>

Expand Down
58 changes: 34 additions & 24 deletions administrator/components/com_banners/models/banners.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public function __construct($config = array())
'clicks', 'a.clicks',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'state', 'sticky', 'a.sticky',
'sticky', 'a.sticky',
'client_id',
'category_id',
'published'
'published',
'level', 'c.level',
);
}

Expand Down Expand Up @@ -114,50 +115,51 @@ protected function getListQuery()
'a.publish_down'
)
);
$query->from($db->quoteName('#__banners') . ' AS a');
$query->from($db->quoteName('#__banners', 'a'));

// Join over the language
$query->select('l.title AS language_title, l.image AS language_image')
->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON l.lang_code = a.language');

// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
$query->select($db->quoteName('uc.name', 'editor'))
->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON uc.id = a.checked_out');

// Join over the categories.
$query->select('c.title AS category_title')
->join('LEFT', '#__categories AS c ON c.id = a.catid');
$query->select($db->quoteName('c.title', 'category_title'))
->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON c.id = a.catid');

// Join over the clients.
$query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type')
->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid');
$query->select($db->quoteName('cl.name', 'client_name'))
->select($db->quoteName('cl.purchase_type', 'client_purchase_type'))
->join('LEFT', $db->quoteName('#__banner_clients', 'cl') . ' ON cl.id = a.cid');

// Filter by published state
$published = $this->getState('filter.published');

if (is_numeric($published))
{
$query->where('a.state = ' . (int) $published);
$query->where($db->quoteName('a.state') . ' = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.state IN (0, 1))');
$query->where($db->quoteName('a.state') . ' IN (0, 1)');
}

// Filter by category.
$categoryId = $this->getState('filter.category_id');

if (is_numeric($categoryId))
{
$query->where('a.catid = ' . (int) $categoryId);
$query->where($db->quoteName('a.catid') . ' = ' . (int) $categoryId);
}

// Filter by client.
$clientId = $this->getState('filter.client_id');

if (is_numeric($clientId))
{
$query->where('a.cid = ' . (int) $clientId);
$query->where($db->quoteName('a.cid') . ' = ' . (int) $clientId);
}

// Filter by search in title
Expand All @@ -167,7 +169,7 @@ protected function getListQuery()
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
$query->where($db->quoteName('a.id') . ' = ' . (int) substr($search, 3));
}
else
{
Expand All @@ -179,14 +181,20 @@ protected function getListQuery()
// Filter on the language.
if ($language = $this->getState('filter.language'))
{
$query->where('a.language = ' . $db->quote($language));
$query->where($db->quoteName('a.language') . ' = ' . $db->quote($language));
}

// Filter on the level.
if ($level = $this->getState('filter.level'))
{
$query->where($db->quoteName('c.level') . ' <= ' . (int) $level);
}

// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'ordering');
$orderCol = $this->state->get('list.ordering', 'a.name');
$orderDirn = $this->state->get('list.direction', 'ASC');

if ($orderCol == 'ordering' || $orderCol == 'category_title')
if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}
Expand Down Expand Up @@ -218,10 +226,11 @@ protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.category_id');
$id .= ':' . $this->getState('filter.client_id');
$id .= ':' . $this->getState('filter.language');
$id .= ':' . $this->getState('filter.level');

return parent::getStoreId($id);
}
Expand Down Expand Up @@ -257,11 +266,12 @@ public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = a
protected function populateState($ordering = 'a.name', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'));
$this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', ''));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', ''));
$this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', ''));
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.published', $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '', 'string'));
$this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', '', 'cmd'));
$this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '', 'string'));
$this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd'));

// Load the parameters.
$this->setState('params', JComponentHelper::getParams('com_banners'));
Expand Down
144 changes: 133 additions & 11 deletions administrator/components/com_banners/models/clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
* Methods supporting a list of banner records.
*
Expand All @@ -35,8 +37,7 @@ public function __construct($config = array())
'state', 'a.state',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'nbanners',
'purchase_type'
'purchase_type', 'a.purchase_type'
);
}

Expand All @@ -58,8 +59,9 @@ public function __construct($config = array())
protected function populateState($ordering = 'a.name', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'));
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', null, 'int'));
$this->setState('filter.purchase_type', $this->getUserStateFromRequest($this->context . '.filter.purchase_type', 'filter_purchase_type'));

// Load the parameters.
$this->setState('params', JComponentHelper::getParams('com_banners'));
Expand All @@ -83,8 +85,8 @@ protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.state');
$id .= ':' . $this->getState('filter.purchase_type');

return parent::getStoreId($id);
}
Expand Down Expand Up @@ -172,16 +174,136 @@ protected function getListQuery()
}
}

$ordering = $this->getState('list.ordering', 'ordering');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.name')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));

return $query;
}

/**
* Overrides the getItems method to attach additional metrics to the list.
*
* @return mixed An array of data items on success, false on failure.
*
* @since __DEPLOY_VERSION__
*/
public function getItems()
{
// Get a storage key.
$store = $this->getStoreId('getItems');

if ($ordering == 'nbanners')
// Try to load the data from internal storage.
if (!empty($this->cache[$store]))
{
$ordering = 'COUNT(b.id)';
return $this->cache[$store];
}

// Add the list ordering clause.
$query->order($db->escape($ordering) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
// Load the list items.
$items = parent::getItems();

return $query;
// If emtpy or an error, just return.
if (empty($items))
{
return array();
}

// Getting the following metric by joins is WAY TOO SLOW.
// Faster to do three queries for very large banner trees.

// Get the clients in the list.
$db = $this->getDbo();
$clientIds = ArrayHelper::getColumn($items, 'id');

// Quote the strings.
$clientIds = implode(
',',
array_map(array($db, 'quote'), $clientIds)
);

// Get the published banners count.
$query = $db->getQuery(true)
->select('cid, COUNT(cid) AS count_published')
->from('#__banners')
->where('state = 1')
->where('cid IN (' . $clientIds . ')')
->group('cid');

$db->setQuery($query);

try
{
$countPublished = $db->loadAssocList('cid', 'count_published');
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());

return false;
}

// Get the unpublished banners count.
$query->clear('where')
->where('state = 0')
->where('cid IN (' . $clientIds . ')');
$db->setQuery($query);

try
{
$countUnpublished = $db->loadAssocList('cid', 'count_published');
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());

return false;
}

// Get the trashed banners count.
$query->clear('where')
->where('state = -2')
->where('cid IN (' . $clientIds . ')');
$db->setQuery($query);

try
{
$countTrashed = $db->loadAssocList('cid', 'count_published');
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());

return false;
}

// Get the archived banners count.
$query->clear('where')
->where('state = 2')
->where('cid IN (' . $clientIds . ')');
$db->setQuery($query);

try
{
$countArchived = $db->loadAssocList('cid', 'count_published');
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());

return false;
}

// Inject the values back into the array.
foreach ($items as $item)
{
$item->count_published = isset($countPublished[$item->id]) ? $countPublished[$item->id] : 0;
$item->count_unpublished = isset($countUnpublished[$item->id]) ? $countUnpublished[$item->id] : 0;
$item->count_trashed = isset($countTrashed[$item->id]) ? $countTrashed[$item->id] : 0;
$item->count_archived = isset($countArchived[$item->id]) ? $countArchived[$item->id] : 0;
}

// Add the items to the internal cache.
$this->cache[$store] = $items;

return $this->cache[$store];
}
}

0 comments on commit 67ee733

Please sign in to comment.