Current File : /home/pacjaorg/public_html/km/administrator/components/com_djcfimporter/models/changelogs.php |
<?php
/**
* @version 1.0
* @package DJCF-Importer
* @subpackage DJCF-Importer Component
* @copyright Copyright (C) 2010 DJ-Extensions.com LTD, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://design-joomla.eu
* @author email contact@design-joomla.eu
* @developer Łukasz Ciastek - lukasz.ciastek@design-joomla.eu
*
*
* DJCF-Importer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DJCF-Importer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DJCF-Importer. If not, see <http://www.gnu.org/licenses/>.
*
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modellist');
class DJCFImporterModelChangelogs extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'a.feed_id', 'a.item_id', 'a.element', 'a.date', 'a.import', 'a.import_id', 'g.update', 'a.new_value ', 'a.old_value', 'i_name'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
// List state information.
parent::populateState('a.date', 'desc');
// Initialise variables.
$app = JFactory::getApplication();
$session = JFactory::getSession();
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$state = $this->getUserStateFromRequest($this->context.'.filter.feed_id', 'filter_feed_id');
$this->setState('filter.feed_id', $state);
$group_id = $this->getUserStateFromRequest($this->context.'.filter.element', 'filter_element');
$this->setState('filter.element', $group_id);
// Load the parameters.
$params = JComponentHelper::getParams('com_djcfimporter');
$this->setState('params', $params);
}
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':'.$this->getState('filter.search');
$id .= ':'.$this->getState('filter.feed_id');
$id .= ':'.$this->getState('filter.element');
return parent::getStoreId($id);
}
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$select_default = 'a.*, i.name as i_name, f.name as f_name ';
$query->select($this->getState('list.select', $select_default));
$query->from('#__djcfi_changelog AS a');
$query->join('LEFT', '#__djcf_items AS i ON i.id=a.item_id');
$query->join('LEFT', '#__djcfi_items AS f ON f.id=a.feed_id');
// 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 {
$search2 = intval($search);
$search = $db->quote('%'.$db->escape($search, true).'%');
$query->where('(a.new_value LIKE '.$search.' OR a.old_value LIKE '.$search.' OR a.import_id = '.$search2.' OR a.item_id = '.$search2.' )');
}
}
$feed = $this->getState('filter.feed_id', false);
if ($feed) {
$query->where('a.feed_id='.(int)$feed);
}
$element = $this->getState('filter.element', false);
if ($element) {
$query->where('a.element='.(int)$element);
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'a.date');
$orderDirn = $this->state->get('list.direction', 'desc');
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'a.date');
$orderDirn = $this->state->get('list.direction', 'desc');
/*if ($orderCol == 'a.ordering' || $orderCol == 'g.name') {
$orderCol = 'g.name '.$orderDirn.', a.ordering';
}*/
$query->order($db->escape($orderCol.' '.$orderDirn));
//echo '<pre>';echo $query;die();
return $query;
}
public function getFeeds() {
$this->_db->setQuery('SELECT id as value, name as text FROM #__djcfi_items ORDER BY name ASC');
$feeds = $this->_db->loadObjectList();
return $feeds;
}
}