| Current Path : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_pay/models/ |
| Current File : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_pay/models/discounts.php |
<?php
// No direct access
defined( '_JEXEC' ) or die;
// Подключаем библиотеку modellist Joomla.
jimport('joomla.application.component.modellist');
/**
* @author kirdinyuri
*/
class PayModelDiscounts extends JModelList
{
/**
* Конструктор класса
* @param Array $config
*/
public function __construct( $config = array() )
{
if ( empty( $config['filter_fields'] ) ) {
$config['filter_fields'] = array(
'id', 'id',
'id1', 'id1',
'id2', 'id2',
'code', 'code',
'date_issue', 'date_issue',
'date_use', 'date_use',
'date_finish', 'date_finish',
'discount', 'discount'
);
}
parent::__construct( $config );
}
/**
* @param String $ordering
* @param String $direction
*/
protected function populateState( $ordering = null, $direction = null )
{
if ( $layout = JFactory::getApplication()->input->get( 'layout' ) ) {
$this->context .= '.' . $layout;
}
$search = $this->getUserStateFromRequest( $this->context . '.filter.search', 'filter_search' );
$this->setState( 'filter.search', $search );
$published = $this->getUserStateFromRequest( $this->context . '.filter.published', 'filter_published', '' );
$this->setState( 'filter.published', $published );
$authorId = $this->getUserStateFromRequest( $this->context . '.filter.author_id', 'filter_author_id' );
$this->setState( 'filter.author_id', $authorId );
parent::populateState( 'id', 'desc' );
}
/**
* @param string $id
* @return string
*/
protected function getStoreId( $id = '' )
{
$id .= ':' . $this->getState( 'filter.search' );
$id .= ':' . $this->getState( 'filter.published' );
$id .= ':' . $this->getState( 'filter.author_id' );
return parent::getStoreId( $id );
}
/**
* Составление запроса для получения списка записей
* @return JDatabaseQuery
*/
protected function getListQuery()
{
$query = $this->getDbo()->getQuery( true );
$query->select( '*' );
$query->from( '#__pay_discounts' );
$orderCol = $this->state->get( 'list.ordering' );
$orderDirn = $this->state->get( 'list.direction' );
$query->order( $this->getDbo()->escape( $orderCol . ' ' . $orderDirn ) );
return $query;
}
/**
* Авторы записей
* @return JDatabaseQuery
*/
public function getAuthors()
{
$query = $this->getDbo()->getQuery( true );
$query->select( 'u.id AS value, u.name AS text' );
$query->from( '#__users AS u' );
$query->join( 'INNER', '#__pay_discounts AS c ON c.created_by = u.id' );
$query->group( 'u.id, u.name' );
$query->order( 'u.name' );
return $this->getDbo()->setQuery( $query )->loadObjectList();
}
}