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

UserGroup::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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