/** * Gets an array of the possible time period values (e.g., years, * years and months) for this filter, and, for each one, * the number of pages that match that time period. */ function getTimePeriodValues() { $possible_dates = array(); $property_value = $this->escaped_property; $dbr = wfGetDB( DB_SLAVE ); if ( $this->time_period == wfMsg( 'sd_filter_month' ) ) { $fields = "YEAR(value_xsd), MONTH(value_xsd)"; } else { $fields = "YEAR(value_xsd)"; } $smw_attributes = $dbr->tableName( 'smw_atts2' ); $smw_ids = $dbr->tableName( 'smw_ids' ); $sql = <<<END SELECT $fields, count(*) FROM semantic_drilldown_values sdv JOIN $smw_attributes a ON sdv.id = a.s_id JOIN $smw_ids p_ids ON a.p_id = p_ids.smw_id WHERE p_ids.smw_title = '$property_value' GROUP BY $fields ORDER BY $fields END; $res = $dbr->query( $sql ); while ( $row = $dbr->fetchRow( $res ) ) { if ( $this->time_period == wfMsg( 'sd_filter_month' ) ) { global $sdgMonthValues; $date_string = SDUtils::monthToString( $row[1] ) . " " . $row[0]; $possible_dates[$date_string] = $row[2]; } else { $date_string = $row[0]; $possible_dates[$date_string] = $row[1]; } } $dbr->freeResult( $res ); return $possible_dates; }
/** * Gets an array of all values that the property belonging to this * filter has, for pages in the passed-in category. */ function getAllOrValues($category) { $possible_values = array(); $property_value = $this->filter->escaped_property; $dbr = wfGetDB(DB_SLAVE, 'smw'); if ($this->filter->is_relation) { $property_table_name = $dbr->tableName('smw_rels2'); $property_table_nickname = "r"; $value_field = 'o_ids.smw_title'; } else { $property_table_name = $dbr->tableName('smw_atts2'); $property_table_nickname = "a"; $value_field = 'value_xsd'; } if ($this->filter->time_period != null) { if ($this->filter->time_period == wfMsg('sd_filter_month')) { $value_field = "YEAR(value_xsd), MONTH(value_xsd)"; } else { $value_field = "YEAR(value_xsd)"; } } $smw_insts = $dbr->tableName('smw_inst2'); $smw_ids = $dbr->tableName('smw_ids'); $cat_ns = NS_CATEGORY; $sql = "\tSELECT {$value_field}\n\tFROM {$property_table_name} {$property_table_nickname}\n\tJOIN {$smw_ids} p_ids ON {$property_table_nickname}.p_id = p_ids.smw_id\n"; if ($this->filter->is_relation) { $sql .= " JOIN {$smw_ids} o_ids ON {$property_table_nickname}.o_id = o_ids.smw_id\n"; } $sql .= "\tJOIN {$smw_insts} insts ON {$property_table_nickname}.s_id = insts.s_id\n\tJOIN {$smw_ids} cat_ids ON insts.o_id = cat_ids.smw_id\n\tWHERE p_ids.smw_title = '{$property_value}'\n\tAND cat_ids.smw_namespace = {$cat_ns}\n\tAND cat_ids.smw_title = '{$category}'\n\tGROUP BY {$value_field}\n\tORDER BY {$value_field}"; $res = $dbr->query($sql); while ($row = $dbr->fetchRow($res)) { if ($this->filter->time_period == wfMsg('sd_filter_month')) { $value_string = SDUtils::monthToString($row[1]) . " " . $row[0]; } else { // why is trim() necessary here??? $value_string = str_replace('_', ' ', trim($row[0])); } $possible_values[] = $value_string; } $dbr->freeResult($res); return $possible_values; }
/** * Gets an array of all values that the property belonging to this * filter has, for pages in the passed-in category. */ function getAllOrValues($category) { $possible_values = array(); $property_value = $this->filter->escaped_property; $dbr = wfGetDB(DB_SLAVE, 'smw'); $property_table_name = $dbr->tableName($this->filter->getTableName()); if ($this->filter->property_type != 'date') { $value_field = $this->filter->getValueField(); } else { // Is this necessary? $date_field = $this->filter->getDateField(); if ($this->filter->getTimePeriod() == 'month') { $value_field = "YEAR({$date_field}), MONTH({$date_field})"; } elseif ($this->filter->getTimePeriod() == 'day') { $value_field = "YEAR({$date_field}), MONTH({$date_field}), DAYOFMONTH({$date_field})"; } elseif ($this->filter->getTimePeriod() == 'year') { $value_field = "YEAR({$date_field})"; } else { // if ( $this->filter->getTimePeriod() == 'year range' ) { $value_field = "YEAR({$date_field})"; } } $smwIDs = $dbr->tableName(SDUtils::getIDsTableName()); $smwCategoryInstances = $dbr->tableName(SDUtils::getCategoryInstancesTableName()); $cat_ns = NS_CATEGORY; $sql = "\tSELECT {$value_field}\n\tFROM {$property_table_name} p\n\tJOIN {$smwIDs} p_ids ON p.p_id = p_ids.smw_id\n"; if ($this->filter->property_type === 'page') { $sql .= " JOIN {$smwIDs} o_ids ON p.o_id = o_ids.smw_id\n"; } $sql .= "\tJOIN {$smwCategoryInstances} insts ON p.s_id = insts.s_id\n\tJOIN {$smwIDs} cat_ids ON insts.o_id = cat_ids.smw_id\n\tWHERE p_ids.smw_title = '{$property_value}'\n\tAND cat_ids.smw_namespace = {$cat_ns}\n\tAND cat_ids.smw_title = {$dbr->addQuotes($category)}\n\tGROUP BY {$value_field}\n\tORDER BY {$value_field}"; $res = $dbr->query($sql); while ($row = $dbr->fetchRow($res)) { if ($this->filter->property_type == 'date' && $this->filter->getTimePeriod() == 'month') { $value_string = SDUtils::monthToString($row[1]) . " " . $row[0]; } else { // why is trim() necessary here??? $value_string = str_replace('_', ' ', trim($row[0])); } $possible_values[] = $value_string; } $dbr->freeResult($res); return $possible_values; }
/** * Gets an array of the possible time period values (e.g., years, * months) for this filter, and, for each one, * the number of pages that match that time period. */ function getTimePeriodValues() { $possible_dates = array(); $property_value = $this->escaped_property; $date_field = $this->getDateField(); $dbr = wfGetDB(DB_SLAVE, 'smw'); if ($this->getTimePeriod() == 'day') { $fields = "YEAR({$date_field}), MONTH({$date_field}), DAYOFMONTH({$date_field})"; } elseif ($this->getTimePeriod() == 'month') { $fields = "YEAR({$date_field}), MONTH({$date_field})"; } elseif ($this->getTimePeriod() == 'year') { $fields = "YEAR({$date_field})"; } else { // if ( $this->getTimePeriod() == 'decade' ) { $fields = "YEAR({$date_field})"; } $datesTable = $dbr->tableName($this->getTableName()); $idsTable = $dbr->tableName(SDUtils::getIDsTableName()); $sql = <<<END \tSELECT {$fields}, count(*) \tFROM semantic_drilldown_values sdv \tJOIN {$datesTable} a ON sdv.id = a.s_id \tJOIN {$idsTable} p_ids ON a.p_id = p_ids.smw_id \tWHERE p_ids.smw_title = '{$property_value}' \tGROUP BY {$fields} \tORDER BY {$fields} END; $res = $dbr->query($sql); while ($row = $dbr->fetchRow($res)) { if ($this->getTimePeriod() == 'day') { $date_string = SDUtils::monthToString($row[1]) . ' ' . $row[2] . ', ' . $row[0]; $possible_dates[$date_string] = $row[3]; } elseif ($this->getTimePeriod() == 'month') { global $sdgMonthValues; $date_string = SDUtils::monthToString($row[1]) . ' ' . $row[0]; $possible_dates[$date_string] = $row[2]; } elseif ($this->getTimePeriod() == 'year') { $date_string = $row[0]; $possible_dates[$date_string] = $row[1]; } else { // if ( $this->getTimePeriod() == 'decade' ) // Unfortunately, there's no SQL DECADE() // function - so we have to take these values, // which are grouped into year "buckets", and // re-group them into decade buckets. $year_string = $row[0]; $start_of_decade = $year_string - $year_string % 10; $end_of_decade = $start_of_decade + 9; $decade_string = $start_of_decade . ' - ' . $end_of_decade; if (!array_key_exists($decade_string, $possible_dates)) { $possible_dates[$decade_string] = $row[1]; } else { $possible_dates[$decade_string] += $row[1]; } } } $dbr->freeResult($res); return $possible_dates; }