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

TimeConverter.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\Time\Type as TimeType;
15 use eZ\Publish\Core\FieldType\FieldSettings;
16 use DateTime;
17
21 class TimeConverter implements Converter
22 {
32 public static function create()
33 {
34 return new self();
35 }
36
43 public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
44 {
45 $storageFieldValue->dataInt = $value->data;
46 $storageFieldValue->sortKeyInt = (int)$value->sortKey;
47 }
48
55 public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
56 {
57 if ($value->dataInt === null) {
58 return;
59 }
60
61 $fieldValue->data = $value->dataInt;
62 $fieldValue->sortKey = $value->sortKeyInt;
63 }
64
71 public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
72 {
73 $fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;
74
75 if ($fieldSettings !== null) {
76 $storageDef->dataInt1 = $fieldSettings['defaultType'];
77 $storageDef->dataInt2 = $fieldSettings['useSeconds'] ? 1 : 0;
78 }
79 }
80
87 public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
88 {
89 $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
90 [
91 'defaultType' => $storageDef->dataInt1,
92 'useSeconds' => (bool)$storageDef->dataInt2,
93 ]
94 );
95
96 // Building default value
97 switch ($fieldDef->fieldTypeConstraints->fieldSettings['defaultType']) {
98 case TimeType::DEFAULT_CURRENT_TIME:
99 $dateTime = new DateTime();
100 $data = $dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp();
101 break;
102 default:
103 $data = null;
104 }
105
106 $fieldDef->defaultValue->data = $data;
107 }
108
118 public function getIndexColumn()
119 {
120 return 'sort_key_int';
121 }
122 }
eZ\Publish\Core\FieldType\FieldSettings
Container for field type specific properties.
Definition: FieldSettings.php:19
eZ\Publish\Core\FieldType\Time\Type
Definition: Core/FieldType/Time/Type.php:17
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter
Time field value converter class.
Definition: TimeConverter.php:22
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\toFieldValue
toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
Converts data from $value to $fieldValue.
Definition: TimeConverter.php:55
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\create
static create()
Factory for current class.
Definition: TimeConverter.php:32
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\getIndexColumn
getIndexColumn()
Returns the name of the index column in the attribute table.
Definition: TimeConverter.php:118
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\toStorageValue
toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
Converts data from $value to $storageFieldValue.
Definition: TimeConverter.php:43
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\toStorageFieldDefinition
toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
Converts field definition data in $fieldDef into $storageFieldDef.
Definition: TimeConverter.php:71
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TimeConverter\toFieldDefinition
toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
Converts field definition data in $storageDef into $fieldDef.
Definition: TimeConverter.php:87
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+.