Completed
Push — location_multi_load ( e5e305...41e541 )
by André
51:38 queued 33:21
created

ImageAssetConverter::toStorageFieldDefinition()   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
    public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
26
    {
27
        $storageFieldValue->dataInt = !empty($value->data['destinationContentId'])
28
            ? $value->data['destinationContentId']
29
            : null;
30
        $storageFieldValue->dataText = !empty($value->data['alternativeText'])
31
            ? $value->data['alternativeText']
32
            : null;
33
        $storageFieldValue->sortKeyInt = (int)$value->sortKey;
34
    }
35
36
    /**
37
     * Converts data from $value to $fieldValue.
38
     *
39
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value
40
     * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue
41
     */
42 View Code Duplication
    public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
43
    {
44
        $fieldValue->data = [
45
            'destinationContentId' => $value->dataInt ?: null,
46
            'alternativeText' => $value->dataText ?: null,
47
        ];
48
        $fieldValue->sortKey = (int)$value->sortKeyInt;
49
    }
50
51
    /**
52
     * Converts field definition data in $fieldDef into $storageFieldDef.
53
     *
54
     * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
55
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
56
     */
57
    public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
58
    {
59
    }
60
61
    /**
62
     * Converts field definition data in $storageDef into $fieldDef.
63
     *
64
     * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
65
     * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
66
     */
67
    public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
68
    {
69
    }
70
71
    /**
72
     * Returns the name of the index column in the attribute table.
73
     *
74
     * Returns the name of the index column the datatype uses, which is either
75
     * "sort_key_int" or "sort_key_string". This column is then used for
76
     * filtering and sorting for this type.
77
     *
78
     * @return string
79
     */
80
    public function getIndexColumn()
81
    {
82
        return 'sort_key_string';
83
    }
84
}
85