Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpolicylimitation.php
Go to the documentation of this file.
1 <?php
17 class eZPolicyLimitation extends eZPersistentObject
18 {
19 // Used for assign subtree matching
20 public $LimitValue;
21
22 public $PolicyID;
23 public $LimitationID;
24 public $Value;
25 public $Values;
26
30 public function __construct( $row )
31 {
32 parent::__construct( $row );
33 $this->NodeID = 0;
34 }
35
36 static function definition()
37 {
38 static $definition = array( "fields" => array( "id" => array( 'name' => 'ID',
39 'datatype' => 'integer',
40 'default' => 0,
41 'required' => true ),
42 'policy_id' => array( 'name' => 'PolicyID',
43 'datatype' => 'integer',
44 'default' => 0,
45 'required' => true,
46 'foreign_class' => 'eZPolicy',
47 'foreign_attribute' => 'id',
48 'multiplicity' => '1..*' ),
49 'identifier' => array( 'name' => 'Identifier',
50 'datatype' => 'string',
51 'default' => '',
52 'required' => true ) ),
53 "keys" => array( "id" ),
54 "function_attributes" => array( 'policy' => 'policy',
55 'values' => 'valueList',
56 'values_as_array' => 'allValues',
57 'values_as_string' => 'allValuesAsString',
58 'values_as_array_with_names' => 'allValuesAsArrayWithNames',
59 'limit_value' => 'limitValue' ),
60 "increment_key" => "id",
61 "sort" => array( "id" => "asc" ),
62 "class_name" => "eZPolicyLimitation",
63 "name" => "ezpolicy_limitation" );
64 return $definition;
65 }
66
67 function limitValue()
68 {
69 return $this->LimitValue;
70 }
71
75 function policy()
76 {
77 return eZPolicy::fetch( $this->attribute( 'policy_id' ) );
78 }
79
80 function setAttribute( $attr, $val )
81 {
82 switch( $attr )
83 {
84 case 'limit_value':
85 {
86 $this->LimitValue = $val;
87 } break;
88
89 default:
90 {
91 parent::setAttribute( $attr, $val );
92 } break;
93 }
94 }
95
100 static function createNew( $policyID, $identifier )
101 {
102 $policyParameter = new eZPolicyLimitation( array() );
103 $policyParameter->setAttribute( 'policy_id', $policyID );
104 $policyParameter->setAttribute( 'identifier', $identifier );
105 $policyParameter->store();
106
107 return $policyParameter;
108 }
109
115 static function create( $policyID, $identifier )
116 {
117 $row = array( 'id' => null,
118 'policy_id' => $policyID,
119 'identifier' => $identifier );
120 return new eZPolicyLimitation( $row );
121 }
122
127 static function removeSelected( $ID )
128 {
129 eZPersistentObject::removeObject( eZPolicyLimitation::definition(),
130 array( "id" => $ID ) );
131 }
132
133 static function fetchByIdentifier( $policyID, $identifier, $asObject = true )
134 {
135 return eZPersistentObject::fetchObject( eZPolicyLimitation::definition(),
136 null,
137 array( "policy_id" => $policyID,
138 "identifier" => $identifier ),
139 $asObject );
140 }
141
142 static function fetchByPolicyID( $policyID, $asObject = true )
143 {
144 return eZPersistentObject::fetchObjectList( eZPolicyLimitation::definition(),
145 null,
146 array( "policy_id" => $policyID ),
147 null,
148 null,
149 $asObject );
150 }
151
156 function copy( $policyID )
157 {
158 $newParameter = eZPolicyLimitation::createNew( $policyID, $this->attribute( 'identifier' ) );
159 foreach( $this->attribute( 'values' ) as $value )
160 {
161 $value->copy( $newParameter->attribute( 'id' ) );
162 }
163 }
164
168 static function removeByID( $id )
169 {
170 $db = eZDB::instance();
171
172 $idString = $db->escapeString( $id );
173 $db->begin();
174
175 $db->query( "DELETE FROM ezpolicy_limitation_value
176 WHERE ezpolicy_limitation_value.limitation_id = '$idString'" );
177
178 $db->query( "DELETE FROM ezpolicy_limitation
179 WHERE ezpolicy_limitation.id = '$idString' " );
180 $db->commit();
181 }
182
187 function removeThis()
188 {
189 eZPolicyLimitation::removeByID( $this->attribute( 'id' ) );
190 }
191
192 function allValuesAsString()
193 {
194 $str='';
195 foreach ( $this->attribute( 'values' ) as $value )
196 {
197 if ( $str == '' )
198 {
199 $str .= $value->attribute( 'value' );
200 }else
201 {
202 $str .= ',' . $value->attribute( 'value' );
203 }
204 }
205 return $str;
206 }
207
208 function allValuesAsArrayWithNames()
209 {
210 $returnValue = null;
211 $valueList = $this->attribute( 'values_as_array' );
212 $names = array();
213 $policy = $this->attribute( 'policy' );
214 if ( !$policy )
215 {
216 return $returnValue;
217 }
218
219 $currentModule = $policy->attribute( 'module_name' );
220 $mod = eZModule::exists( $currentModule );
221 if ( !is_object( $mod ) )
222 {
223 eZDebug::writeError( 'Failed to fetch instance for module ' . $currentModule );
224 return $returnValue;
225 }
226 $functions = $mod->attribute( 'available_functions' );
227 $functionNames = array_keys( $functions );
228
229 $currentFunction = $policy->attribute( 'function_name' );
230 $limitationValueArray = array();
231
232 $limitation = $functions[$currentFunction ][$this->attribute( 'identifier' )];
233
234 if ( $limitation &&
235 isset( $limitation['class'] ) &&
236 count( $limitation[ 'values' ] ) == 0 )
237 {
238 $obj = new $limitation['class']( array() );
239 $limitationValueList = call_user_func_array ( array( $obj , $limitation['function']) , $limitation['parameter'] );
240 foreach( $limitationValueList as $limitationValue )
241 {
242 $limitationValuePair = array();
243 $limitationValuePair['Name'] = $limitationValue[ 'name' ];
244 $limitationValuePair['value'] = $limitationValue[ 'id' ];
245 $limitationValueArray[] = $limitationValuePair;
246 }
247 }
248 else if ( $limitation['name'] === 'Node' )
249 {
250 foreach ( $valueList as $value )
251 {
252 $node = eZContentObjectTreeNode::fetch( $value, false, false );
253 if ( $node == null )
254 continue;
255 $limitationValuePair = array();
256 $limitationValuePair['Name'] = $node['name'];
257 $limitationValuePair['value'] = $value;
258 $limitationValuePair['node_data'] = $node;
259 $limitationValueArray[] = $limitationValuePair;
260 }
261 }
262 else if ( $limitation['name'] === 'Subtree' )
263 {
264 foreach ( $valueList as $value )
265 {
266 $subtreeObject = eZContentObjectTreeNode::fetchByPath( $value, false );
267 if ( $subtreeObject != null )
268 {
269 $limitationValuePair = array();
270 $limitationValuePair['Name'] = $subtreeObject['name'];
271 $limitationValuePair['value'] = $value;
272 $limitationValuePair['node_data'] = $subtreeObject;
273 $limitationValueArray[] = $limitationValuePair;
274 }
275 }
276 }
277 else
278 {
279 $limitationValueArray = $limitation[ 'values' ];
280 }
281 $limitationValuesWithNames = array();
282 foreach ( array_keys( $valueList ) as $key )
283 {
284 $value = $valueList[$key];
285 if ( isset( $limitationValueArray ) )
286 {
287 reset( $limitationValueArray );
288 foreach ( array_keys( $limitationValueArray ) as $ckey )
289 {
290 if ( $value == $limitationValueArray[$ckey]['value'] )
291 {
292 $limitationValuesWithNames[] = $limitationValueArray[$ckey];
293 }
294 }
295 }
296 }
297
298 return $limitationValuesWithNames;
299 }
300
306 function limitArray()
307 {
308 $limitValues = $this->attribute( 'values' );
309
310 $valueArray = array();
311
312 foreach ( array_keys( $limitValues ) as $valueKey )
313 {
314 $valueArray[] = $limitValues[$valueKey]->attribute( 'value' );
315 }
316
317 return array( $this->attribute( 'identifier' ) => $valueArray );
318 }
319
320 function allValues()
321 {
322 $values = array();
323 foreach ( $this->attribute( 'values' ) as $value )
324 {
325 $values[] = $value->attribute( 'value' );
326 }
327
328 return $values;
329 }
330
331 function valueList()
332 {
333 if ( !isset( $this->Values ) )
334 {
335 $values = eZPersistentObject::fetchObjectList( eZPolicyLimitationValue::definition(),
336 null, array( 'limitation_id' => $this->attribute( 'id') ), null, null,
337 true);
338
339 if ( $this->LimitValue )
340 {
341 $values[] = new eZPolicyLimitationValue( array ( 'id' => -1,
342 'value' => $this->LimitValue ) );
343 }
344
345 $this->Values = $values;
346 }
347
348 return $this->Values;
349 }
350
351 static function findByType( $type, $value, $asObject = true, $useLike = true )
352 {
353 $cond = '';
354 $db = eZDB::instance();
355 $value = $db->escapeString( $value );
356 $type = $db->escapeString( $type );
357 if ( $useLike === true )
358 {
359 $cond = "ezpolicy_limitation_value.value like '$value%' ";
360 }
361 else
362 {
363 $cond = "ezpolicy_limitation_value.value = '$value' ";
364 }
365
366 $query = "SELECT DISTINCT ezpolicy_limitation.*
367 FROM ezpolicy_limitation,
368 ezpolicy_limitation_value
369 WHERE
370 ezpolicy_limitation.identifier = '$type' AND
371 $cond AND
372 ezpolicy_limitation_value.limitation_id = ezpolicy_limitation.id";
373
374 $dbResult = $db->arrayQuery( $query );
375 $resultArray = array();
376 $resultCount = count( $dbResult );
377 for( $i = 0; $i < $resultCount; $i++ )
378 {
379 if ( $asObject )
380 {
381 $resultArray[] = new eZPolicyLimitation( $dbResult[$i] );
382 }
383 else
384 {
385 $resultArray[] = $dbResult[$i]['id'];
386 }
387 }
388 return $resultArray;
389 }
390 }
391
392 ?>
eZContentObjectTreeNode\fetchByPath
static fetchByPath( $pathString, $asObject=true)
Definition: ezcontentobjecttreenode.php:2938
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZModule\exists
static exists( $moduleName, $pathList=null, $showError=false)
Definition: ezmodule.php:1990
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\$ID
$ID
Definition: ezpersistentobject.php:1448
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZPolicyLimitationValue
Defines a limitation value for a policy in the permission system.
Definition: ezpolicylimitationvalue.php:18
eZPolicyLimitationValue\definition
static definition()
Definition: ezpolicylimitationvalue.php:23
eZPolicyLimitation
Defines a limitation for a policy in the permission system.
Definition: ezpolicylimitation.php:18
eZPolicyLimitation\findByType
static findByType( $type, $value, $asObject=true, $useLike=true)
Definition: ezpolicylimitation.php:351
eZPolicyLimitation\removeSelected
static removeSelected( $ID)
Definition: ezpolicylimitation.php:127
eZPolicyLimitation\$PolicyID
$PolicyID
Definition: ezpolicylimitation.php:22
eZPolicyLimitation\createNew
static createNew( $policyID, $identifier)
Definition: ezpolicylimitation.php:100
eZPolicyLimitation\copy
copy( $policyID)
Definition: ezpolicylimitation.php:156
eZPolicyLimitation\allValuesAsArrayWithNames
allValuesAsArrayWithNames()
Definition: ezpolicylimitation.php:208
eZPolicyLimitation\allValues
allValues()
Definition: ezpolicylimitation.php:320
eZPolicyLimitation\$LimitationID
$LimitationID
Definition: ezpolicylimitation.php:23
eZPolicyLimitation\$LimitValue
$LimitValue
Definition: ezpolicylimitation.php:20
eZPolicyLimitation\removeByID
static removeByID( $id)
Definition: ezpolicylimitation.php:168
eZPolicyLimitation\removeThis
removeThis()
Definition: ezpolicylimitation.php:187
eZPolicyLimitation\setAttribute
setAttribute( $attr, $val)
Definition: ezpolicylimitation.php:80
eZPolicyLimitation\limitArray
limitArray()
Definition: ezpolicylimitation.php:306
eZPolicyLimitation\fetchByPolicyID
static fetchByPolicyID( $policyID, $asObject=true)
Definition: ezpolicylimitation.php:142
eZPolicyLimitation\$Values
$Values
Definition: ezpolicylimitation.php:25
eZPolicyLimitation\__construct
__construct( $row)
Definition: ezpolicylimitation.php:30
eZPolicyLimitation\create
static create( $policyID, $identifier)
Definition: ezpolicylimitation.php:115
eZPolicyLimitation\$Value
$Value
Definition: ezpolicylimitation.php:24
eZPolicyLimitation\limitValue
limitValue()
Definition: ezpolicylimitation.php:67
eZPolicyLimitation\policy
policy()
Definition: ezpolicylimitation.php:75
eZPolicyLimitation\fetchByIdentifier
static fetchByIdentifier( $policyID, $identifier, $asObject=true)
Definition: ezpolicylimitation.php:133
eZPolicyLimitation\definition
static definition()
Definition: ezpolicylimitation.php:36
eZPolicyLimitation\valueList
valueList()
Definition: ezpolicylimitation.php:331
eZPolicyLimitation\allValuesAsString
allValuesAsString()
Definition: ezpolicylimitation.php:192
eZPolicy\fetch
static fetch( $policyID)
Definition: ezpolicy.php:377
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.