/** * init some needed objects and variables */ protected function init() { //$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager'); $this->eventRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_CzSimpleCal_Domain_Repository_EventRepository'); $this->indexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_CzSimpleCal_Indexer_Event'); $this->persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManager'); try { $this->maxExecutionTime = intval(ini_get('max_execution_time')); } catch (Exception $e) { } if (!$this->maxExecutionTime || $this->maxExecutionTime < 5) { // if value could not be determined or it seems faulty $this->maxExecutionTime = 30; } try { $memoryLimit = ini_get('memory_limit'); $this->memoryLimit = \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement($memoryLimit); } catch (Exception $e) { } if (!$this->memoryLimit || $this->memoryLimit < 0x2000000) { // if value could not be determined or it seems faulty $this->memoryLimit = 0x2000000; // =32M } $this->minIndexAgeAbsolute = $this->minIndexAge ? Tx_CzSimpleCal_Utility_StrToTime::strtotime($this->minIndexAge) : null; }
public function testWeeksStartWithMonday() { self::assertEquals(strtotime('2009-02-02 00:00:00GMT'), Tx_CzSimpleCal_Utility_StrToTime::strtotime('monday this week', strtotime('2009-02-08 00:00:00')), '"monday this week" when on a sunday'); self::assertEquals(strtotime('2009-02-02 00:00:00GMT'), Tx_CzSimpleCal_Utility_StrToTime::strtotime('monday this week', strtotime('2009-02-02 00:00:00')), '"monday this week" when on a monday'); self::assertEquals(strtotime('2009-02-08 00:00:00GMT'), Tx_CzSimpleCal_Utility_StrToTime::strtotime('sunday this week', strtotime('2009-02-08 00:00:00')), '"sunday this week" when on a sunday'); self::assertEquals(strtotime('2009-02-08 00:00:00GMT'), Tx_CzSimpleCal_Utility_StrToTime::strtotime('sunday this week', strtotime('2009-02-02 00:00:00')), '"sunday this week" when on a monday'); self::assertEquals(strtotime('2009-12-28 00:00:00GMT'), Tx_CzSimpleCal_Utility_StrToTime::strtotime('monday this week', strtotime('2010-01-01 00:00:00')), '"monday this week" on a year switch'); }
/** * do grouping by some time related constraint * * @param Tx_Extbase_Persistence_QueryResultInterface $events * @param string $string * @return array */ protected function groupByTime($events, $string) { $result = array(); foreach ($events as $event) { $key = Tx_CzSimpleCal_Utility_StrToTime::strtotime($string, $event->getStart()); if (!array_key_exists($key, $result)) { $result[$key] = array('info' => $key, 'events' => array()); } $result[$key]['events'][] = $event; } return $result; }
/** * normalizes anything that describes a time * and sets it to be a timestamp * * @param mixed $value * @return void */ protected function normalizeArgumentToTimestamp($value) { if (empty($value)) { return; } elseif (is_numeric($value)) { return \TYPO3\CMS\Core\Utility\GeneralUtility::intInRange($this->argumentName, 0); } elseif (is_string($value)) { return Tx_CzSimpleCal_Utility_StrToTime::strtotime($value); } elseif ($value instanceof DateTime) { return intval($value->format('U')); } return; }
/** * Validates the additional fields' values * * @param array An array containing the data submitted by the add/edit task form * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController Reference to the scheduler backend module * @return boolean True if validation was ok (or selected class is not relevant), false otherwise */ public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) { if (empty($submittedData['tx_czsimplecal_minindexage'])) { $submittedData['tx_czsimplecal_minindexage'] = null; } elseif (!is_string($submittedData['tx_czsimplecal_minindexage'])) { $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:cz_simple_cal/Resources/Private/Language/locallang_mod.xml:tx_czsimplecal_scheduler_index.minindexage.nostring'), t3lib_FlashMessage::ERROR); return false; } else { if (Tx_CzSimpleCal_Utility_StrToTime::strtotime($submittedData['tx_czsimplecal_minindexage']) === false) { $schedulerModule->addMessage(sprintf($GLOBALS['LANG']->sL('LLL:EXT:cz_simple_cal/Resources/Private/Language/locallang_mod.xml:tx_czsimplecal_scheduler_index.minindexage.parseerror'), $submittedData['tx_czsimplecal_minindexage']), t3lib_FlashMessage::ERROR); return false; } } return true; }
public function isValid($value) { $setterMethodName = 'set' . $this->options['propertyName']; $getterMethodName = 'get' . $this->options['propertyName']; $object = $this->options['object']; // check that value and domain property match if ($value != $object->{$getterMethodName}()) { throw new RuntimeException('the given value and the value of the object don\'t match in ' . get_class($this)); } // required if (empty($value)) { if ($this->options['required']) { $this->addError('no value given', 'required'); return false; } else { return true; } } // sanitize input if (is_numeric($value) && $value > 0) { $object->{$setterMethodName}(intval($value)); $value = intval($value); } else { $day = Tx_CzSimpleCal_Utility_StrToTime::strtotime($value . ' | 00:00'); if ($day === false) { $this->addError('could not be parsed.', 'parseError'); return false; } else { $object->{$setterMethodName}($day); $value = $day; } } // minimum if ($this->options['minimum']) { if ($value < $this->options['minimum']) { $this->addError(sprintf('No dates before %s allowed.', strftime('%Y-%m-%d', $this->options['minimum'])), 'minimum'); return false; } } // maximum if ($this->options['maximum']) { if ($value > $this->options['maximum']) { $this->addError(sprintf('No dates after %s allowed.', strftime('%Y-%m-%d', $this->options['maximum'])), 'maximum'); return false; } } return true; }
/** * test the next view */ public function testActionNext() { $this->openPageAlias('action-next'); $this->assertElementPresent('css=div.vcalendar-next', 'next-view is shown'); $this->assertEquals(1, $this->selenium->getXpathCount('//*[contains(@class, "vevent")]'), 'only one event is shown'); $firstDate = $this->getDateOfFirstEvent(); $minDate = Tx_CzSimpleCal_Utility_StrToTime::strtotime('now'); $maxDate = Tx_CzSimpleCal_Utility_StrToTime::strtotime('+2 days'); $this->assertGreaterThanOrEqual($minDate, $firstDate, 'event starts later than now'); $this->assertLessThanOrEqual($maxDate, $firstDate, 'event start before the next two days'); // no further tests as all other settings were tested in the list-action }
/** * do the modification to a relative date * * @param $timestamp * @param $get * @return string */ protected function modifyDate($timestamp, $get) { return Tx_CzSimpleCal_Utility_StrToTime::strtotime($get, $timestamp); }
/** * validate an Event submitted by the user * * @return bool */ public function isValid($value) { // title $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_StringLengthValidator'); $validator->setOptions(array('minimum' => 3, 'maximum' => 255)); $this->addPropertyValidator('title', $validator); // startDay $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_DateValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'startDay', 'required' => true, 'minimum' => Tx_CzSimpleCal_Utility_StrToTime::strtotime('midnight'))); $this->addPropertyValidator('startDay', $validator); // startTime $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_TimeValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'startTime', 'required' => false)); $this->addPropertyValidator('startTime', $validator); // endDay $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_DateValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'endDay', 'required' => false, 'minimum' => Tx_CzSimpleCal_Utility_StrToTime::strtotime('midnight'))); $this->addPropertyValidator('endDay', $validator); // endTime $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_TimeValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'endTime', 'required' => false)); $this->addPropertyValidator('endTime', $validator); // description $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_DisjunctionValidator'); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_NoTagsValidator')); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_EmptyValidator')); $this->addPropertyValidator('description', $validator); // locationName $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_DisjunctionValidator'); $stringValidator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_StringLengthValidator'); $stringValidator->setOptions(array('minimum' => 3, 'maximum' => 255)); $validator->addValidator($stringValidator); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_EmptyValidator')); $this->addPropertyValidator('locationName', $validator); // locationAddress $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_DisjunctionValidator'); $stringValidator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_StringLengthValidator'); $stringValidator->setOptions(array('minimum' => 3, 'maximum' => 255)); $validator->addValidator($stringValidator); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_EmptyValidator')); $this->addPropertyValidator('locationAddress', $validator); // locationCity $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_DisjunctionValidator'); $stringValidator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_StringLengthValidator'); $stringValidator->setOptions(array('minimum' => 3, 'maximum' => 255)); $validator->addValidator($stringValidator); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_EmptyValidator')); $this->addPropertyValidator('locationCity', $validator); // showPageInstead $validator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_DisjunctionValidator'); $andValidator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_ConjunctionValidator'); $stringValidator = $this->getObjectManager()->get('Tx_Extbase_Validation_Validator_StringLengthValidator'); $stringValidator->setOptions(array('minimum' => 10, 'maximum' => 255)); $andValidator->addValidator($stringValidator); $urlValidator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_UrlValidator'); $urlValidator->setOptions(array('object' => $value, 'propertyName' => 'showPageInstead')); $andValidator->addValidator($urlValidator); $validator->addValidator($andValidator); $validator->addValidator($this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_EmptyValidator')); $this->addPropertyValidator('showPageInstead', $validator); // twitterHashtags $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_TwitterHashtagValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'twitterHashtags', 'required' => false)); $this->addPropertyValidator('twitterHashtags', $validator); // flickrTags $validator = $this->getObjectManager()->get('Tx_CzSimpleCal_Domain_Validator_FlickrTagValidator'); $validator->setOptions(array('object' => $value, 'propertyName' => 'flickrTags', 'required' => false)); $this->addPropertyValidator('flickrTags', $validator); $isValid = parent::isValid($value); // check: event does not end before it starts if ($value->getDateTimeObjectStart()->getTimestamp() > $value->getDateTimeObjectEnd()->getTimestamp()) { $this->addError('This event is not allowed to start before it ends.', 1316261470); $isValid = false; } // prevent descriptions from having tags (will be parsed with parsefunc_RTE $value->setDescription(htmlspecialchars($value->getDescription(), null, null, false)); return $isValid; }