/** * @since 2.5 * * @param Query $query * * @return string */ public static function get(Query $query) { $serialized = array(); $serialized['conditions'] = $query->getQueryString(); $serialized['parameters'] = array('limit=' . $query->getLimit(), 'offset=' . $query->getOffset(), 'mainlabel=' . $query->getMainlabel()); if ($query->getQuerySource() !== null && $query->getQuerySource() !== '') { $serialized['parameters'] = array_merge($serialized['parameters'], array('source=' . $query->getQuerySource())); } list($serialized['sort'], $serialized['order']) = self::doSerializeSortKeys($query); $serialized['printouts'] = self::doSerializePrintouts($query); $encoded = $serialized['conditions'] . '|' . ($serialized['printouts'] !== array() ? implode('|', $serialized['printouts']) . '|' : '') . implode('|', $serialized['parameters']) . ($serialized['sort'] !== array() ? '|sort=' . implode(',', $serialized['sort']) : '') . ($serialized['order'] !== array() ? '|order=' . implode(',', $serialized['order']) : ''); return $encoded; }
/** * Returns a serialized SMWQueryResult object with additional meta data * * This methods extends the serializeToArray() for additional meta * that are useful when handling data via the api * * @note should be used instead of SMWQueryResult::serializeToArray() * as this method contains additional informaion * * @since 1.9 * * @return array */ public function toArray() { // @note micro optimization: We call getSerializedQueryResult() // only once and create the hash here instead of calling getHash() // to avoid getSerializedQueryResult() being called again // @note count + offset equals total therefore we deploy both values $serializeArray = $this->serializeToArray(); return array_merge($serializeArray, array('meta' => array('hash' => HashBuilder::createHashIdForContent($serializeArray), 'count' => $this->getCount(), 'offset' => $this->mQuery->getOffset(), 'source' => $this->mQuery->getQuerySource()))); }