|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZApproveType class 00004 // 00005 // Created on: <16-Apr-2002 11:08:14 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \class eZApproveType ezapprovetype.php 00033 \brief Event type for user approvals 00034 00035 WorkflowEvent storage fields : data_text1 - selected_sections 00036 data_text2 - selected_usergroups 00037 data_text3 - approve_users 00038 data_text4 - approve_groups 00039 data_int2 - language_list 00040 data_int3 - content object version option 00041 */ 00042 00043 //include_once( "kernel/classes/ezworkflowtype.php" ); 00044 //include_once( 'kernel/classes/collaborationhandlers/ezapprove/ezapprovecollaborationhandler.php' ); 00045 00046 class eZApproveType extends eZWorkflowEventType 00047 { 00048 const WORKFLOW_TYPE_STRING = "ezapprove"; 00049 00050 const COLLABORATION_NOT_CREATED = 0; 00051 const COLLABORATION_CREATED = 1; 00052 00053 const VERSION_OPTION_FIRST_ONLY = 1; 00054 const VERSION_OPTION_EXCEPT_FIRST = 2; 00055 const VERSION_OPTION_ALL = 3; 00056 00057 function eZApproveType() 00058 { 00059 $this->eZWorkflowEventType( eZApproveType::WORKFLOW_TYPE_STRING, ezi18n( 'kernel/workflow/event', "Approve" ) ); 00060 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before' ) ) ) ); 00061 } 00062 00063 function attributeDecoder( $event, $attr ) 00064 { 00065 switch ( $attr ) 00066 { 00067 case 'selected_sections': 00068 { 00069 $attributeValue = trim( $event->attribute( 'data_text1' ) ); 00070 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue ); 00071 }break; 00072 00073 case 'approve_users': 00074 { 00075 $attributeValue = trim( $event->attribute( 'data_text3' ) ); 00076 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue ); 00077 }break; 00078 00079 case 'approve_groups': 00080 { 00081 $attributeValue = trim( $event->attribute( 'data_text4' ) ); 00082 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue ); 00083 }break; 00084 00085 case 'selected_usergroups': 00086 { 00087 $attributeValue = trim( $event->attribute( 'data_text2' ) ); 00088 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue ); 00089 }break; 00090 00091 case 'language_list': 00092 { 00093 $returnValue = array(); 00094 $attributeValue = $event->attribute( 'data_int2' ); 00095 if ( $attributeValue != 0 ) 00096 { 00097 //include_once( 'kernel/classes/ezcontentlanguage.php' ); 00098 $languages = eZContentLanguage::languagesByMask( $attributeValue ); 00099 foreach ( $languages as $language ) 00100 { 00101 $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' ); 00102 } 00103 } 00104 }break; 00105 00106 case 'version_option': 00107 { 00108 $returnValue = eZApproveType::VERSION_OPTION_ALL & $event->attribute( 'data_int3' ); 00109 }break; 00110 00111 default: 00112 $returnValue = null; 00113 } 00114 return $returnValue; 00115 } 00116 00117 function typeFunctionalAttributes( ) 00118 { 00119 return array( 'selected_sections', 00120 'approve_users', 00121 'approve_groups', 00122 'selected_usergroups', 00123 'language_list', 00124 'version_option' ); 00125 } 00126 00127 function attributes() 00128 { 00129 return array_merge( array( 'sections', 00130 'languages', 00131 'users', 00132 'usergroups' ), 00133 eZWorkflowEventType::attributes() ); 00134 00135 } 00136 00137 function hasAttribute( $attr ) 00138 { 00139 return in_array( $attr, $this->attributes() ); 00140 } 00141 00142 function attribute( $attr ) 00143 { 00144 switch( $attr ) 00145 { 00146 case 'sections': 00147 { 00148 //include_once( 'kernel/classes/ezsection.php' ); 00149 $sections = eZSection::fetchList( false ); 00150 foreach ( $sections as $key => $section ) 00151 { 00152 $sections[$key]['Name'] = $section['name']; 00153 $sections[$key]['value'] = $section['id']; 00154 } 00155 return $sections; 00156 }break; 00157 case 'languages': 00158 { 00159 //include_once( 'kernel/classes/ezcontentlanguage.php' ); 00160 return eZContentLanguage::fetchList(); 00161 }break; 00162 } 00163 return eZWorkflowEventType::attribute( $attr ); 00164 } 00165 00166 function execute( $process, $event ) 00167 { 00168 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process, 'eZApproveType::execute' ); 00169 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'eZApproveType::execute' ); 00170 $parameters = $process->attribute( 'parameter_list' ); 00171 $versionID = $parameters['version']; 00172 $objectID = $parameters['object_id']; 00173 $object = eZContentObject::fetch( $objectID ); 00174 00175 if ( !$object ) 00176 { 00177 eZDebugSetting::writeError( 'kernel-workflow-approve', "No object with ID $objectID", 'eZApproveType::execute' ); 00178 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00179 } 00180 00181 $version = $object->version( $versionID ); 00182 00183 if ( !$version ) 00184 { 00185 eZDebugSetting::writeError( 'kernel-workflow-approve', "No version $versionID for object with ID $objectID", 'eZApproveType::execute' ); 00186 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00187 } 00188 00189 // version option checking 00190 $version_option = $event->attribute( 'version_option' ); 00191 if ( ( $version_option == eZApproveType::VERSION_OPTION_FIRST_ONLY and $parameters['version'] > 1 ) or 00192 ( $version_option == eZApproveType::VERSION_OPTION_EXCEPT_FIRST and $parameters['version'] == 1 ) ) 00193 { 00194 return eZWorkflowType::STATUS_ACCEPTED; 00195 } 00196 00197 /* 00198 If we run event first time ( when we click publish in admin ) we do not have user_id set in workflow process, 00199 so we take current user and store it in workflow process, so next time when we run event from cronjob we fetch 00200 user_id from there. 00201 */ 00202 if ( $process->attribute( 'user_id' ) == 0 ) 00203 { 00204 $user = eZUser::currentUser(); 00205 $process->setAttribute( 'user_id', $user->id() ); 00206 } 00207 else 00208 { 00209 $user = eZUser::instance( $process->attribute( 'user_id' ) ); 00210 } 00211 00212 $userGroups = array_merge( $user->attribute( 'groups' ), array( $user->attribute( 'contentobject_id' ) ) ); 00213 $workflowSections = explode( ',', $event->attribute( 'data_text1' ) ); 00214 $workflowGroups = $event->attribute( 'data_text2' ) == '' ? array() : explode( ',', $event->attribute( 'data_text2' ) ); 00215 $editors = $event->attribute( 'data_text3' ) == '' ? array() : explode( ',', $event->attribute( 'data_text3' ) ); 00216 $approveGroups = $event->attribute( 'data_text4' ) == '' ? array() : explode( ',', $event->attribute( 'data_text4' ) ); 00217 $languageMask = $event->attribute( 'data_int2' ); 00218 00219 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user, 'eZApproveType::execute::user' ); 00220 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, 'eZApproveType::execute::userGroups' ); 00221 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $editors, 'eZApproveType::execute::editor' ); 00222 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $approveGroups, 'eZApproveType::execute::approveGroups' ); 00223 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections, 'eZApproveType::execute::workflowSections' ); 00224 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, 'eZApproveType::execute::workflowGroups' ); 00225 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $languageMask, 'eZApproveType::execute::languageMask' ); 00226 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $object->attribute( 'section_id'), 'eZApproveType::execute::section_id' ); 00227 00228 $section = $object->attribute( 'section_id' ); 00229 $correctSection = false; 00230 00231 if ( !in_array( $section, $workflowSections ) && !in_array( -1, $workflowSections ) ) 00232 { 00233 $assignedNodes = $object->attribute( 'assigned_nodes' ); 00234 if ( $assignedNodes ) 00235 { 00236 foreach( $assignedNodes as $assignedNode ) 00237 { 00238 $parent = $assignedNode->attribute( 'parent' ); 00239 $parentObject = $parent->object(); 00240 $section = $parentObject->attribute( 'section_id'); 00241 00242 if ( in_array( $section, $workflowSections ) ) 00243 { 00244 $correctSection = true; 00245 break; 00246 } 00247 } 00248 } 00249 } 00250 else 00251 $correctSection = true; 00252 00253 $inExcludeGroups = count( array_intersect( $userGroups, $workflowGroups ) ) != 0; 00254 00255 $userIsEditor = ( in_array( $user->id(), $editors ) || 00256 count( array_intersect( $userGroups, $approveGroups ) ) != 0 ); 00257 00258 // All languages match by default 00259 $hasLanguageMatch = true; 00260 if ( $languageMask != 0 ) 00261 { 00262 // Examine if the published version contains one of the languages we 00263 // match for. 00264 // If the language ID is part of the mask the result is non-zero. 00265 $languageID = (int)$version->attribute( 'initial_language_id' ); 00266 $hasLanguageMatch = (bool)( $languageMask & $languageID ); 00267 } 00268 00269 if ( $hasLanguageMatch and 00270 !$userIsEditor and 00271 !$inExcludeGroups and 00272 $correctSection ) 00273 { 00274 00275 /* Get user IDs from approve user groups */ 00276 $userClassIDArray = eZUser::contentClassIDs(); 00277 $approveUserIDArray = array(); 00278 foreach ( $approveGroups as $approveUserGroupID ) 00279 { 00280 if ( $approveUserGroupID != false ) 00281 { 00282 $approveUserGroup = eZContentObject::fetch( $approveUserGroupID ); 00283 if ( isset( $approveUserGroup ) ) 00284 { 00285 foreach ( $approveUserGroup->attribute( 'assigned_nodes' ) as $assignedNode ) 00286 { 00287 $userNodeArray = $assignedNode->subTree( array( 'ClassFilterType' => 'include', 00288 'ClassFilterArray' => $userClassIDArray, 00289 'Limitation' => array() ) ); 00290 foreach ( $userNodeArray as $userNode ) 00291 { 00292 $approveUserIDArray[] = $userNode->attribute( 'contentobject_id' ); 00293 } 00294 } 00295 } 00296 } 00297 } 00298 $approveUserIDArray = array_merge( $approveUserIDArray, $editors ); 00299 $approveUserIDArray = array_unique( $approveUserIDArray ); 00300 00301 $collaborationID = false; 00302 $db = eZDb::instance(); 00303 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) ); 00304 if ( count( $taskResult ) > 0 ) 00305 $collaborationID = $taskResult[0]['collaboration_id']; 00306 00307 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $collaborationID, 'approve collaborationID' ); 00308 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process->attribute( 'event_state'), 'approve $process->attribute( \'event_state\')' ); 00309 if ( $collaborationID === false ) 00310 { 00311 $this->createApproveCollaboration( $process, $event, $user->id(), $object->attribute( 'id' ), $versionID, $approveUserIDArray ); 00312 $this->setInformation( "We are going to create approval" ); 00313 $process->setAttribute( 'event_state', eZApproveType::COLLABORATION_CREATED ); 00314 $process->store(); 00315 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve execute' ); 00316 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; 00317 } 00318 else if ( $process->attribute( 'event_state') == eZApproveType::COLLABORATION_NOT_CREATED ) 00319 { 00320 eZApproveCollaborationHandler::activateApproval( $collaborationID ); 00321 $process->setAttribute( 'event_state', eZApproveType::COLLABORATION_CREATED ); 00322 $process->store(); 00323 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve re-execute' ); 00324 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; 00325 } 00326 else //eZApproveType::COLLABORATION_CREATED 00327 { 00328 $this->setInformation( "we are checking approval now" ); 00329 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'check approval' ); 00330 return $this->checkApproveCollaboration( $process, $event ); 00331 } 00332 } 00333 else 00334 { 00335 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections , "we are not going to create approval " . $object->attribute( 'section_id') ); 00336 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, "we are not going to create approval" ); 00337 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, "we are not going to create approval" ); 00338 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user->id(), "we are not going to create approval " ); 00339 return eZWorkflowType::STATUS_ACCEPTED; 00340 } 00341 } 00342 00343 function initializeEvent( $event ) 00344 { 00345 } 00346 00347 function validateUserIDList( $userIDList, &$reason ) 00348 { 00349 $returnState = eZInputValidator::STATE_ACCEPTED; 00350 foreach ( $userIDList as $userID ) 00351 { 00352 if ( !is_numeric( $userID ) or 00353 !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) ) 00354 { 00355 $returnState = eZInputValidator::STATE_INVALID; 00356 $reason[ 'list' ][] = $userID; 00357 } 00358 } 00359 $reason[ 'text' ] = "Some of passed user IDs are not valid, must be IDs of existing users only."; 00360 return $returnState; 00361 } 00362 00363 function validateGroupIDList( $userGroupIDList, &$reason ) 00364 { 00365 $returnState = eZInputValidator::STATE_ACCEPTED; 00366 $groupClassNames = eZUser::fetchUserGroupClassNames(); 00367 if ( count( $groupClassNames ) > 0 ) 00368 { 00369 foreach( $userGroupIDList as $userGroupID ) 00370 { 00371 if ( !is_numeric( $userGroupID ) or 00372 !is_object( $userGroup = eZContentObject::fetch( $userGroupID ) ) or 00373 !in_array( $userGroup->attribute( 'class_identifier' ), $groupClassNames ) ) 00374 { 00375 $returnState = eZInputValidator::STATE_INVALID; 00376 $reason[ 'list' ][] = $userGroupID; 00377 } 00378 } 00379 $reason[ 'text' ] = "Some of passed user-group IDs are not valid, must be IDs of existing user groups only."; 00380 } 00381 else 00382 { 00383 $returnState = eZInputValidator::STATE_INVALID; 00384 $reason[ 'text' ] = "There is no one user-group classes among the user accounts, please choose standalone users."; 00385 } 00386 return $returnState; 00387 } 00388 00389 function validateHTTPInput( $http, $base, $workflowEvent, &$validation ) 00390 { 00391 $returnState = eZInputValidator::STATE_ACCEPTED; 00392 $reason = array(); 00393 00394 if ( !$http->hasSessionVariable( 'BrowseParameters' ) ) 00395 { 00396 // check approve-users 00397 $approversIDs = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_users' ) ); 00398 if ( is_array( $approversIDs ) and 00399 count( $approversIDs ) > 0 ) 00400 { 00401 $returnState = eZApproveType::validateUserIDList( $approversIDs, $reason ); 00402 } 00403 else 00404 $returnState = false; 00405 00406 if ( $returnState != eZInputValidator::STATE_INVALID ) 00407 { 00408 // check approve-groups 00409 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_groups' ) ); 00410 if ( is_array( $userGroupIDList ) and 00411 count( $userGroupIDList ) > 0 ) 00412 { 00413 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason ); 00414 } 00415 else if ( $returnState === false ) 00416 { 00417 // if no one user or user-group was passed as approvers 00418 $returnState = eZInputValidator::STATE_INVALID; 00419 $reason[ 'text' ] = "There must be passed at least one valid user or user group who approves content for the event."; 00420 } 00421 00422 // check excluded-users 00423 /* 00424 if ( $returnState != eZInputValidator::STATE_INVALID ) 00425 { 00426 // TODO: 00427 // .... 00428 } 00429 */ 00430 00431 // check excluded-groups 00432 if ( $returnState != eZInputValidator::STATE_INVALID ) 00433 { 00434 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ) ); 00435 if ( is_array( $userGroupIDList ) and 00436 count( $userGroupIDList ) > 0 ) 00437 { 00438 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason ); 00439 } 00440 } 00441 } 00442 } 00443 else 00444 { 00445 $browseParameters = $http->sessionVariable( 'BrowseParameters' ); 00446 if ( isset( $browseParameters['custom_action_data'] ) ) 00447 { 00448 $customData = $browseParameters['custom_action_data']; 00449 if ( isset( $customData['event_id'] ) and 00450 $customData['event_id'] == $workflowEvent->attribute( 'id' ) ) 00451 { 00452 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and 00453 $http->hasPostVariable( 'SelectedObjectIDArray' ) ) 00454 { 00455 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' ); 00456 if ( is_array( $objectIDArray ) and 00457 count( $objectIDArray ) > 0 ) 00458 { 00459 switch( $customData['browse_action'] ) 00460 { 00461 case "AddApproveUsers": 00462 { 00463 $returnState = eZApproveType::validateUserIDList( $objectIDArray, $reason ); 00464 } break; 00465 case 'AddApproveGroups': 00466 case 'AddExcludeUser': 00467 { 00468 $returnState = eZApproveType::validateGroupIDList( $objectIDArray, $reason ); 00469 } break; 00470 case 'AddExcludedGroups': 00471 { 00472 // TODO: 00473 // ..... 00474 } break; 00475 } 00476 } 00477 } 00478 } 00479 } 00480 } 00481 00482 if ( $returnState == eZInputValidator::STATE_INVALID ) 00483 { 00484 $validation[ 'processed' ] = true; 00485 $validation[ 'events' ][] = array( 'id' => $workflowEvent->attribute( 'id' ), 00486 'placement' => $workflowEvent->attribute( 'placement' ), 00487 'workflow_type' => &$this, 00488 'reason' => $reason ); 00489 } 00490 return $returnState; 00491 } 00492 00493 00494 function fetchHTTPInput( $http, $base, $event ) 00495 { 00496 $sectionsVar = $base . "_event_ezapprove_section_" . $event->attribute( "id" ); 00497 if ( $http->hasPostVariable( $sectionsVar ) ) 00498 { 00499 $sectionsArray = $http->postVariable( $sectionsVar ); 00500 if ( in_array( '-1', $sectionsArray ) ) 00501 { 00502 $sectionsArray = array( -1 ); 00503 } 00504 $sectionsString = implode( ',', $sectionsArray ); 00505 $event->setAttribute( "data_text1", $sectionsString ); 00506 } 00507 00508 $languageVar = $base . "_event_ezapprove_languages_" . $event->attribute( "id" ); 00509 if ( $http->hasPostVariable( $languageVar ) ) 00510 { 00511 $languageArray = $http->postVariable( $languageVar ); 00512 if ( in_array( '-1', $languageArray ) ) 00513 { 00514 $languageArray = array(); 00515 } 00516 $languageMask = 0; 00517 foreach ( $languageArray as $languageID ) 00518 { 00519 $languageMask |= $languageID; 00520 } 00521 $event->setAttribute( "data_int2", $languageMask ); 00522 } 00523 00524 $versionOptionVar = $base . "_event_ezapprove_version_option_" . $event->attribute( "id" ); 00525 if ( $http->hasPostVariable( $versionOptionVar ) ) 00526 { 00527 $versionOptionArray = $http->postVariable( $versionOptionVar ); 00528 $versionOption = 0; 00529 if ( is_array( $versionOptionArray ) ) 00530 { 00531 foreach ( $versionOptionArray as $vv ) 00532 { 00533 $versionOption = $versionOption | $vv; 00534 } 00535 } 00536 $versionOption = $versionOption & eZApproveType::VERSION_OPTION_ALL; 00537 $event->setAttribute( 'data_int3', $versionOption ); 00538 } 00539 00540 if ( $http->hasSessionVariable( 'BrowseParameters' ) ) 00541 { 00542 $browseParameters = $http->sessionVariable( 'BrowseParameters' ); 00543 if ( isset( $browseParameters['custom_action_data'] ) ) 00544 { 00545 $customData = $browseParameters['custom_action_data']; 00546 if ( isset( $customData['event_id'] ) && 00547 $customData['event_id'] == $event->attribute( 'id' ) ) 00548 { 00549 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and 00550 $http->hasPostVariable( 'SelectedObjectIDArray' ) ) 00551 { 00552 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' ); 00553 if ( is_array( $objectIDArray ) and 00554 count( $objectIDArray ) > 0 ) 00555 { 00556 00557 switch( $customData['browse_action'] ) 00558 { 00559 case 'AddApproveUsers': 00560 { 00561 foreach( $objectIDArray as $key => $userID ) 00562 { 00563 if ( !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) ) 00564 { 00565 unset( $objectIDArray[$key] ); 00566 } 00567 } 00568 $event->setAttribute( 'data_text3', implode( ',', 00569 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_users' ), 00570 $objectIDArray ) ) ) ); 00571 } break; 00572 00573 case 'AddApproveGroups': 00574 { 00575 $event->setAttribute( 'data_text4', implode( ',', 00576 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_groups' ), 00577 $objectIDArray ) ) ) ); 00578 } break; 00579 00580 case 'AddExcludeUser': 00581 { 00582 $event->setAttribute( 'data_text2', implode( ',', 00583 array_unique( array_merge( $this->attributeDecoder( $event, 'selected_usergroups' ), 00584 $objectIDArray ) ) ) ); 00585 } break; 00586 00587 case 'AddExcludedGroups': 00588 { 00589 // TODO: 00590 // ..... 00591 } break; 00592 } 00593 } 00594 $http->removeSessionVariable( 'BrowseParameters' ); 00595 } 00596 } 00597 } 00598 } 00599 } 00600 00601 function createApproveCollaboration( $process, $event, $userID, $contentobjectID, $contentobjectVersion, $editors ) 00602 { 00603 if ( $editors === null ) 00604 return false; 00605 $authorID = $userID; 00606 $collaborationItem = eZApproveCollaborationHandler::createApproval( $contentobjectID, $contentobjectVersion, 00607 $authorID, $editors ); 00608 $db = eZDb::instance(); 00609 $db->query( 'INSERT INTO ezapprove_items( workflow_process_id, collaboration_id ) 00610 VALUES(' . $process->attribute( 'id' ) . ',' . $collaborationItem->attribute( 'id' ) . ' ) ' ); 00611 } 00612 00613 /* 00614 \reimp 00615 */ 00616 function customWorkflowEventHTTPAction( $http, $action, $workflowEvent ) 00617 { 00618 $eventID = $workflowEvent->attribute( "id" ); 00619 $module =& $GLOBALS['eZRequestedModule']; 00620 //$siteIni = eZINI::instance(); 00621 //include_once( 'kernel/classes/ezcontentclass.php' ); 00622 00623 switch ( $action ) 00624 { 00625 case 'AddApproveUsers' : 00626 { 00627 $userClassNames = eZUser::fetchUserClassNames(); 00628 if ( count( $userClassNames ) > 0 ) 00629 { 00630 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00631 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers', 00632 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ), 00633 'custom_action_data' => array( 'event_id' => $eventID, 00634 'browse_action' => $action ), 00635 'class_array' => $userClassNames ), 00636 $module ); 00637 } 00638 } break; 00639 00640 case 'RemoveApproveUsers' : 00641 { 00642 if ( $http->hasPostVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) 00643 { 00644 $workflowEvent->setAttribute( 'data_text3', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_users' ), 00645 $http->postVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) ) ); 00646 } 00647 } break; 00648 00649 case 'AddApproveGroups' : 00650 case 'AddExcludeUser' : 00651 { 00652 $groupClassNames = eZUser::fetchUserGroupClassNames(); 00653 if ( count( $groupClassNames ) > 0 ) 00654 { 00655 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00656 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers', 00657 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ), 00658 'custom_action_data' => array( 'event_id' => $eventID, 00659 'browse_action' => $action ), 00660 'class_array' => $groupClassNames ), 00661 $module ); 00662 } 00663 } break; 00664 00665 case 'RemoveApproveGroups' : 00666 { 00667 if ( $http->hasPostVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) 00668 { 00669 $workflowEvent->setAttribute( 'data_text4', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_groups' ), 00670 $http->postVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) ) ); 00671 } 00672 } break; 00673 00674 case 'RemoveExcludeUser' : 00675 { 00676 if ( $http->hasPostVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) 00677 { 00678 $workflowEvent->setAttribute( 'data_text2', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ), 00679 $http->postVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) ) ); 00680 } 00681 } break; 00682 00683 case 'AddExcludedGroups' : 00684 { 00685 // TODO: 00686 // ..... 00687 } break; 00688 00689 case 'RemoveExcludedGroups' : 00690 { 00691 // TODO: 00692 // ..... 00693 } break; 00694 } 00695 } 00696 00697 /* 00698 \reimp 00699 */ 00700 function cleanupAfterRemoving( $attr = array() ) 00701 { 00702 foreach ( array_keys( $attr ) as $attrKey ) 00703 { 00704 switch ( $attrKey ) 00705 { 00706 case 'DeleteContentObject': 00707 { 00708 $contentObjectID = (int)$attr[ $attrKey ]; 00709 $db = eZDb::instance(); 00710 // Cleanup "User who approves content" 00711 $db->query( "UPDATE ezworkflow_event 00712 SET data_int1 = '0' 00713 WHERE workflow_type_string = '{$this->TypeString}' AND 00714 data_int1 = $contentObjectID" ); 00715 // Cleanup "Excluded user groups" 00716 $excludedGroupsID = $db->arrayQuery( "SELECT data_text2, id 00717 FROM ezworkflow_event 00718 WHERE workflow_type_string = '{$this->TypeString}' AND 00719 data_text2 like '%$contentObjectID%'" ); 00720 00721 if ( is_array( $excludedGroupsID ) ) 00722 { 00723 foreach ( $excludedGroupsID as $groupID ) 00724 { 00725 // $IDArray will contain IDs of "Excluded user groups" 00726 $IDArray = split( ',', $groupID[ 'data_text2' ] ); 00727 // $newIDArray will contain array without $contentObjectID 00728 $newIDArray = array_filter( $IDArray, create_function( '$v', 'return ( $v != ' . $contentObjectID .' );' ) ); 00729 $newValues = $db->escapeString( implode( ',', $newIDArray ) ); 00730 $db->query( "UPDATE ezworkflow_event 00731 SET data_text2 = '$newValues' 00732 WHERE id = {$groupID['id']}" ); 00733 } 00734 } 00735 } break; 00736 } 00737 } 00738 } 00739 00740 function checkApproveCollaboration( $process, $event ) 00741 { 00742 $db = eZDb::instance(); 00743 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) ); 00744 $collaborationID = $taskResult[0]['collaboration_id']; 00745 $collaborationItem = eZCollaborationItem::fetch( $collaborationID ); 00746 $contentObjectVersion = eZApproveCollaborationHandler::contentObjectVersion( $collaborationItem ); 00747 $approvalStatus = eZApproveCollaborationHandler::checkApproval( $collaborationID ); 00748 if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_WAITING ) 00749 { 00750 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval still waiting' ); 00751 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; 00752 } 00753 else if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_ACCEPTED ) 00754 { 00755 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was accepted' ); 00756 $status = eZWorkflowType::STATUS_ACCEPTED; 00757 } 00758 else if ( $approvalStatus == eZApproveCollaborationHandler::STATUS_DENIED or 00759 $approvalStatus == eZApproveCollaborationHandler::STATUS_DEFERRED ) 00760 { 00761 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was denied' ); 00762 $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT ); 00763 $status = eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00764 } 00765 else 00766 { 00767 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, "approval unknown status '$approvalStatus'" ); 00768 $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_REJECTED ); 00769 $status = eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00770 } 00771 $contentObjectVersion->sync(); 00772 if ( $approvalStatus != eZApproveCollaborationHandler::STATUS_DEFERRED ) 00773 $db->query( 'DELETE FROM ezapprove_items WHERE workflow_process_id = ' . $process->attribute( 'id' ) ); 00774 return $status; 00775 } 00776 } 00777 00778 eZWorkflowEventType::registerEventType( eZApproveType::WORKFLOW_TYPE_STRING, "eZApproveType" ); 00779 00780 ?>