Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php |
— | — | @@ -18,9 +18,6 @@ |
19 | 19 | var $possible_applied_filters = array(); |
20 | 20 | |
21 | 21 | function load($filter_name) { |
22 | | - global $sdgContLang; |
23 | | - $sd_props = $sdgContLang->getSpecialPropertiesArray(); |
24 | | - |
25 | 22 | $f = new SDFilter(); |
26 | 23 | $f->name = $filter_name; |
27 | 24 | $properties_used = sdfGetValuesForProperty($filter_name, SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY); |
— | — | @@ -72,7 +69,156 @@ |
73 | 70 | return $f; |
74 | 71 | } |
75 | 72 | |
| 73 | + |
76 | 74 | /** |
| 75 | + * Gets an array of the possible time period values (e.g., years, |
| 76 | + * years and months) for this filter, and, for each one, |
| 77 | + * the number of pages that match that time period. |
| 78 | + */ |
| 79 | + function getTimePeriodValues() { |
| 80 | + global $smwgDefaultStore; |
| 81 | + |
| 82 | + $possible_dates = array(); |
| 83 | + $property_value = str_replace(' ', '_', $this->property); |
| 84 | + $dbr = wfGetDB( DB_SLAVE ); |
| 85 | + if ($this->time_period == wfMsg('sd_filter_month')) { |
| 86 | + $fields = "YEAR(value_xsd), MONTH(value_xsd)"; |
| 87 | + } else { |
| 88 | + $fields = "YEAR(value_xsd)"; |
| 89 | + } |
| 90 | + if ($smwgDefaultStore == 'SMWSQLStore2') { |
| 91 | + $smw_attributes = $dbr->tableName( 'smw_atts2' ); |
| 92 | + $smw_ids = $dbr->tableName( 'smw_ids' ); |
| 93 | + $sql =<<<END |
| 94 | + SELECT $fields, count(*) |
| 95 | + FROM semantic_drilldown_values sdv |
| 96 | + JOIN $smw_attributes a ON sdv.id = a.s_id |
| 97 | + JOIN $smw_ids p_ids ON a.p_id = p_ids.smw_id |
| 98 | + WHERE p_ids.smw_title = '$property_value' |
| 99 | + GROUP BY $fields |
| 100 | + ORDER BY $fields |
| 101 | + |
| 102 | +END; |
| 103 | + } else { |
| 104 | + $smw_attributes = $dbr->tableName( 'smw_attributes' ); |
| 105 | + $sql =<<<END |
| 106 | + SELECT $fields, count(*) |
| 107 | + FROM semantic_drilldown_values sdv |
| 108 | + JOIN $smw_attributes a ON sdv.id = a.subject_id |
| 109 | + WHERE a.attribute_title = '$property_value' |
| 110 | + GROUP BY $fields |
| 111 | + ORDER BY $fields |
| 112 | + |
| 113 | +END; |
| 114 | + } |
| 115 | + $res = $dbr->query($sql); |
| 116 | + while ($row = $dbr->fetchRow($res)) { |
| 117 | + if ($this->time_period == wfMsg('sd_filter_month')) { |
| 118 | + global $sdgMonthValues; |
| 119 | + $date_string = sdfMonthToString($row[1]) . " " . $row[0]; |
| 120 | + $possible_dates[$date_string] = $row[2]; |
| 121 | + } else { |
| 122 | + $date_string = $row[0]; |
| 123 | + $possible_dates[$date_string] = $row[1]; |
| 124 | + } |
| 125 | + } |
| 126 | + $dbr->freeResult($res); |
| 127 | + return $possible_dates; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Gets an array of all values that the property belonging to this |
| 132 | + * filter has, and, for each one, the number of pages |
| 133 | + * that match that value. |
| 134 | + */ |
| 135 | + function getAllValues() { |
| 136 | + global $smwgDefaultStore; |
| 137 | + if ($this->time_period != NULL) { |
| 138 | + return $this->getTimePeriodValues(); |
| 139 | + } elseif ($smwgDefaultStore == 'SMWSQLStore2') { |
| 140 | + return $this->getAllValues_2(); |
| 141 | + } else { |
| 142 | + return $this->getAllValues_orig(); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + function getAllValues_orig() { |
| 147 | + $possible_values = array(); |
| 148 | + $property_value = str_replace(' ', '_', $this->property); |
| 149 | + $dbr = wfGetDB( DB_SLAVE ); |
| 150 | + if ($this->is_relation) { |
| 151 | + $property_table_name = $dbr->tableName('smw_relations'); |
| 152 | + $property_table_nickname = "r"; |
| 153 | + $property_field = 'relation_title'; |
| 154 | + $value_field = 'object_title'; |
| 155 | + } else { |
| 156 | + $property_table_name = $dbr->tableName('smw_attributes'); |
| 157 | + $property_table_nickname = "a"; |
| 158 | + $property_field = 'attribute_title'; |
| 159 | + $value_field = 'value_xsd'; |
| 160 | + } |
| 161 | + $sql = "SELECT $value_field, count(*) |
| 162 | + FROM semantic_drilldown_values sdv |
| 163 | + JOIN $property_table_name $property_table_nickname |
| 164 | + ON sdv.id = $property_table_nickname.subject_id |
| 165 | + WHERE $property_table_nickname.$property_field = '$property_value' |
| 166 | + AND $value_field != '' |
| 167 | + GROUP BY $value_field |
| 168 | + ORDER BY $value_field"; |
| 169 | + $res = $dbr->query($sql); |
| 170 | + while ($row = $dbr->fetchRow($res)) { |
| 171 | + $value_string = str_replace('_', ' ', $row[0]); |
| 172 | + $possible_values[$value_string] = $row[1]; |
| 173 | + } |
| 174 | + $dbr->freeResult($res); |
| 175 | + return $possible_values; |
| 176 | + } |
| 177 | + |
| 178 | + function getAllValues_2() { |
| 179 | + $possible_values = array(); |
| 180 | + $property_value = str_replace(' ', '_', $this->property); |
| 181 | + $dbr = wfGetDB( DB_SLAVE ); |
| 182 | + if ($this->is_relation) { |
| 183 | + $property_table_name = $dbr->tableName('smw_rels2'); |
| 184 | + $property_table_nickname = "r"; |
| 185 | + $value_field = 'o_ids.smw_title'; |
| 186 | + } else { |
| 187 | + $property_table_name = $dbr->tableName('smw_atts2'); |
| 188 | + $property_table_nickname = "a"; |
| 189 | + $value_field = 'value_xsd'; |
| 190 | + } |
| 191 | + $smw_ids = $dbr->tableName( 'smw_ids' ); |
| 192 | + $prop_ns = SMW_NS_PROPERTY; |
| 193 | + $sql =<<<END |
| 194 | + SELECT $value_field, count(*) |
| 195 | + FROM semantic_drilldown_values sdv |
| 196 | + JOIN $property_table_name $property_table_nickname ON sdv.id = $property_table_nickname.s_id |
| 197 | + |
| 198 | +END; |
| 199 | + if ($this->is_relation) { |
| 200 | + $sql .= " JOIN $smw_ids o_ids ON r.o_id = o_ids.smw_id"; |
| 201 | + } |
| 202 | + $sql .=<<<END |
| 203 | + JOIN $smw_ids p_ids ON $property_table_nickname.p_id = p_ids.smw_id |
| 204 | + WHERE p_ids.smw_title = '$property_value' |
| 205 | + AND p_ids.smw_namespace = $prop_ns |
| 206 | + AND $value_field != '' |
| 207 | + GROUP BY $value_field |
| 208 | + ORDER BY $value_field |
| 209 | + |
| 210 | +END; |
| 211 | + $res = $dbr->query($sql); |
| 212 | + while ($row = $dbr->fetchRow($res)) { |
| 213 | + $value_string = str_replace('_', ' ', $row[0]); |
| 214 | + $possible_values[$value_string] = $row[1]; |
| 215 | + } |
| 216 | + $dbr->freeResult($res); |
| 217 | + return $possible_values; |
| 218 | + } |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + /** |
77 | 223 | * Creates a temporary database table, semantic_drilldown_filter_values, |
78 | 224 | * that holds every value held by any page in the wiki that matches |
79 | 225 | * the property associated with this filter. This table is useful |