/** * @return string[] */ static public function fetchProvincesAndCities() { $db = MMDB::instance(); $table = self::TABLE_NAME_DEFINITION; $query = "SELECT DISTINCT province, city from $table order by province asc, city asc"; $results = $db->arrayQuery($query); $tab = self::arrayfy($results, 'province', 'city'); StringTool::sortAlphaKeys($tab); foreach($tab as $key=>$value) { StringTool::sortAlphaValues($tab[$key]); } return $tab; }
public function facetResult( &$solrResult ) { $translations = $this->translations(); $facetResult = array(); $this->needsRefresh = false; $values = $this->values; if( empty( $values ) && !$this->forcedUnchecked ) $values = $this->forcedValues; $totalCount = 0; foreach( $solrResult['facet_counts']['facet_fields'][$this->facetSolrIdFieldName()] as $id => $count ) { $totalCount += $count; $toRemove = false; if (!in_array($id, $this->fieldsToShow)) { continue; } if( empty($this->defaultValues) || in_array($id, $this->defaultValues, true) ) { $checked = ( $count && (in_array( $id , $values, true ) || $this->precheckedValue == $id) ) ? 1 : 0; if( $this->forcedUnchecked ) $checked = 0; if ( isset($translations[$id]) ) { $facetResult[$translations[$id]] = array( 'count' => (int)$count, 'id' => $id, 'checked' => $checked ); } // a value set for filter returns 0 results => we need to refresh the solr search if ( in_array( $id, $values, true ) ) { // $toRemove = true; } } elseif( in_array( $id, $this->values, true ) ) { // $toRemove = true; } if( $toRemove ) { unset( $values[array_search($id, $values)] ); $this->values = array_values($values); if( empty( $this->values ) ) $this->forcedUnchecked = true; $this->needsRefresh = true; } } if($this->sort == 'alpha') { StringTool::sortAlphaKeys($facetResult); } elseif ( $this->sort == 'count' ) { foreach( $facetResult as $key => $value) { $facetResult[$key]['key'] = $key; } uasort ( $facetResult, array(self, 'sortCount' ) ); foreach( $facetResult as $key => $value) { unset($facetResult[$key]['key']); } } $facetResult[$this->allValuesTranslation] = array( 'checked' => (count($values) == 0 || (count($values) == 1 && $values[0] == 'all')), 'count' => $totalCount, 'id' => 'all', ); return $facetResult; }
/** * @param array $solrResult * @return array */ public function facetResult( &$solrResult ) { $translations = $this->translations(); $facetResult = array(); $this->needsRefresh = false; $values = $this->values; if( empty( $values ) && !$this->forcedUnchecked ) $values = $this->forcedValues; foreach( $solrResult['facet_counts']['facet_fields'][$this->facetSolrIdFieldName()] as $id => $count ) { $toRemove = false; $id = strval($id); if( empty($this->defaultValues) || in_array($id, $this->defaultValues, true) ) { $checked = ( $count && in_array( $id , $values, true ) ) ? 1 : 0; if( $this->forcedUnchecked ) $checked = 0; if ( isset($translations[$id]) ) { $facetResult[$translations[$id]] = array( 'count' => (int)$count, 'id' => $id, 'checked' => $checked, 'forceChecked' => (in_array($id, $this->forcedCheckedTaxonomy) ? $id : false ) ); } // a value set for filter returns 0 results => we need to refresh the solr search if ( in_array( $id, $values, true ) && $count == 0 ) { $toRemove = true; } } elseif( in_array( $id, $this->values, true ) ) { $toRemove = true; } if( $toRemove ) { unset( $values[array_search($id, $values)] ); $this->values = array_values($values); if( empty( $this->values ) ) $this->forcedUnchecked = true; $this->needsRefresh = true; } } if($this->sort == 'alpha') { StringTool::sortAlphaKeys($facetResult); } elseif ( $this->sort == 'count' ) { foreach( $facetResult as $key => $value) { $facetResult[$key]['key'] = $key; } uasort ( $facetResult, array(self, 'sortCount' ) ); foreach( $facetResult as $key => $value) { unset($facetResult[$key]['key']); } } return $facetResult; }