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