/** * Implementation of SMWStore::getInProperties(). This function is meant to * be used for finding properties that link to wiki pages. * * @since 1.8 * @see SMWStore::getInProperties * @param SMWDataItem $value * @param SMWRequestOptions $requestoptions * * @return array of SMWWikiPageValue */ public function getInProperties(SMWDataItem $value, $requestoptions = null) { wfProfileIn("SMWSQLStore3::getInProperties (SMW)"); $db = wfGetDB(DB_SLAVE); $result = array(); // Potentially need to get more results, since options apply to union. if ($requestoptions !== null) { $suboptions = clone $requestoptions; $suboptions->limit = $requestoptions->limit + $requestoptions->offset; $suboptions->offset = 0; } else { $suboptions = null; } $diType = $value->getDIType(); foreach (SMWSQLStore3::getPropertyTables() as $proptable) { if ($diType != $proptable->diType) { continue; } $where = $from = ''; if ($proptable->fixedproperty == false) { // join smw_ids to get property titles $from = $db->tableName('smw_ids') . " INNER JOIN " . $db->tableName($proptable->name) . " AS t1 ON t1.p_id=smw_id"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->store->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), 'SMW::getInProperties', $this->store->getSQLOptions($suboptions, 'smw_sortkey')); foreach ($res as $row) { try { $result[] = new SMWDIProperty($row->smw_title); } catch (SMWDataItemException $e) { // has been observed to happen (empty property title); cause unclear; ignore this data } } } else { $from = $db->tableName($proptable->name) . " AS t1"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $res = $db->select($from, '*', $where, 'SMW::getInProperties', array('LIMIT' => 1)); if ($db->numRows($res) > 0) { $result[] = new SMWDIProperty($proptable->fixedproperty); } } $db->freeResult($res); } $result = $this->store->applyRequestOptions($result, $requestoptions); // apply options to overall result wfProfileOut("SMWSQLStore3::getInProperties (SMW)"); return $result; }
/** * Implementation of SMWStore::getInProperties(). This function is meant to * be used for finding properties that link to wiki pages. * * @since 1.8 * @see SMWStore::getInProperties * * @param SMWDataItem $value * @param SMWRequestOptions|null $requestOptions * * @return array of SMWWikiPageValue */ public function getInProperties(SMWDataItem $value, SMWRequestOptions $requestOptions = null) { $db = $this->store->getConnection(); $result = array(); // Potentially need to get more results, since options apply to union. if ($requestOptions !== null) { $subOptions = clone $requestOptions; $subOptions->limit = $requestOptions->limit + $requestOptions->offset; $subOptions->offset = 0; } else { $subOptions = null; } $diType = $value->getDIType(); foreach ($this->store->getPropertyTables() as $proptable) { if ($diType != $proptable->getDiType()) { continue; } $where = $from = ''; if (!$proptable->isFixedPropertyTable()) { // join ID table to get property titles $from = $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " INNER JOIN " . $db->tableName($proptable->getName()) . " AS t1 ON t1.p_id=smw_id"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $where .= " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW); $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey,smw_iw', $where . $this->store->getSQLConditions($subOptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), __METHOD__, $this->store->getSQLOptions($subOptions, 'smw_sortkey')); foreach ($res as $row) { try { $result[] = new SMW\DIProperty($row->smw_title); } catch (SMWDataItemException $e) { // has been observed to happen (empty property title); cause unclear; ignore this data } } } else { $from = $db->tableName($proptable->getName()) . " AS t1"; $this->prepareValueQuery($from, $where, $proptable, $value, 1); $res = $db->select($from, '*', $where, __METHOD__, array('LIMIT' => 1)); if ($db->numRows($res) > 0) { $result[] = new SMW\DIProperty($proptable->getFixedProperty()); } } $db->freeResult($res); } $result = $this->store->applyRequestOptions($result, $requestOptions); // apply options to overall result return $result; }