FundacionLQDVI_WebCongresos/www/administrator/components/com_sql2excel/models/sqlexceldatabases.php

135 lines
3.1 KiB
PHP

<?php
/*
* @component SQL 2 Excel Component
* @copyright Copyright (C) Joomla-R-Us, joomla-r-us.com
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
*/
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
class Sql2excelModelSqlexceldatabases extends JModel
{
var $_data = null;
var $_pagination = null;
function __construct()
{
parent::__construct();
global $mainframe, $option;
// Get the pagination request variables
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
// In case limit has been changed, adjust limitstart accordingly
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
}
/**
* Returns the query
* @return string The query to be used to retrieve the rows from the database
*/
function _buildQuery()
{
global $mainframe;
$where = array();
$context = 'com_sql2excel.sqlexceldatabases.list.';
// Get sort order
$filter_Column = $mainframe->getUserStateFromRequest(
$context.'filter_order',
'filter_order',
'a.ordering',
'cmd' );
$sort_Order = $mainframe->getUserStateFromRequest(
$context.'filter_order_Dir',
'filter_order_Dir',
'',
'word' );
if ( $filter_Column == '' ) { $filter_Column = 'a.ordering'; }
// Published / Unpublished State
$filter_state = $mainframe->getUserStateFromRequest(
$context.'filter_state',
'filter_state',
'',
'word' );
// Get search string
$searchStr = $mainframe->getUserStateFromRequest(
$context.'search',
'search',
'',
'string' );
$searchStr = JString::strtolower( $searchStr );
if ($searchStr) {
$where[] = 'LOWER(a.title) LIKE '.$this->_db->Quote('%'.$searchStr.'%');
}
$where[] = 'b.id = a.access';
$where = ' WHERE ' . implode(' AND ', $where);
// Assemble it all to a SQL query
$query = ' SELECT * '
. ' FROM #__sql2excel_databases '
. ' ORDER BY ID';
// . $where
// . ' ORDER BY ' . $filter_Column . ' ' . $sort_Order;
return $query;
}
/**
* @return array Array of objects containing the data from the database
*/
function getData()
{
if (empty($this->_data)){
$query = $this->_buildQuery();
$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
}
return $this->_data;
}
/**
* @return number of objects
*/
function getTotal()
{
if (empty($this->_total)) {
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}
/**
* @return pagination for the recordset
*/
function getPagination()
{
if (empty($this->_pagination)) {
jimport('joomla.html.pagination');
$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_pagination;
}
}