/**
  * @since  1.9
  *
  * @param ParserParameterProcessor $parameters
  *
  * @return string|null
  */
 public function parse(ParserParameterProcessor $parameters)
 {
     $count = 0;
     $template = '';
     $subject = $this->parserData->getSemanticData()->getSubject();
     $parametersToArray = $parameters->toArray();
     if (isset($parametersToArray['template'])) {
         $template = $parametersToArray['template'][0];
         unset($parametersToArray['template']);
     }
     foreach ($parametersToArray as $property => $values) {
         $last = count($values) - 1;
         // -1 because the key starts with 0
         foreach ($values as $key => $value) {
             $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject);
             if ($this->parserData->canModifySemanticData()) {
                 $this->parserData->addDataValue($dataValue);
             }
             $this->messageFormatter->addFromArray($dataValue->getErrors());
             $this->addFieldsToTemplate($template, $dataValue, $property, $value, $last == $key, $count);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml();
     return array($html, 'noparse' => $template === '', 'isHTML' => false);
 }
Ejemplo n.º 2
0
 /**
  * @since 1.9
  *
  * @param ArrayFormatter $params
  *
  * @return string|null
  */
 public function parse(ArrayFormatter $parameters)
 {
     $this->addDataValuesToSubobject($parameters);
     $this->parserData->getSemanticData()->addSubobject($this->subobject);
     $this->parserData->pushSemanticDataToParserOutput();
     return $this->messageFormatter->addFromArray($this->subobject->getErrors())->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml();
 }
Ejemplo n.º 3
0
 /**
  * @since  1.9
  *
  * @param ArrayFormatter $parameters
  *
  * @return string|null
  */
 public function parse(ArrayFormatter $parameters)
 {
     $subject = $this->parserData->getSemanticData()->getSubject();
     foreach ($parameters->toArray() as $property => $values) {
         foreach ($values as $value) {
             $dataValue = DataValueFactory::getInstance()->newPropertyValue($property, $value, false, $subject);
             $this->parserData->addDataValue($dataValue);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     return $this->messageFormatter->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml();
 }
 /**
  * @dataProvider exceptionDataProvider
  *
  * InvalidPropertyException is thrown but caught and returning with a
  * SMWDIError instead
  *
  * @since 1.9
  */
 public function testInvalidPropertyException($property)
 {
     $instance = $this->newInstance($property);
     $results = $instance->getResults();
     $this->assertInternalType('array', $results);
     $this->assertEquals(1, $instance->getCount());
     $this->assertInstanceOf('SMWDIError', $results[0]);
     $this->assertContains($property, MessageFormatter::newFromArray($this->getLanguage(), array($results[0]->getErrors()))->getHtml());
 }
 /**
  * @test MessageFormatter::newFromArray
  * @test MessageFormatter::setType
  * @test MessageFormatter::getHtml
  * @dataProvider getDataProvider
  *
  * @since  1.9
  *
  * @param array $messages
  */
 public function testNewFromArray(array $messages)
 {
     $instance = MessageFormatter::newFromArray($this->getLanguage(), $messages);
     $instance->setType('error');
     $this->assertInternalType('string', $instance->getHtml());
     $instance->setType('warning');
     $this->assertInternalType('string', $instance->getHtml());
     $instance->setType('info');
     $this->assertInternalType('string', $instance->getHtml());
 }
 /**
  * Parse parameters, return concept information box and update the
  * ParserOutput with the concept object
  *
  * @since 1.9
  *
  * @param array $params
  *
  * @return string|null
  */
 public function parse(array $rawParams)
 {
     $this->parserData->getOutput()->addModules('ext.smw.style');
     $title = $this->parserData->getTitle();
     $property = new DIProperty('_CONC');
     if (!($title->getNamespace() === SMW_NS_CONCEPT)) {
         return $this->messageFormatter->addFromKey('smw_no_concept_namespace')->getHtml();
     } elseif (count($this->parserData->getSemanticData()->getPropertyValues($property)) > 0) {
         return $this->messageFormatter->addFromKey('smw_multiple_concepts')->getHtml();
     }
     // Remove parser object from parameters array
     if (isset($rawParams[0]) && $rawParams[0] instanceof Parser) {
         array_shift($rawParams);
     }
     // Use first parameter as concept (query) string
     $conceptQuery = array_shift($rawParams);
     // Use second parameter, if any as a description
     $conceptDocu = array_shift($rawParams);
     $query = $this->buildQuery($conceptQuery);
     $conceptQueryString = $query->getDescription()->getQueryString();
     $this->parserData->getSemanticData()->addPropertyObjectValue($property, new DIConcept($conceptQueryString, $conceptDocu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth()));
     $this->messageFormatter->addFromArray($query->getErrors())->addFromArray($this->parserData->getErrors());
     $this->addQueryProfile($query);
     $this->parserData->pushSemanticDataToParserOutput();
     if ($this->messageFormatter->exists()) {
         return $this->messageFormatter->getHtml();
     }
     return $this->buildConceptInfoBox($title, $conceptQueryString, $conceptDocu);
 }
 /**
  * @since 1.9
  *
  * @param ParserParameterProcessor $params
  *
  * @return string|null
  */
 public function parse(ParserParameterProcessor $parameters)
 {
     if ($this->parserData->canModifySemanticData() && $this->addDataValuesToSubobject($parameters) && !$this->subobject->getSemanticData()->isEmpty()) {
         $this->parserData->getSemanticData()->addSubobject($this->subobject);
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->messageFormatter->addFromArray($this->subobject->getErrors())->addFromArray($this->parserData->getErrors())->addFromArray($parameters->getErrors())->getHtml();
     // An empty output in MW forces an extra <br> element.
     //if ( $html == '' ) {
     //	$html = '<p></p>';
     //}
     return $html;
 }
Ejemplo n.º 8
0
 /**
  * @since  1.9
  *
  * @param ArrayFormatter $parameters
  *
  * @return string|null
  */
 public function parse(ArrayFormatter $parameters)
 {
     $count = 0;
     $template = '';
     $subject = $this->parserData->getSemanticData()->getSubject();
     $parametersToArray = $parameters->toArray();
     if (isset($parametersToArray['template'])) {
         $template = $parametersToArray['template'][0];
         unset($parametersToArray['template']);
     }
     foreach ($parametersToArray as $property => $values) {
         foreach ($values as $value) {
             $dataValue = DataValueFactory::getInstance()->newPropertyValue($property, $value, false, $subject);
             $this->parserData->addDataValue($dataValue);
             $this->messageFormatter->addFromArray($dataValue->getErrors());
             $this->addFieldsToTemplate($template, $dataValue, $property, $value, $count);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml();
     return array($html, 'noparse' => true, 'isHTML' => true);
 }
 /**
  * {{#ask}} is disabled (see $smwgQEnabled)
  *
  * @since 1.9
  *
  * @return string|null
  */
 public function isQueryDisabled()
 {
     return $this->messageFormatter->addFromKey('smw_iq_disabled')->getHtml();
 }