TYPO3  7.6
DatabaseRowDateTimeFields.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
32  public function addData(array $result)
33  {
34  $dateTimeFormats = $this->getDatabase()->getDateTimeFormats($result['tableName']);
35  foreach ($result['processedTca']['columns'] as $column => $columnConfig) {
36  if (isset($columnConfig['config']['dbType'])
37  && GeneralUtility::inList('date,datetime', $columnConfig['config']['dbType'])
38  ) {
39  if (!empty($result['databaseRow'][$column])
40  && $result['databaseRow'][$column] !== $dateTimeFormats[$columnConfig['config']['dbType']]['empty']
41  ) {
42  // Create a timestamp from current field data
43  $result['databaseRow'][$column] = strtotime($result['databaseRow'][$column]);
44  } else {
45  // Set to 0 timespamp
46  $result['databaseRow'][$column] = 0;
47  }
48  }
49  }
50  return $result;
51  }
52 
56  protected function getDatabase()
57  {
58  return $GLOBALS['TYPO3_DB'];
59  }
60 }