protected function createDataItemByPropertyId($propertyId)
 {
     $dataItem = null;
     switch ($propertyId) {
         case DIProperty::TYPE_MODIFICATION_DATE:
             $dataItem = DITime::newFromTimestamp($this->pageInfo->getModificationDate());
             break;
         case DIProperty::TYPE_CREATION_DATE:
             $dataItem = DITime::newFromTimestamp($this->pageInfo->getCreationDate());
             break;
         case DIProperty::TYPE_NEW_PAGE:
             $dataItem = new DIBoolean($this->pageInfo->isNewPage());
             break;
         case DIProperty::TYPE_LAST_EDITOR:
             $dataItem = $this->pageInfo->getLastEditor() ? DIWikiPage::newFromTitle($this->pageInfo->getLastEditor()) : null;
             break;
         case DIProperty::TYPE_MEDIA:
             $dataItem = $this->pageInfo->isFilePage() && $this->pageInfo->getMediaType() !== '' && $this->pageInfo->getMediaType() !== null ? new DIBlob($this->pageInfo->getMediaType()) : null;
             break;
         case DIProperty::TYPE_MIME:
             $dataItem = $this->pageInfo->isFilePage() && $this->pageInfo->getMimeType() !== '' && $this->pageInfo->getMimeType() !== null ? new DIBlob($this->pageInfo->getMimeType()) : null;
             break;
     }
     return $dataItem;
 }
 protected function createDataItemByPropertyId($propertyId)
 {
     $dataItem = null;
     switch ($propertyId) {
         case DIProperty::TYPE_MODIFICATION_DATE:
             $dataItem = DITime::newFromTimestamp($this->pageInfo->getModificationDate());
             break;
         case DIProperty::TYPE_CREATION_DATE:
             $dataItem = DITime::newFromTimestamp($this->pageInfo->getCreationDate());
             break;
         case DIProperty::TYPE_NEW_PAGE:
             $dataItem = new DIBoolean($this->pageInfo->isNewPage());
             break;
         case DIProperty::TYPE_LAST_EDITOR:
             $dataItem = $this->pageInfo->getLastEditor() ? DIWikiPage::newFromTitle($this->pageInfo->getLastEditor()) : null;
             break;
         case DIProperty::TYPE_MEDIA:
             // @codingStandardsIgnoreStart phpcs, ignore --sniffs=Generic.Files.LineLength
             $dataItem = $this->pageInfo->isFilePage() && $this->pageInfo->getMediaType() !== '' && $this->pageInfo->getMediaType() !== null ? new DIBlob($this->pageInfo->getMediaType()) : null;
             // @codingStandardsIgnoreEnd
             break;
         case DIProperty::TYPE_MIME:
             // @codingStandardsIgnoreStart phpcs, ignore --sniffs=Generic.Files.LineLength
             $dataItem = $this->pageInfo->isFilePage() && $this->pageInfo->getMimeType() !== '' && $this->pageInfo->getMimeType() !== null ? new DIBlob($this->pageInfo->getMimeType()) : null;
             // @codingStandardsIgnoreEnd
             break;
     }
     return $dataItem;
 }
 public function propertyObjectProvider()
 {
     $provider = array();
     // #0
     $provider[] = array(new DIProperty('_MDAT'), DITime::newFromTimestamp(1272508903));
     return $provider;
 }
 /**
  * @return array
  */
 public function removePropertyObjectProvider()
 {
     $provider = array();
     $title = Title::newFromText('Foo');
     // #0
     $provider[] = array($title, new DIProperty('_MDAT'), DITime::newFromTimestamp(1272508903));
     return $provider;
 }
 public function testPredefinedModificationDatePropertyAndChangedDefaultsortForNewPage()
 {
     $this->applicationFactory->getSettings()->set('smwgPageSpecialProperties', array('_MDAT'));
     $title = Title::newFromText(__METHOD__);
     $subject = DIWikiPage::newFromTitle($title);
     $this->pageCreator->createPage($title, '{{DEFAULTSORT:SortForFoo}}');
     $dvPageModificationTime = $this->dataValueFactory->newDataItemValue(DITime::newFromTimestamp($this->pageCreator->getPage()->getTimestamp()));
     $expected = array('propertyCount' => 2, 'propertyKeys' => array('_MDAT', '_SKEY'), 'propertyValues' => array($dvPageModificationTime->getISO8601Date(), 'SortForFoo'));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $this->getStore()->getSemanticData($subject));
 }
Exemple #6
0
 /**
  * @return array
  */
 public function removePropertyObjectProvider()
 {
     $provider = array();
     $title = Title::newFromText(__METHOD__);
     $subobject = $this->newSubobject($title, __METHOD__, '999');
     // #0
     $provider[] = array($title, new DIProperty('_MDAT'), DITime::newFromTimestamp(1272508903));
     // #1
     $provider[] = array($title, $subobject->getProperty(), $subobject->getContainer());
     return $provider;
 }
 public function testNewFromTimestamp()
 {
     $instance = DITime::newFromTimestamp('1362200400');
     $this->assertInstanceOf('\\SMWDITime', $instance);
 }
 protected function parseUserValue($value)
 {
     $value = trim($value);
     // ignore whitespace
     $this->m_wikivalue = $value;
     if ($this->m_caption === false) {
         // Store the caption now.
         $this->m_caption = $value;
     }
     $this->m_dataitem = null;
     /// TODO Direct JD input currently cannot cope with decimal numbers
     $datecomponents = array();
     $calendarmodel = $era = $hours = $minutes = $seconds = $timeoffset = false;
     // Check if it's parseable by wfTimestamp when it's not a year (which is wrongly interpreted).
     if (strlen($value) != 4 && wfTimestamp(TS_MW, $value) !== false) {
         $this->m_dataitem = SMWDITime::newFromTimestamp($value);
     } elseif ($this->parseDateString($value, $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset)) {
         if ($calendarmodel === false && $era === false && count($datecomponents) == 1 && intval(end($datecomponents)) >= 100000) {
             $calendarmodel = 'JD';
             // default to JD input if a single number was given as the date
         }
         if ($calendarmodel == 'JD' || $calendarmodel == 'MJD') {
             if ($era === false && $hours === false && $timeoffset == 0) {
                 try {
                     $jd = floatval(reset($datecomponents));
                     if ($calendarmodel == 'MJD') {
                         $jd += self::MJD_EPOCH;
                     }
                     $this->m_dataitem = SMWDITime::newFromJD($jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT, $this->m_typeid);
                 } catch (SMWDataItemException $e) {
                     $this->addError(wfMessage('smw_nodatetime', $this->m_wikivalue)->inContentLanguage()->text());
                 }
             } else {
                 $this->addError(wfMessage('smw_nodatetime', $this->m_wikivalue)->inContentLanguage()->text());
             }
         } else {
             $this->setDateFromParsedValues($datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset);
         }
     }
     if (is_null($this->m_dataitem)) {
         // make sure that m_dataitem is set in any case
         $this->m_dataitem = new SMWDITime(SMWDITime::CM_GREGORIAN, 32202);
     }
 }
 protected function parseUserValue($value)
 {
     $value = $this->convertDoubleWidth($value);
     $this->m_wikivalue = $value;
     if ($this->m_caption === false) {
         // Store the caption now.
         $this->m_caption = $value;
     }
     $this->m_dataitem = null;
     $datecomponents = array();
     $calendarmodel = $era = $hours = $minutes = $seconds = $microseconds = $timeoffset = $timezone = false;
     if ($this->isInterpretableAsYearOnly($value)) {
         $this->m_dataitem = new SMWDITime($this->getCalendarModel(null, $value, null, null), $value);
     } elseif ($this->isInterpretableAsTimestamp($value)) {
         $this->m_dataitem = SMWDITime::newFromTimestamp($value);
     } elseif ($this->parseDateString($value, $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $microseconds, $timeoffset, $timezone)) {
         if ($calendarmodel === false && $era === false && count($datecomponents) == 1 && intval(end($datecomponents)) >= 100000) {
             $calendarmodel = 'JD';
             // default to JD input if a single number was given as the date
         }
         if ($calendarmodel == 'JD' || $calendarmodel == 'MJD') {
             if ($era === false && $hours === false && $timeoffset == 0) {
                 try {
                     $jd = floatval(isset($datecomponents[1]) ? $datecomponents[0] . '.' . $datecomponents[1] : $datecomponents[0]);
                     if ($calendarmodel == 'MJD') {
                         $jd += self::MJD_EPOCH;
                     }
                     $this->m_dataitem = SMWDITime::newFromJD($jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT, $timezone);
                 } catch (SMWDataItemException $e) {
                     $this->addErrorMsg(array('smw-datavalue-time-invalid-jd', $this->m_wikivalue, $e->getMessage()));
                 }
             } else {
                 $this->addErrorMsg(array('smw-datavalue-time-invalid-jd', $this->m_wikivalue, "NO_EXCEPTION"));
             }
         } else {
             $this->setDateFromParsedValues($datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $microseconds, $timeoffset, $timezone);
         }
     }
     if (is_null($this->m_dataitem)) {
         // make sure that m_dataitem is set in any case
         $this->m_dataitem = new SMWDITime(SMWDITime::CM_GREGORIAN, 32202);
     }
 }