Spade
Mini Shell
| Directory:~$ /home/lmsyaran/public_html/administrator/components/com_invoices/models/ |
| [Home] [System Details] [Kill Me] |
<?php
/*------------------------------------------------------------------------
# com_invoices - Invoice Manager for Joomla
# ------------------------------------------------------------------------
# author Germinal Camps
# copyright Copyright (C) 2012 - 2016 JoomlaThat.com. All Rights
Reserved.
# @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.joomlathat.com
# Technical Support: Forum - http://www.joomlathat.com/support
-------------------------------------------------------------------------*/
//no direct access
defined('_JEXEC') or die('Restricted access.');
jimport( 'joomla.application.component.model' );
class ContactsModelContacts extends JModelLegacy
{
var $_data;
var $_total = null;
var $_pagination = null;
var $_keywords = null;
var $input;
function __construct(){
parent::__construct();
$mainframe = JFactory::getApplication();
$this->input = $mainframe->input;
// Get pagination request variables
$limit =
$mainframe->getUserStateFromRequest('invoices.contacts.limit',
'limit', 20, 'int');
$limitstart =
$mainframe->getUserStateFromRequest('invoices.contacts.limitstart',
'limitstart', 0, 'int');
$keywords =
trim($mainframe->getUserStateFromRequest('invoices.contacts.keywords','keywords','','string'));
$filter_order =
$mainframe->getUserStateFromRequest('invoices.contacts.filter_order',
'filter_order', 'co.id', 'cmd' );
$filter_order_Dir =
$mainframe->getUserStateFromRequest('invoices.contacts.filter_order_Dir',
'filter_order_Dir', 'DESC', 'word' );
$this->setState('filter_order', $filter_order);
$this->setState('filter_order_Dir', $filter_order_Dir);
$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
$this->setState('keywords', $keywords);
}
function getTotal()
{
// Load the content if it doesn't already exist
if (empty($this->_total)) {
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}
function getPagination()
{
// Load the content if it doesn't already exist
if (empty($this->_pagination)) {
jimport('joomla.html.pagination');
$this->_pagination = new JPagination($this->getTotal(),
$this->getState('limitstart'),
$this->getState('limit') );
}
return $this->_pagination;
}
function getKeywords(){
if (empty($this->_keywords)) {
$this->_keywords = $this->getState('keywords') ;
}
return $this->_keywords;
}
function getFilterOrder(){
return $this->getState('filter_order') ;
}
function getFilterOrderDir(){
return $this->getState('filter_order_Dir') ;
}
function _buildContentOrderBy()
{
$filter_order = $this->getState('filter_order' ) ;
$filter_order_Dir = $this->getState('filter_order_Dir') ;
$orderby = ' ORDER BY '.$filter_order.'
'.$filter_order_Dir . ' ';
return $orderby;
}
function _buildQuery()
{
$keywords = $this->getKeywords();
$where_clause = array();
if ($keywords != ""){
$where_clause[] = ' ( u.username LIKE
"%'.$keywords.'%" OR co.name LIKE
"%'.$keywords.'%" OR co.company LIKE
"%'.$keywords.'%" OR co.email LIKE
"%'.$keywords.'%" ) ';
}
$orderby = $this->_buildContentOrderBy();
// Build the where clause of the content record query
$where_clause = (count($where_clause) ? ' WHERE
'.implode(' AND ', $where_clause) : '');
$query = ' SELECT co.*, u.username '
. ' FROM #__invoices_contacts as co '
.' LEFT JOIN #__users AS u ON u.id = co.user_id '
.$where_clause
.$orderby
;
return $query;
}
function getData(){
if (empty( $this->_data )){
$query = $this->_buildQuery();
$this->_data = $this->_getList($query,
$this->getState('limitstart'),
$this->getState('limit'));
$params = JComponentHelper::getParams( 'com_invoices' );
for($i = 0; $i < count($this->_data) ; $i++){
$row =& $this->_data[$i] ;
$query = ' SELECT SUM(i.computed_total) AS total_invoices,
COUNT(DISTINCT i.id) AS nun_invoices
FROM #__invoices_invoices AS i
WHERE i.user_id = '.$row->id
.' AND i.type = 1 ' ;
$this->_db->setQuery($query);
$invoices = $this->_db->loadObject();
$row->total_invoices = $invoices->total_invoices;
$row->num_invoices = $invoices->nun_invoices;
$row->formatted_total_invoices =
InvoicesHelper::format($row->total_invoices,
$params->get('currency_before'),
$params->get('currency_after'));
if($row->user_id) $row->joomlauser = $row->username;
else $row->joomlauser = JText::_('JNO');
}
}
return $this->_data;
}
}