/**
  * @covers ::smwfHTMLtoUTF8
  * @test smwfHTMLtoUTF8
  *
  * @since 1.9
  */
 public function testSmwfHTMLtoUTF8()
 {
     $result = smwfHTMLtoUTF8("Ĉio bonas dans l'école, Ĉio bonas dans l'école!");
     $expected = "Ĉio bonas dans l'école, Ĉio bonas dans l'école!";
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 2
0
 /**
  * Create an SWMExpElement that encodes the data of the given
  * dataitem object. This method is meant to be used when exporting a
  * dataitem as a subject or object. To get the URI of a property, use
  * SMWExporter::getResourceElementForProperty() or
  * SMWExporter::getSpecialPropertyResource().
  * 
  * @param $dataItem SMWDataItem
  * @return SMWExpElement
  */
 public static function getDataItemExpElement(SMWDataItem $dataItem)
 {
     switch ($dataItem->getDIType()) {
         case SMWDataItem::TYPE_NUMBER:
             $lit = new SMWExpLiteral($dataItem->getNumber(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem);
             return $lit;
         case SMWDataItem::TYPE_STRING:
         case SMWDataItem::TYPE_BLOB:
             $lit = new SMWExpLiteral(smwfHTMLtoUTF8($dataItem->getString()), 'http://www.w3.org/2001/XMLSchema#string', $dataItem);
             return $lit;
         case SMWDataItem::TYPE_BOOLEAN:
             $xsdvalue = $dataItem->getBoolean() ? 'true' : 'false';
             $lit = new SMWExpLiteral($xsdvalue, 'http://www.w3.org/2001/XMLSchema#boolean', $dataItem);
             return $lit;
         case SMWDataItem::TYPE_URI:
             $res = new SMWExpResource($dataItem->getURI(), $dataItem);
             return $res;
         case SMWDataItem::TYPE_TIME:
             $gregorianTime = $dataItem->getForCalendarModel(SMWDITime::CM_GREGORIAN);
             if ($gregorianTime->getYear() > 0) {
                 $xsdvalue = str_pad($gregorianTime->getYear(), 4, "0", STR_PAD_LEFT);
             } else {
                 $xsdvalue = '-' . str_pad(1 - $gregorianTime->getYear(), 4, "0", STR_PAD_LEFT);
             }
             $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYear';
             if ($gregorianTime->getPrecision() >= SMWDITime::PREC_YM) {
                 $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYearMonth';
                 $xsdvalue .= '-' . str_pad($gregorianTime->getMonth(), 2, "0", STR_PAD_LEFT);
                 if ($gregorianTime->getPrecision() >= SMWDITime::PREC_YMD) {
                     $xsdtype = 'http://www.w3.org/2001/XMLSchema#date';
                     $xsdvalue .= '-' . str_pad($gregorianTime->getDay(), 2, "0", STR_PAD_LEFT);
                     if ($gregorianTime->getPrecision() == SMWDITime::PREC_YMDT) {
                         $xsdtype = 'http://www.w3.org/2001/XMLSchema#dateTime';
                         $xsdvalue .= 'T' . sprintf("%02d", $gregorianTime->getHour()) . ':' . sprintf("%02d", $gregorianTime->getMinute()) . ':' . sprintf("%02d", $gregorianTime->getSecond());
                     }
                 }
             }
             $xsdvalue .= 'Z';
             $lit = new SMWExpLiteral($xsdvalue, $xsdtype, $gregorianTime);
             return $lit;
         case SMWDataItem::TYPE_GEO:
             /// TODO
             return null;
         case SMWDataItem::TYPE_CONTAINER:
             return self::makeExportData($dataItem->getSemanticData());
         case SMWDataItem::TYPE_WIKIPAGE:
             return self::getResourceElementForWikiPage($dataItem);
         case SMWDataItem::TYPE_CONCEPT:
             /// TODO
             return null;
         case SMWDataItem::TYPE_PROPERTY:
             return self::getResourceElementForProperty($dataItem);
     }
 }
 private function parseToStringValue(DIBlob $dataItem)
 {
     $this->xsdValue = smwfHTMLtoUTF8($dataItem->getString());
     $this->xsdType = 'http://www.w3.org/2001/XMLSchema#string';
 }