/** * Apply custom sorting for tags. * * This also applies the normal, built-in sorting. * * @param Omeka_Db_Select $select * @param string $sortField Sorting field. * @param string $sortDir Sorting direction, suitable for direct * inclusion in SQL (ASC or DESC). */ public function applySorting($select, $sortField, $sortDir) { parent::applySorting($select, $sortField, $sortDir); switch ($sortField) { case 'time': $select->order(array("records_tags.time {$sortDir}", 'tags.name ASC')); break; case 'count': $select->order("tagCount {$sortDir}"); break; default: break; } }
public function applySorting($select, $sortField, $sortDir) { parent::applySorting($select, $sortField, $sortDir); switch ($sortField) { case 'added': $db = $this->getDb(); $itemAlias = $this->getTable('Item')->getTableAlias(); $select->join(array($itemAlias => $db->Item), "item_id = {$itemAlias}.id", 'added'); $select->order("{$itemAlias}.added {$sortDir}"); break; case 'contributor': $db = $this->getDb(); $userAlias = $this->getTable('User')->getTableAlias(); $itemAlias = $this->getTable('Item')->getTableAlias(); if (!$select->hasJoin($itemAlias)) { $select->join(array($itemAlias => $db->Item), "item_id = {$itemAlias}.id", array()); } $select->join(array($userAlias => $db->user), "{$itemAlias}.owner_id = {$userAlias}.id", 'name'); $select->order("{$userAlias}.name {$sortDir}"); break; } }
/** * Enables sorting based on ElementSet,Element field strings. * * @param Omeka_Db_Select $select * @param string $sortField Field to sort on * @param string $sortDir Sorting direction (ASC or DESC) */ public function applySorting($select, $sortField, $sortDir) { parent::applySorting($select, $sortField, $sortDir); $db = $this->getDb(); $fieldData = explode(',', $sortField); if (count($fieldData) == 2) { $element = $db->getTable('Element')->findByElementSetNameAndElementName($fieldData[0], $fieldData[1]); if ($element) { $select->joinLeft(array('et_sort' => $db->ElementText), "et_sort.record_id = collections.id AND et_sort.record_type = 'Collection' AND et_sort.element_id = {$element->id}", array())->group('collections.id')->order(array("IF(ISNULL(et_sort.text), 1, 0) {$sortDir}", "et_sort.text {$sortDir}")); } } }