Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsubtreenotificationrule.php
Go to the documentation of this file.
1 <?php
16 class eZSubtreeNotificationRule extends eZPersistentObject
17 {
18 static function definition()
19 {
20 return array( "fields" => array( "id" => array( 'name' => 'ID',
21 'datatype' => 'integer',
22 'default' => 0,
23 'required' => true ),
24 "user_id" => array( 'name' => "UserID",
25 'datatype' => 'integer',
26 'default' => '',
27 'required' => true,
28 'foreign_class' => 'eZUser',
29 'foreign_attribute' => 'contentobject_id',
30 'multiplicity' => '1..*' ),
31 "use_digest" => array( 'name' => "UseDigest",
32 'datatype' => 'integer',
33 'default' => 0,
34 'required' => true ),
35 "node_id" => array( 'name' => "NodeID",
36 'datatype' => 'integer',
37 'default' => 0,
38 'required' => true,
39 'foreign_class' => 'eZContentObjectTreeNode',
40 'foreign_attribute' => 'node_id',
41 'multiplicity' => '1..*' ) ),
42 "keys" => array( "id" ),
43 "function_attributes" => array( 'node' => 'node' ),
44 "increment_key" => "id",
45 "sort" => array( "id" => "asc" ),
46 "class_name" => "eZSubtreeNotificationRule",
47 "name" => "ezsubtree_notification_rule" );
48 }
49
50
51 static function create( $nodeID, $userID, $useDigest = 0 )
52 {
53 $rule = new eZSubtreeNotificationRule( array( 'user_id' => $userID,
54 'use_digest' => $useDigest,
55 'node_id' => $nodeID ) );
56 return $rule;
57 }
58
59 static function fetchNodesForUserID( $userID, $asObject = true )
60 {
61 $nodeIDList = eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(),
62 array( 'node_id' ), array( 'user_id' => $userID ),
63 null,null,false );
64 $nodes = array();
65 if ( $asObject )
66 {
67 foreach ( $nodeIDList as $nodeRow )
68 {
69 $nodes[] = eZContentObjectTreeNode::fetch( $nodeRow['node_id'] );
70 }
71 }
72 else
73 {
74 foreach ( $nodeIDList as $nodeRow )
75 {
76 $nodes[] = $nodeRow['node_id'];
77 }
78 }
79 return $nodes;
80 }
81
82 static function fetchList( $userID, $asObject = true, $offset = false, $limit = false )
83 {
84 return eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(),
85 null, array( 'user_id' => $userID ),
86 null, array( 'offset' => $offset,
87 'length' => $limit ), $asObject );
88 }
89
90 static function fetchListCount( $userID )
91 {
92 $countRes = eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(),
93 array(),
94 array( 'user_id' => $userID ),
95 false,
96 null,
97 false,
98 false,
99 array( array( 'operation' => 'count( id )',
100 'name' => 'count' ) ) );
101 return $countRes[0]['count'];
102 }
103
113 static function fetchUserList( $nodeIDList, $contentObject )
114 {
115 if ( count( $nodeIDList ) == 0 )
116 {
117 $retValue = array();
118 return $retValue;
119 }
120
121 $db = eZDB::instance();
122 $concatString = $db->concatString( array( 'user_tree.path_string', "'%'" ) );
123
124 // Select affected users
125 $sqlINString = $db->generateSQLINStatement( $nodeIDList, 'subtree_rule.node_id', false, false, 'int' );
126 $sql = "SELECT DISTINCT subtree_rule.user_id,
127 user_node.node_id
128 FROM ezsubtree_notification_rule subtree_rule,
129 ezcontentobject_tree user_node,
130 ezuser_setting
131 WHERE $sqlINString AND
132 user_node.contentobject_id = subtree_rule.user_id AND
133 ezuser_setting.user_id = subtree_rule.user_id AND
134 user_node.is_invisible = 0 AND
135 ezuser_setting.is_enabled = 1";
136 $userPart = $db->arrayQuery( $sql );
137
138 // Remove duplicates
139 $userNodeIDList = array();
140 foreach ( $userPart as $row )
141 $userNodeIDList[] = $row['node_id'];
142 $userNodeIDList = array_unique( $userNodeIDList );
143
144 if ( count( $userNodeIDList ) == 0 )
145 {
146 $retValue = array();
147 return $retValue;
148 }
149
150 // Select affected nodes
151 $sqlINString = $db->generateSQLINStatement( $userNodeIDList, 'user_node.node_id', false, false, 'int' );
152 $sql = "SELECT DISTINCT user_node.node_id,
153 user_node.path_string,
154 user_tree.contentobject_id
155 FROM ezcontentobject_tree user_node,
156 ezcontentobject_tree user_tree
157 WHERE $sqlINString AND
158 user_node.path_string LIKE $concatString";
159 $nodePart = $db->arrayQuery( $sql );
160
161 // Remove duplicates
162 $objectIDList = array();
163 foreach ( $nodePart as $row )
164 if ( $row['contentobject_id'] != '0' )
165 $objectIDList[] = $row['contentobject_id'];
166 $objectIDList = array_unique( $objectIDList );
167
168 if ( count( $objectIDList ) == 0 )
169 {
170 $retValue = array();
171 return $retValue;
172 }
173
174 // Select affected roles and policies
175 $sqlINString = $db->generateSQLINStatement( $objectIDList, 'user_role.contentobject_id', false, false, 'int' );
176 $sql = "SELECT DISTINCT user_role.contentobject_id,
177 policy.id AS policy_id,
178 user_role.limit_identifier AS limitation,
179 user_role.limit_value AS value
180 FROM ezuser_role user_role,
181 ezpolicy policy
182 WHERE $sqlINString AND
183 ( user_role.role_id=policy.role_id AND
184 ( policy.module_name='*' OR
185 ( policy.module_name='content' AND
186 ( policy.function_name='*' OR
187 policy.function_name='read'
188 )
189 )
190 )
191 )";
192 $rolePart = $db->arrayQuery( $sql );
193
194 // Build resultArray. Make sure there are no duplicates.
195 $resultArray = array();
196 foreach ( $userPart as $up )
197 {
198 foreach ( $nodePart as $np )
199 {
200 if ( $up['node_id'] == $np['node_id'] )
201 {
202 foreach ( $rolePart as $rp )
203 {
204 if ( $np['contentobject_id'] == $rp['contentobject_id'] )
205 {
206 $key = $rp['policy_id'] . $up['user_id'] . $rp['limitation'] . $rp['value'];
207 $resultArray[$key] = array( 'policy_id' => $rp['policy_id'],
208 'user_id' => $up['user_id'],
209 'limitation' => $rp['limitation'],
210 'value' => $rp['value'] );
211 }
212 }
213 }
214 }
215 }
216
217 $policyIDArray = array();
218 $limitedPolicyIDArray = array();
219 $userIDArray = array();
220 foreach( $resultArray as $result )
221 {
222 $userIDArray[(string)$result['user_id']] = (int)$result['user_id'];
223 }
224
225 foreach( $resultArray as $result )
226 {
227 if ( $result['limitation'] == '' )
228 {
229 $policyIDArray[(string)$result['policy_id']][] =& $userIDArray[(string)$result['user_id']];
230 }
231 else
232 {
233 $limitedPolicyIDArray[] = array( 'user_id' => $userIDArray[(string)$result['user_id']],
234 'limitation' => $result['limitation'],
235 'value' => $result['value'],
236 'policyID' => $result['policy_id'] );
237 }
238 }
239
240 $acceptedUserArray = array();
241 foreach( array_keys( $policyIDArray ) as $policyID )
242 {
243 foreach( array_keys( $policyIDArray[$policyID] ) as $key )
244 {
245 if ( $policyIDArray[$policyID][$key] === false )
246 {
247 unset( $policyIDArray[$policyID][$key] );
248 }
249 }
250
251 if ( count( $policyIDArray[$policyID] ) == 0 )
252 {
253 continue;
254 }
255
256 $userArray = eZSubtreeNotificationRule::checkObjectAccess( $contentObject, $policyID, $policyIDArray[$policyID] );
257 $acceptedUserArray = array_merge( $acceptedUserArray, $userArray );
258
259 foreach ( $userArray as $userID )
260 {
261 $userIDArray[(string)$userID] = false;
262 }
263 }
264
265 foreach( $limitedPolicyIDArray as $policyEntry )
266 {
267 if ( $policyEntry['user_id'] === false )
268 {
269 continue;
270 }
271
272 $userArray = eZSubtreeNotificationRule::checkObjectAccess( $contentObject,
273 $policyEntry['policyID'],
274 array( $policyEntry['user_id'] ),
275 array( $policyEntry['limitation'] => $policyEntry['value'] ) );
276
277 $acceptedUserArray = array_merge( $acceptedUserArray, $userArray );
278 foreach ( $userArray as $userID )
279 {
280 $userIDArray[(string)$userID] = false;
281 }
282 }
283 $acceptedUserArray = array_unique( $acceptedUserArray );
284
285 foreach( array_keys( $acceptedUserArray ) as $key )
286 {
287 if ( !is_int( $acceptedUserArray[$key] ) or $acceptedUserArray[$key] == 0 )
288 {
289 unset( $acceptedUserArray[$key] );
290 }
291 }
292
293 if ( count( $acceptedUserArray ) == 0 )
294 {
295 $retValue = array();
296 return $retValue;
297 }
298
299 $nodeIDWhereString = $db->generateSQLINStatement( $nodeIDList, 'rule.node_id', false, false, 'int' );
300 $userIDWhereString = $db->generateSQLINStatement( $acceptedUserArray, 'rule.user_id', false, false, 'int' );
301 $rules = $db->arrayQuery( "SELECT rule.user_id, rule.use_digest, ezuser.email as address
302 FROM ezsubtree_notification_rule rule, ezuser
303 WHERE rule.user_id=ezuser.contentobject_id AND
304 $nodeIDWhereString AND
305 $userIDWhereString" );
306 return $rules;
307 }
308
321 static function checkObjectAccess( $contentObject, $policyID, $userIDArray, $userLimits = false )
322 {
323 $policy = eZPolicy::fetch( $policyID );
324 if ( $userLimits )
325 {
326 reset( $userLimits );
327 $policy->setAttribute( 'limit_identifier', 'User_' . key( $userLimits ) );
328 $policy->setAttribute( 'limit_value', current( $userLimits ) );
329 }
330
331 $limitationArray = $policy->accessArray();
332 $limitationArray = current( current( $limitationArray ) );
333 $accessUserIDArray = $userIDArray;
334
335 if ( isset( $limitationArray['*'] ) &&
336 $limitationArray['*'] == '*' )
337 {
338 $returnArray = array();
339 foreach ( $accessUserIDArray as $userID )
340 {
341 $returnArray[] = $userID;
342 }
343 return $returnArray;
344 }
345
346 $limitationArray = current( $limitationArray );
347
348 $user = eZUser::currentUser();
349 $classID = $contentObject->attribute( 'contentclass_id' );
350 $nodeArray = $contentObject->attribute( 'assigned_nodes' );
351
352 if ( isset( $limitationArray['Subtree' ] ) )
353 {
354 $checkedSubtree = false;
355 }
356 else
357 {
358 $checkedSubtree = true;
359 $nodeSubtree = true;
360 }
361 if ( isset( $limitationArray['Node'] ) )
362 {
363 $checkedNode = false;
364 }
365 else
366 {
367 $checkedNode = true;
368 $nodeLimit = true;
369 }
370
371 foreach ( array_keys( $limitationArray ) as $key )
372 {
373 if ( count( $accessUserIDArray ) == 0 )
374 {
375 return array();
376 }
377 switch( $key )
378 {
379 case 'Class':
380 {
381 if ( !in_array( $contentObject->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
382 {
383 return array();
384 }
385 } break;
386
387 case 'ParentClass':
388 {
389
390 if ( !in_array( $contentObject->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
391 {
392 return array();
393 }
394 } break;
395
396 case 'Section':
397 case 'User_Section':
398 {
399 if ( !in_array( $contentObject->attribute( 'section_id' ), $limitationArray[$key] ) )
400 {
401 return array();
402 }
403 } break;
404
405 case 'Owner':
406 {
407 if ( in_array( $contentObject->attribute( 'owner_id' ), $userIDArray ) )
408 {
409 $accessUserIDArray = array( $contentObject->attribute( 'owner_id' ) );
410 }
411 else if ( in_array( $contentObject->attribute( 'id' ), $userIDArray ) )
412 {
413 $accessUserIDArray = array( $contentObject->attribute( 'id' ) );
414 }
415 else
416 {
417 return array();
418 }
419 } break;
420
421 case 'Node':
422 {
423 $nodeLimit = true;
424 foreach ( $nodeArray as $node )
425 {
426 if( in_array( $node->attribute( 'node_id' ), $limitationArray[$key] ) )
427 {
428 $nodeLimit = false;
429 break;
430 }
431 }
432 if ( $nodeLimit && $checkedSubtree && $nodeSubtree )
433 {
434 return array();
435 }
436 $checkedNode = true;
437 } break;
438
439 case 'Subtree':
440 {
441 $nodeSubtree = true;
442 foreach ( $nodeArray as $node )
443 {
444 $path = $node->attribute( 'path_string' );
445 $subtreeArray = $limitationArray[$key];
446 $validSubstring = false;
447 foreach ( $subtreeArray as $subtreeString )
448 {
449 if ( strstr( $path, $subtreeString ) )
450 {
451 $nodeSubtree = false;
452 break;
453 }
454 }
455 if ( !$nodeSubtree )
456 {
457 break;
458 }
459 }
460 if ( $nodeSubtree && $checkedNode && $nodeLimit )
461 {
462 return array();
463 }
464 $checkedSubtree = true;
465 } break;
466
467 case 'User_Subtree':
468 {
469 $userSubtreeLimit = true;
470 foreach ( $nodeArray as $node )
471 {
472 $path = $node->attribute( 'path_string' );
473 $subtreeArray = $limitationArray[$key];
474 $validSubstring = false;
475 foreach ( $subtreeArray as $subtreeString )
476 {
477 if ( strstr( $path, $subtreeString ) )
478 {
479 $userSubtreeLimit = false;
480 break;
481 }
482 }
483 if ( !$userSubtreeLimit )
484 {
485 break;
486 }
487 }
488 if ( $userSubtreeLimit )
489 {
490 return array();
491 }
492 } break;
493 default:
494 {
495 //check object state group limitation
496 if ( strncmp( $key, 'StateGroup_', 11 ) === 0 )
497 {
498 if ( count( array_intersect( $limitationArray[$key],
499 $contentObject->attribute( 'state_id_array' ) ) ) == 0 )
500 {
501 return array();
502 }
503 }
504 }
505 }
506 }
507
508 $returnArray = array();
509 foreach ( $accessUserIDArray as $userID )
510 {
511 $returnArray[] = $userID;
512 }
513 return $returnArray;
514 }
515
516 function node()
517 {
518 if ( $this->Node == null )
519 {
520 $this->Node = eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) );
521 }
522 return $this->Node;
523 }
524
525 static function removeByNodeAndUserID( $userID, $nodeID )
526 {
527 eZPersistentObject::removeObject( eZSubtreeNotificationRule::definition(), array( 'user_id' => $userID,
528 'node_id' => $nodeID ) );
529 }
530
538 static function removeByUserID( $userID )
539 {
540 eZPersistentObject::removeObject( eZSubtreeNotificationRule::definition(), array( 'user_id' => $userID ) );
541 }
542
547 static function cleanup()
548 {
549 $db = eZDB::instance();
550 $db->query( "DELETE FROM ezsubtree_notification_rule" );
551 }
552
553 public $Node = null;
554 }
555
556 ?>
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
eZPersistentObject
Definition: ezpersistentobject.php:33
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
eZPolicy\fetch
static fetch( $policyID)
Definition: ezpolicy.php:377
eZSubtreeNotificationRule
The class eZSubtreeNotificationRule does.
Definition: ezsubtreenotificationrule.php:17
eZSubtreeNotificationRule\fetchUserList
static fetchUserList( $nodeIDList, $contentObject)
Definition: ezsubtreenotificationrule.php:113
eZSubtreeNotificationRule\definition
static definition()
Definition: ezsubtreenotificationrule.php:18
eZSubtreeNotificationRule\checkObjectAccess
static checkObjectAccess( $contentObject, $policyID, $userIDArray, $userLimits=false)
Definition: ezsubtreenotificationrule.php:321
eZSubtreeNotificationRule\cleanup
static cleanup()
Definition: ezsubtreenotificationrule.php:547
eZSubtreeNotificationRule\fetchListCount
static fetchListCount( $userID)
Definition: ezsubtreenotificationrule.php:90
eZSubtreeNotificationRule\removeByUserID
static removeByUserID( $userID)
Definition: ezsubtreenotificationrule.php:538
eZSubtreeNotificationRule\$Node
$Node
Definition: ezsubtreenotificationrule.php:553
eZSubtreeNotificationRule\node
node()
Definition: ezsubtreenotificationrule.php:516
eZSubtreeNotificationRule\create
static create( $nodeID, $userID, $useDigest=0)
Definition: ezsubtreenotificationrule.php:51
eZSubtreeNotificationRule\fetchNodesForUserID
static fetchNodesForUserID( $userID, $asObject=true)
Definition: ezsubtreenotificationrule.php:59
eZSubtreeNotificationRule\fetchList
static fetchList( $userID, $asObject=true, $offset=false, $limit=false)
Definition: ezsubtreenotificationrule.php:82
eZSubtreeNotificationRule\removeByNodeAndUserID
static removeByNodeAndUserID( $userID, $nodeID)
Definition: ezsubtreenotificationrule.php:525
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.