Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

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