/** * Generic SamsonCMS table pagination handler * @param dbQuery $query Query object * @param Pager $pager Pagination object */ public function pagination(dbQuery &$query) { // If pager is passed if (isset($this->pager)) { // Clone query for count request $count_query = clone $query; $this->pager->update($count_query->innerCount()); //elapsed('pagination'.$this->pager->total); // Set originl query limit $query->limit($this->pager->start, $this->pager->end, true); } }
public function searchMaterials($page = 1) { // Create condition for searching $conditionOR = new Condition('OR'); $conditionOR->add('Value', '%' . $this->key . '%', dbRelation::LIKE); $words = explode(' ', $this->key); // If we have many words in searching value if (sizeof($words) > 1) { $conditionAnd = new Condition('AND'); foreach ($words as $word) { $conditionAnd->add('Value', '%' . $word . '%', dbRelation::LIKE); } $conditionOR->add($conditionAnd); } if (is_numeric($this->key)) { $conditionOR->add('numeric_value', intval($this->key)); } // Get collection of founded material identifiers $materialIds = dbQuery('materialfield')->cond($conditionOR)->cond('FieldID', $this->searchFields)->cond('Active', 1)->join('material')->cond('material.Active', 1)->cond('material.Published', 1)->cond('material.Draft', 0)->group_by('MaterialID'); // Set external query handler if (isset($this->MatFieldExternalHandler)) { $materialIds->handler($this->MatFieldExternalHandler); } $foundedIds = dbQuery('\\samson\\cms\\CMSMaterial'); // Try to get founded materials $arrayIds = array(); if ($materialIds->fieldsNew('MaterialID', $arrayIds)) { $foundedIds = dbQuery('\\samson\\cms\\CMSMaterial')->cond('MaterialID', $arrayIds)->join('gallery'); if (isset($this->structures)) { $foundedIds->join('\\samson\\cms\\CMSNavMaterial')->cond('structurematerial_StructureID', $this->structures); } } else { // Create 100% empty condition $foundedIds->cond('MaterialID', 0); } $foundedIds = $foundedIds->fieldsNew('MaterialID'); if (sizeof($foundedIds)) { $result = dbQuery('material')->id($foundedIds); // Clone for count query $materialsCount = clone $result; // Create pager $this->pager = new \samson\pager\Pager($page, $this->itemsOnPage, $this->pagerPrefix, null, $this->getParams); $this->pager->update($materialsCount->count()); $result->limit($this->pager->start, $this->pager->end); $response = dbQuery('\\samson\\cms\\CMSMaterial')->id($result->fieldsNew('MaterialID')); // Call external material handler if (isset($this->MaterialExternalHandler)) { $response->handler($this->MaterialExternalHandler); } // Return query result return $response->join('gallery')->exec(); } else { return array(); } }