本文整理汇总了PHP中SMWQueryResult::getCount方法的典型用法代码示例。如果您正苦于以下问题:PHP SMWQueryResult::getCount方法的具体用法?PHP SMWQueryResult::getCount怎么用?PHP SMWQueryResult::getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMWQueryResult
的用法示例。
在下文中一共展示了SMWQueryResult::getCount方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResultCount
/**
* Returns number of available results.
*
* @return int
*/
public function getResultCount()
{
if (!is_null($this->queryResult)) {
return $this->queryResult->getCount();
} else {
return 0;
}
}
示例2: addQueryResult
/**
* 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();
}
}
示例3: getNavigationBar
/**
* Build the navigation for some given query result, reuse url-tail parameters.
*
* @param SMWQueryResult $res
* @param array $urlArgs
*
* @return string
*/
protected function getNavigationBar(SMWQueryResult $res, array $urlArgs)
{
global $smwgQMaxInlineLimit, $wgLang;
$offset = $this->m_params['offset'];
$limit = $this->params['limit']->getValue();
// Prepare navigation bar.
if ($offset > 0) {
$navigation = Html::element('a', array('href' => SpecialPage::getSafeTitleFor('Ask')->getLocalURL(array('offset' => max(0, $offset - $limit), 'limit' => $limit) + $urlArgs), 'rel' => 'nofollow'), wfMessage('smw_result_prev')->text());
} else {
$navigation = wfMessage('smw_result_prev')->text();
}
// @todo FIXME: i18n: Patchwork text.
$navigation .= '     <b>' . wfMessage('smw_result_results')->text() . ' ' . $wgLang->formatNum($offset + 1) . ' – ' . $wgLang->formatNum($offset + $res->getCount()) . '</b>    ';
if ($res->hasFurtherResults()) {
$navigation .= Html::element('a', array('href' => SpecialPage::getSafeTitleFor('Ask')->getLocalURL(array('offset' => $offset + $limit, 'limit' => $limit) + $urlArgs), 'rel' => 'nofollow'), wfMessage('smw_result_next')->text());
} else {
$navigation .= wfMessage('smw_result_next')->text();
}
$first = true;
foreach (array(20, 50, 100, 250, 500) as $l) {
if ($l > $smwgQMaxInlineLimit) {
break;
}
if ($first) {
$navigation .= '        (';
$first = false;
} else {
$navigation .= ' | ';
}
if ($limit != $l) {
$navigation .= Html::element('a', array('href' => SpecialPage::getSafeTitleFor('Ask')->getLocalURL(array('offset' => $offset, 'limit' => $l) + $urlArgs), 'rel' => 'nofollow'), $l);
} else {
$navigation .= '<b>' . $l . '</b>';
}
}
$navigation .= ')';
return $navigation;
}
示例4: getResultText
protected function getResultText(SMWQueryResult $res, $outputmode)
{
if ($this->mFormat == 'template' && $this->mTemplate == false) {
$res->addErrors(array(wfMessage('smw_notemplategiven')->inContentLanguage()->text()));
return '';
}
// Determine mark-up strings used around list items:
if ($this->mFormat == 'ul' || $this->mFormat == 'ol') {
$header = "<" . $this->mFormat . ">\n";
$footer = "</" . $this->mFormat . ">\n";
$rowstart = "\t<li>";
$rowend = "</li>\n";
$plainlist = false;
} else {
// "list" and "template" format
$header = '';
$footer = '';
$rowstart = '';
$rowend = '';
$plainlist = true;
}
if ($this->mSep !== '') {
// always respect custom separator
$listsep = $this->mSep;
$finallistsep = $listsep;
} elseif ($this->mFormat == 'list') {
// make default list ", , , and "
// TODO: No default separator for "ul" and "ol" to not break
// compatibility with SMW pre 1.7.1. But they really should have
// default separators, i.e. the check should be for
// $this->mFormat !== 'template'
$listsep = ', ';
$finallistsep = wfMessage('smw_finallistconjunct')->inContentLanguage()->text() . ' ';
} else {
// no default separators for format "template", "ul", "ol"
$listsep = '';
$finallistsep = '';
}
// Initialise more values
$result = '';
$column_width = 0;
$rows_per_column = -1;
// usually unnecessary
$rows_in_cur_column = -1;
// Set up floating divs, if there's more than one column
if ($this->mColumns > 1) {
$column_width = floor(100 / $this->mColumns);
$result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n";
$rows_per_column = ceil($res->getCount() / $this->mColumns);
$rows_in_cur_column = 0;
}
if ($header !== '') {
$result .= $header;
}
if ($this->mIntroTemplate !== '') {
$result .= "{{" . $this->mIntroTemplate . "}}";
}
// Now print each row
$rownum = -1;
while ($row = $res->getNext()) {
$this->printRow($row, $rownum, $rows_in_cur_column, $rows_per_column, $this->mFormat, $plainlist, $header, $footer, $rowstart, $rowend, $result, $column_width, $res, $listsep, $finallistsep);
}
if ($this->mOutroTemplate !== '') {
$result .= "{{" . $this->mOutroTemplate . "}}";
}
// Make label for finding further results
if ($this->linkFurtherResults($res) && ($this->mFormat != 'ol' || $this->getSearchLabel(SMW_OUTPUT_WIKI))) {
$this->showFurtherResults($result, $res, $rowstart, $rowend, $outputmode);
}
// Print footer
if ($footer !== '') {
$result .= $footer;
}
if ($this->mColumns > 1) {
$result .= "</div>\n";
}
if ($this->mColumns > 1) {
$result .= '<br style="clear: both" />' . "\n";
}
// Make sure that if the result set turns empty and if available display default
if ($this->params['default'] !== '' && $result === '') {
$result = $this->params['default'];
}
return $result;
}
示例5: getResultText
protected function getResultText(SMWQueryResult $res, $outputmode)
{
global $wgContLang;
// <H3> will generate TOC entries otherwise. Probably need another way
// to accomplish this -- user might still want TOC for other page content.
$result = '__NOTOC__';
$num = $res->getCount();
$prev_first_char = "";
$rows_per_column = ceil($num / $this->mNumColumns);
// column width is a percentage
$column_width = floor(100 / $this->mNumColumns);
// Print all result rows:
$rowindex = 0;
$row = $res->getNext();
while ($row !== false) {
$nextrow = $res->getNext();
// look ahead
$content = $row[0]->getContent();
$cur_first_char = $wgContLang->firstChar($content[0]->getDIType() == SMWDataItem::TYPE_WIKIPAGE ? $res->getStore()->getWikiPageSortKey($content[0]) : $content[0]->getSortKey());
if ($rowindex % $rows_per_column == 0) {
$result .= "\n\t\t\t<div style=\"float: left; width: {$column_width}%;\">\n";
if ($cur_first_char == $prev_first_char) {
$result .= "\t\t\t\t<h3>{$cur_first_char} " . wfMessage('listingcontinuesabbrev')->text() . "</h3>\n\t\t\t\t<ul>\n";
}
}
// if we're at a new first letter, end
// the last list and start a new one
if ($cur_first_char != $prev_first_char) {
if ($rowindex % $rows_per_column > 0) {
$result .= "\t\t\t\t</ul>\n";
}
$result .= "\t\t\t\t<h3>{$cur_first_char}</h3>\n\t\t\t\t<ul>\n";
}
$prev_first_char = $cur_first_char;
$result .= '<li>';
$first_col = true;
if ($this->mTemplate !== '') {
// build template code
$this->hasTemplates = true;
$wikitext = $this->mUserParam ? "|userparam={$this->mUserParam}" : '';
$i = 1;
// explicitly number parameters for more robust parsing (values may contain "=")
foreach ($row as $field) {
$wikitext .= '|' . $i++ . '=';
$first_value = true;
while (($text = $field->getNextText(SMW_OUTPUT_WIKI, $this->getLinker($first_col))) !== false) {
if ($first_value) {
$first_value = false;
} else {
$wikitext .= $this->mDelim . ' ';
}
$wikitext .= $text;
}
$first_col = false;
}
$wikitext .= "|#={$rowindex}";
$result .= '{{' . $this->mTemplate . $wikitext . '}}';
// str_replace('|', '|', // encode '|' for use in templates (templates fail otherwise) -- this is not the place for doing this, since even DV-Wikitexts contain proper "|"!
} else {
// build simple list
$first_col = true;
$found_values = false;
// has anything but the first column been printed?
foreach ($row as $field) {
$first_value = true;
while (($text = $field->getNextText(SMW_OUTPUT_WIKI, $this->getLinker($first_col))) !== false) {
if (!$first_col && !$found_values) {
// first values after first column
$result .= ' (';
$found_values = true;
} elseif ($found_values || !$first_value) {
// any value after '(' or non-first values on first column
$result .= ', ';
}
if ($first_value) {
// first value in any column, print header
$first_value = false;
if ($this->mShowHeaders && $field->getPrintRequest()->getLabel() !== '') {
$result .= $field->getPrintRequest()->getText(SMW_OUTPUT_WIKI, $this->mLinker) . ' ';
}
}
$result .= $text;
// actual output value
}
$first_col = false;
}
if ($found_values) {
$result .= ')';
}
}
$result .= '</li>';
$row = $nextrow;
// end list if we're at the end of the column
// or the page
if (($rowindex + 1) % $rows_per_column == 0 && $rowindex + 1 < $num) {
$result .= "\t\t\t\t</ul>\n\t\t\t</div> <!-- end column -->";
}
$rowindex++;
}
// Make label for finding further results
//.........这里部分代码省略.........
示例6: getResultText
protected function getResultText( SMWQueryResult $res, $outputmode ) {
if ( ( $this->mFormat == 'template' ) && ( $this->mTemplate == false ) ) {
$res->addErrors( array( wfMsgForContent( 'smw_notemplategiven' ) ) );
return '';
}
// Determine mark-up strings used around list items:
if ( ( $this->mFormat == 'ul' ) || ( $this->mFormat == 'ol' ) ) {
$header = "<" . $this->mFormat . ">\n";
$footer = "</" . $this->mFormat . ">\n";
$rowstart = "\t<li>";
$rowend = "</li>\n";
$plainlist = false;
$finallistsep = '';
$listsep = '';
} else { // "list" and "template" format
$header = '';
$footer = '';
$rowstart = '';
$rowend = '';
$plainlist = true;
if ( $this->mSep !== '' ) { // always respect custom separator
$listsep = $this->mSep;
$finallistsep = $listsep;
} elseif ( $this->mFormat == 'list' ) { // make default list ", , , and "
$listsep = ', ';
$finallistsep = wfMsgForContent( 'smw_finallistconjunct' ) . ' ';
} else { // no default separators for format "template"
$listsep = '';
$finallistsep = '';
}
}
// Initialise more values
$result = '';
$column_width = 0;
$rows_per_column = -1; // usually unnecessary
$rows_in_cur_column = -1;
// Set up floating divs, if there's more than one column
if ( $this->mColumns > 1 ) {
$column_width = floor( 100 / $this->mColumns );
$result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n";
$rows_per_column = ceil( $res->getCount() / $this->mColumns );
$rows_in_cur_column = 0;
}
if ( $header !== '' ) {
$result .= $header;
}
if ( $this->mIntroTemplate !== '' ) {
$result .= "{{" . $this->mIntroTemplate . "}}";
}
// Now print each row
$rownum = -1;
while ( $row = $res->getNext() ) {
$this->printRow( $row, $rownum, $rows_in_cur_column,
$rows_per_column, $this->mFormat, $plainlist,
$header, $footer, $rowstart, $rowend, $result,
$column_width, $res, $listsep, $finallistsep );
}
if ( $this->mOutroTemplate !== '' ) {
$result .= "{{" . $this->mOutroTemplate . "}}";
}
// Make label for finding further results
if ( $this->linkFurtherResults( $res ) && ( ( $this->mFormat != 'ol' ) || ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) ) ) {
$this->showFurtherResults( $result, $res, $rowstart, $rowend );
}
// Print footer
if ( $footer !== '' ) {
$result .= $footer;
}
if ( $this->mColumns > 1 ) {
$result .= "</div>\n";
}
if ( $this->mColumns > 1 ) {
$result .= '<br style="clear: both" />' . "\n";
}
return $result;
}
示例7: getResultText
/**
* Returns a string that is to be sent to the caller
*
* @param SMWQueryResult $res
* @param integer $outputMode
*
* @return string
*/
protected function getResultText(SMWQueryResult $res, $outputMode)
{
if ($outputMode == SMW_OUTPUT_FILE) {
if ($res->getCount() == 0) {
$res->addErrors(array(wfMessage('smw_result_noresults')->inContentLanguage()->text()));
return '';
}
$result = $this->getFeed($res, $this->params['type']);
} else {
// Points to the Feed link
$result = $this->getLink($res, $outputMode)->getText($outputMode, $this->mLinker);
$this->isHTML = $outputMode == SMW_OUTPUT_HTML;
}
return $result;
}
示例8: getResult
/**
* Main entry point: takes an SMWQueryResult and parameters given as key-value-pairs in an array,
* and returns the serialised version of the results, formatted as HTML or Wiki or whatever is
* specified. Normally this is not overwritten by subclasses.
*
* If the outputmode is SMW_OUTPUT_WIKI, then the function will return something that is suitable
* for being used in a MediaWiki parser function, i.e. a wikitext strong *or* an array with flags
* and the string as entry 0. See Parser::setFunctionHook() for documentation on this. In all other
* cases, the function returns just a string.
*
* For outputs SMW_OUTPUT_WIKI and SMW_OUTPUT_HTML, error messages or standard "further results" links
* are directly generated and appended. For SMW_OUTPUT_FILE, only the plain generated text is returned.
*
* @note A note on recursion: some query printers may return wiki code that comes from other pages,
* e.g. from templates that are used in formatting or from embedded result pages. Both kinds of pages
* may contain \#ask queries that do again use new pages, so we must care about recursion. We do so
* by simply counting how often this method starts a subparse and stopping at depth 2. There is one
* special case: if this method is called outside parsing, and the concrete printer returns wiki text,
* and wiki text is requested, then we may return wiki text with sub-queries to the caller. If the
* caller parses this (which is likely) then this will again call us in parse-context and all recursion
* checks catch. Only the first level of parsing is done outside and thus not counted. Thus you
* effectively can get down to level 3. The basic maximal depth of 2 can be changed by setting the
* variable SMWResultPrinter::$maxRecursionDepth (in LocalSettings.php, after enableSemantics()).
* Do this at your own risk.
*
* @param $results SMWQueryResult
* @param $params array
* @param $outputmode integer
*
* @return string
*/
public function getResult(SMWQueryResult $results, array $params, $outputmode)
{
$this->isHTML = false;
$this->hasTemplates = false;
$this->handleParameters($params, $outputmode);
// Default output for normal printers:
if ($outputmode != SMW_OUTPUT_FILE && $results->getCount() == 0 && $this->getMimeType($results) === false) {
// normal printer -> take over processing
if (!$results->hasFurtherResults()) {
return $this->escapeText($this->mDefault, $outputmode) . $this->getErrorString($results);
} elseif ($this->mInline) {
$label = $this->mSearchlabel;
if ($label === null) {
// apply defaults
$label = wfMsgForContent('smw_iq_moreresults');
}
if ($label !== '') {
$link = $results->getQueryLink($this->escapeText($label, $outputmode));
$result = $link->getText($outputmode, $this->mLinker);
} else {
$result = '';
}
$result .= $this->getErrorString($results);
return $result;
}
}
// Get output from printer:
$result = $this->getResultText($results, $outputmode);
if ($outputmode != SMW_OUTPUT_FILE) {
$result = $this->handleNonFileResult($result, $results, $outputmode);
}
if ($GLOBALS['wgDBtype'] == 'postgres') {
$result = pg_unescape_bytea($result);
}
return $result;
}
示例9: __construct
/**
* Constructor
*
* @param SMWQueryResult $res
*/
public function __construct(SMWQueryResult $res)
{
$this->results = $res;
$this->count = $res->getCount();
}
示例10: buildResult
/**
* Build and return the HTML result.
*
* @since 1.8
*
* @param SMWQueryResult $results
*
* @return string
*/
protected function buildResult(SMWQueryResult $results)
{
$this->isHTML = false;
$this->hasTemplates = false;
$outputMode = $this->outputMode;
// Default output for normal printers:
if ($outputMode !== SMW_OUTPUT_FILE && $results->getCount() == 0) {
if (!$results->hasFurtherResults()) {
return $this->escapeText($this->mDefault, $outputMode) . $this->getErrorString($results);
} elseif ($this->mInline) {
return $this->getFurtherResultsLink($results, $outputMode)->getText($outputMode, $this->mLinker) . $this->getErrorString($results);
}
}
// Get output from printer:
$result = $this->getResultText($results, $outputMode);
if ($outputMode !== SMW_OUTPUT_FILE) {
$result = $this->handleNonFileResult($result, $results, $outputMode);
}
if ($GLOBALS['wgDBtype'] == 'postgres') {
$result = pg_unescape_bytea($result);
}
return $result;
}