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
|
|
|
use eZ\Publish\API\Repository\Values\ContentType\ContentType; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* This class represents a user group. |
16
|
|
|
* |
17
|
|
|
* @internal Meant for internal use by Repository, type hint against API object instead. |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class UserGroup extends APIUserGroup |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Internal content representation. |
23
|
|
|
* |
24
|
|
|
* @var \eZ\Publish\API\Repository\Values\Content\Content |
25
|
|
|
*/ |
26
|
|
|
protected $content; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the VersionInfo for this version. |
30
|
|
|
* |
31
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
32
|
|
|
*/ |
33
|
|
|
public function getVersionInfo() |
34
|
|
|
{ |
35
|
|
|
return $this->content->getVersionInfo(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getContentType(): ContentType |
39
|
|
|
{ |
40
|
|
|
return $this->content->getContentType(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns a field value for the given value |
45
|
|
|
* $version->fields[$fieldDefId][$languageCode] is an equivalent call |
46
|
|
|
* if no language is given on a translatable field this method returns |
47
|
|
|
* the value of the initial language of the version if present, otherwise null. |
48
|
|
|
* On non translatable fields this method ignores the languageCode parameter. |
49
|
|
|
* |
50
|
|
|
* @param string $fieldDefIdentifier |
51
|
|
|
* @param string $languageCode |
52
|
|
|
* |
53
|
|
|
* @return mixed a primitive type or a field type Value object depending on the field type. |
54
|
|
|
*/ |
55
|
|
|
public function getFieldValue($fieldDefIdentifier, $languageCode = null) |
56
|
|
|
{ |
57
|
|
|
return $this->content->getFieldValue($fieldDefIdentifier, $languageCode); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* This method returns the complete fields collection. |
62
|
|
|
* |
63
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] |
64
|
|
|
*/ |
65
|
|
|
public function getFields() |
66
|
|
|
{ |
67
|
|
|
return $this->content->getFields(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* This method returns the fields for a given language and non translatable fields. |
72
|
|
|
* |
73
|
|
|
* If note set the initialLanguage of the content version is used. |
74
|
|
|
* |
75
|
|
|
* @param string $languageCode |
76
|
|
|
* |
77
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] with field identifier as keys |
78
|
|
|
*/ |
79
|
|
|
public function getFieldsByLanguage($languageCode = null) |
80
|
|
|
{ |
81
|
|
|
return $this->content->getFieldsByLanguage($languageCode); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* This method returns the field for a given field definition identifier and language. |
86
|
|
|
* |
87
|
|
|
* If not set the initialLanguage of the content version is used. |
88
|
|
|
* |
89
|
|
|
* @param string $fieldDefIdentifier |
90
|
|
|
* @param string|null $languageCode |
91
|
|
|
* |
92
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found |
93
|
|
|
*/ |
94
|
|
|
public function getField($fieldDefIdentifier, $languageCode = null) |
95
|
|
|
{ |
96
|
|
|
return $this->content->getField($fieldDefIdentifier, $languageCode); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Function where list of properties are returned. |
101
|
|
|
* |
102
|
|
|
* Override to add dynamic properties |
103
|
|
|
* |
104
|
|
|
* @uses \parent::getProperties() |
105
|
|
|
* |
106
|
|
|
* @param array $dynamicProperties |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
protected function getProperties($dynamicProperties = ['id', 'contentInfo', 'versionInfo', 'fields']) |
111
|
|
|
{ |
112
|
|
|
return parent::getProperties($dynamicProperties); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Magic getter for retrieving convenience properties. |
117
|
|
|
* |
118
|
|
|
* @param string $property The name of the property to retrieve |
119
|
|
|
* |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function __get($property) |
123
|
|
|
{ |
124
|
|
|
switch ($property) { |
125
|
|
|
case 'contentInfo': |
126
|
|
|
return $this->getVersionInfo()->getContentInfo(); |
127
|
|
|
|
128
|
|
|
case 'id': |
129
|
|
|
return $this->getVersionInfo()->getContentInfo()->id; |
130
|
|
|
|
131
|
|
|
case 'versionInfo': |
132
|
|
|
return $this->getVersionInfo(); |
133
|
|
|
|
134
|
|
|
case 'fields': |
135
|
|
|
return $this->getFields(); |
136
|
|
|
|
137
|
|
|
case 'content': |
138
|
|
|
// trigger error for this, but for BC let it pass on to normal __get lookup for now |
139
|
|
|
@trigger_error( |
|
|
|
|
140
|
|
|
sprintf('%s is and internal property, usage is deprecated as of 6.10. UserGroup itself exposes everything needed.', $property), |
141
|
|
|
E_USER_DEPRECATED |
142
|
|
|
); |
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
|
|
|
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.