public function doBuildQuery(array $values)
 {
     $query = parent::doBuildQuery($values);
     if ($values['taxon_level_ref'] != '') {
         $query->andWhere('taxon_level_ref = ?', intval($values['taxon_level_ref']));
     }
     $this->addNamingColumnQuery($query, 'taxonomy', 'taxon_name_indexed', $values['taxon_name'], null, 'taxon_name_indexed');
     $query->limit($this->getCatalogueRecLimits());
     return $query;
 }
 public function doBuildQuery(array $values)
 {
     $this->encoding_collection = $this->getCollectionWithRights($this->options['user'], true);
     $query = DQ::create()->select('s.*,
     gtu_location[0] as latitude,
     gtu_location[1] as longitude,
     (collection_ref in (' . implode(',', $this->encoding_collection) . ')) as has_encoding_rights')->from('Specimens s');
     if ($values['with_multimedia']) {
         $query->where("EXISTS (select m.id from multimedia m where m.referenced_relation = 'specimens' AND m.record_id = s.id)");
     }
     $this->options['query'] = $query;
     $query = parent::doBuildQuery($values);
     $this->cols = $this->getCollectionWithRights($this->options['user']);
     if (!empty($values['collection_ref'])) {
         $this->cols = array_intersect($values['collection_ref'], $this->cols);
     }
     $query->andwhereIn('collection_ref ', $this->cols);
     if (!empty($values['specimen_status'])) {
         $query->andwhere('specimen_status = ?', $values['specimen_status']);
     }
     if ($values['count_operator'] != '' && $values['count'] != '') {
         if ($values['count_operator'] == 'e') {
             $query->andwhere('specimen_count_max = ?', $values['count']);
         }
         if ($values['count_operator'] == 'l') {
             $query->andwhere('specimen_count_max <= ?', $values['count']);
         }
         if ($values['count_operator'] == 'g') {
             $query->andwhere('specimen_count_min >= ?', $values['count']);
         }
     }
     if ($values['people_ref'] != '') {
         $this->addPeopleSearchColumnQuery($query, $values['people_ref'], $values['role_ref']);
     }
     if ($values['acquisition_category'] != '') {
         $query->andWhere('acquisition_category = ?', $values['acquisition_category']);
     }
     if ($values['taxon_level_ref'] != '') {
         $query->andWhere('taxon_level_ref = ?', intval($values['taxon_level_ref']));
     }
     if ($values['chrono_level_ref'] != '') {
         $query->andWhere('chrono_level_ref = ?', intval($values['chrono_level_ref']));
     }
     if ($values['litho_level_ref'] != '') {
         $query->andWhere('litho_level_ref = ?', intval($values['litho_level_ref']));
     }
     if ($values['lithology_level_ref'] != '') {
         $query->andWhere('lithology_level_ref = ?', intval($values['lithology_level_ref']));
     }
     if ($values['mineral_level_ref'] != '') {
         $query->andWhere('mineral_level_ref = ?', intval($values['mineral_level_ref']));
     }
     $this->addLatLonColumnQuery($query, $values);
     $this->addNamingColumnQuery($query, 'expeditions', 'expedition_name_indexed', $values['expedition_name'], 's', 'expedition_name_indexed');
     $this->addNamingColumnQuery($query, 'taxonomy', 'taxon_name_indexed', $values['taxon_name'], 's', 'taxon_name_indexed');
     $this->addNamingColumnQuery($query, 'chronostratigraphy', 'chrono_name_indexed', $values['chrono_name'], 's', 'chrono_name_indexed');
     $this->addNamingColumnQuery($query, 'lithostratigraphy', 'litho_name_indexed', $values['litho_name'], 's', 'litho_name_indexed');
     $this->addNamingColumnQuery($query, 'lithology', 'lithology_name_indexed', $values['lithology_name'], 's', 'lithology_name_indexed');
     $this->addNamingColumnQuery($query, 'mineralogy', 'mineral_name_indexed', $values['mineral_name'], 's', 'mineral_name_indexed');
     $this->addPropertiesQuery($query, $values['property_type'], $values['property_applies_to'], $values['property_value_from'], $values['property_value_to'], $values['property_units']);
     $this->addCommentsQuery($query, $values['comment_notion_concerned'], $values['comment']);
     $fields = array('gtu_from_date', 'gtu_to_date');
     $this->addDateFromToColumnQuery($query, $fields, $values['gtu_from_date'], $values['gtu_to_date']);
     $this->addDateFromToColumnQuery($query, array('ig_date'), $values['ig_from_date'], $values['ig_to_date']);
     $this->addDateFromToColumnQuery($query, array('acquisition_date'), $values['acquisition_from_date'], $values['acquisition_to_date']);
     $this->addCatalogueRelationColumnQuery($query, $values['taxon_item_ref'], $values['taxon_relation'], 'taxonomy', 'taxon', $values['taxon_child_syn_included']);
     $this->addCatalogueRelationColumnQuery($query, $values['chrono_item_ref'], $values['chrono_relation'], 'chronostratigraphy', 'chrono', $values['chrono_child_syn_included']);
     $this->addCatalogueRelationColumnQuery($query, $values['litho_item_ref'], $values['litho_relation'], 'lithostratigraphy', 'litho', $values['litho_child_syn_included']);
     $this->addCatalogueRelationColumnQuery($query, $values['lithology_item_ref'], $values['lithology_relation'], 'lithology', 'lithology', $values['lithology_child_syn_included']);
     $this->addCatalogueRelationColumnQuery($query, $values['mineral_item_ref'], $values['mineral_relation'], 'mineralogy', 'mineral', $values['mineral_child_syn_included']);
     $query->limit($this->getCatalogueRecLimits());
     return $query;
 }
 public function doBuildQuery(array $values)
 {
     $query = Doctrine_Query::create()->from('Specimens s');
     $this->options['query'] = $query;
     $query = parent::doBuildQuery($values);
     if ($values['taxon_level_ref'] != '') {
         $query->andWhere('taxon_level_ref = ?', intval($values['taxon_level_ref']));
     }
     if ($values['chrono_level_ref'] != '') {
         $query->andWhere('chrono_level_ref = ?', intval($values['chrono_level_ref']));
     }
     if ($values['litho_level_ref'] != '') {
         $query->andWhere('litho_level_ref = ?', intval($values['litho_level_ref']));
     }
     if ($values['lithology_level_ref'] != '') {
         $query->andWhere('lithology_level_ref = ?', intval($values['lithology_level_ref']));
     }
     if ($values['mineral_level_ref'] != '') {
         $query->andWhere('mineral_level_ref = ?', intval($values['mineral_level_ref']));
     }
     if ($values['taxon_common_name'] != '') {
         $this->addCommonNamesColumnQuery($query, 'taxonomy', 'taxon_ref', $values['taxon_common_name']);
     }
     if ($values['chrono_common_name'] != '') {
         $this->addCommonNamesColumnQuery($query, 'chronostratigraphy', 'chrono_ref', $values['chrono_common_name']);
     }
     if ($values['litho_common_name'] != '') {
         $this->addCommonNamesColumnQuery($query, 'lithostratigraphy', 'litho_ref', $values['litho_common_name']);
     }
     if ($values['lithology_common_name'] != '') {
         $this->addCommonNamesColumnQuery($query, 'lithology', 'lithology_ref', $values['lithology_common_name']);
     }
     if ($values['mineral_common_name'] != '') {
         $this->addCommonNamesColumnQuery($query, 'mineralogy', 'mineral_ref', $values['mineral_common_name']);
     }
     $this->addNamingColumnQuery($query, 'taxonomy', 'taxon_name_indexed', $values['taxon_name'], 's', 'taxon_name_indexed');
     $this->addNamingColumnQuery($query, 'chronostratigraphy', 'chrono_name_indexed', $values['chrono_name'], 's', 'chrono_name_indexed');
     $this->addNamingColumnQuery($query, 'lithostratigraphy', 'litho_name_indexed', $values['litho_name'], 's', 'litho_name_indexed');
     $this->addNamingColumnQuery($query, 'lithology', 'lithology_name_indexed', $values['lithology_name'], 's', 'lithology_name_indexed');
     $this->addNamingColumnQuery($query, 'mineralogy', 'mineral_name_indexed', $values['mineral_name'], 's', 'mineral_name_indexed');
     $query->andWhere('collection_is_public = true');
     if ($values['tags'] != '') {
         $query->andWhere("gtu_country_tag_indexed && getTagsIndexedAsArray(?)", $values['tags']);
     }
     $query->limit($this->getCatalogueRecLimits());
     return $query;
 }