Exemplo n.º 1
0
 /**
  * @param Omeka_Db_Select $select
  * @param array $params
  */
 public function applySearchFilters($select, $params)
 {
     $alias = $this->getTableAlias();
     $paramNames = array('record_id', 'rating', 'user_id');
     foreach ($paramNames as $paramName) {
         if (isset($params[$paramName])) {
             $select->where($alias . '.' . $paramName . ' = ?', array($params[$paramName]));
         }
     }
     if (isset($params['sort'])) {
         switch ($params['sort']) {
             case 'asc':
                 $select->order("{$alias}.rating ASC");
                 break;
             case 'dsc':
                 $select->order("{$alias}.rating DSC");
                 break;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Manipulate a Select object based on a set of criteria.
  * 
  * @param Omeka_Db_Select $select
  * @param array $params Possible parameters include:
  * <ul>
  *      <li>record_types - array - Usually one or more of the following:
  * All, Item, File</li>
  *      <li>sort - string - One of the following values: alpha</li>
  *      <li>element_set_name - string - Name of the element set to which
  * results should belong.</li>
  * </ul>
  */
 public function applySearchFilters($select, $params)
 {
     $db = $this->getDb();
     // Retrieve only elements matching a specific record type.
     if (array_key_exists('record_types', $params)) {
         $where = array();
         foreach ($params['record_types'] as $recordTypeName) {
             if ($recordTypeName == 'All') {
                 $where[] = 'element_sets.record_type IS NULL';
             } else {
                 $where[] = 'element_sets.record_type = ' . $db->quote($recordTypeName);
             }
         }
         $select->where('(' . join(' OR ', $where) . ')');
     }
     if (array_key_exists('sort', $params)) {
         if ($params['sort'] == 'alpha') {
             $select->order('elements.name ASC');
         } else {
             if ($params['sort'] == 'alphaBySet') {
                 $select->order('element_sets.name ASC')->order('elements.name ASC');
             }
         }
     }
     if (array_key_exists('element_set_name', $params)) {
         $select->where('element_sets.name = binary ?', (string) $params['element_set_name']);
     }
     if (array_key_exists('element_name', $params)) {
         $select->where('elements.name = binary ?', (string) $params['element_name']);
     }
     // Retrive results including, but not limited to, a specific item type.
     if (array_key_exists('item_type_id', $params)) {
         $select->joinLeft(array('item_types_elements' => $db->ItemTypesElements), 'item_types_elements.element_id = elements.id', array());
         $select->where('item_types_elements.item_type_id = ? OR item_types_elements.item_type_id IS NULL', (int) $params['item_type_id']);
     } else {
         if (array_key_exists('exclude_item_type', $params)) {
             $select->where('element_sets.name != ?', ElementSet::ITEM_TYPE_NAME);
         } else {
             if (array_key_exists('item_type', $params)) {
                 //for the API for item_types
                 $select->joinLeft(array('item_types_elements' => $db->ItemTypesElements), 'item_types_elements.element_id = elements.id', array());
                 $select->where('item_types_elements.item_type_id = ? ', (int) $params['item_type']);
             }
         }
     }
     // REST API params.
     if (array_key_exists('name', $params)) {
         $select->where("elements.name = ?", $params['name']);
     }
     if (array_key_exists('element_set', $params)) {
         $select->where("elements.element_set_id = ?", $params['element_set']);
     }
 }
Exemplo n.º 3
0
 /**
  * Define filters for browse and findBy.
  *
  * Available filters are: "tag" or "tags", "public" and "featured". "sort"
  * also adds specific sorting strategies "alpha" and "recent", but the
  * normal sorting can also be used.
  *
  * @param Omeka_Db_Select $select
  * @param array $params Key-value array of search parameters
  * @return Omeka_Db_Select
  */
 public function applySearchFilters($select, $params)
 {
     $db = $this->getDb();
     foreach ($params as $paramName => $paramValue) {
         switch ($paramName) {
             case 'tag':
             case 'tags':
                 $tags = explode(',', $paramValue);
                 $select->joinInner(array('tg' => $db->RecordsTags), 'tg.record_id = exhibits.id', array());
                 $select->joinInner(array('t' => $db->Tag), "t.id = tg.tag_id", array());
                 foreach ($tags as $k => $tag) {
                     $select->where('t.name = ?', trim($tag));
                 }
                 $select->where("tg.record_type = ? ", array('Exhibit'));
                 break;
             case 'sort':
                 switch ($paramValue) {
                     case 'alpha':
                         $select->order("exhibits.title ASC");
                         break;
                     case 'recent':
                         $select->order("exhibits.id DESC");
                         break;
                 }
                 break;
             case 'public':
                 $this->filterByPublic($select, $params['public']);
                 break;
             case 'range':
                 $this->filterByRange($select, $params['range']);
                 break;
             case 'featured':
                 $this->filterByFeatured($select, $params['featured']);
                 break;
         }
     }
     return $select;
 }
Exemplo n.º 4
0
 /**
  * Apply default column-based sorting for a table.
  *
  * @param Omeka_Db_Select $select
  * @param string $sortField Field to sort on.
  * @param string $sortDir Direction to sort.
  */
 public function applySorting($select, $sortField, $sortDir)
 {
     if (empty($sortField) || empty($sortDir)) {
         return;
     }
     if (in_array($sortField, $this->getColumns())) {
         $alias = $this->getTableAlias();
         $select->order("{$alias}.{$sortField} {$sortDir}");
     } else {
         if ($sortField == 'random') {
             $select->order('RAND()');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Apply default column-based sorting for a table.
  *
  * @param Omeka_Db_Select $select
  * @param string $sortField Field to sort on.
  * @param string $sortDir Direction to sort.
  */
 public function applySorting($select, $sortField, $sortDir)
 {
     if ($sortField == 'volet') {
         $select->joinInner(array('hierarchy' => 'omeka_hierarchies'), 'items.id = hierarchy.id', array('hierarchy.atom_top_parent_id'));
         $select->order("hierarchy.atom_top_parent_id {$sortDir}");
         return;
     }
     if ($sortField == 'guide') {
         $select->joinInner(array('hierarchy' => 'omeka_hierarchies'), 'items.id = hierarchy.id', array('hierarchy.atom_top_parent_id'));
         $select->order("hierarchy.order {$sortDir}");
         return;
     }
     if (empty($sortField) || empty($sortDir)) {
         return;
     }
     if (in_array($sortField, $this->getColumns())) {
         $alias = $this->getTableAlias();
         $select->order("{$alias}.{$sortField} {$sortDir}");
     } else {
         if ($sortField == 'random') {
             $select->order('RAND()');
         }
     }
 }