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; }
/** * This method renders the result set provided by SMW according to the printer * * @param res SMWQueryResult, result set of the ask query provided by SMW * @param outputmode ? * @return String, rendered HTML output of this printer for the ask-query * */ protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( !is_callable( 'renderGraphviz' ) ) { wfWarn( 'The SRF Graph printer needs the GraphViz extension to be installed.' ); return ''; } global $wgContLang; // content language object // // GraphViz settings // global $wgGraphVizSettings; $this->isHTML = true; // // Iterate all rows in result set // $row = $res->getNext(); // get initial row (i.e. array of SMWResultArray) while ( $row !== false ) { $subject = $row[0]->getResultSubject(); // get Subject of the Result // creates a new node if $val has type wikipage if ( $subject->getTypeID() == '_wpg' ) { $val = $subject->getShortWikiText(); $node = $this->m_process->makeNode( $val, $val ); } // // Iterate all colums of the row (which describe properties of the proces node) // foreach ( $row as $field ) { // check column title $req = $field->getPrintRequest(); switch ( ( strtolower( $req->getLabel() ) ) ) { case strtolower( $wgContLang->getNsText( NS_CATEGORY ) ): foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); if ( $val == ( $wgContLang->getNsText( NS_CATEGORY ) . ':' . $this->m_processCategory ) ) $node->setAtomic( false ); } break; case "haslabel": $value = current($field->getContent()); // save only the first if (($value !== false)) { $val = $value->getLongWikiText(); if ($this->m_process->getUseOtherLabels()) { $val = str_replace("&","and",$val); $node->setLabel($val); } } break; case "hasrole": foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $role = $this->m_process->makeRole( $val, $val ); $node->addRole( $role ); } break; case "usesresource": foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $xres = $this->m_process->makeRessource( $val, $val ); $node->addUsedRessource( $xres ); } break; case "producesresource": foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $xres = $this->m_process->makeRessource( $val, $val ); $node->addProducedRessource( $xres ); } break; case "hassuccessor": if ( count( $field->getContent() ) > 1 ) { // SplitParallel $edge = new SplitParallelEdge(); $edge->setFrom( $node ); foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $edge->addTo( $this->m_process->makeNode( $val, $val ) ); } } else { // Sequence foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $edge = new SequentialEdge(); $edge->setFrom( $node ); $edge->setTo( $this->m_process->makeNode( $val, $val ) ); } } break; case "hasorsuccessor": if ( count( $field->getContent() ) > 0 ) { // SplitExclusiveOr $edge = new SplitExclusiveOrEdge(); $edge->setFrom( $node ); foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $edge->addTo( $this->m_process->makeNode( $val, $val ) ); } } break; case "hascontruesuccessor": if ( count( $field->getContent() ) > 0 ) { // SplitConditional if ( !isset( $cond_edge ) ) { $cond_edge = new SplitConditionalOrEdge(); $cond_edge->setFrom( $node ); } // should be only one foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $cond_edge->setToTrue( $this->m_process->makeNode( $val, $val ) ); } } break; case "hasconfalsesuccessor": if ( count( $field->getContent() ) > 0 ) { // SplitConditional if ( !isset( $cond_edge ) ) { $cond_edge = new SplitConditionalOrEdge(); $cond_edge->setFrom( $node ); } // should be only one foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $cond_edge->setToFalse( $this->m_process->makeNode( $val, $val ) ); } } break; case "hascondition": if ( count( $field->getContent() ) > 0 ) { // SplitConditional if ( !isset( $cond_edge ) ) { $cond_edge = new SplitConditionalOrEdge(); $cond_edge->setFrom( $node ); } // should be only one foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $cond_edge->setConditionText( $val ); } } break; case "hasstatus": // should be only one foreach ( $field->getContent() as $value ) { $val = $value->getShortWikiText(); $node->setStatus( $val ); } break; default: // TODO - redundant column in result } } // reset row variables unset( $node ); unset( $cond_edge ); $row = $res->getNext(); // switch to next row } // // generate graphInput // $graphInput = $this->m_process->getGraphVizCode(); // // render graphViz code // $result = renderGraphviz( $graphInput ); $debug = ''; if ( $this->m_isDebugSet ) $debug = '<pre>' . $graphInput . '</pre>'; return $result . $debug; }