Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php |
— | — | @@ -204,11 +204,11 @@ |
205 | 205 | $cat_ns = NS_CATEGORY; |
206 | 206 | $sql .= "AND p.page_namespace != $cat_ns "; |
207 | 207 | foreach ($applied_filters as $i => $af) { |
208 | | - // if any of these filter's values are 'none', |
| 208 | + // if any of this filter's values is 'none', |
209 | 209 | // include another table to get this information |
210 | 210 | $includes_none = false; |
211 | 211 | foreach ($af->values as $fv) { |
212 | | - if ($af->values[0]->text === '_none' || $af->values[0]->text === ' none') { |
| 212 | + if ($fv->text === '_none' || $fv->text === ' none') { |
213 | 213 | $includes_none = true; |
214 | 214 | break; |
215 | 215 | } |
— | — | @@ -236,7 +236,7 @@ |
237 | 237 | } |
238 | 238 | foreach ($applied_filters as $i => $af) { |
239 | 239 | if ($af->filter->is_relation) { |
240 | | - $sql .= "JOIN $smw_relations r$i |
| 240 | + $sql .= "LEFT OUTER JOIN $smw_relations r$i |
241 | 241 | ON p.page_id = r$i.subject_id "; |
242 | 242 | } else { |
243 | 243 | $sql .= "JOIN $smw_attributes a$i |
— | — | @@ -283,11 +283,11 @@ |
284 | 284 | ON ids.smw_id = insts.s_id |
285 | 285 | AND ids.smw_namespace != $cat_ns "; |
286 | 286 | foreach ($applied_filters as $i => $af) { |
287 | | - // if any of these filter's values are 'none', |
| 287 | + // if any of this filter's values is 'none', |
288 | 288 | // include another table to get this information |
289 | 289 | $includes_none = false; |
290 | 290 | foreach ($af->values as $fv) { |
291 | | - if ($af->values[0]->text === '_none' || $af->values[0]->text === ' none') { |
| 291 | + if ($fv->text === '_none' || $fv->text === ' none') { |
292 | 292 | $includes_none = true; |
293 | 293 | break; |
294 | 294 | } |
— | — | @@ -297,26 +297,31 @@ |
298 | 298 | $property_table_name = $smw_rels; |
299 | 299 | $property_table_nickname = "nr$i"; |
300 | 300 | $property_field = 'p_id'; |
301 | | - $value_field = "o_ids$i.smw_title"; |
302 | 301 | } else { |
303 | 302 | $property_table_name = $smw_atts; |
304 | 303 | $property_table_nickname = "na$i"; |
305 | 304 | $property_field = 'p_id'; |
306 | | - $value_field = 'value_xsd'; |
307 | 305 | } |
308 | 306 | $property_value = str_replace(' ', '_', $af->filter->property); |
309 | 307 | $property_value = str_replace("'", "\'", $property_value); |
310 | 308 | $sql .= "LEFT OUTER JOIN |
311 | | - (SELECT s_id, $value_field |
| 309 | + (SELECT s_id |
312 | 310 | FROM $property_table_name |
313 | | - WHERE $property_field = '$property_value') $property_table_nickname |
| 311 | + WHERE $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns)) $property_table_nickname |
314 | 312 | ON ids.smw_id = $property_table_nickname.s_id "; |
315 | 313 | } |
316 | 314 | } |
317 | 315 | foreach ($applied_filters as $i => $af) { |
| 316 | + $sql .= "\n "; |
318 | 317 | if ($af->filter->is_relation) { |
319 | | - $sql .= "JOIN $smw_rels r$i ON ids.smw_id = r$i.s_id |
320 | | - JOIN $smw_ids o_ids$i ON r$i.o_id = o_ids$i.smw_id "; |
| 318 | + if ($includes_none) { |
| 319 | + $sql .= "LEFT OUTER "; |
| 320 | + } |
| 321 | + $sql .= "JOIN $smw_rels r$i ON ids.smw_id = r$i.s_id\n "; |
| 322 | + if ($includes_none) { |
| 323 | + $sql .= "LEFT OUTER "; |
| 324 | + } |
| 325 | + $sql .= "JOIN $smw_ids o_ids$i ON r$i.o_id = o_ids$i.smw_id "; |
321 | 326 | } else { |
322 | 327 | $sql .= "JOIN $smw_atts a$i ON ids.smw_id = a$i.s_id "; |
323 | 328 | } |
— | — | @@ -338,11 +343,15 @@ |
339 | 344 | $property_value = str_replace(' ', '_', $af->filter->property); |
340 | 345 | if ($af->filter->is_relation) { |
341 | 346 | $property_field = "r$i.p_id"; |
342 | | - $sql .= "AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND "; |
| 347 | + $sql .= "\n AND ($property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns)"; |
| 348 | + if ($includes_none) { |
| 349 | + $sql .= " OR $property_field IS NULL"; |
| 350 | + } |
| 351 | + $sql .= ")\n AND "; |
343 | 352 | $value_field = "o_ids$i.smw_title"; |
344 | 353 | } else { |
345 | 354 | $property_field = "a$i.p_id"; |
346 | | - $sql .= "AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND "; |
| 355 | + $sql .= "\n AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND "; |
347 | 356 | $value_field = "a$i.value_xsd"; |
348 | 357 | } |
349 | 358 | $sql .= $af->checkSQL($value_field); |
— | — | @@ -989,12 +998,12 @@ |
990 | 999 | $sql = "SELECT DISTINCT ids.smw_title AS title, |
991 | 1000 | ids.smw_title AS value, |
992 | 1001 | ids.smw_namespace AS namespace, |
993 | | - ids.smw_sortkey AS sortkey "; |
| 1002 | + ids.smw_sortkey AS sortkey\n"; |
994 | 1003 | } else { |
995 | 1004 | $sql = "SELECT DISTINCT p.page_title AS title, |
996 | 1005 | p.page_title AS value, |
997 | 1006 | p.page_namespace AS namespace, |
998 | | - c.cl_sortkey AS sortkey "; |
| 1007 | + c.cl_sortkey AS sortkey\n"; |
999 | 1008 | } |
1000 | 1009 | $sql .= $this->getSQLFromClause($this->category, $this->subcategory, $this->all_subcategories, $this->applied_filters); |
1001 | 1010 | return $sql; |