-
Notifications
You must be signed in to change notification settings - Fork 32
/
CheckboxConverter.php
90 lines (82 loc) · 3.2 KB
/
CheckboxConverter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
use eZ\Publish\SPI\Persistence\Content\FieldValue;
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
class CheckboxConverter implements Converter
{
/**
* Factory for current class.
*
* Note: Class should instead be configured as service if it gains dependencies.
*
* @deprecated since 6.8, will be removed in 7.x, use default constructor instead.
*
* @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\CheckboxConverter
*/
public static function create()
{
return new self();
}
/**
* Converts data from $value to $storageFieldValue.
*
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue
*/
public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
{
$storageFieldValue->dataInt = (int)$value->data;
$storageFieldValue->sortKeyInt = (int)$value->data;
}
/**
* Converts data from $value to $fieldValue.
*
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue
*/
public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
{
$fieldValue->data = (bool)$value->dataInt;
$fieldValue->sortKey = $value->dataInt;
}
/**
* Converts field definition data in $fieldDef into $storageFieldDef.
*
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt3 = (int)$fieldDef->defaultValue->data;
}
/**
* Converts field definition data in $storageDef into $fieldDef.
*
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
*/
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
{
$fieldDef->defaultValue->data = !empty($storageDef->dataInt3) ? (bool)$storageDef->dataInt3 : false;
}
/**
* Returns the name of the index column in the attribute table.
*
* Returns the name of the index column the datatype uses, which is either
* "sort_key_int" or "sort_key_string". This column is then used for
* filtering and sorting for this type.
*
* @return string
*/
public function getIndexColumn()
{
return 'sort_key_int';
}
}