1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Core\Persistence\Legacy\Content\FieldValue\Converter; |
4
|
|
|
|
5
|
|
|
use eZ\Publish\Core\FieldType\FieldSettings; |
6
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter as ConverterInterface; |
7
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition; |
8
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue; |
9
|
|
|
use eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints; |
10
|
|
|
use eZ\Publish\SPI\Persistence\Content\FieldValue; |
11
|
|
|
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; |
12
|
|
|
|
13
|
|
|
class Converter implements ConverterInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Converts data from $value to $storageFieldValue. |
17
|
|
|
* |
18
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value |
19
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue |
20
|
|
|
*/ |
21
|
|
|
public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) |
22
|
|
|
{ |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Converts data from $value to $fieldValue. |
27
|
|
|
* |
28
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
29
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue |
30
|
|
|
*/ |
31
|
|
|
public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) |
32
|
|
|
{ |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Converts field definition data in $fieldDef into $storageFieldDef. |
37
|
|
|
* |
38
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
39
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
40
|
|
|
*/ |
41
|
|
|
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) |
42
|
|
|
{ |
43
|
|
|
$storageDef->dataInt1 = isset($fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize']) ? |
44
|
|
|
$fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize'] : |
45
|
|
|
0; |
46
|
|
|
$storageDef->dataText1 = isset($fieldDef->fieldTypeConstraints->fieldSettings['allowedTypes']) ? |
47
|
|
|
$fieldDef->fieldTypeConstraints->fieldSettings['allowedTypes'] : |
48
|
|
|
''; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Converts field definition data in $storageDef into $fieldDef. |
53
|
|
|
* |
54
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
55
|
|
|
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
56
|
|
|
*/ |
57
|
|
|
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef) |
58
|
|
|
{ |
59
|
|
|
$fieldDef->fieldTypeConstraints = new FieldTypeConstraints( |
60
|
|
|
array( |
61
|
|
|
'validators' => array( |
62
|
|
|
'FileSizeValidator' => array( |
63
|
|
|
'maxFileSize' => (0 !== $storageDef->dataInt1 |
64
|
|
|
? $storageDef->dataInt1 |
65
|
|
|
: false), |
66
|
|
|
), |
67
|
|
|
), |
68
|
|
|
'fieldSettings' => new FieldSettings(array( |
69
|
|
|
'allowedTypes' => $storageDef->dataText1, |
70
|
|
|
)), |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the name of the index column in the attribute table. |
77
|
|
|
* |
78
|
|
|
* Returns the name of the index column the datatype uses, which is either |
79
|
|
|
* "sort_key_int" or "sort_key_string". This column is then used for |
80
|
|
|
* filtering and sorting for this type. |
81
|
|
|
* |
82
|
|
|
* If the indexing is not supported, this method must return false. |
83
|
|
|
* |
84
|
|
|
* @return string|false |
85
|
|
|
*/ |
86
|
|
|
public function getIndexColumn() |
87
|
|
|
{ |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|