Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -350,20 +350,135 @@ |
351 | 351 | $sid = $this->getSMWPageID($subject->getDBkey(), $subject->getNamespace(),$subject->getInterwiki()); |
352 | 352 | } |
353 | 353 | $pid = $this->getSMWPageID($property->getDBkey(), SMW_NS_PROPERTY, $property->getInterwiki()); |
354 | | - if ( ($sid == 0) || ($pid == 0)) { |
| 354 | + if ( ( ($sid == 0) && ($subject !== NULL) ) || ($pid == 0)) { |
355 | 355 | wfProfileOut("SMWSQLStore2::getPropertyValues (SMW)"); |
356 | 356 | return array(); |
357 | 357 | } |
358 | | - $sd = $this->getSemanticData($subject,array(SMWDataValueFactory::getPropertyObjectTypeID($property))); |
359 | | - $result = $this->applyRequestOptions($sd->getPropertyValues($property),$requestoptions); |
360 | | - if ($outputformat != '') { |
361 | | - $newres = array(); |
362 | | - foreach ($result as $dv) { |
363 | | - $ndv = clone $dv; |
364 | | - $ndv->setOutputFormat($outputformat); |
365 | | - $newres[] = $ndv; |
| 358 | + |
| 359 | + if ($sid != 0) { // subject given, use semantic data cache: |
| 360 | + $sd = $this->getSemanticData($subject,array(SMWDataValueFactory::getPropertyObjectTypeID($property))); |
| 361 | + $result = $this->applyRequestOptions($sd->getPropertyValues($property),$requestoptions); |
| 362 | + if ($outputformat != '') { // reformat cached values |
| 363 | + $newres = array(); |
| 364 | + foreach ($result as $dv) { |
| 365 | + $ndv = clone $dv; |
| 366 | + $ndv->setOutputFormat($outputformat); |
| 367 | + $newres[] = $ndv; |
| 368 | + } |
| 369 | + $result = $newres; |
366 | 370 | } |
367 | | - $result = $newres; |
| 371 | + } else { // no subject given, get all values for the given property |
| 372 | + $result = array(); |
| 373 | + $id = SMWDataValueFactory::getPropertyObjectTypeID($property); |
| 374 | + switch ($id) { |
| 375 | + case '_txt': case '_cod': |
| 376 | + $res = $db->select( 'smw_text2', 'value_blob', |
| 377 | + 'p_id=' . $db->addQuotes($pid), |
| 378 | + 'SMW::getPropertyValues', $this->getSQLOptions($requestoptions) ); |
| 379 | + while($row = $db->fetchObject($res)) { |
| 380 | + $dv = SMWDataValueFactory::newPropertyObjectValue($property); |
| 381 | + $dv->setOutputFormat($outputformat); |
| 382 | + $dv->setXSDValue($row->value_blob, ''); |
| 383 | + $result[] = $dv; |
| 384 | + } |
| 385 | + $db->freeResult($res); |
| 386 | + break; |
| 387 | + case '_wpg': |
| 388 | + $res = $db->select( array('smw_rels2', 'smw_ids'), |
| 389 | + 'smw_namespace, smw_title, smw_iw', |
| 390 | + 'p_id=' . $db->addQuotes($pid) . ' AND o_id=smw_id' . |
| 391 | + $this->getSQLConditions($requestoptions,'smw_title','smw_title'), |
| 392 | + 'SMW::getPropertyValues', $this->getSQLOptions($requestoptions,'smw_title') ); |
| 393 | + while($row = $db->fetchObject($res)) { |
| 394 | + $dv = SMWDataValueFactory::newPropertyObjectValue($property); |
| 395 | + $dv->setOutputFormat($outputformat); |
| 396 | + $dv->setValues($row->smw_title, $row->smw_namespace, false, $row->smw_iw); |
| 397 | + $result[] = $dv; |
| 398 | + } |
| 399 | + $db->freeResult($res); |
| 400 | + break; |
| 401 | + case '__nry': ///TODO: currently disabled |
| 402 | +// $type = SMWDataValueFactory::getPropertyObjectTypeValue($property); |
| 403 | +// $subtypes = $type->getTypeValues(); |
| 404 | +// $res = $db->select( $db->tableName('smw_nary'), |
| 405 | +// 'nary_key', |
| 406 | +// $subjectcond . |
| 407 | +// 'attribute_title=' . $db->addQuotes($property->getDBkey()), |
| 408 | +// 'SMW::getPropertyValues', $this->getSQLOptions($requestoptions) ); |
| 409 | +// ///TODO: presumably slow. Try to do less SQL queries by making a join with smw_nary |
| 410 | +// while($row = $db->fetchObject($res)) { |
| 411 | +// $values = array(); |
| 412 | +// for ($i=0; $i < count($subtypes); $i++) { // init array |
| 413 | +// $values[$i] = NULL; |
| 414 | +// } |
| 415 | +// $res2 = $db->select( $db->tableName('smw_nary_attributes'), |
| 416 | +// 'nary_pos, value_unit, value_xsd', |
| 417 | +// $subjectcond . |
| 418 | +// 'nary_key=' . $db->addQuotes($row->nary_key), |
| 419 | +// 'SMW::getPropertyValues'); |
| 420 | +// while($row2 = $db->fetchObject($res2)) { |
| 421 | +// if ($row2->nary_pos < count($subtypes)) { |
| 422 | +// $dv = SMWDataValueFactory::newTypeObjectValue($subtypes[$row2->nary_pos]); |
| 423 | +// $dv->setXSDValue($row2->value_xsd, $row2->value_unit); |
| 424 | +// $values[$row2->nary_pos] = $dv; |
| 425 | +// } |
| 426 | +// } |
| 427 | +// $db->freeResult($res2); |
| 428 | +// $res2 = $db->select( $db->tableName('smw_nary_longstrings'), |
| 429 | +// 'nary_pos, value_blob', |
| 430 | +// $subjectcond . |
| 431 | +// 'nary_key=' . $db->addQuotes($row->nary_key), |
| 432 | +// 'SMW::getPropertyValues'); |
| 433 | +// while($row2 = $db->fetchObject($res2)) { |
| 434 | +// if ( $row2->nary_pos < count($subtypes) ) { |
| 435 | +// $dv = SMWDataValueFactory::newTypeObjectValue($subtypes[$row2->nary_pos]); |
| 436 | +// $dv->setXSDValue($row2->value_blob, ''); |
| 437 | +// $values[$row2->nary_pos] = $dv; |
| 438 | +// } |
| 439 | +// } |
| 440 | +// $db->freeResult($res2); |
| 441 | +// $res2 = $db->select( $db->tableName('smw_nary_relations'), |
| 442 | +// 'nary_pos, object_title, object_namespace, object_id', |
| 443 | +// $subjectcond . |
| 444 | +// 'nary_key=' . $db->addQuotes($row->nary_key), |
| 445 | +// 'SMW::getPropertyValues'); |
| 446 | +// while($row2 = $db->fetchObject($res2)) { |
| 447 | +// if ( ($row2->nary_pos < count($subtypes)) && |
| 448 | +// ($subtypes[$row2->nary_pos]->getXSDValue() == '_wpg') ) { |
| 449 | +// $dv = SMWDataValueFactory::newTypeIDValue('_wpg'); |
| 450 | +// $dv->setValues($row2->object_title, $row2->object_namespace, $row2->object_id); |
| 451 | +// $values[$row2->nary_pos] = $dv; |
| 452 | +// } |
| 453 | +// } |
| 454 | +// $db->freeResult($res2); |
| 455 | +// $dv = SMWDataValueFactory::newPropertyObjectValue($property); |
| 456 | +// $dv->setOutputFormat($outputformat); |
| 457 | +// $dv->setDVs($values); |
| 458 | +// $result[] = $dv; |
| 459 | +// } |
| 460 | +// $db->freeResult($res); |
| 461 | + break; |
| 462 | + default: |
| 463 | + if ( ($requestoptions !== NULL) && ($requestoptions->boundary !== NULL) && |
| 464 | + ($requestoptions->boundary->isNumeric()) ) { |
| 465 | + $value_column = 'value_num'; |
| 466 | + } else { |
| 467 | + $value_column = 'value_xsd'; |
| 468 | + } |
| 469 | + $sql = 'p_id=' . $db->addQuotes($pid) . |
| 470 | + $this->getSQLConditions($requestoptions,$value_column,'value_xsd'); |
| 471 | + $res = $db->select( 'smw_atts2', 'value_unit, value_xsd', |
| 472 | + 'p_id=' . $db->addQuotes($pid) . |
| 473 | + $this->getSQLConditions($requestoptions,$value_column,'value_xsd'), |
| 474 | + 'SMW::getPropertyValues', $this->getSQLOptions($requestoptions,$value_column) ); |
| 475 | + while($row = $db->fetchObject($res)) { |
| 476 | + $dv = SMWDataValueFactory::newPropertyObjectValue($property); |
| 477 | + $dv->setOutputFormat($outputformat); |
| 478 | + $dv->setXSDValue($row->value_xsd, $row->value_unit); |
| 479 | + $result[] = $dv; |
| 480 | + } |
| 481 | + $db->freeResult($res); |
| 482 | + } |
368 | 483 | } |
369 | 484 | wfProfileOut("SMWSQLStore2::getPropertyValues (SMW)"); |
370 | 485 | return $result; |