‪TYPO3CMS  10.4
DatabaseRowDateTimeFields.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
32  public function ‪addData(array $result)
33  {
34  $dateTimeTypes = ‪QueryHelper::getDateTimeTypes();
35  $dateTimeFormats = ‪QueryHelper::getDateTimeFormats();
36 
37  foreach ($result['processedTca']['columns'] as $column => $columnConfig) {
38  if (isset($columnConfig['config']['dbType'])
39  && in_array($columnConfig['config']['dbType'], $dateTimeTypes, true)
40  ) {
41  if (!empty($result['databaseRow'][$column])
42  && $result['databaseRow'][$column] !== $dateTimeFormats[$columnConfig['config']['dbType']]['empty']
43  ) {
44  // Create an ISO-8601 date from current field data; the database always contains UTC
45  // The field value is something like "2016-01-01" or "2016-01-01 10:11:12", so appending "UTC"
46  // makes date() treat it as a UTC date (which is what we store in the database).
47  $result['databaseRow'][$column] = date('c', (int)strtotime($result['databaseRow'][$column] . ' UTC'));
48  } else {
49  $result['databaseRow'][$column] = null;
50  }
51  }
52  // its a UNIX timestamp! We do not modify this here, as it will only be treated as a datetime because
53  // of eval being set to "date" or "datetime". This is handled in InputTextElement then.
54  }
55  return $result;
56  }
57 }
‪TYPO3\CMS\Core\Database\Query\QueryHelper\getDateTimeFormats
‪static array getDateTimeFormats()
Definition: QueryHelper.php:177
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDateTimeFields
Definition: DatabaseRowDateTimeFields.php:25
‪TYPO3\CMS\Core\Database\Query\QueryHelper\getDateTimeTypes
‪static array getDateTimeTypes()
Definition: QueryHelper.php:202
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDateTimeFields\addData
‪array addData(array $result)
Definition: DatabaseRowDateTimeFields.php:32
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23