Ejemplo n.º 1
0
 /**
  * Load results of the given print request and result subject. This is only
  * done when needed.
  */
 protected function loadContent()
 {
     if ($this->mContent !== false) {
         return;
     }
     wfProfileIn('SMWQueryResult::loadContent (SMW)');
     switch ($this->mPrintRequest->getMode()) {
         case SMWPrintRequest::PRINT_THIS:
             // NOTE: The limit is ignored here.
             $this->mContent = array($this->mResult);
             break;
         case SMWPrintRequest::PRINT_CATS:
             // Always recompute cache here to ensure output format is respected.
             self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'), $this->getRequestOptions(false));
             self::$catCacheObj = $this->mResult->getHash();
             $limit = $this->mPrintRequest->getParameter('limit');
             $this->mContent = $limit === false ? self::$catCache : array_slice(self::$catCache, 0, $limit);
             break;
         case SMWPrintRequest::PRINT_PROP:
             $propertyValue = $this->mPrintRequest->getData();
             if ($propertyValue->isValid()) {
                 $this->mContent = $this->mStore->getPropertyValues($this->mResult, $propertyValue->getDataItem(), $this->getRequestOptions());
             } else {
                 $this->mContent = array();
             }
             // Print one component of a multi-valued string.
             // Known limitation: the printrequest still is of type _rec, so if printers check
             // for this then they will not recognize that it returns some more concrete type.
             if ($this->mPrintRequest->getTypeID() == '_rec' && $this->mPrintRequest->getParameter('index') !== false) {
                 $pos = $this->mPrintRequest->getParameter('index') - 1;
                 $newcontent = array();
                 foreach ($this->mContent as $diContainer) {
                     /* SMWRecordValue */
                     $recordValue = SMWDataValueFactory::newDataItemValue($diContainer, $propertyValue->getDataItem());
                     $dataItems = $recordValue->getDataItems();
                     if (array_key_exists($pos, $dataItems) && !is_null($dataItems[$pos])) {
                         $newcontent[] = $dataItems[$pos];
                     }
                 }
                 $this->mContent = $newcontent;
             }
             break;
         case SMWPrintRequest::PRINT_CCAT:
             ///NOTE: The limit is ignored here.
             if (self::$catCacheObj != $this->mResult->getHash()) {
                 self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'));
                 self::$catCacheObj = $this->mResult->getHash();
             }
             $found = false;
             $prkey = $this->mPrintRequest->getData()->getDBkey();
             foreach (self::$catCache as $cat) {
                 if ($cat->getDBkey() == $prkey) {
                     $found = true;
                     break;
                 }
             }
             $this->mContent = array(new SMWDIBoolean($found));
             break;
         default:
             $this->mContent = array();
             // Unknown print request.
     }
     reset($this->mContent);
     wfProfileOut('SMWQueryResult::loadContent (SMW)');
 }