fork download
  1. <?php
  2.  
  3. defined('_JEXEC') or die;
  4.  
  5. jimport('joomla.application.component.modellist');
  6.  
  7. /**
  8.  * Methods supporting a list of Entrusters records.
  9.  */
  10. class EntrustersModelItems extends JModelList {
  11.  
  12. /**
  13.   * Constructor.
  14.   *
  15.   * @param array An optional associative array of configuration settings.
  16.   * @see JController
  17.   * @since 1.6
  18.   */
  19. public function __construct($config = array()) {
  20. parent::__construct($config);
  21. }
  22.  
  23. /**
  24.   * Method to auto-populate the model state.
  25.   *
  26.   * Note. Calling getState in this method will result in recursion.
  27.   *
  28.   * @since 1.6
  29.   */
  30. protected function populateState($ordering = null, $direction = null) {
  31.  
  32. // Initialise variables.
  33. $app = JFactory::getApplication();
  34.  
  35. // List state information
  36. $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
  37. $this->setState('list.limit', $limit);
  38.  
  39. $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
  40. $this->setState('list.start', $limitstart);
  41.  
  42.  
  43. if(empty($ordering)) {
  44. $ordering = 'a.ordering';
  45. }
  46.  
  47. // List state information.
  48. parent::populateState($ordering, $direction);
  49. }
  50.  
  51. /**
  52.   * Build an SQL query to load the list data.
  53.   *
  54.   * @return JDatabaseQuery
  55.   * @since 1.6
  56.   */
  57. protected function getListQuery() {
  58. // Create a new query object.
  59. $db = $this->getDbo();
  60. $query = $db->getQuery(true);
  61.  
  62. // Select the required fields from the table.
  63. $query->select(
  64. $this->getState(
  65. 'list.select', 'a.*'
  66. )
  67. );
  68.  
  69. $query->from('`#__entrusters_items` AS a');
  70.  
  71.  
  72.  
  73. // Join over the users for the checked out user.
  74.  
  75. $query->select('uc.name AS editor');
  76.  
  77. $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
  78.  
  79.  
  80. // Join over the created by field 'created_by'
  81. $query->select('created_by.name AS created_by');
  82. $query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
  83.  
  84.  
  85. // Filter by search in title
  86. $search = $this->getState('filter.search');
  87. if (!empty($search)) {
  88. if (stripos($search, 'id:') === 0) {
  89. $query->where('a.id = ' . (int) substr($search, 3));
  90. } else {
  91. $search = $db->Quote('%' . $db->escape($search, true) . '%');
  92. $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.' )');
  93. }
  94. }
  95.  
  96.  
  97.  
  98. //Filtering created
  99. $filter_created_from = $this->state->get("filter.created.from");
  100. if ($filter_created_from) {
  101. $query->where("a.created >= '".$filter_created_from."'");
  102. }
  103. $filter_created_to = $this->state->get("filter.created.to");
  104. if ($filter_created_to) {
  105. $query->where("a.created <= '".$filter_created_to."'");
  106. }
  107.  
  108. //Filtering updated
  109. $filter_updated_from = $this->state->get("filter.updated.from");
  110. if ($filter_updated_from) {
  111. $query->where("a.updated >= '".$filter_updated_from."'");
  112. }
  113. $filter_updated_to = $this->state->get("filter.updated.to");
  114. if ($filter_updated_to) {
  115. $query->where("a.updated <= '".$filter_updated_to."'");
  116. }
  117.  
  118. //Filtering created_by
  119. $filter_created_by = $this->state->get("filter.created_by");
  120. if ($filter_created_by) {
  121. $query->where("a.created_by = '".$filter_created_by."'");
  122. }
  123.  
  124. //Filtering status
  125. $filter_status = $this->state->get("filter.status");
  126. if ($filter_status) {
  127. $query->where("a.status = '".$filter_status."'");
  128. }
  129.  
  130. //Filtering online_stores
  131. $filter_online_stores = $this->state->get("filter.online_stores");
  132. if ($filter_online_stores) {
  133. $query->where("a.online_stores = '".$filter_online_stores."'");
  134. }
  135.  
  136. //Filtering physical_store
  137.  
  138. //Filtering requiredby
  139. $filter_requiredby_from = $this->state->get("filter.requiredby.from");
  140. if ($filter_requiredby_from) {
  141. $query->where("a.requiredby >= '".$filter_requiredby_from."'");
  142. }
  143. $filter_requiredby_to = $this->state->get("filter.requiredby.to");
  144. if ($filter_requiredby_to) {
  145. $query->where("a.requiredby <= '".$filter_requiredby_to."'");
  146. }
  147.  
  148. //Filtering accepted_bidder
  149.  
  150. //Filtering accepted_journey
  151.  
  152. return $query;
  153. }
  154.  
  155. public function getItems() {
  156. return parent::getItems();
  157. }
  158.  
  159. /*
  160.   code added by DL
  161.   */
  162. public function getBidsByItemId() {
  163. $db = JFactory::getDbo();
  164. $query = $db->getQuery(true);
  165. $query->select('COUNT(*)');
  166. $query->from($db->quoteName('#__entrusters_bids'));
  167. $query->where($db->quoteName('item_id')." = ".$id);
  168.  
  169. // Reset the query using our newly populated query object.
  170. $db->setQuery($query);
  171. $count = $db->loadResult();
  172.  
  173. }
  174.  
  175. }
  176.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty