Completed
Push — master ( 895cca...4892d1 )
by
unknown
34:47
created

ImageAssetConverter::toFieldDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
10
11
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
12
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
13
use eZ\Publish\SPI\Persistence\Content\FieldValue;
14
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
15
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
16
17
class ImageAssetConverter implements Converter
18
{
19
    /**
20
     * Converts data from $value to $storageFieldValue.
21
     *
22
     * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value
23
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue
24
     */
25 View Code Duplication
    public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
26
    {
27
        $storageFieldValue->dataInt = !empty($value->data['destinationContentId'])
28
            ? $value->data['destinationContentId']
29
            : null;
30
        $storageFieldValue->sortKeyInt = (int)$value->sortKey;
31
    }
32
33
    /**
34
     * Converts data from $value to $fieldValue.
35
     *
36
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
37
     * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue
38
     */
39 View Code Duplication
    public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
40
    {
41
        $fieldValue->data = [
42
            'destinationContentId' => $value->dataInt ?: null,
43
        ];
44
        $fieldValue->sortKey = (int)$value->sortKeyInt;
45
    }
46
47
    /**
48
     * Converts field definition data in $fieldDef into $storageFieldDef.
49
     *
50
     * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
51
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
52
     */
53
    public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
54
    {
55
    }
56
57
    /**
58
     * Converts field definition data in $storageDef into $fieldDef.
59
     *
60
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
61
     * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
62
     */
63
    public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
64
    {
65
    }
66
67
    /**
68
     * Returns the name of the index column in the attribute table.
69
     *
70
     * Returns the name of the index column the datatype uses, which is either
71
     * "sort_key_int" or "sort_key_string". This column is then used for
72
     * filtering and sorting for this type.
73
     *
74
     * @return string
75
     */
76
    public function getIndexColumn()
77
    {
78
        return 'sort_key_string';
79
    }
80
}
81