Completed
Push — api_content_name_shorthand ( 929e38...fc49b1 )
by André
20:47
created

User::getFieldsByLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the eZ\Publish\Core\Repository\Values\User\User class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\Values\User;
10
11
use eZ\Publish\API\Repository\Values\User\User as APIUser;
12
13
/**
14
 * This class represents a user value.
15
 *
16
 * @internal Meant for internal use by Repository, type hint against API object instead.
17
 */
18
class User extends APIUser
19
{
20
    /**
21
     * @var int MD5 of password, not recommended
22
     */
23
    const PASSWORD_HASH_MD5_PASSWORD = 1;
24
25
    /**
26
     * @var int MD5 of user and password
27
     */
28
    const PASSWORD_HASH_MD5_USER = 2;
29
30
    /**
31
     * @var int MD5 of site, user and password
32
     */
33
    const PASSWORD_HASH_MD5_SITE = 3;
34
35
    /**
36
     * @var int Passwords in plaintext, should not be used for real sites
37
     */
38
    const PASSWORD_HASH_PLAINTEXT = 5;
39
40
    /**
41
     * Internal content representation.
42
     *
43
     * @var \eZ\Publish\API\Repository\Values\Content\Content
44
     */
45
    protected $content;
46
47
    /**
48
     * Returns the VersionInfo for this version.
49
     *
50
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
51
     */
52
    public function getVersionInfo()
53
    {
54
        return $this->content->getVersionInfo();
55
    }
56
57
    /**
58
     * Returns a field value for the given value
59
     * $version->fields[$fieldDefId][$languageCode] is an equivalent call
60
     * if no language is given on a translatable field this method returns
61
     * the value of the initial language of the version if present, otherwise null.
62
     * On non translatable fields this method ignores the languageCode parameter.
63
     *
64
     * @param string $fieldDefIdentifier
65
     * @param string $languageCode
66
     *
67
     * @return mixed a primitive type or a field type Value object depending on the field type.
68
     */
69
    public function getFieldValue($fieldDefIdentifier, $languageCode = null)
70
    {
71
        return $this->content->getFieldValue($fieldDefIdentifier, $languageCode);
72
    }
73
74
    /**
75
     * This method returns the complete fields collection.
76
     *
77
     * @return \eZ\Publish\API\Repository\Values\Content\Field[]
78
     */
79
    public function getFields()
80
    {
81
        return $this->content->getFields();
82
    }
83
84
    /**
85
     * This method returns the fields for a given language and non translatable fields.
86
     *
87
     * If note set the initialLanguage of the content version is used.
88
     *
89
     * @param string $languageCode
90
     *
91
     * @return \eZ\Publish\API\Repository\Values\Content\Field[] with field identifier as keys
92
     */
93
    public function getFieldsByLanguage($languageCode = null)
94
    {
95
        return $this->content->getFieldsByLanguage($languageCode);
96
    }
97
98
    /**
99
     * This method returns the field for a given field definition identifier and language.
100
     *
101
     * If not set the initialLanguage of the content version is used.
102
     *
103
     * @param string $fieldDefIdentifier
104
     * @param string|null $languageCode
105
     *
106
     * @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found
107
     */
108
    public function getField($fieldDefIdentifier, $languageCode = null)
109
    {
110
        return $this->content->getField($fieldDefIdentifier, $languageCode);
111
    }
112
113
    /**
114
     * Function where list of properties are returned.
115
     *
116
     * Override to add dynamic properties
117
     *
118
     * @uses \parent::getProperties()
119
     *
120
     * @param array $dynamicProperties
121
     *
122
     * @return array
123
     */
124
    protected function getProperties($dynamicProperties = array('id', 'contentInfo'))
125
    {
126
        return parent::getProperties($dynamicProperties);
127
    }
128
129
    /**
130
     * Magic getter for retrieving convenience properties.
131
     *
132
     * @param string $property The name of the property to retrieve
133
     *
134
     * @return mixed
135
     */
136 View Code Duplication
    public function __get($property)
137
    {
138
        switch ($property) {
139
            case 'contentInfo':
140
                return $this->getVersionInfo()->getContentInfo();
141
142
            case 'id':
143
                $versionInfo = $this->getVersionInfo();
144
                if (empty($versionInfo)) {
145
                    return null;
146
                }
147
148
                return $versionInfo->getContentInfo()->id;
149
150
            case 'versionInfo':
151
                return $this->getVersionInfo();
152
153
            case 'fields':
154
                return $this->getFields();
155
        }
156
157
        return parent::__get($property);
158
    }
159
160
    /**
161
     * Magic isset for signaling existence of convenience properties.
162
     *
163
     * @param string $property
164
     *
165
     * @return bool
166
     */
167 View Code Duplication
    public function __isset($property)
168
    {
169
        if ($property === 'contentInfo') {
170
            return true;
171
        }
172
173
        if ($property === 'id') {
174
            return true;
175
        }
176
177
        if ($property === 'versionInfo') {
178
            return true;
179
        }
180
181
        if ($property === 'fields') {
182
            return true;
183
        }
184
185
        return parent::__isset($property);
186
    }
187
}
188