r44906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44905‎ | r44906 | r44907 >
Date:17:49, 22 December 2008
Author:yaron
Status:deferred
Tags:
Comment:
'getAllOrValues' functions moved here from /specials/SD_BrowseData.php
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_AppliedFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_AppliedFilter.php
@@ -99,4 +99,109 @@
100100 $sql .= ")";
101101 return $sql;
102102 }
 103+
 104+
 105+ /**
 106+ * Gets an array of all values that the property belonging to this
 107+ * filter has, for pages in the passed-in category.
 108+ */
 109+ function getAllOrValues($category) {
 110+ global $smwgDefaultStore;
 111+ if ($smwgDefaultStore == 'SMWSQLStore2') {
 112+ return $this->getAllOrValues_2($category);
 113+ } else {
 114+ return $this->getAllOrValues_orig($category);
 115+ }
 116+ }
 117+
 118+ function getAllOrValues_orig($category) {
 119+ $possible_values = array();
 120+ $property_value = str_replace(' ', '_', $this->filter->property);
 121+ $dbr = wfGetDB( DB_SLAVE );
 122+ if ($this->filter->is_relation) {
 123+ $property_table_name = $dbr->tableName('smw_relations');
 124+ $property_table_nickname = "r";
 125+ $property_field = 'relation_title';
 126+ $value_field = 'object_title';
 127+ } else {
 128+ $property_table_name = $dbr->tableName('smw_attributes');
 129+ $property_table_nickname = "a";
 130+ $property_field = 'attribute_title';
 131+ $value_field = 'value_xsd';
 132+ }
 133+ if ($this->filter->time_period != NULL) {
 134+ if ($this->filter->time_period == wfMsg('sd_filter_month')) {
 135+ $value_field = "YEAR(value_xsd), MONTH(value_xsd)";
 136+ } else {
 137+ $value_field = "YEAR(value_xsd)";
 138+ }
 139+ }
 140+ $categorylinks = $dbr->tableName( 'categorylinks' );
 141+ $sql = "SELECT $value_field
 142+ FROM $property_table_name $property_table_nickname
 143+ JOIN $categorylinks c
 144+ ON $property_table_nickname.subject_id = c.cl_from
 145+ WHERE $property_table_nickname.$property_field = '$property_value'
 146+ AND c.cl_to = '$category'
 147+ GROUP BY $value_field
 148+ ORDER BY $value_field";
 149+ $res = $dbr->query($sql);
 150+ while ($row = $dbr->fetchRow($res)) {
 151+ if ($this->filter->time_period == wfMsg('sd_filter_month'))
 152+ $value_string = sdfMonthToString($row[1]) . " " . $row[0];
 153+ else
 154+ // why is trim() necessary here???
 155+ $value_string = str_replace('_', ' ', trim($row[0]));
 156+ $possible_values[] = $value_string;
 157+ }
 158+ $dbr->freeResult($res);
 159+ return $possible_values;
 160+ }
 161+
 162+ function getAllOrValues_2($category) {
 163+ $possible_values = array();
 164+ $property_value = str_replace(' ', '_', $this->filter->property);
 165+ $dbr = wfGetDB( DB_SLAVE );
 166+ if ($this->filter->is_relation) {
 167+ $property_table_name = $dbr->tableName('smw_rels2');
 168+ $property_table_nickname = "r";
 169+ $value_field = 'r.o_id';
 170+ } else {
 171+ $property_table_name = $dbr->tableName('smw_atts2');
 172+ $property_table_nickname = "a";
 173+ $value_field = 'value_xsd';
 174+ }
 175+ if ($this->filter->time_period != NULL) {
 176+ if ($this->filter->time_period == wfMsg('sd_filter_month')) {
 177+ $value_field = "YEAR(value_xsd), MONTH(value_xsd)";
 178+ } else {
 179+ $value_field = "YEAR(value_xsd)";
 180+ }
 181+ }
 182+ $smw_insts = $dbr->tableName( 'smw_inst2' );
 183+ $smw_ids = $dbr->tableName( 'smw_ids' );
 184+ $cat_ns = NS_CATEGORY;
 185+ $sql = "SELECT $value_field
 186+ FROM $property_table_name $property_table_nickname
 187+ JOIN $smw_ids p_ids ON $property_table_nickname.p_id = p_ids.smw_id
 188+ JOIN $smw_insts insts ON $property_table_nickname.s_id = insts.s_id
 189+ JOIN $smw_ids cat_ids ON insts.o_id = cat_ids.smw_id
 190+ WHERE p_ids.smw_title = '$property_value'
 191+ AND cat_ids.smw_namespace = $cat_ns
 192+ AND cat_ids.smw_title = '$category'
 193+ GROUP BY $value_field
 194+ ORDER BY $value_field";
 195+ $res = $dbr->query($sql);
 196+ while ($row = $dbr->fetchRow($res)) {
 197+ if ($this->filter->time_period == wfMsg('sd_filter_month'))
 198+ $value_string = sdfMonthToString($row[1]) . " " . $row[0];
 199+ else
 200+ // why is trim() necessary here???
 201+ $value_string = str_replace('_', ' ', trim($row[0]));
 202+ $possible_values[] = $value_string;
 203+ }
 204+ $dbr->freeResult($res);
 205+ return $possible_values;
 206+ }
 207+
103208 }

Status & tagging log