Example #1
0
 public function testSetLabel()
 {
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem(new DIProperty('Foo'));
     $instance = new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue);
     $this->assertEquals(null, $instance->getLabel());
     $this->assertEquals(null, $instance->getWikiText());
     $instance->setLabel('Bar');
     $this->assertEquals('Bar', $instance->getLabel());
     $this->assertEquals('Bar', $instance->getWikiText());
 }
Example #2
0
 /**
  * Make a request option object based on the given parameters, and
  * return NULL if no such object is required. The parameter defines
  * if the limit should be taken into account, which is not always desired
  * (especially if results are to be cached for future use).
  * 
  * @param boolean $useLimit
  * 
  * @return SMWRequestOptions or null
  */
 protected function getRequestOptions($useLimit = true)
 {
     $limit = $useLimit ? $this->mPrintRequest->getParameter('limit') : false;
     $order = trim($this->mPrintRequest->getParameter('order'));
     // Important: use "!=" for order, since trim() above does never return "false", use "!==" for limit since "0" is meaningful here.
     if ($limit !== false || $order != false) {
         $options = new SMWRequestOptions();
         if ($limit !== false) {
             $options->limit = trim($limit);
         }
         if ($order == 'descending' || $order == 'reverse' || $order == 'desc') {
             $options->sort = true;
             $options->ascending = false;
         } elseif ($order == 'ascending' || $order == 'asc') {
             $options->sort = true;
             $options->ascending = true;
         }
     } else {
         $options = null;
     }
     return $options;
 }
	/**
	 * Hanldes a single property value. Returns an array with data for a single event or false.
	 * 
	 * FIXME: 13 arguments, of which a whole bunch are byref... not a good design :)
	 * 
	 * @since 1.5.3
	 * 
	 * @param SMWDataValue $object
	 * @param $outputmode
	 * @param SMWPrintRequest $pr
	 * @param boolean $first_col
	 * @param boolean &$hastitle
	 * @param boolean &$hastime
	 * @param boolean $first_value
	 * @param boolean $isEventline
	 * @param string &$curmeta
	 * @param string &$curdata
	 * @param &$date_value
	 * @param boolean &$output
	 * @param array &$positions
	 * 
	 * @return false or array
	 */
	protected function handlePropertyValue( SMWDataValue $object, $outputmode, SMWPrintRequest $pr, $first_col, 
		&$hastitle, &$hastime, $first_value, $isEventline, &$curmeta, &$curdata, $date_value, &$output, array &$positions ) {
			global $curarticle, $cururl;
		
		$event = false;
		
		$l = $this->getLinker( $first_col );
		
		if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this
			$l = null;
		}
		
		if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage
			$objectlabel = $object->getLongText( $outputmode, $l );
		} else {
			$objectlabel = $object->getShortText( $outputmode, $l );
		}
		
		$urlobject =  ( $l !== null );
		$header = '';
		
		if ( $first_value ) {
			// find header for current value:
			if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) {
				$header = $pr->getText( $outputmode, $this->mLinker ) . ': ';
			}
			
			// is this a start date?
			if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
			     ( $date_value == $this->m_tlstart ) ) {
				// FIXME: Timeline scripts should support XSD format explicitly. They
				// currently seem to implement iso8601 which deviates from XSD in cases.
				// NOTE: We can assume $object to be an SMWDataValue in this case.
				$curmeta .= Html::element(
					'span',
					array( 'class' => 'smwtlstart' ),
					$object->getXMLSchemaDate()
				);
				$positions[$object->getHash()] = $object->getXMLSchemaDate();
				$hastime = true;
			}
			
			// is this the end date?
			if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
			     ( $date_value == $this->m_tlend ) ) {
				// NOTE: We can assume $object to be an SMWDataValue in this case.
				$curmeta .= Html::element(
					'span',
					array( 'class' => 'smwtlend' ),
					$object->getXMLSchemaDate( false )
				);
			}
			
			// find title for displaying event
			if ( !$hastitle ) {
				$curmeta .= Html::element(
					'span',
					array(
						'class' => $urlobject ? 'smwtlurl' : 'smwtltitle'
					),
					$objectlabel
				);

				if ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) {
					$curarticle = $object->getShortText( $outputmode, false );
					$cururl = $object->getTitle()->getFullUrl();
				}
				
				// NOTE: type Title of $object implied
				$hastitle = true;
			}
		} elseif ( $output ) {
			// it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row
			$curdata .= ', '; 
		}
		
		if ( !$first_col || !$first_value || $isEventline ) {
			$curdata .= $header . $objectlabel;
			$output = true;
		}
		
		if ( $isEventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) {
			$event = array(
				$object->getXMLSchemaDate(),
				$pr->getLabel(),
				$object->getDataItem()->getSortKey(),
			);
		}
	
		return $event;
	}
Example #4
0
 function addSemanticResultWrapper($dbr, $res, $num, $query, $mainlabel, $printouts)
 {
     $qr = array();
     $count = 0;
     $store = smwfGetStore();
     while ($count < $num && ($row = $dbr->fetchObject($res))) {
         $count++;
         if (class_exists('SMWDIWikiPage')) {
             // SMW 1.6
             $qr[] = new SMWDIWikiPage($row->t, $row->ns, null);
         } else {
             $qr[] = SMWWikiPageValue::makePage($row->t, $row->ns, $row->sortkey);
         }
         if (method_exists($store, 'cacheSMWPageID')) {
             if (method_exists('SMWDIWikiPage', 'getSubobjectName')) {
                 // SMW 1.6
                 $store->cacheSMWPageID($row->id, $row->t, $row->ns, $row->iw, '');
             } else {
                 $store->cacheSMWPageID($row->id, $row->t, $row->ns, $row->iw);
             }
         }
     }
     if ($dbr->fetchObject($res)) {
         $count++;
     }
     $dbr->freeResult($res);
     $printrequest = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $mainlabel);
     $main_printout = array();
     $main_printout[$printrequest->getHash()] = $printrequest;
     $printouts = array_merge($main_printout, $printouts);
     return new SMWQueryResult($printouts, $query, $qr, $store, $count > $num);
 }
Example #5
0
 /**
  * Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue).
  *
  * @since 1.0
  *
  * @param SMWDataValue $object
  * @param SMWPrintRequest $printRequest
  *
  * @return string
  */
 protected function handleResultProperty(SMWDataValue $object, SMWPrintRequest $printRequest)
 {
     if ($this->template) {
         if ($object instanceof SMWWikiPageValue) {
             return $object->getTitle()->getPrefixedText();
         } else {
             return $object->getLongText(SMW_OUTPUT_WIKI, NULL);
         }
     }
     if ($this->linkAbsolute) {
         $t = Title::newFromText($printRequest->getHTMLText(NULL), SMW_NS_PROPERTY);
         if ($t instanceof Title && $t->exists()) {
             $propertyName = $propertyName = Html::element('a', array('href' => $t->getFullUrl()), $printRequest->getHTMLText(NULL));
         } else {
             $propertyName = $printRequest->getHTMLText(NULL);
         }
     } else {
         $propertyName = $printRequest->getHTMLText(smwfGetLinker());
     }
     if ($this->linkAbsolute) {
         $hasPage = $object->getTypeID() == '_wpg';
         if ($hasPage) {
             $t = Title::newFromText($object->getLongText($this->outputmode, NULL), NS_MAIN);
             $hasPage = $t->exists();
         }
         if ($hasPage) {
             $propertyValue = Html::element('a', array('href' => $t->getFullUrl()), $object->getLongText($this->outputmode, NULL));
         } else {
             $propertyValue = $object->getLongText($this->outputmode, NULL);
         }
     } else {
         $propertyValue = $object->getLongText($this->outputmode, smwfGetLinker());
     }
     return $propertyName . ($propertyName === '' ? '' : ': ') . $propertyValue;
 }
Example #6
0
 /**
  * Rewrite printrequests in the way that subselection are cut down to normal property selections
  * in order to display them properly.
  *
  * @param SMWPrintRequest $pr
  * @return SMWPrintRequest
  */
 private function rewritePrintrequest($pr)
 {
     $data = $pr->getData();
     $rewritten_prs = $pr;
     if ($data instanceof Title) {
         // property chain appear as Title
         $titleText = $data->getText();
         $chain = explode(".", $titleText);
         if (count($chain) > 1) {
             $newtitle = Title::newFromText($chain[count($chain) - 1], SMW_NS_PROPERTY);
             if ($newtitle->exists()) {
                 $newlabel = $pr->getLabel() != $titleText ? $pr->getLabel() : $newtitle->getText();
                 $newData = SMWPropertyValue::makeUserProperty($newtitle->getText());
             } else {
                 $newlabel = $pr->getLabel() != $titleText ? $pr->getLabel() : $newtitle->getText();
                 $newData = $newtitle;
             }
             $rewritten_prs = new SMWPrintRequest($newtitle->exists() ? SMWPrintRequest::PRINT_PROP : SMWPrintRequest::PRINT_THIS, $newlabel, $newData, $pr->getOutputFormat());
             $rewritten_prs->getHash();
         }
     }
     return $rewritten_prs;
 }
Example #7
0
 function addSemanticResultWrapper($dbr, $res, $num, $query, $mainlabel, $printouts)
 {
     $qr = array();
     $count = 0;
     $store = SDUtils::getSMWStore();
     while ($count < $num && ($row = $dbr->fetchObject($res))) {
         $count++;
         $qr[] = new SMWDIWikiPage($row->t, $row->ns, '');
         if (method_exists($store, 'cacheSMWPageID')) {
             $store->cacheSMWPageID($row->id, $row->t, $row->ns, $row->iw, '');
         }
     }
     if ($dbr->fetchObject($res)) {
         $count++;
     }
     $dbr->freeResult($res);
     $printrequest = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $mainlabel);
     $main_printout = array();
     $main_printout[$printrequest->getHash()] = $printrequest;
     $printouts = array_merge($main_printout, $printouts);
     return new SMWQueryResult($printouts, $query, $qr, $store, $count > $num);
 }