[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZSubtreeNotificationRule class 4 // 5 // Created on: <14-May-2003 16:20:24 sp> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezsubtreenotificationrule.php 30 */ 31 32 /*! 33 \class eZSubtreeNotificationRule ezsubtreenotificationrule.php 34 \brief The class eZSubtreeNotificationRule does 35 36 */ 37 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 38 39 class eZSubtreeNotificationRule extends eZPersistentObject 40 { 41 /*! 42 Constructor 43 */ 44 function eZSubtreeNotificationRule( $row ) 45 { 46 $this->eZPersistentObject( $row ); 47 } 48 49 function definition() 50 { 51 return array( "fields" => array( "id" => array( 'name' => 'ID', 52 'datatype' => 'integer', 53 'default' => 0, 54 'required' => true ), 55 "user_id" => array( 'name' => "UserID", 56 'datatype' => 'integer', 57 'default' => '', 58 'required' => true, 59 'foreign_class' => 'eZUser', 60 'foreign_attribute' => 'contentobject_id', 61 'multiplicity' => '1..*' ), 62 "use_digest" => array( 'name' => "UseDigest", 63 'datatype' => 'integer', 64 'default' => 0, 65 'required' => true ), 66 "node_id" => array( 'name' => "NodeID", 67 'datatype' => 'integer', 68 'default' => 0, 69 'required' => true, 70 'foreign_class' => 'eZContentObjectTreeNode', 71 'foreign_attribute' => 'node_id', 72 'multiplicity' => '1..*' ) ), 73 "keys" => array( "id" ), 74 "function_attributes" => array( 'node' => 'node' ), 75 "increment_key" => "id", 76 "sort" => array( "id" => "asc" ), 77 "class_name" => "eZSubtreeNotificationRule", 78 "name" => "ezsubtree_notification_rule" ); 79 } 80 81 82 function create( $nodeID, $userID, $useDigest = 0 ) 83 { 84 $rule = new eZSubtreeNotificationRule( array( 'user_id' => $userID, 85 'use_digest' => $useDigest, 86 'node_id' => $nodeID ) ); 87 return $rule; 88 } 89 90 function fetchNodesForUserID( $userID, $asObject = true ) 91 { 92 $nodeIDList = eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(), 93 array( 'node_id' ), array( 'user_id' => $userID ), 94 null,null,false ); 95 $nodes = array(); 96 if ( $asObject ) 97 { 98 foreach ( $nodeIDList as $nodeRow ) 99 { 100 $nodes[] = eZContentObjectTreeNode::fetch( $nodeRow['node_id'] ); 101 } 102 } 103 else 104 { 105 foreach ( $nodeIDList as $nodeRow ) 106 { 107 $nodes[] = $nodeRow['node_id']; 108 } 109 } 110 return $nodes; 111 } 112 113 function fetchList( $userID, $asObject = true, $offset = false, $limit = false ) 114 { 115 return eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(), 116 null, array( 'user_id' => $userID ), 117 null, array( 'offset' => $offset, 118 'length' => $limit ), $asObject ); 119 } 120 121 function fetchListCount( $userID ) 122 { 123 $custom = array( array( 'operation' => 'count( id )', 124 'name' => 'count' ) ); 125 $countRes = eZPersistentObject::fetchObjectList( eZSubtreeNotificationRule::definition(), 126 array(), array( 'user_id' => $userID ), 127 false, null, false, false, $custom ); 128 return $countRes[0]['count']; 129 } 130 131 /*! 132 Fetch allowed subtreenotification rules based upon node id list and array pf nodes 133 134 \param node id list for notification event. 135 \param content object to add 136 137 \return array of eZSubtreeNotificationRule objects 138 */ 139 function fetchUserList( $nodeIDList, $contentObject ) 140 { 141 if ( count( $nodeIDList ) == 0 ) 142 { 143 $retValue = array(); 144 return $retValue; 145 } 146 147 $db =& eZDB::instance(); 148 $concatString = $db->concatString( array( 'user_tree.path_string', "'%'" ) ); 149 150 $sql = 'SELECT DISTINCT policy.id AS policy_id, subtree_rule.user_id, 151 user_role.limit_identifier AS limitation, 152 user_role.limit_value AS value 153 FROM ezuser_role user_role, 154 ezsubtree_notification_rule subtree_rule, 155 ezcontentobject_tree user_tree, 156 ezcontentobject_tree user_node, 157 ezpolicy policy 158 WHERE subtree_rule.node_id IN ( ' . $db->implodeWithTypeCast( ', ', $nodeIDList, 'int' ) . ' ) AND 159 user_node.contentobject_id=subtree_rule.user_id AND 160 user_node.path_string like ' . $concatString . " AND 161 user_role.contentobject_id=user_tree.contentobject_id AND 162 ( user_role.role_id=policy.role_id AND ( policy.module_name='*' OR ( policy.module_name='content' AND ( policy.function_name='*' OR policy.function_name='read' ) ) ) )"; 163 164 $resultArray = $db->arrayQuery( $sql ); 165 166 $policyIDArray = array(); 167 $limitedPolicyIDArray = array(); 168 $userIDArray = array(); 169 foreach( $resultArray as $result ) 170 { 171 $userIDArray[(string)$result['user_id']] = (int)$result['user_id']; 172 } 173 174 foreach( $resultArray as $result ) 175 { 176 if ( $result['limitation'] == '' ) 177 { 178 $policyIDArray[(string)$result['policy_id']][] =& $userIDArray[(string)$result['user_id']]; 179 } 180 else 181 { 182 $limitedPolicyIDArray[] = array( 'user_id' => &$userIDArray[(string)$result['user_id']], 183 'limitation' => $result['limitation'], 184 'value' => $result['value'], 185 'policyID' => $result['policy_id'] ); 186 } 187 } 188 189 include_once ( 'kernel/classes/ezpolicy.php' ); 190 $acceptedUserArray = array(); 191 foreach( array_keys( $policyIDArray ) as $policyID ) 192 { 193 foreach( array_keys( $policyIDArray[$policyID] ) as $key ) 194 { 195 if ( $policyIDArray[$policyID][$key] === false ) 196 { 197 unset( $policyIDArray[$policyID][$key] ); 198 } 199 } 200 201 if ( count( $policyIDArray[$policyID] ) == 0 ) 202 { 203 continue; 204 } 205 206 $userArray = eZSubtreeNotificationRule::checkObjectAccess( $contentObject, $policyID, $policyIDArray[$policyID] ); 207 $acceptedUserArray = array_unique( array_merge( $acceptedUserArray, $userArray ) ); 208 209 foreach ( $userArray as $userID ) 210 { 211 $userIDArray[(string)$userID] = false; 212 } 213 } 214 215 foreach( $limitedPolicyIDArray as $policyEntry ) 216 { 217 if ( $policyEntry['user_id'] === false ) 218 { 219 continue; 220 } 221 222 $userArray = eZSubtreeNotificationRule::checkObjectAccess( $contentObject, 223 $policyEntry['policyID'], 224 array( $policyEntry['user_id'] ), 225 array( $policyEntry['limitation'] => $policyEntry['value'] ) ); 226 227 $acceptedUserArray = array_unique( array_merge( $acceptedUserArray, $userArray ) ); 228 foreach ( $userArray as $userID ) 229 { 230 $userIDArray[(string)$userID] = false; 231 } 232 } 233 234 foreach( array_keys( $acceptedUserArray ) as $key ) 235 { 236 if ( !is_int( $acceptedUserArray[$key] ) || $acceptedUserArray[$key] == 0 ) 237 { 238 unset( $acceptedUserArray[$key] ); 239 } 240 } 241 242 if ( count( $acceptedUserArray ) == 0 ) 243 { 244 $retValue = array(); 245 return $retValue; 246 } 247 248 $nodeIDWhereString = $db->implodeWithTypeCast( ', ', $nodeIDList, 'int' ); 249 $userIDWhereString = $db->implodeWithTypeCast( ', ', $acceptedUserArray, 'int' ); 250 $rules = $db->arrayQuery( "SELECT rule.user_id, rule.use_digest, ezuser.email as address 251 FROM ezsubtree_notification_rule rule, ezuser 252 WHERE rule.user_id=ezuser.contentobject_id AND 253 rule.node_id IN ( $nodeIDWhereString ) AND 254 rule.user_id IN ( $userIDWhereString )" ); 255 return $rules; 256 } 257 258 /*! 259 \private 260 261 Check access for specified policy on object, and user list. 262 263 \param Content object 264 \param policyID 265 \param userID array 266 \param user limits 267 268 \return array of user ID's which has access to object 269 */ 270 function checkObjectAccess( $contentObject, $policyID, $userIDArray, $userLimits = false ) 271 { 272 $policy = eZPolicy::fetch( $policyID ); 273 if ( $userLimits ) 274 { 275 reset( $userLimits ); 276 $policy->setAttribute( 'limit_identifier', 'User_' . key( $userLimits ) ); 277 $policy->setAttribute( 'limit_value', current( $userLimits ) ); 278 } 279 280 $limitationArray = $policy->accessArray(); 281 $limitationArray = current( current( $limitationArray ) ); 282 $accessUserIDArray = $userIDArray; 283 284 if ( isset( $limitationArray['*'] ) && 285 $limitationArray['*'] == '*' ) 286 { 287 $returnArray = array(); 288 foreach ( $accessUserIDArray as $userID ) 289 { 290 $returnArray[] = $userID; 291 } 292 return $returnArray; 293 } 294 295 $limitationArray = current( $limitationArray ); 296 297 $user =& eZUser::currentUser(); 298 $classID = $contentObject->attribute( 'contentclass_id' ); 299 $nodeArray = $contentObject->attribute( 'assigned_nodes' ); 300 301 if ( isset( $limitationArray['Subtree' ] ) ) 302 { 303 $checkedSubtree = false; 304 } 305 else 306 { 307 $checkedSubtree = true; 308 $nodeSubtree = true; 309 } 310 if ( isset( $limitationArray['Node'] ) ) 311 { 312 $checkedNode = false; 313 } 314 else 315 { 316 $checkedNode = true; 317 $nodeLimit = true; 318 } 319 320 foreach ( array_keys( $limitationArray ) as $key ) 321 { 322 if ( count( $accessUserIDArray ) == 0 ) 323 { 324 return array(); 325 } 326 switch( $key ) 327 { 328 case 'Class': 329 { 330 if ( !in_array( $contentObject->attribute( 'contentclass_id' ), $limitationArray[$key] ) ) 331 { 332 return array(); 333 } 334 } break; 335 336 case 'ParentClass': 337 { 338 339 if ( !in_array( $contentObject->attribute( 'contentclass_id' ), $limitationArray[$key] ) ) 340 { 341 return array(); 342 } 343 } break; 344 345 case 'Section': 346 case 'User_Section': 347 { 348 if ( !in_array( $contentObject->attribute( 'section_id' ), $limitationArray[$key] ) ) 349 { 350 return array(); 351 } 352 } break; 353 354 case 'Owner': 355 { 356 if ( in_array( $contentObject->attribute( 'owner_id' ), $userIDArray ) ) 357 { 358 $accessUserIDArray = array_intersect( $contentObject->attribute( 'owner_id' ), $accessUserIDArray ); 359 } 360 else if ( in_array( $contentObject->ID, $userIDArray ) ) 361 { 362 $accessUserIDArray = array_intersect( $contentObject->ID, $accessUserIDArray ); 363 } 364 else 365 { 366 return array(); 367 } 368 } break; 369 370 case 'Node': 371 { 372 $nodeLimit = true; 373 foreach ( $nodeArray as $node ) 374 { 375 if( in_array( $node->attribute( 'node_id' ), $limitationArray[$key] ) ) 376 { 377 $nodeLimit = false; 378 break; 379 } 380 } 381 if ( $nodeLimit && $checkedSubtree && $nodeSubtree ) 382 { 383 return array(); 384 } 385 $checkedNode = true; 386 } break; 387 388 case 'Subtree': 389 { 390 $nodeSubtree = true; 391 foreach ( $nodeArray as $node ) 392 { 393 $path = $node->attribute( 'path_string' ); 394 $subtreeArray = $limitationArray[$key]; 395 $validSubstring = false; 396 foreach ( $subtreeArray as $subtreeString ) 397 { 398 if ( strstr( $path, $subtreeString ) ) 399 { 400 $nodeSubtree = false; 401 break; 402 } 403 } 404 if ( !$nodeSubtree ) 405 { 406 break; 407 } 408 } 409 if ( $nodeSubtree && $checkedNode && $nodeLimit ) 410 { 411 return array(); 412 } 413 $checkedSubtree = true; 414 } break; 415 416 case 'User_Subtree': 417 { 418 $userSubtreeLimit = true; 419 foreach ( $nodeArray as $node ) 420 { 421 $path = $node->attribute( 'path_string' ); 422 $subtreeArray = $limitationArray[$key]; 423 $validSubstring = false; 424 foreach ( $subtreeArray as $subtreeString ) 425 { 426 if ( strstr( $path, $subtreeString ) ) 427 { 428 $userSubtreeLimit = false; 429 break; 430 } 431 } 432 if ( !$userSubtreeLimit ) 433 { 434 break; 435 } 436 } 437 if ( $userSubtreeLimit ) 438 { 439 return array(); 440 } 441 } break; 442 } 443 } 444 445 $returnArray = array(); 446 foreach ( $accessUserIDArray as $userID ) 447 { 448 $returnArray[] = $userID; 449 } 450 return $returnArray; 451 } 452 453 function &node() 454 { 455 if ( $this->Node == null ) 456 { 457 $this->Node = eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) ); 458 } 459 return $this->Node; 460 } 461 462 function removeByNodeAndUserID( $userID, $nodeID ) 463 { 464 eZPersistentObject::removeObject( eZSubtreeNotificationRule::definition(), array( 'user_id' => $userID, 465 'node_id' => $nodeID ) ); 466 } 467 468 /*! 469 \static 470 471 Remove notifications by user id 472 473 \param userID 474 */ 475 function removeByUserID( $userID ) 476 { 477 eZPersistentObject::removeObject( eZSubtreeNotificationRule::definition(), array( 'user_id' => $userID ) ); 478 } 479 480 /*! 481 \static 482 Cleans up all notification rules for all users. 483 */ 484 function cleanup() 485 { 486 $db =& eZDB::instance(); 487 $db->query( "DELETE FROM ezsubtree_notification_rule" ); 488 } 489 490 var $Node = null; 491 } 492 493 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |