| Current Path : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_poll/models/ |
| Current File : /var/www/iplanru/data/www/i-plan.ru/administrator/components/com_poll/models/answers.php |
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
* @author kirdinyuri
*/
class PollModelAnswers extends JModelList
{
/**
* Конструктор класса
* @param Array $config
*/
public function __construct( $config = array() )
{
if ( empty( $config['filter_fields'] ) ) {
$config['filter_fields'] = array( 'ip', 'cookie', 'mail', 'date' );
}
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;
}
$ip = $this->getUserStateFromRequest( $this->context . '.filter.ip', 'filter_ip' );
$this->setState( 'filter.ip', $ip );
$cookie = $this->getUserStateFromRequest( $this->context . '.filter.cookie', 'filter_cookie', '' );
$this->setState( 'filter.published', $published );
$date = $this->getUserStateFromRequest( $this->context . '.filter.date', 'filter_date' );
$this->setState( 'filter.author_id', $authorId );
parent::populateState( 'id', 'desc' );
}
/**
* @param string $id
* @return string
*/
protected function getStoreId( $id = '' )
{
$id .= ':' . $this->getState( 'filter.ip' );
$id .= ':' . $this->getState( 'filter.cookie' );
$id .= ':' . $this->getState( 'filter.date' );
return parent::getStoreId( $id );
}
/**
* Составление запроса для получения списка записей
* @return JDatabaseQuery
*/
protected function getListQuery()
{
$query = $this->getDbo()->getQuery( true );
$query->select( '*' );
$query->from( '#__pollanswers' );
$query->order('id desc');
$ip = $this->getState( 'filter.ip' );
if ( $ip ) {
$query->where( 'ip="'.$ip.'"' );
}
$cookie = $this->getState( 'filter.cookie' );
if ( $cookie ) {
$query->where( 'cookie="'.$cookie.'"' );
}
$date = $this->getState( 'filter.date' );
if ( $date ) {
$query->where( 'ip="'.$date.'"' );
}
$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->order( 'u.name' );
return $this->getDbo()->setQuery( $query )->loadObjectList();
}
}