Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

DateConverter.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
8
9 use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
10 use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
11 use eZ\Publish\SPI\Persistence\Content\FieldValue;
12 use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
13 use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
14 use eZ\Publish\Core\FieldType\Date\Type as DateType;
15 use eZ\Publish\Core\FieldType\FieldSettings;
16
20 class DateConverter implements Converter
21 {
31 public static function create()
32 {
33 return new self();
34 }
35
42 public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
43 {
44 $storageFieldValue->dataInt = ($value->data !== null ? $value->data['timestamp'] : null);
45 $storageFieldValue->sortKeyInt = (int)$value->sortKey;
46 }
47
54 public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
55 {
56 if ($value->dataInt === null || $value->dataInt == 0) {
57 return;
58 }
59
60 $fieldValue->data = [
61 'timestamp' => $value->dataInt,
62 'rfc850' => null,
63 ];
64 $fieldValue->sortKey = $value->sortKeyInt;
65 }
66
73 public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
74 {
75 $storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultType'] ?? null;
76 }
77
84 public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
85 {
86 $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
87 [
88 'defaultType' => $storageDef->dataInt1,
89 ]
90 );
91
92 // Building default value
93 switch ($fieldDef->fieldTypeConstraints->fieldSettings['defaultType']) {
94 case DateType::DEFAULT_CURRENT_DATE:
95 $data = [
96 'timestamp' => time(), // @deprecated timestamp is no longer used and will be removed in a future version.
97 'rfc850' => null,
98 'timestring' => 'now',
99 ];
100 break;
101 default:
102 $data = null;
103 }
104
105 $fieldDef->defaultValue->data = $data;
106 }
107
117 public function getIndexColumn()
118 {
119 return 'sort_key_int';
120 }
121 }
eZ\Publish\Core\FieldType\Date\Type
Definition: Core/FieldType/Date/Type.php:17
eZ\Publish\Core\FieldType\FieldSettings
Container for field type specific properties.
Definition: FieldSettings.php:19
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter
Date field value converter class.
Definition: DateConverter.php:21
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\create
static create()
Factory for current class.
Definition: DateConverter.php:31
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\toFieldValue
toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
Converts data from $value to $fieldValue.
Definition: DateConverter.php:54
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\getIndexColumn
getIndexColumn()
Returns the name of the index column in the attribute table.
Definition: DateConverter.php:117
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\toStorageFieldDefinition
toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
Converts field definition data in $fieldDef into $storageFieldDef.
Definition: DateConverter.php:73
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\toFieldDefinition
toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
Converts field definition data in $storageDef into $fieldDef.
Definition: DateConverter.php:84
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter\toStorageValue
toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
Converts data from $value to $storageFieldValue.
Definition: DateConverter.php:42
eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition
Definition: StorageFieldDefinition.php:12
eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue
Definition: StorageFieldValue.php:12
eZ\Publish\SPI\Persistence\Content\FieldValue
Definition: FieldValue.php:12
eZ\Publish\SPI\Persistence\Content\FieldValue\$data
$data
Definition: FieldValue.php:23
eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
Definition: SPI/Persistence/Content/Type/FieldDefinition.php:18
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
Converter for field values in legacy storage.
Definition: Persistence/Legacy/Content/FieldValue/Converter.php:18
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
Definition: AuthorConverter.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.