コード例 #1
0
 /**
  * PlanningUtility constructor.
  */
 public function __construct()
 {
     $this->objM = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     $this->sessionRepository = $this->objM->get(AnySessionRepository::class);
     $this->db = $GLOBALS['TYPO3_DB'];
     $dateTimeFormats = $this->db->getDateTimeFormats('tx_sessions_domain_model_session');
     $this->dbDateTimeFormat = $dateTimeFormats['datetime']['format'];
 }
コード例 #2
0
 /**
  * @test
  */
 public function addDataConvertsDateTimeStringToTimestamp()
 {
     $oldTimezone = date_default_timezone_get();
     date_default_timezone_set('UTC');
     $input = ['tableName' => 'aTable', 'processedTca' => ['columns' => ['aField' => ['config' => ['dbType' => 'datetime']]]], 'databaseRow' => ['aField' => '2015-07-27 15:25:32']];
     $expected = $input;
     $expected['databaseRow']['aField'] = 1438010732;
     // 27.07.2015 15:25:32 UTC
     $this->dbProphecy->getDateTimeFormats(Argument::cetera())->willReturn($this->dateFormats);
     $this->assertEquals($expected, $this->subject->addData($input));
     date_default_timezone_set($oldTimezone);
 }
コード例 #3
0
ファイル: DataHandler.php プロジェクト: rickymathew/TYPO3.CMS
 /**
  * Evaluate "input" type values.
  *
  * @param string $value The value to set.
  * @param array $tcaFieldConf Field configuration from TCA
  * @param string $table Table name
  * @param int $id UID of record
  * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
  * @param string $field Field name
  * @return array $res The result array. The processed value (if any!) is set in the "value" key.
  */
 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field)
 {
     // Handle native date/time fields
     $isDateOrDateTimeField = false;
     $format = '';
     $emptyValue = '';
     if (isset($tcaFieldConf['dbType']) && ($tcaFieldConf['dbType'] === 'date' || $tcaFieldConf['dbType'] === 'datetime')) {
         $isDateOrDateTimeField = true;
         $dateTimeFormats = $this->databaseConnection->getDateTimeFormats($table);
         // Convert the date/time into a timestamp for the sake of the checks
         $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
         $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
         // At this point in the processing, the timestamps are still based on UTC
         $timeZone = new \DateTimeZone('UTC');
         $dateTime = \DateTime::createFromFormat('!' . $format, $value, $timeZone);
         $value = $value === $emptyValue ? 0 : $dateTime->getTimestamp();
     }
     // Secures the string-length to be less than max.
     if ((int) $tcaFieldConf['max'] > 0) {
         $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, (string) $value, 0, (int) $tcaFieldConf['max']);
     }
     // Checking range of value:
     // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
     if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int) $value !== (int) $tcaFieldConf['default']) {
         if (isset($tcaFieldConf['range']['upper']) && (int) $value > (int) $tcaFieldConf['range']['upper']) {
             $value = $tcaFieldConf['range']['upper'];
         }
         if (isset($tcaFieldConf['range']['lower']) && (int) $value < (int) $tcaFieldConf['range']['lower']) {
             $value = $tcaFieldConf['range']['lower'];
         }
     }
     if (empty($tcaFieldConf['eval'])) {
         $res = array('value' => $value);
     } else {
         // Process evaluation settings:
         $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
         if ($this->runtimeCache->has($cacheId)) {
             $evalCodesArray = $this->runtimeCache->get($cacheId);
         } else {
             $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], true);
             $this->runtimeCache->set($cacheId, $evalCodesArray);
         }
         $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
         // Process UNIQUE settings:
         // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...
         if ($field && $realPid >= 0 && !empty($res['value'])) {
             if (in_array('uniqueInPid', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
             }
             if ($res['value'] && in_array('unique', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
             }
         }
     }
     // Handle native date/time fields
     if ($isDateOrDateTimeField) {
         // Convert the timestamp back to a date/time
         $res['value'] = $res['value'] ? date($format, $res['value']) : $emptyValue;
     }
     return $res;
 }