protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     global $wgSitename;
     $result = '';
     if ($outputmode == SMW_OUTPUT_FILE) {
         // make file
         if ($this->m_title == '') {
             $this->m_title = $wgSitename;
         }
         $items = array();
         while ($row = $res->getNext()) {
             $items[] = $this->getItemForResultRow($row)->text();
         }
         $result = implode('', $items);
     } else {
         // just make link to export
         if ($this->getSearchLabel($outputmode)) {
             $label = $this->getSearchLabel($outputmode);
         } else {
             $label = wfMessage('srf_bibtex_link')->inContentLanguage()->text();
         }
         $link = $res->getQueryLink($label);
         $link->setParameter('bibtex', 'format');
         if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') {
             $link->setParameter($this->getSearchLabel(SMW_OUTPUT_WIKI), 'searchlabel');
         }
         $result .= $link->getText($outputmode, $this->mLinker);
         $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
         // yes, our code can be viewed as HTML if requested, no more parsing needed
     }
     return $result;
 }
Beispiel #2
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $this->isHTML = true;
     $t = "";
     $n = "";
     // if there is only one column in the results then stop right away
     if ($res->getColumnCount() == 1) {
         return "";
     }
     // print all result rows
     $first = true;
     $max = 0;
     // the biggest value. needed for scaling
     while ($row = $res->getNext()) {
         $name = $row[0]->getNextDataValue()->getShortWikiText();
         foreach ($row as $field) {
             while (($object = $field->getNextDataValue()) !== false) {
                 // use numeric sortkey
                 if ($object->isNumeric()) {
                     $nr = $object->getDataItem()->getSortKey();
                     $max = max($max, $nr);
                     if ($first) {
                         $first = false;
                         $t .= $nr;
                         $n = $name;
                     } else {
                         $t = $nr . ',' . $t;
                         $n = $name . '|' . $n;
                     }
                 }
             }
         }
     }
     return '<img src="http://chart.apis.google.com/chart?cht=p3&chs=' . $this->m_width . 'x' . $this->m_height . '&chds=0,' . $max . '&chd=t:' . $t . '&chl=' . $n . '" width="' . $this->m_width . '" height="' . $this->m_height . '"  />';
 }
	protected function addQueryResult( SMWQueryResult $queryResult ) {
		$serialized = $queryResult->serializeToArray();
		$result = $this->getResult();

		$result->setIndexedTagName( $serialized['results'], 'result' );
		$result->setIndexedTagName( $serialized['printrequests'], 'printrequest' );
		
		foreach ( $serialized['results'] as $subjectName => $subject ) {
			if ( is_array( $subject ) && array_key_exists( 'printouts', $subject ) ) {
				foreach ( $subject['printouts'] as $property => $values ) {
					if ( is_array( $values ) ) {
						$result->setIndexedTagName( $serialized['results'][$subjectName]['printouts'][$property], 'value' );
					}
				}
			}
		}
		
		$result->addValue( null, 'query', $serialized );
		
		if ( $queryResult->hasFurtherResults() ) {
			// TODO: obtain continuation data from store
			$result->disableSizeCheck();
			$result->addValue( null, 'query-continue', 0 );
			$result->enableSizeCheck();
		}
	}
 /**
  * Return relevant data set
  *
  * @param SMWQueryResult $res
  * @param $outputMode
  *
  * @return array
  */
 protected function getResultData(SMWQueryResult $res, $outputMode)
 {
     // Init
     $properties = array();
     $excludeProperties = explode($this->params['sep'], $this->params['exclude']);
     // Options used when retrieving data from the store
     $reqOptions = new SMWRequestOptions();
     $reqOptions->sort = true;
     $reqOptions->limit = $this->params['limit'];
     foreach ($res->getResults() as $key => $page) {
         // Find properties assigned to selected subject page
         foreach ($res->getStore()->getInProperties($page, $reqOptions) as $property) {
             $propertyLabel = $property->getLabel();
             // Exclude property from result set
             if (in_array($propertyLabel, $excludeProperties)) {
                 continue;
             }
             // NOTE There could be thousands of incoming links for one property,
             // counting the length of an array is inefficient but we don't want
             // to implement any native db select outside of smw core and rather
             // would like to see a counting method available but to counter
             // any potential inefficiencies we curb the selection by using
             // SMWRequestOptions -> limit as boundary
             $count = count($res->getStore()->getPropertySubjects($property, $page, $reqOptions));
             // Limit ouput by threshold
             if ($this->params['min'] <= $count) {
                 $properties[$propertyLabel] = $count;
             }
         }
     }
     return $properties;
 }
Beispiel #5
0
 /**
  * Returns an array with the numerical data
  *
  * @since 1.8
  *
  * @param SMWQueryResult $result
  * @param $outputMode
  *
  * @return array
  */
 protected function getResultData(SMWQueryResult $res, $outputMode)
 {
     $data = array();
     $data['series'] = array();
     while ($row = $res->getNext()) {
         // Loop over their fields (properties)
         $label = '';
         $i = 0;
         foreach ($row as $field) {
             $i++;
             $rowNumbers = array();
             // Grouping by subject (page object) or property
             if ($this->params['group'] === 'subject') {
                 $groupedBy = $field->getResultSubject()->getTitle()->getText();
             } else {
                 $groupedBy = $field->getPrintRequest()->getLabel();
             }
             // Property label
             $property = $field->getPrintRequest()->getLabel();
             // First column property typeid
             $i == 1 ? $data['fcolumntypeid'] = $field->getPrintRequest()->getTypeID() : '';
             // Loop over all values for the property.
             while (($object = $field->getNextDataValue()) !== false) {
                 if ($object->getDataItem()->getDIType() == SMWDataItem::TYPE_NUMBER) {
                     $number = $object->getNumber();
                     // Checking against the row and in case the first column is a numeric
                     // value it is handled as label with the remaining steps continue to work
                     // as it were a text label
                     // The first column container will not be part of the series container
                     if ($i == 1) {
                         $label = $number;
                         continue;
                     }
                     if ($label !== '' && $number >= $this->params['min']) {
                         // Reference array summarize all items per row
                         $rowNumbers += array('subject' => $label, 'value' => $number, 'property' => $property);
                         // Store plain numbers for simpler handling
                         $data['series'][$groupedBy][] = $number;
                     }
                 } elseif ($object->getDataItem()->getDIType() == SMWDataItem::TYPE_TIME) {
                     $label = $object->getShortWikiText();
                 } else {
                     $label = $object->getWikiValue();
                 }
             }
             // Only for array's with numbers
             if (count($rowNumbers) > 0) {
                 // For cases where mainlabel=- we assume that the subject should not be
                 // used as identifier and therefore we try to match the groupby
                 // with the first available text label
                 if ($this->params['mainlabel'] == '-' && $this->params['group'] === 'subject') {
                     $data[$this->params['group']][$label][] = $rowNumbers;
                 } else {
                     $data[$this->params['group']][$groupedBy][] = $rowNumbers;
                 }
             }
         }
     }
     return $data;
 }
Beispiel #6
0
 protected function addQueryResult(SMWQueryResult $queryResult)
 {
     $serialized = $queryResult->serializeToArray();
     $result = $this->getResult();
     $result->setIndexedTagName($serialized['results'], 'result');
     $result->setIndexedTagName($serialized['printrequests'], 'printrequest');
     foreach ($serialized['results'] as $subjectName => $subject) {
         if (is_array($subject) && array_key_exists('printouts', $subject)) {
             foreach ($subject['printouts'] as $property => $values) {
                 if (is_array($values)) {
                     $result->setIndexedTagName($serialized['results'][$subjectName]['printouts'][$property], 'value');
                 }
             }
         }
     }
     $output = array();
     header("Content-type: Application/JSON");
     foreach ($serialized['results'] as $r) {
         $common = count($r['printouts']['Has common name']) > 0 ? $r['printouts']['Has common name'][0]['fulltext'] : '';
         $taxo = count($r['printouts']['Is taxonomy type']) > 0 ? $r['printouts']['Is taxonomy type'][0]['fulltext'] : '';
         $output[$r['fulltext']] = array('taxonomy' => $taxo, 'common' => $common);
     }
     echo json_encode($output);
     exit;
 }
 /**
  * Return serialised results in specified format.
  * Implemented by subclasses.
  */
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $html = '';
     $id = uniqid();
     // build an array of article IDs contained in the result set
     $objects = array();
     foreach ($res->getResults() as $key => $object) {
         $objects[] = array($object->getTitle()->getArticleId());
         $html .= $key . ': ' . $object->getSerialization() . "<br>\n";
     }
     // build an array of data about the printrequests
     $printrequests = array();
     foreach ($res->getPrintRequests() as $key => $printrequest) {
         $data = $printrequest->getData();
         if ($data instanceof SMWPropertyValue) {
             $name = $data->getDataItem()->getKey();
         } else {
             $name = null;
         }
         $printrequests[] = array($printrequest->getMode(), $printrequest->getLabel(), $name, $printrequest->getOutputFormat(), $printrequest->getParameters());
     }
     // write out results and query params into JS arrays
     // Define the srf_filtered_values array
     SMWOutputs::requireScript('srf_slideshow', Html::inlineScript('srf_slideshow = {};'));
     SMWOutputs::requireScript('srf_slideshow' . $id, Html::inlineScript('srf_slideshow["' . $id . '"] = ' . json_encode(array($objects, $this->params['template'], $this->params['delay'] * 1000, $this->params['height'], $this->params['width'], $this->params['nav controls'], $this->params['effect'], json_encode($printrequests))) . ';'));
     SMWOutputs::requireResource('ext.srf.slideshow');
     if ($this->params['nav controls']) {
         SMWOutputs::requireResource('jquery.ui.slider');
     }
     return Html::element('div', array('id' => $id, 'class' => 'srf-slideshow ' . $id . ' ' . $this->params['class']));
 }
Beispiel #8
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     if ($outputmode == SMW_OUTPUT_FILE) {
         // make RDF file
         $serializer = $this->syntax == 'turtle' ? new SMWTurtleSerializer() : new SMWRDFXMLSerializer();
         $serializer->startSerialization();
         $serializer->serializeExpData(SMWExporter::getOntologyExpData(''));
         while ($row = $res->getNext()) {
             $subjectDi = reset($row)->getResultSubject();
             $data = SMWExporter::makeExportDataForSubject($subjectDi);
             foreach ($row as $resultarray) {
                 $printreq = $resultarray->getPrintRequest();
                 $property = null;
                 switch ($printreq->getMode()) {
                     case SMWPrintRequest::PRINT_PROP:
                         $property = $printreq->getData()->getDataItem();
                         break;
                     case SMWPrintRequest::PRINT_CATS:
                         $property = new SMWDIProperty('_TYPE');
                         break;
                     case SMWPrintRequest::PRINT_CCAT:
                         // not serialised right now
                         break;
                     case SMWPrintRequest::PRINT_THIS:
                         // ignored here (object is always included in export)
                         break;
                 }
                 if (!is_null($property)) {
                     SMWExporter::addPropertyValues($property, $resultarray->getContent(), $data, $subjectDi);
                 }
             }
             $serializer->serializeExpData($data);
         }
         $serializer->finishSerialization();
         return $serializer->flushContent();
     } else {
         // just make link to feed
         if ($this->getSearchLabel($outputmode)) {
             $label = $this->getSearchLabel($outputmode);
         } else {
             $label = wfMsgForContent('smw_rdf_link');
         }
         $link = $res->getQueryLink($label);
         $link->setParameter('rdf', 'format');
         $link->setParameter($this->syntax, 'syntax');
         if (array_key_exists('limit', $this->params)) {
             $link->setParameter($this->params['limit'], 'limit');
         } else {
             // use a reasonable default limit
             $link->setParameter(100, 'limit');
         }
         $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
         // yes, our code can be viewed as HTML if requested, no more parsing needed
         return $link->getText($outputmode, $this->mLinker);
     }
 }
 public function testIsFromCache()
 {
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $printRequests = array();
     $results = array();
     $instance = new QueryResult($printRequests, $query, $results, $store);
     $this->assertFalse($instance->isFromCache());
     $instance->setFromCache(true);
     $this->assertTrue($instance->isFromCache());
 }
 public function testVerifyThatAfterSerializeToArrayResultNextCanBeUsed()
 {
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $printRequests = array();
     $results = array(new DIWikiPage('Foo', 0), new DIWikiPage('Bar', 0));
     $instance = new QueryResult($printRequests, $query, $results, $store);
     $instance->serializeToArray();
     $this->assertInternalType('array', $instance->getNext());
     $instance->getHash();
     $this->assertInternalType('array', $instance->getNext());
 }
Beispiel #11
0
 /**
  * Gets a list of all numbers.
  * 
  * @since 1.6
  * 
  * @param SMWQueryResult $res
  * 
  * @return array
  */
 protected function getNumbers(SMWQueryResult $res)
 {
     $numbers = array();
     while ($row = $res->getNext()) {
         foreach ($row as $resultArray) {
             foreach ($resultArray->getContent() as $dataItem) {
                 self::addNumbersForDataItem($dataItem, $numbers);
             }
         }
     }
     return $numbers;
 }
Beispiel #12
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $result = '';
     if ($outputmode == SMW_OUTPUT_FILE) {
         // make CSV file
         $csv = fopen('php://temp', 'r+');
         if ($this->mShowHeaders) {
             $header_items = array();
             foreach ($res->getPrintRequests() as $pr) {
                 $header_items[] = $pr->getLabel();
             }
             fputcsv($csv, $header_items, $this->m_sep);
         }
         while ($row = $res->getNext()) {
             $row_items = array();
             foreach ($row as $field) {
                 $growing = array();
                 while (($object = $field->getNextDataValue()) !== false) {
                     $growing[] = Sanitizer::decodeCharReferences($object->getWikiValue());
                 }
                 $row_items[] = implode(',', $growing);
             }
             fputcsv($csv, $row_items, $this->m_sep);
         }
         rewind($csv);
         $result .= stream_get_contents($csv);
     } else {
         // just make link to feed
         if ($this->getSearchLabel($outputmode)) {
             $label = $this->getSearchLabel($outputmode);
         } else {
             $label = wfMsgForContent('smw_csv_link');
         }
         $link = $res->getQueryLink($label);
         $link->setParameter('csv', 'format');
         $link->setParameter($this->m_sep, 'sep');
         if (array_key_exists('mainlabel', $this->params) && $this->params['mainlabel'] !== false) {
             $link->setParameter($this->params['mainlabel'], 'mainlabel');
         }
         $link->setParameter($this->mShowHeaders ? 'show' : 'hide', 'headers');
         if (array_key_exists('limit', $this->params)) {
             $link->setParameter($this->params['limit'], 'limit');
         } else {
             // use a reasonable default limit
             $link->setParameter(100, 'limit');
         }
         $result .= $link->getText($outputmode, $this->mLinker);
         $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
         // yes, our code can be viewed as HTML if requested, no more parsing needed
     }
     return $result;
 }
Beispiel #13
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $result = '';
     $columnClasses = array();
     if ($this->mShowHeaders != SMW_HEADERS_HIDE) {
         // building headers
         $headers = array();
         foreach ($res->getPrintRequests() as $pr) {
             $attribs = array();
             $columnClass = str_replace(array(' ', '_'), '-', $pr->getText(SMW_OUTPUT_WIKI));
             $attribs['class'] = $columnClass;
             // Also add this to the array of classes, for
             // use in displaying each row.
             $columnClasses[] = $columnClass;
             $text = $pr->getText($outputmode, $this->mShowHeaders == SMW_HEADERS_PLAIN ? null : $this->mLinker);
             $headers[] = Html::rawElement('th', $attribs, $text === '' ? '&nbsp;' : $text);
         }
         $headers = '<tr>' . implode("\n", $headers) . '</tr>';
         if ($outputmode == SMW_OUTPUT_HTML) {
             $headers = '<thead>' . $headers . '</thead>';
         }
         $headers = "\n{$headers}\n";
         $result .= $headers;
     }
     $tableRows = array();
     $rowNum = 1;
     while ($subject = $res->getNext()) {
         $tableRows[] = $this->getRowForSubject($subject, $outputmode, $columnClasses, $rowNum++);
     }
     $tableRows = implode("\n", $tableRows);
     if ($outputmode == SMW_OUTPUT_HTML) {
         $tableRows = '<tbody>' . $tableRows . '</tbody>';
     }
     $result .= $tableRows;
     // print further results footer
     if ($this->linkFurtherResults($res)) {
         $link = $res->getQueryLink();
         if ($this->getSearchLabel($outputmode)) {
             $link->setCaption($this->getSearchLabel($outputmode));
         }
         $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText($outputmode, $this->mLinker) . "</td></tr>\n";
     }
     // Put the <table> tag around the whole thing
     $tableAttrs = array('class' => $this->mHTMLClass);
     if ($this->mFormat == 'broadtable') {
         $tableAttrs['width'] = '100%';
     }
     $result = Xml::tags('table', $tableAttrs, $result);
     $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
     // yes, our code can be viewed as HTML if requested, no more parsing needed
     return $result;
 }
Beispiel #14
0
 /**
  * Returns an array with sortkeys for dates pointing to their source DataItems.
  *
  * @param SMWQueryResult $res
  *
  * @return array
  */
 protected function getSortKeys(SMWQueryResult $res)
 {
     $seconds = array();
     while ($row = $res->getNext()) {
         foreach ($row as $resultArray) {
             foreach ($resultArray->getContent() as $dataItem) {
                 if ($dataItem->getDIType() === SMWDataItem::TYPE_TIME) {
                     $seconds[$dataItem->getSortKey()] = $dataItem;
                 }
             }
         }
     }
     return $seconds;
 }
 /**
  * Returns an array with numerical data
  *
  * @since 1.8
  *
  * @param SMWQueryResult $result
  * @param $outputMode
  *
  * @return array
  */
 protected function getAggregatedTimeSeries(SMWQueryResult $result, $outputMode)
 {
     $values = array();
     $aggregatedValues = array();
     while ($row = $result->getNext()) {
         // Objects (pages)
         $timeStamp = '';
         $value = '';
         $series = array();
         foreach ($row as $field) {
             $value = array();
             $sum = array();
             $rowSum = array();
             // Group by subject (page object)  or property
             if ($this->params['group'] == 'subject') {
                 $group = $field->getResultSubject()->getTitle()->getText();
             } else {
                 $group = $field->getPrintRequest()->getLabel();
             }
             while (($dataValue = $field->getNextDataValue()) !== false) {
                 // Data values
                 // Find the timestamp
                 if ($dataValue->getDataItem()->getDIType() == SMWDataItem::TYPE_TIME) {
                     // We work with a timestamp, we have to use intval because DataItem
                     // returns a string but we want a numeric representation of the timestamp
                     $timeStamp = intval($dataValue->getDataItem()->getMwTimestamp());
                 }
                 // Find the values (numbers only)
                 if ($dataValue->getDataItem()->getDIType() == SMWDataItem::TYPE_NUMBER) {
                     $sum[] = $dataValue->getNumber();
                 }
             }
             // Aggegate individual values into a sum
             $rowSum = array_sum($sum);
             // Check the sum and threshold/min
             if ($timeStamp !== '' && $rowSum == true && $rowSum >= $this->params['min']) {
                 $series[$group] = array($timeStamp, $rowSum);
             }
         }
         $values[] = $series;
     }
     // Re-assign values according to their group
     foreach ($values as $key => $value) {
         foreach ($values[$key] as $row => $rowvalue) {
             $aggregatedValues[$row][] = $rowvalue;
         }
     }
     return $aggregatedValues;
 }
Beispiel #16
0
 /**
  * Returns an array with the tags (keys) and the number of times they occur (values).
  *
  * @since 1.5.3
  *
  * @param SMWQueryResult $results
  * @param $outputmode
  *
  * @return array
  */
 protected function getTags(SMWQueryResult $results, $outputmode)
 {
     $tags = array();
     $excludetags = explode(';', $this->params['excludetags']);
     while ($row = $results->getNext()) {
         // Objects (pages)
         for ($i = 0, $n = count($row); $i < $n; $i++) {
             // SMWResultArray for a sinlge property
             /**
              * @var SMWDataValue $dataValue
              */
             while (($dataValue = $row[$i]->getNextDataValue()) !== false) {
                 // Data values
                 $isSubject = $row[$i]->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS;
                 // If the main object should not be included, skip it.
                 if ($i == 0 && !$this->params['includesubject'] && $isSubject) {
                     continue;
                 }
                 // Get the HTML for the tag content. Pages are linked, other stuff is just plaintext.
                 if ($dataValue->getTypeID() == '_wpg') {
                     $value = $dataValue->getTitle()->getText();
                     $html = $dataValue->getLongText($outputmode, $this->getLinker($isSubject));
                 } else {
                     $html = $dataValue->getShortText($outputmode, $this->getLinker(false));
                     $value = $html;
                 }
                 // Exclude tags from result set
                 if (in_array($value, $excludetags)) {
                     continue;
                 }
                 // Replace content with template inclusion
                 $html = $this->params['template'] !== '' ? $this->addTemplateOutput($value, $rownum) : $html;
                 if (!array_key_exists($value, $tags)) {
                     $tags[$value] = 0;
                     $this->tagsHtml[$value] = $html;
                     // Store the HTML separetely, so sorting can be done easily.
                 }
                 $tags[$value]++;
             }
         }
     }
     foreach ($tags as $name => $count) {
         if ($count < $this->params['mincount']) {
             unset($tags[$name]);
         }
     }
     return $tags;
 }
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
		$this->isHTML = true;

		$t = "";
		$n = "";

		// if there is only one column in the results then stop right away
		if ($res->getColumnCount() == 1) return "";

		// print all result rows
		$first = true;
		$count = 0; // How many bars will they be? Needed to calculate the height of the image
		$max = 0; // the biggest value. needed for scaling
		
		while ( $row = $res->getNext() ) {
			$name = $row[0]->getNextDataValue()->getShortWikiText();
			foreach ( $row as $field ) {
				while ( ( $object = $field->getNextDataValue() ) !== false ) {
					
					// use numeric sortkey
					if ( $object->isNumeric() ) {
						$nr = $object->getDataItem()->getSortKey();

						$count++;
						$max = max( $max, $nr );

						if ( $first ) {
							$first = false;
							$t .= $nr;
							$n = $name;
						} else {
							$t = $nr . ',' . $t;
							$n .= '|' . $name; // yes, this is correct, it needs to be the other way
						}
					}
				}
			}
		}
		
		$barwidth = 20; // width of each bar
		$bardistance = 4; // distance between two bars
		$height = $count * ( $barwidth + $bardistance ) + 15; // calculates the height of the image
		
		return 	'<img src="http://chart.apis.google.com/chart?cht=bhs&chbh=' . $barwidth . ',' . $bardistance . '&chs=' . $this->m_width . 'x' . $height . '&chds=0,' . $max . '&chd=t:' . $t . '&chxt=y&chxl=0:|' . $n . '" width="' . $this->m_width . '" height="' . $height . '" />';

	}
Beispiel #18
0
 /**
  * Returns number of available results.
  *
  * @return int
  */
 public function getResultCount()
 {
     if (!is_null($this->queryResult)) {
         return $this->queryResult->getCount();
     } else {
         return 0;
     }
 }
 private function getConceptDescription(DIWikiPage $concept)
 {
     $value = $this->queryResult->getStore()->getPropertyValues($concept, new DIProperty('_CONC'));
     if ($value === null || $value === array()) {
         return new ThingDescription();
     }
     $value = end($value);
     return ApplicationFactory::getInstance()->newQueryParser()->getQueryDescription($value->getConceptQuery());
 }
 /**
  * Returns an array with the tags (keys) and the number of times they occur (values).
  *
  * @since 1.7
  *
  * @param SMWQueryResult $results
  * @param $outputMode
  *
  * @return array
  */
 protected function getResultValues(SMWQueryResult $results, $outputMode)
 {
     $tags = array();
     /**
      * @var $row SMWResultArray Objects (pages)
      * @var $dataValue SMWDataValue
      *
      * @return array
      */
     while ($row = $results->getNext()) {
         // SMWResultArray for a sinlge property
         for ($i = 0, $n = count($row); $i < $n; $i++) {
             while (($dataValue = $row[$i]->getNextDataValue()) !== false) {
                 $isSubject = $row[$i]->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS;
                 // If the main object should not be included, skip it.
                 if ($i == 0 && !$this->params['includesubject'] && $isSubject) {
                     continue;
                 }
                 // Get the HTML for the tag content. Pages are linked, other stuff is just plaintext.
                 if ($dataValue->getTypeID() == '_wpg') {
                     $value = $dataValue->getTitle()->getText();
                     $html = $dataValue->getLongText($outputMode, $this->getLinker($isSubject));
                 } else {
                     $html = $dataValue->getShortText($outputMode, $this->getLinker(false));
                     $value = $html;
                 }
                 if (!array_key_exists($value, $tags)) {
                     $tags[$value] = 0;
                     $this->tagsHtml[$value] = $html;
                     // Store the HTML separetely, so sorting can be done easily.
                 }
                 $tags[$value]++;
             }
         }
     }
     foreach ($tags as $name => $count) {
         if ($count < $this->params['min']) {
             unset($tags[$name]);
         }
     }
     return $tags;
 }
Beispiel #21
0
 public function SMWWSQueryResult($printrequests, $query, $results, $store, $furtherres = false)
 {
     parent::__construct($printrequests, $query, $results, $store, $furtherres);
     // retrieve result subjects for faster access
     $this->mResultSubjects = array();
     foreach ($results as $r) {
         $keys = array_keys($r);
         $rs = $r[$keys[0]]->getResultSubject();
         $this->mResultSubjects[] = $rs;
     }
 }
Beispiel #22
0
 /**
  * Adds in the pages from a new query result to the existing set of
  * pages - only pages that weren't in the set already get added.
  * 
  * @param SMWQueryResult $new_result
  */
 public function addResult(SMWQueryResult $newResult)
 {
     $existingPageNames = array();
     while ($row = $this->getNext()) {
         if ($row[0] instanceof SMWResultArray) {
             $content = $row[0]->getContent();
             $existingPageNames[] = $content[0]->getLongText(SMW_OUTPUT_WIKI);
         }
     }
     while (($row = $newResult->getNext()) !== false) {
         if (property_exists($newResult, 'display_options')) {
             $row[0]->display_options = $newResult->display_options;
         }
         $content = $row[0]->getContent();
         $pageName = $content[0]->getLongText(SMW_OUTPUT_WIKI);
         if (!in_array($pageName, $existingPageNames)) {
             $this->m_content[] = $row;
         }
     }
     reset($this->m_content);
 }
 /**
  * Extracts the data we need to build a networkdiag DSL from the
  * semantic result
  *
  * @param  SMWQueryResult $result Result of the query
  *
  * @return array                  Array of data to be fed to generateDiagCode()
  */
 protected function getResultData(SMWQueryResult $result)
 {
     $data = array();
     while ($rows = $result->getNext()) {
         foreach ($rows as $field) {
             $propertyLabel = $field->getPrintRequest()->getLabel();
             $server_name = $field->getResultSubject()->getTitle();
             $server_name = strtolower($server_name->getFullText());
             while (($dataValue = $field->getNextDataValue()) !== false) {
                 if ($propertyLabel === "ipv4") {
                     $ip_address = $dataValue->getWikiValue();
                     $data[$server_name]["ip_address"] = $ip_address;
                 } elseif ($propertyLabel === "fqdn") {
                     $fqdn = strtolower($dataValue->getWikiValue());
                     if (isset($this->params['domain'])) {
                         $fqdn = str_replace($this->params['domain'], '', $fqdn);
                     }
                     $domain_parts = explode('.', $fqdn);
                     $hostname = $domain_parts[0];
                     $group = '';
                     if (count($domain_parts) >= 1) {
                         $group = $domain_parts[1];
                         $node_host = sprintf('%s.%s', $hostname, $group);
                     }
                     $data[$server_name]["fqdn"] = $fqdn;
                     $data[$server_name]["node_host"] = !empty($group) ? $node_host : $hostname;
                     $data[$server_name]["group"] = $group;
                 }
             }
             // If a row does not have a value for the FQDN property label, it will not be returned
             // by $field->getNextDataValue()
             if (!isset($data[$server_name]["fqdn"])) {
                 $data[$server_name]["fqdn"] = $server_name;
                 $data[$server_name]["node_host"] = $server_name;
                 $data[$server_name]["group"] = $server_name;
             }
         }
     }
     return $data;
 }
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     if (!isset($this->paramWidth)) {
         $this->paramWidth = -1;
     }
     $this->isHTML = true;
     global $wgOut;
     $wgOut->addModules('ext.SemanticImageAnnotator.ResultFormat');
     $resultPages = $res->getResults();
     $store = smwfGetStore();
     $annotationArray = array();
     foreach ($resultPages as $page) {
         $namespace = $page->getNamespace();
         if ($namespace != 380) {
             continue;
         }
         $coords = "";
         $imgUrl = "";
         $pageName = $page->getDBkey();
         $propertyCoords = new SMWDIProperty("__SIA_RECTCOORDS");
         $propertyImgUrl = new SMWDIProperty("__SIA_IMG_URL");
         $coordValues = $store->getPropertyValues($page, $propertyCoords);
         $urlValues = $store->getPropertyValues($page, $propertyImgUrl);
         if (count($coordValues) == 1 && $coordValues[0] instanceof SMWDIString) {
             $coords = $coordValues[0]->getString();
         }
         if (count($urlValues) == 1 && $coordValues[0] instanceof SMWDIString) {
             $imgUrl = $urlValues[0]->getString();
         }
         if ($coords != "" && $imgUrl != "") {
             $annotationArray[$imgUrl][] = array($pageName, $coords);
         }
     }
     $returnString = "";
     foreach ($annotationArray as $image => $annotationData) {
         $returnString .= $this->createAnnotatedImg($image, $annotationData);
     }
     return $returnString;
 }
Beispiel #25
0
 /**
  * Get the serialization for a SMWQueryResult object.
  *
  * @since 1.7
  *
  * @param SMWQueryResult $result
  *
  * @return array
  */
 public static function getSerializedQueryResult(SMWQueryResult $queryResult)
 {
     $results = array();
     $printRequests = array();
     foreach ($queryResult->getPrintRequests() as $printRequest) {
         $printRequests[] = array('label' => $printRequest->getLabel(), 'typeid' => $printRequest->getTypeID(), 'mode' => $printRequest->getMode());
     }
     foreach ($queryResult->getResults() as $diWikiPage) {
         $result = array('printouts' => array());
         foreach ($queryResult->getPrintRequests() as $printRequest) {
             $resultAarray = new SMWResultArray($diWikiPage, $printRequest, $queryResult->getStore());
             if ($printRequest->getMode() === SMWPrintRequest::PRINT_THIS) {
                 $dataItems = $resultAarray->getContent();
                 $result += self::getSerialization(array_shift($dataItems));
             } else {
                 $result['printouts'][$printRequest->getLabel()] = array_map(array(__CLASS__, 'getSerialization'), $resultAarray->getContent());
             }
         }
         $results[$diWikiPage->getTitle()->getFullText()] = $result;
     }
     return array('printrequests' => $printRequests, 'results' => $results);
 }
Beispiel #26
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     if (!is_callable('renderGraphviz')) {
         wfWarn('The SRF Graph printer needs the GraphViz extension to be installed.');
         return '';
     }
     global $wgGraphVizSettings;
     $this->isHTML = true;
     $graphInput = "digraph {$this->m_graphName} {";
     if ($this->m_graphSize != '') {
         $graphInput .= "size=\"{$this->m_graphSize}\";";
     }
     if ($this->m_nodeShape) {
         $graphInput .= "node [shape={$this->m_nodeShape}];";
     }
     $graphInput .= "rankdir={$this->m_rankdir};";
     while ($row = $res->getNext()) {
         $graphInput .= $this->getGVForItem($row, $outputmode);
     }
     $graphInput .= "}";
     // Calls renderGraphViz function from MediaWiki GraphViz extension
     $result = renderGraphviz($graphInput);
     if ($this->m_graphLegend && $this->m_graphColor) {
         $arrayCount = 0;
         $arraySize = count($this->m_graphColors);
         $result .= "<P>";
         foreach ($this->m_labelArray as $m_label) {
             if ($arrayCount >= $arraySize) {
                 $arrayCount = 0;
             }
             $color = $this->m_graphColors[$arrayCount];
             $result .= "<font color={$color}>{$color}: {$m_label} </font><br />";
             $arrayCount += 1;
         }
         $result .= "</P>";
     }
     return $result;
 }
Beispiel #27
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $result = '';
     if ($outputmode == SMW_OUTPUT_FILE) {
         // make CSV file
         $csv = fopen('php://temp', 'r+');
         $sep = str_replace('_', ' ', $this->params['sep']);
         if ($this->params['showsep']) {
             fputs($csv, "sep=" . $sep . "\n");
         }
         if ($this->mShowHeaders) {
             $header_items = array();
             foreach ($res->getPrintRequests() as $pr) {
                 $header_items[] = $pr->getLabel();
             }
             fputcsv($csv, $header_items, $sep);
         }
         while ($row = $res->getNext()) {
             $row_items = array();
             foreach ($row as $field) {
                 $growing = array();
                 while (($object = $field->getNextDataValue()) !== false) {
                     $growing[] = Sanitizer::decodeCharReferences($object->getWikiValue());
                 }
                 $row_items[] = implode(',', $growing);
             }
             fputcsv($csv, $row_items, $this->m_sep);
         }
         rewind($csv);
         $result .= stream_get_contents($csv);
     } else {
         // just make link to feed
         $result .= $this->getLink($res, $outputmode)->getText($outputmode, $this->mLinker);
         $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
         // yes, our code can be viewed as HTML if requested, no more parsing needed
     }
     return $result;
 }
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $result = '';
     if ($outputmode == SMW_OUTPUT_FILE) {
         $people = array();
         $row = $res->getNext();
         while ($row !== false) {
             $people[] = new PersonPageValues($row[0]->getResultSubject());
             $row = $res->getNext();
         }
         $printer = new Gedcom5FilePrinter();
         $printer->addPeople($people);
         $result = $printer->getFile();
     } else {
         // just make link
         if ($this->getSearchLabel($outputmode)) {
             $label = $this->getSearchLabel($outputmode);
         } else {
             $label = wfMsgForContent('semanticgenealogy-gedcomexport-link');
         }
         $link = $res->getQueryLink($label);
         $link->setParameter('gedcom5', 'format');
         if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') {
             $link->setParameter($this->getSearchLabel(SMW_OUTPUT_WIKI), 'searchlabel');
         }
         if (array_key_exists('limit', $this->m_params)) {
             $link->setParameter($this->m_params['limit'], 'limit');
         } else {
             // use a reasonable default limit
             $link->setParameter(20, 'limit');
         }
         $result .= $link->getText($outputmode, $this->mLinker);
         $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
         // yes, our code can be viewed as HTML if requested, no more parsing needed
     }
     return $result;
 }
Beispiel #29
0
 /**
  * Add the query result to the API output.
  *
  * @since 1.6.2
  *
  * @param SMWQueryResult $queryResult
  */
 protected function addQueryResult(SMWQueryResult $queryResult)
 {
     $serialized = $queryResult->serializeToArray();
     $result = $this->getResult();
     $result->setIndexedTagName($serialized['results'], 'result');
     $result->setIndexedTagName($serialized['printrequests'], 'printrequest');
     foreach ($serialized['results'] as $subjectName => $subject) {
         if (is_array($subject) && array_key_exists('printouts', $subject)) {
             foreach ($subject['printouts'] as $property => $values) {
                 if (is_array($values)) {
                     $result->setIndexedTagName($serialized['results'][$subjectName]['printouts'][$property], 'value');
                 }
             }
         }
     }
     $result->addValue(null, 'query', $serialized);
     if ($queryResult->hasFurtherResults()) {
         $result->disableSizeCheck();
         // TODO: right now this returns an offset that we can use for continuation, just like done
         // in other places in SMW. However, this is not efficient, so we should change this at some point.
         $result->addValue(null, 'query-continue-offset', $this->parameters['offset']->getValue() + $queryResult->getCount());
         $result->enableSizeCheck();
     }
 }
 /**
  * @since 2.3
  *
  * @return DIWikiPage[]|[]
  */
 public function getQueryDependencySubjectList()
 {
     // Resolving dependencies for non-embedded queries or limit=0 (which only
     // links to Special:Ask via further results) is not required
     if ($this->getSubject() === null || $this->getQuery()->getLimit() == 0) {
         return array();
     }
     $description = $this->getQuery()->getDescription();
     $dependencySubjectList = array($this->getSubject());
     // Find entities described by the query
     $this->doResolveDependenciesFromDescription($dependencySubjectList, $description);
     $this->doResolveDependenciesFromPrintRequest($dependencySubjectList, $description->getPrintRequests());
     $dependencySubjectList = array_merge($dependencySubjectList, $this->queryResult->getResults());
     $this->queryResult->reset();
     return $dependencySubjectList;
 }