[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZApproveType class 4 // 5 // Created on: <16-Apr-2002 11:08:14 amos> 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 /*! 30 \class eZApproveType ezapprovetype.php 31 \brief Event type for user approvals 32 33 WorkflowEvent storage fields : data_text1 - selected_sections 34 data_text2 - selected_usergroups 35 data_text3 - approve_users 36 data_text4 - approve_groups 37 data_int2 - language_list 38 data_int3 - content object version option 39 */ 40 41 include_once ( "kernel/classes/ezworkflowtype.php" ); 42 include_once ( 'kernel/classes/collaborationhandlers/ezapprove/ezapprovecollaborationhandler.php' ); 43 44 define( "EZ_WORKFLOW_TYPE_APPROVE_ID", "ezapprove" ); 45 46 define( "EZ_APPROVE_COLLABORATION_NOT_CREATED", 0 ); 47 define( "EZ_APPROVE_COLLABORATION_CREATED", 1 ); 48 49 define( 'EZ_APPROVE_VERSION_OPTION_FIRST_ONLY', 1 ); 50 define( 'EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST', 2 ); 51 define( 'EZ_APPROVE_VERSION_OPTION_ALL', EZ_APPROVE_VERSION_OPTION_FIRST_ONLY | EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST ); 52 53 class eZApproveType extends eZWorkflowEventType 54 { 55 function eZApproveType() 56 { 57 $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_APPROVE_ID, ezi18n( 'kernel/workflow/event', "Approve" ) ); 58 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before' ) ) ) ); 59 } 60 61 function &attributeDecoder( &$event, $attr ) 62 { 63 switch ( $attr ) 64 { 65 case 'selected_sections': 66 { 67 $returnValue = explode( ',', $event->attribute( 'data_text1' ) ); 68 return $returnValue; 69 } break; 70 71 case 'approve_users': 72 { 73 if ( $event->attribute( 'data_text3' ) == '' ) 74 { 75 $returnValue = array(); 76 return $returnValue; 77 } 78 $returnValue = explode( ',', $event->attribute( 'data_text3' ) ); 79 return $returnValue; 80 }break; 81 82 case 'approve_groups': 83 { 84 if ( $event->attribute( 'data_text4' ) == '' ) 85 { 86 $returnValue = array(); 87 return $returnValue; 88 } 89 $returnValue = explode( ',', $event->attribute( 'data_text4' ) ); 90 return $returnValue; 91 }break; 92 93 case 'selected_usergroups': 94 { 95 if ( $event->attribute( 'data_text2' ) == '' ) 96 { 97 $returnValue = array(); 98 return $returnValue; 99 } 100 $returnValue = explode( ',', $event->attribute( 'data_text2' ) ); 101 return $returnValue; 102 } break; 103 104 case 'language_list': 105 { 106 if ( $event->attribute( 'data_int2' ) == 0 ) 107 { 108 $returnValue = array(); 109 return $returnValue; 110 } 111 include_once ( 'kernel/classes/ezcontentlanguage.php' ); 112 $languages = eZContentLanguage::languagesByMask( $event->attribute( 'data_int2' ) ); 113 $returnValue = array(); 114 foreach ( $languages as $language ) 115 { 116 $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' ); 117 } 118 return $returnValue; 119 } break; 120 121 case 'version_option': 122 { 123 $retValue = EZ_APPROVE_VERSION_OPTION_ALL & $event->attribute( 'data_int3' ); 124 return $retValue; 125 } break; 126 } 127 $retValue = null; 128 return $retValue; 129 } 130 131 function typeFunctionalAttributes( ) 132 { 133 return array( 'selected_sections', 134 'approve_users', 135 'approve_groups', 136 'selected_usergroups', 137 'language_list', 138 'version_option' ); 139 } 140 141 function attributes() 142 { 143 return array_merge( array( 'sections', 144 'languages', 145 'users', 146 'usergroups' ), 147 eZWorkflowEventType::attributes() ); 148 149 } 150 151 function hasAttribute( $attr ) 152 { 153 return in_array( $attr, $this->attributes() ); 154 } 155 156 function &attribute( $attr ) 157 { 158 switch( $attr ) 159 { 160 case 'sections': 161 { 162 include_once ( 'kernel/classes/ezsection.php' ); 163 $sections = eZSection::fetchList( false ); 164 foreach ( array_keys( $sections ) as $key ) 165 { 166 $section =& $sections[$key]; 167 $section['Name'] = $section['name']; 168 $section['value'] = $section['id']; 169 } 170 return $sections; 171 }break; 172 case 'languages': 173 { 174 include_once ( 'kernel/classes/ezcontentlanguage.php' ); 175 $languages = eZContentLanguage::fetchList(); 176 return $languages; 177 }break; 178 } 179 $eventValue =& eZWorkflowEventType::attribute( $attr ); 180 return $eventValue; 181 } 182 183 function execute( &$process, &$event ) 184 { 185 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process, 'eZApproveType::execute' ); 186 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'eZApproveType::execute' ); 187 $parameters = $process->attribute( 'parameter_list' ); 188 $versionID =& $parameters['version']; 189 $object =& eZContentObject::fetch( $parameters['object_id'] ); 190 191 if ( !$object ) 192 { 193 eZDebugSetting::writeError( 'kernel-workflow-approve', $parameters['object_id'], 'eZApproveType::execute' ); 194 return EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED; 195 } 196 197 // version option checking 198 $version_option = $event->attribute( 'version_option' ); 199 if ( ( $version_option == EZ_APPROVE_VERSION_OPTION_FIRST_ONLY and $parameters['version'] > 1 ) or 200 ( $version_option == EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST and $parameters['version'] == 1 ) ) 201 { 202 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED; 203 } 204 205 /* 206 If we run event first time ( when we click publish in admin ) we do not have user_id set in workflow process, 207 so we take current user and store it in workflow process, so next time when we run event from cronjob we fetch 208 user_id from there. 209 */ 210 if ( $process->attribute( 'user_id' ) == 0 ) 211 { 212 $user =& eZUser::currentUser(); 213 $process->setAttribute( 'user_id', $user->id() ); 214 } 215 else 216 { 217 $user =& eZUser::instance( $process->attribute( 'user_id' ) ); 218 } 219 220 $userGroups = array_merge( $user->attribute( 'groups' ), $user->attribute( 'contentobject_id' ) ); 221 $workflowSections = explode( ',', $event->attribute( 'data_text1' ) ); 222 $workflowGroups = explode( ',', $event->attribute( 'data_text2' ) ); 223 $editors = explode( ',', $event->attribute( 'data_text3' ) ); //$event->attribute( 'data_int1' ); 224 $approveGroups = explode( ',', $event->attribute( 'data_text4' ) ); 225 $languageMask = $event->attribute( 'data_int2' ); 226 227 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user, 'eZApproveType::execute::user' ); 228 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, 'eZApproveType::execute::userGroups' ); 229 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $editors, 'eZApproveType::execute::editor' ); 230 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections, 'eZApproveType::execute::workflowSections' ); 231 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, 'eZApproveType::execute::workflowGroups' ); 232 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $languageMask, 'eZApproveType::execute::languageMask' ); 233 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $object->attribute( 'section_id'), 'eZApproveType::execute::section_id' ); 234 235 $section = $object->attribute( 'section_id'); 236 $correctSection = false; 237 238 if ( !in_array( $section, $workflowSections ) && !in_array( -1, $workflowSections ) ) 239 { 240 $assignedNodes = $object->attribute( 'assigned_nodes' ); 241 if ( $assignedNodes ) 242 { 243 foreach( $assignedNodes as $assignedNode ) 244 { 245 $parent =& $assignedNode->attribute( 'parent' ); 246 $parentObject =& $parent->object(); 247 $section = $parentObject->attribute( 'section_id'); 248 249 if ( in_array( $section, $workflowSections ) ) 250 { 251 $correctSection = true; 252 break; 253 } 254 } 255 } 256 } 257 else 258 $correctSection = true; 259 260 $inExcludeGroups = count( array_intersect( $userGroups, $workflowGroups ) ) != 0; 261 262 $userIsEditor = ( in_array( $user->id(), $editors ) || 263 count( array_intersect( $userGroups, $approveGroups ) ) != 0 ); 264 265 // All languages match by default 266 $hasLanguageMatch = true; 267 if ( $languageMask != 0 ) 268 { 269 // Examine if the published version contains one of the languages we 270 // match for. 271 $version =& $object->version( $versionID ); 272 // If the language ID is part of the mask the result is non-zero. 273 $languageID = (int)$version->attribute( 'initial_language_id' ); 274 $hasLanguageMatch = (bool)( $languageMask & $languageID ); 275 } 276 277 if ( $hasLanguageMatch and 278 !$userIsEditor and 279 !$inExcludeGroups and 280 $correctSection ) 281 { 282 283 /* Get user IDs from approve user groups */ 284 $ini =& eZINI::instance(); 285 $userClassIDArray = array( $ini->variable( 'UserSettings', 'UserClassID' ) ); 286 $approveUserIDArray = array(); 287 foreach( $approveGroups as $approveUserGroupID ) 288 { 289 if ( $approveUserGroupID != false ) 290 { 291 $approveUserGroup =& eZContentObject::fetch( $approveUserGroupID ); 292 if ( isset( $approveUserGroup ) ) 293 foreach( $approveUserGroup->attribute( 'assigned_nodes' ) as $assignedNode ) 294 { 295 $userNodeArray =& $assignedNode->subTree( array( 'ClassFilterType' => 'include', 296 'ClassFilterArray' => $userClassIDArray, 297 'Limitation' => array() ) ); 298 foreach( $userNodeArray as $userNode ) 299 { 300 $approveUserIDArray[] = $userNode->attribute( 'contentobject_id' ); 301 } 302 } 303 } 304 } 305 $approveUserIDArray = array_merge( $approveUserIDArray, $editors ); 306 $approveUserIDArray = array_unique( $approveUserIDArray ); 307 308 $collaborationID = false; 309 $db = & eZDb::instance(); 310 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) ); 311 if ( count( $taskResult ) > 0 ) 312 $collaborationID = $taskResult[0]['collaboration_id']; 313 314 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $collaborationID, 'approve collaborationID' ); 315 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process->attribute( 'event_state'), 'approve $process->attribute( \'event_state\')' ); 316 if ( $collaborationID === false ) 317 { 318 $this->createApproveCollaboration( $process, $event, $user->id(), $object->attribute( 'id' ), $versionID, $approveUserIDArray ); 319 $this->setInformation( "We are going to create approval" ); 320 $process->setAttribute( 'event_state', EZ_APPROVE_COLLABORATION_CREATED ); 321 $process->store(); 322 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve execute' ); 323 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT; 324 } 325 else if ( $process->attribute( 'event_state') == EZ_APPROVE_COLLABORATION_NOT_CREATED ) 326 { 327 eZApproveCollaborationHandler::activateApproval( $collaborationID ); 328 $process->setAttribute( 'event_state', EZ_APPROVE_COLLABORATION_CREATED ); 329 $process->store(); 330 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve re-execute' ); 331 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT; 332 } 333 else //EZ_APPROVE_COLLABORATION_CREATED 334 { 335 $this->setInformation( "we are checking approval now" ); 336 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'check approval' ); 337 return $this->checkApproveCollaboration( $process, $event ); 338 } 339 } 340 else 341 { 342 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections , "we are not going to create approval " . $object->attribute( 'section_id') ); 343 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, "we are not going to create approval" ); 344 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, "we are not going to create approval" ); 345 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user->id(), "we are not going to create approval " ); 346 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED; 347 } 348 } 349 350 function initializeEvent( &$event ) 351 { 352 } 353 354 function validateUserIDList( $userIDList, &$reason ) 355 { 356 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 357 foreach ( $userIDList as $userID ) 358 { 359 if ( !is_numeric( $userID ) or 360 !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) ) 361 { 362 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID; 363 $reason[ 'list' ][] = $userID; 364 } 365 } 366 $reason[ 'text' ] = "Some of passed user IDs are not valid, must be IDs of existing users only."; 367 return $returnState; 368 } 369 370 function validateGroupIDList( $userGroupIDList, &$reason ) 371 { 372 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 373 $groupClassNames = eZUser::fetchUserGroupClassNames(); 374 if ( count( $groupClassNames ) > 0 ) 375 { 376 foreach( $userGroupIDList as $userGroupID ) 377 { 378 if ( !is_numeric( $userGroupID ) or 379 !is_object( $userGroup =& eZContentObject::fetch( $userGroupID ) ) or 380 !in_array( $userGroup->attribute( 'class_identifier' ), $groupClassNames ) ) 381 { 382 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID; 383 $reason[ 'list' ][] = $userGroupID; 384 } 385 } 386 $reason[ 'text' ] = "Some of passed user-group IDs are not valid, must be IDs of existing user groups only."; 387 } 388 else 389 { 390 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID; 391 $reason[ 'text' ] = "There is no one user-group classes among the user accounts, please choose standalone users."; 392 } 393 return $returnState; 394 } 395 396 function validateHTTPInput( &$http, $base, &$workflowEvent, &$validation ) 397 { 398 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 399 $reason = array(); 400 401 if ( !$http->hasSessionVariable( 'BrowseParameters' ) ) 402 { 403 // check approve-users 404 $approversIDs = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_users' ) ); 405 if ( is_array( $approversIDs ) and 406 count( $approversIDs ) > 0 ) 407 { 408 $returnState = eZApproveType::validateUserIDList( $approversIDs, $reason ); 409 } 410 else 411 $returnState = false; 412 413 if ( $returnState != EZ_INPUT_VALIDATOR_STATE_INVALID ) 414 { 415 // check approve-groups 416 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_groups' ) ); 417 if ( is_array( $userGroupIDList ) and 418 count( $userGroupIDList ) > 0 ) 419 { 420 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason ); 421 } 422 else if ( $returnState === false ) 423 { 424 // if no one user or user-group was passed as approvers 425 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID; 426 $reason[ 'text' ] = "There must be passed at least one valid user or user group who approves content for the event."; 427 } 428 429 // check excluded-users 430 /* 431 if ( $returnState != EZ_INPUT_VALIDATOR_STATE_INVALID ) 432 { 433 // TODO: 434 // .... 435 } 436 */ 437 438 // check excluded-groups 439 if ( $returnState != EZ_INPUT_VALIDATOR_STATE_INVALID ) 440 { 441 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ) ); 442 if ( is_array( $userGroupIDList ) and 443 count( $userGroupIDList ) > 0 ) 444 { 445 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason ); 446 } 447 } 448 } 449 } 450 else 451 { 452 $browseParameters =& $http->sessionVariable( 'BrowseParameters' ); 453 if ( isset( $browseParameters['custom_action_data'] ) ) 454 { 455 $customData = $browseParameters['custom_action_data']; 456 if ( isset( $customData['event_id'] ) and 457 $customData['event_id'] == $workflowEvent->attribute( 'id' ) ) 458 { 459 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and 460 $http->hasPostVariable( 'SelectedObjectIDArray' ) ) 461 { 462 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' ); 463 if ( is_array( $objectIDArray ) and 464 count( $objectIDArray ) > 0 ) 465 { 466 switch( $customData['browse_action'] ) 467 { 468 case "AddApproveUsers": 469 { 470 $returnState = eZApproveType::validateUserIDList( $objectIDArray, $reason ); 471 } break; 472 case 'AddApproveGroups': 473 case 'AddExcludeUser': 474 { 475 $returnState = eZApproveType::validateGroupIDList( $objectIDArray, $reason ); 476 } break; 477 case 'AddExcludedGroups': 478 { 479 // TODO: 480 // ..... 481 } break; 482 } 483 } 484 } 485 } 486 } 487 } 488 489 if ( $returnState == EZ_INPUT_VALIDATOR_STATE_INVALID ) 490 { 491 $validation[ 'processed' ] = true; 492 $validation[ 'events' ][] = array( 'id' => $workflowEvent->attribute( 'id' ), 493 'placement' => $workflowEvent->attribute( 'placement' ), 494 'workflow_type' => &$this, 495 'reason' => $reason ); 496 } 497 return $returnState; 498 } 499 500 501 function fetchHTTPInput( &$http, $base, &$event ) 502 { 503 $sectionsVar = $base . "_event_ezapprove_section_" . $event->attribute( "id" ); 504 if ( $http->hasPostVariable( $sectionsVar ) ) 505 { 506 $sectionsArray = $http->postVariable( $sectionsVar ); 507 if ( in_array( '-1', $sectionsArray ) ) 508 { 509 $sectionsArray = array( -1 ); 510 } 511 $sectionsString = implode( ',', $sectionsArray ); 512 $event->setAttribute( "data_text1", $sectionsString ); 513 } 514 515 $languageVar = $base . "_event_ezapprove_languages_" . $event->attribute( "id" ); 516 if ( $http->hasPostVariable( $languageVar ) ) 517 { 518 $languageArray = $http->postVariable( $languageVar ); 519 if ( in_array( '-1', $languageArray ) ) 520 { 521 $languageArray = array(); 522 } 523 $languageMask = 0; 524 foreach ( $languageArray as $languageID ) 525 { 526 $languageMask |= $languageID; 527 } 528 $event->setAttribute( "data_int2", $languageMask ); 529 } 530 531 $versionOptionVar = $base . "_event_ezapprove_version_option_" . $event->attribute( "id" ); 532 if ( $http->hasPostVariable( $versionOptionVar ) ) 533 { 534 $versionOptionArray = $http->postVariable( $versionOptionVar ); 535 $versionOption = 0; 536 if ( is_array( $versionOptionArray ) ) 537 { 538 foreach ( $versionOptionArray as $vv ) 539 { 540 $versionOption = $versionOption | $vv; 541 } 542 } 543 $versionOption = $versionOption & EZ_APPROVE_VERSION_OPTION_ALL; 544 $event->setAttribute( 'data_int3', $versionOption ); 545 } 546 547 if ( $http->hasSessionVariable( 'BrowseParameters' ) ) 548 { 549 $browseParameters = $http->sessionVariable( 'BrowseParameters' ); 550 if ( isset( $browseParameters['custom_action_data'] ) ) 551 { 552 $customData = $browseParameters['custom_action_data']; 553 if ( isset( $customData['event_id'] ) && 554 $customData['event_id'] == $event->attribute( 'id' ) ) 555 { 556 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and 557 $http->hasPostVariable( 'SelectedObjectIDArray' ) ) 558 { 559 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' ); 560 if ( is_array( $objectIDArray ) and 561 count( $objectIDArray ) > 0 ) 562 { 563 564 switch( $customData['browse_action'] ) 565 { 566 case 'AddApproveUsers': 567 { 568 foreach( $objectIDArray as $key => $userID ) 569 { 570 if ( !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) ) 571 { 572 unset( $objectIDArray[$key] ); 573 } 574 } 575 $event->setAttribute( 'data_text3', implode( ',', 576 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_users' ), 577 $objectIDArray ) ) ) ); 578 } break; 579 580 case 'AddApproveGroups': 581 { 582 $event->setAttribute( 'data_text4', implode( ',', 583 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_groups' ), 584 $objectIDArray ) ) ) ); 585 } break; 586 587 case 'AddExcludeUser': 588 { 589 $event->setAttribute( 'data_text2', implode( ',', 590 array_unique( array_merge( $this->attributeDecoder( $event, 'selected_usergroups' ), 591 $objectIDArray ) ) ) ); 592 } break; 593 594 case 'AddExcludedGroups': 595 { 596 // TODO: 597 // ..... 598 } break; 599 } 600 } 601 $http->removeSessionVariable( 'BrowseParameters' ); 602 } 603 } 604 } 605 } 606 } 607 608 function createApproveCollaboration( &$process, &$event, $userID, $contentobjectID, $contentobjectVersion, $editors ) 609 { 610 if ( $editors === null ) 611 return false; 612 $authorID = $userID; 613 $collaborationItem = eZApproveCollaborationHandler::createApproval( $contentobjectID, $contentobjectVersion, 614 $authorID, $editors ); 615 $db = & eZDb::instance(); 616 $db->query( 'INSERT INTO ezapprove_items( workflow_process_id, collaboration_id ) 617 VALUES(' . $process->attribute( 'id' ) . ',' . $collaborationItem->attribute( 'id' ) . ' ) ' ); 618 } 619 620 /* 621 \reimp 622 */ 623 function customWorkflowEventHTTPAction( &$http, $action, &$workflowEvent ) 624 { 625 $eventID = $workflowEvent->attribute( "id" ); 626 $module =& $GLOBALS['eZRequestedModule']; 627 //$siteIni =& eZINI::instance(); 628 include_once ( 'kernel/classes/ezcontentclass.php' ); 629 630 switch ( $action ) 631 { 632 case 'AddApproveUsers' : 633 { 634 $userClassNames = eZUser::fetchUserClassNames(); 635 if ( count( $userClassNames ) > 0 ) 636 { 637 include_once ( 'kernel/classes/ezcontentbrowse.php' ); 638 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers', 639 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ), 640 'custom_action_data' => array( 'event_id' => $eventID, 641 'browse_action' => $action ), 642 'class_array' => $userClassNames ), 643 $module ); 644 } 645 } break; 646 647 case 'RemoveApproveUsers' : 648 { 649 if ( $http->hasPostVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) 650 { 651 $workflowEvent->setAttribute( 'data_text3', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_users' ), 652 $http->postVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) ) ); 653 } 654 } break; 655 656 case 'AddApproveGroups' : 657 case 'AddExcludeUser' : 658 { 659 $groupClassNames = eZUser::fetchUserGroupClassNames(); 660 if ( count( $groupClassNames ) > 0 ) 661 { 662 include_once ( 'kernel/classes/ezcontentbrowse.php' ); 663 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers', 664 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ), 665 'custom_action_data' => array( 'event_id' => $eventID, 666 'browse_action' => $action ), 667 'class_array' => $groupClassNames ), 668 $module ); 669 } 670 } break; 671 672 case 'RemoveApproveGroups' : 673 { 674 if ( $http->hasPostVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) 675 { 676 $workflowEvent->setAttribute( 'data_text4', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_groups' ), 677 $http->postVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) ) ); 678 } 679 } break; 680 681 case 'RemoveExcludeUser' : 682 { 683 if ( $http->hasPostVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) 684 { 685 $workflowEvent->setAttribute( 'data_text2', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ), 686 $http->postVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) ) ); 687 } 688 } break; 689 690 case 'AddExcludedGroups' : 691 { 692 // TODO: 693 // ..... 694 } break; 695 696 case 'RemoveExcludedGroups' : 697 { 698 // TODO: 699 // ..... 700 } break; 701 } 702 } 703 704 /* 705 \reimp 706 */ 707 function cleanupAfterRemoving( $attr = array() ) 708 { 709 foreach ( array_keys( $attr ) as $attrKey ) 710 { 711 switch ( $attrKey ) 712 { 713 case 'DeleteContentObject': 714 { 715 $contentObjectID = (int)$attr[ $attrKey ]; 716 $db = & eZDb::instance(); 717 // Cleanup "User who approves content" 718 $db->query( 'UPDATE ezworkflow_event 719 SET data_int1 = \'0\' 720 WHERE data_int1 = \'' . $contentObjectID . '\'' ); 721 // Cleanup "Excluded user groups" 722 $excludedGroupsID = $db->arrayQuery( 'SELECT data_text2, id 723 FROM ezworkflow_event 724 WHERE data_text2 like \'%' . $contentObjectID . '%\'' ); 725 if ( count( $excludedGroupsID ) > 0 ) 726 { 727 foreach ( $excludedGroupsID as $groupID ) 728 { 729 // $IDArray will contain IDs of "Excluded user groups" 730 $IDArray = split( ',', $groupID[ 'data_text2' ] ); 731 // $newIDArray will contain array without $contentObjectID 732 $newIDArray = array_filter( $IDArray, create_function( '$v', 'return ( $v != ' . $contentObjectID .' );' ) ); 733 $newValues = implode( ',', $newIDArray ); 734 $db->query( 'UPDATE ezworkflow_event 735 SET data_text2 = \''. $newValues .'\' 736 WHERE id = ' . $groupID[ 'id' ] ); 737 } 738 } 739 } break; 740 } 741 } 742 } 743 744 function checkApproveCollaboration( &$process, &$event ) 745 { 746 $db = & eZDb::instance(); 747 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) ); 748 $collaborationID = $taskResult[0]['collaboration_id']; 749 $collaborationItem = eZCollaborationItem::fetch( $collaborationID ); 750 $contentObjectVersion = eZApproveCollaborationHandler::contentObjectVersion( $collaborationItem ); 751 $approvalStatus = eZApproveCollaborationHandler::checkApproval( $collaborationID ); 752 if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_WAITING ) 753 { 754 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval still waiting' ); 755 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT; 756 } 757 else if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED ) 758 { 759 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was accepted' ); 760 $status = EZ_WORKFLOW_TYPE_STATUS_ACCEPTED; 761 } 762 else if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_DENIED or 763 $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_DEFERRED ) 764 { 765 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was denied' ); 766 $contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); 767 $status = EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED; 768 } 769 else 770 { 771 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, "approval unknown status '$approvalStatus'" ); 772 $contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_REJECTED ); 773 $status = EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED; 774 } 775 $contentObjectVersion->sync(); 776 if ( $approvalStatus != EZ_COLLABORATION_APPROVE_STATUS_DEFERRED ) 777 $db->query( 'DELETE FROM ezapprove_items WHERE workflow_process_id = ' . $process->attribute( 'id' ) ); 778 return $status; 779 } 780 } 781 782 eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_APPROVE_ID, "ezapprovetype" ); 783 784 ?>
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 |