Completed
Push — api_content_name_shorthand ( e0a75f )
by André
17:01
created

User::getName()   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
     * {@inheritdoc}
59
     */
60
    public function getName($languageCode = null)
61
    {
62
        return $this->content->getVersionInfo()->getName($languageCode);
63
    }
64
65
    /**
66
     * Returns a field value for the given value
67
     * $version->fields[$fieldDefId][$languageCode] is an equivalent call
68
     * if no language is given on a translatable field this method returns
69
     * the value of the initial language of the version if present, otherwise null.
70
     * On non translatable fields this method ignores the languageCode parameter.
71
     *
72
     * @param string $fieldDefIdentifier
73
     * @param string $languageCode
74
     *
75
     * @return mixed a primitive type or a field type Value object depending on the field type.
76
     */
77
    public function getFieldValue($fieldDefIdentifier, $languageCode = null)
78
    {
79
        return $this->content->getFieldValue($fieldDefIdentifier, $languageCode);
80
    }
81
82
    /**
83
     * This method returns the complete fields collection.
84
     *
85
     * @return \eZ\Publish\API\Repository\Values\Content\Field[]
86
     */
87
    public function getFields()
88
    {
89
        return $this->content->getFields();
90
    }
91
92
    /**
93
     * This method returns the fields for a given language and non translatable fields.
94
     *
95
     * If note set the initialLanguage of the content version is used.
96
     *
97
     * @param string $languageCode
98
     *
99
     * @return \eZ\Publish\API\Repository\Values\Content\Field[] with field identifier as keys
100
     */
101
    public function getFieldsByLanguage($languageCode = null)
102
    {
103
        return $this->content->getFieldsByLanguage($languageCode);
104
    }
105
106
    /**
107
     * This method returns the field for a given field definition identifier and language.
108
     *
109
     * If not set the initialLanguage of the content version is used.
110
     *
111
     * @param string $fieldDefIdentifier
112
     * @param string|null $languageCode
113
     *
114
     * @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found
115
     */
116
    public function getField($fieldDefIdentifier, $languageCode = null)
117
    {
118
        return $this->content->getField($fieldDefIdentifier, $languageCode);
119
    }
120
121
    /**
122
     * Function where list of properties are returned.
123
     *
124
     * Override to add dynamic properties
125
     *
126
     * @uses \parent::getProperties()
127
     *
128
     * @param array $dynamicProperties
129
     *
130
     * @return array
131
     */
132
    protected function getProperties($dynamicProperties = array('id', 'contentInfo'))
133
    {
134
        return parent::getProperties($dynamicProperties);
135
    }
136
137
    /**
138
     * Magic getter for retrieving convenience properties.
139
     *
140
     * @param string $property The name of the property to retrieve
141
     *
142
     * @return mixed
143
     */
144
    public function __get($property)
145
    {
146
        switch ($property) {
147
            case 'contentInfo':
148
                return $this->getVersionInfo()->getContentInfo();
149
150
            case 'id':
151
                return $this->getVersionInfo()->getContentInfo()->id;
152
153
            case 'versionInfo':
154
                return $this->getVersionInfo();
155
156
            case 'fields':
157
                return $this->getFields();
158
        }
159
160
        return parent::__get($property);
161
    }
162
163
    /**
164
     * Magic isset for signaling existence of convenience properties.
165
     *
166
     * @param string $property
167
     *
168
     * @return bool
169
     */
170 View Code Duplication
    public function __isset($property)
171
    {
172
        if ($property === 'contentInfo') {
173
            return true;
174
        }
175
176
        if ($property === 'id') {
177
            return true;
178
        }
179
180
        if ($property === 'versionInfo') {
181
            return true;
182
        }
183
184
        if ($property === 'fields') {
185
            return true;
186
        }
187
188
        return parent::__isset($property);
189
    }
190
}
191