<?php
jimport('joomla.application.component.modellist');
/**
* Methods supporting a list of Entrusters records.
*/
class EntrustersModelItems extends JModelList {
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct
($config = array()) { parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null) {
// Initialise variables.
$app = JFactory::getApplication();
// List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
$this->setState('list.limit', $limit);
$limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
$this->setState('list.start', $limitstart);
$ordering = 'a.ordering';
}
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
* @since 1.6
*/
protected function getListQuery() {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select', 'a.*'
)
);
$query->from('`#__entrusters_items` AS a');
// Join over the users for the checked out user.
$query->select('uc.name AS editor');
$query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Join over the created by field 'created_by'
$query->select('created_by.name AS created_by');
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
// Filter by search in title
$search = $this->getState('filter.search');
if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int
) substr($search, 3)); } else {
$search = $db->Quote('%' . $db->escape($search, true) . '%');
$query->where('( a.deliverydestination LIKE '.$search.' OR a.itemtitle LIKE '.$search.' OR a.physical_store LIKE '.$search.' OR a.itemlocation LIKE '.$search.' OR a.item_details LIKE '.$search.' OR a.model LIKE '.$search.' )');
}
}
//Filtering created
$filter_created_from = $this->state->get("filter.created.from");
if ($filter_created_from) {
$query->where("a.created >= '".$filter_created_from."'");
}
$filter_created_to = $this->state->get("filter.created.to");
if ($filter_created_to) {
$query->where("a.created <= '".$filter_created_to."'");
}
//Filtering updated
$filter_updated_from = $this->state->get("filter.updated.from");
if ($filter_updated_from) {
$query->where("a.updated >= '".$filter_updated_from."'");
}
$filter_updated_to = $this->state->get("filter.updated.to");
if ($filter_updated_to) {
$query->where("a.updated <= '".$filter_updated_to."'");
}
//Filtering created_by
$filter_created_by = $this->state->get("filter.created_by");
if ($filter_created_by) {
$query->where("a.created_by = '".$filter_created_by."'");
}
//Filtering status
$filter_status = $this->state->get("filter.status");
if ($filter_status) {
$query->where("a.status = '".$filter_status."'");
}
//Filtering online_stores
$filter_online_stores = $this->state->get("filter.online_stores");
if ($filter_online_stores) {
$query->where("a.online_stores = '".$filter_online_stores."'");
}
//Filtering physical_store
//Filtering requiredby
$filter_requiredby_from = $this->state->get("filter.requiredby.from");
if ($filter_requiredby_from) {
$query->where("a.requiredby >= '".$filter_requiredby_from."'");
}
$filter_requiredby_to = $this->state->get("filter.requiredby.to");
if ($filter_requiredby_to) {
$query->where("a.requiredby <= '".$filter_requiredby_to."'");
}
//Filtering accepted_bidder
//Filtering accepted_journey
return $query;
}
public function getItems() {
return parent::getItems();
}
/*
code added by DL
*/
public function getBidsByItemId() {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__entrusters_bids'));
$query->where($db->quoteName('item_id')." = ".$id);
// Reset the query using our newly populated query object.
$db->setQuery($query);
$count = $db->loadResult();
}
}