Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezworkflow.php
Go to the documentation of this file.
1 <?php
13
17 class eZWorkflow extends eZPersistentObject
18 {
19 const STATUS_NONE = 0;
20 const STATUS_BUSY = 1;
21 const STATUS_DONE = 2;
22 const STATUS_FAILED = 3;
23 const STATUS_DEFERRED_TO_CRON = 4;
24 const STATUS_CANCELLED = 5;
25 const STATUS_FETCH_TEMPLATE = 6;
26 const STATUS_REDIRECT = 7;
27 const STATUS_RESET = 8;
28 const STATUS_WAITING_PARENT = 9;
29 const STATUS_FETCH_TEMPLATE_REPEAT = 10;
30
31 static function definition()
32 {
33 return array( "fields" => array( "id" => array( 'name' => 'ID',
34 'datatype' => 'integer',
35 'default' => 0,
36 'required' => true ),
37 "version" => array( 'name' => "Version",
38 'datatype' => 'integer',
39 'default' => 0,
40 'required' => true ),
41 "is_enabled" => array( 'name' => "IsEnabled",
42 'datatype' => 'integer',
43 'default' => 0,
44 'required' => true ),
45 "workflow_type_string" => array( 'name' => "WorkflowTypeString",
46 'datatype' => 'string',
47 'default' => '',
48 'required' => true,
49 'max_length' => 50 ),
50 "name" => array( 'name' => "Name",
51 'datatype' => 'string',
52 'default' => '',
53 'required' => true,
54 'max_length' => 255 ),
55 "creator_id" => array( 'name' => "CreatorID",
56 'datatype' => 'integer',
57 'default' => 0,
58 'required' => true,
59 'foreign_class' => 'eZUser',
60 'foreign_attribute' => 'contentobject_id',
61 'multiplicity' => '1..*' ),
62 "modifier_id" => array( 'name' => "ModifierID",
63 'datatype' => 'integer',
64 'default' => 0,
65 'required' => true,
66 'foreign_class' => 'eZUser',
67 'foreign_attribute' => 'contentobject_id',
68 'multiplicity' => '1..*' ),
69 "created" => array( 'name' => "Created",
70 'datatype' => 'integer',
71 'default' => 0,
72 'required' => true ),
73 "modified" => array( 'name' => "Modified",
74 'datatype' => 'integer',
75 'default' => 0,
76 'required' => true ) ),
77 "keys" => array( "id", "version" ),
78 'function_attributes' => array( 'creator' => 'creator',
79 'modifier' => 'modifier',
80 'workflow_type' => 'workflowType',
81 'event_count' => 'fetchEventCount',
82 'ordered_event_list' => 'fetchEvents',
83 'ingroup_list' => 'ingroupList',
84 'ingroup_id_list' => 'ingroupIDList',
85 'group_list' => 'groupList' ),
86 "increment_key" => "id",
87 "class_name" => "eZWorkflow",
88 "sort" => array( "name" => "asc" ),
89 "name" => "ezworkflow" );
90 }
91
92 static function statusName( $status )
93 {
94 $statusNameMap = self::statusNameMap();
95 if ( isset( $statusNameMap[$status] ) )
96 return $statusNameMap[$status];
97 return false;
98 }
99
100 static function create( $user_id )
101 {
102 $date_time = time();
103 $row = array(
104 "id" => null,
105 "workflow_type_string" => "group_ezserial",
106 "version" => 1,
107 "is_enabled" => 1,
108 "name" => "",
109 "creator_id" => $user_id,
110 "modifier_id" => $user_id,
111 "created" => $date_time,
112 "modified" => $date_time );
113 return new eZWorkflow( $row );
114 }
115
116 static function setIsEnabled( $enabled, $id, $version = 0 )
117 {
118 eZPersistentObject::updateObjectList( array(
119 "definition" => eZWorkflow::definition(),
120 "update_fields" => array( "is_enabled" => ( $enabled ? 1 : 0 ) ),
121 "conditions" => array( "id" => $id,
122 "version" => $version )
123 )
124 );
125 }
126
131 static function removeWorkflow( $id, $version )
132 {
133 eZPersistentObject::removeObject( eZWorkflow::definition(),
134 array( "id" => $id,
135 "version" => $version ) );
136 }
137
142 function removeThis( $remove_childs = false )
143 {
144 $db = eZDB::instance();
145 $db->begin();
146 if ( is_array( $remove_childs ) )
147 {
148 foreach( $remove_childs as $event )
149 {
150 $event->remove();
151 }
152 }
153 else if ( $remove_childs )
154 {
155 eZPersistentObject::removeObject( eZWorkflowEvent::definition(),
156 array( "workflow_id" => $this->ID,
157 "version" => $this->Version ) );
158 }
159
160 $this->remove();
161 $db->commit();
162 }
163
170 static function removeTemporary()
171 {
172 $version = 1;
173 $temporaryWorkflows = eZWorkflow::fetchList( $version, null, true );
174
175 $db = eZDB::instance();
176 $db->begin();
177 foreach ( $temporaryWorkflows as $workflow )
178 {
179 $workflow->removeThis( true );
180 }
181 eZPersistentObject::removeObject( eZWorkflowEvent::definition(),
182 array( 'version' => $version ) );
183 $db->commit();
184 }
185
190 static function removeEvents( $events = false, $id = false, $version = false )
191 {
192 if ( is_array( $events ) )
193 {
194 $db = eZDB::instance();
195 $db->begin();
196 foreach( $events as $event )
197 {
198 $event->remove();
199 }
200 $db->commit();
201 }
202 else
203 {
204 $condArray = array();
205 if ( $version !== false )
206 {
207 $condArray['version'] = $version;
208 }
209 if ( $id !== false )
210 {
211 $condArray['workflow_id'] = $id;
212 }
213 eZPersistentObject::removeObject( eZWorkflowEvent::definition(),
214 $condArray );
215 }
216 }
217
218 static function adjustEventPlacements( $events )
219 {
220 if ( !is_array( $events ) )
221 return;
222 $i = 0;
223 foreach( $events as $event )
224 {
225 $event->setAttribute( "placement", ++$i );
226 }
227 }
228
233 function store( $store_childs = false )
234 {
235 $db = eZDB::instance();
236 $db->begin();
237 if ( is_array( $store_childs ) or $store_childs )
238 {
239 if ( is_array( $store_childs ) )
240 {
241 $events = $store_childs;
242 }
243 else
244 {
245 $events = $this->fetchEvents();
246 }
247 foreach ( $events as $event )
248 {
249 $event->store();
250 }
251 }
252 parent::store();
253 $db->commit();
254 }
259 function storeDefined( $store_childs = false )
260 {
261 $db = eZDB::instance();
262 $db->begin();
263 if ( is_array( $store_childs ) or $store_childs )
264 {
265 if ( is_array( $store_childs ) )
266 {
267 $events = $store_childs;
268 }
269 else
270 {
271 $events = $this->fetchEvents();
272 }
273 foreach ( $events as $event )
274 {
275 $event->storeDefined();
276 }
277 }
278 parent::store();
279 $db->commit();
280 }
281
282 function setVersion( $version, $set_childs = false )
283 {
284 if ( is_array( $set_childs ) or $set_childs )
285 {
286 if ( is_array( $set_childs ) )
287 {
288 $events = $set_childs;
289 }
290 else
291 {
292 $events = $this->fetchEvents();
293 }
294 foreach( $events as $event )
295 {
296 $event->setAttribute( "version", $version );
297 }
298 }
299 $this->setAttribute( "version", $version );
300 }
301
302 static function fetch( $id, $asObject = true, $version = 0 )
303 {
304 return eZPersistentObject::fetchObject( eZWorkflow::definition(),
305 null,
306 array( "id" => $id,
307 "version" => $version ),
308 $asObject );
309 }
310
321 static function fetchLimited( $moduleName, $functionName, $connectType )
322 {
323 $workflowArray = eZWorkflow::fetchList();
324 $returnArray = array();
325
326 foreach ( array_keys( $workflowArray ) as $key )
327 {
328 if ( $workflowArray[$key]->isAllowed( $moduleName,
329 $functionName,
330 $connectType ) )
331 {
332 $returnArray[] = $workflowArray[$key];
333 }
334 }
335
336 return $returnArray;
337 }
338
348 function isAllowed( $moduleName, $functionName, $connectType )
349 {
350 $eventArray = $this->fetchEvents();
351
352 foreach ( array_keys( $eventArray ) as $key )
353 {
354 $eventType = $eventArray[$key]->attribute( 'workflow_type' );
355 if ( !is_object( $eventType ) or !$eventType->isAllowed( $moduleName, $functionName, $connectType ) )
356 {
357 return false;
358 }
359 }
360
361 return true;
362 }
363
364 static function fetchList( $version = 0, $enabled = 1, $asObject = true )
365 {
366 $conds = array( 'version' => $version );
367 if ( $enabled !== null )
368 $conds['is_enabled'] = $enabled;
369 return eZPersistentObject::fetchObjectList( eZWorkflow::definition(),
370 null, $conds, null, null,
371 $asObject );
372 }
373
374 static function fetchListCount( $version = 0, $enabled = 1 )
375 {
376 $list = eZPersistentObject::fetchObjectList( eZWorkflow::definition(),
377 array(),
378 array( 'version' => $version,
379 'is_enabled' => $enabled ),
380 false,
381 null,
382 false,
383 null,
384 array( array( 'operation' => 'count( id )',
385 'name' => 'count' ) ) );
386 return $list[0]["count"];
387 }
388
389 function fetchEventIndexed( $index )
390 {
391 $id = $this->ID;
392 eZDebugSetting::writeDebug( 'workflow-event', $index, 'index in fetchEventIndexed' );
393 $list = eZPersistentObject::fetchObjectList( eZWorkflowEvent::definition(),
394 array( "id", "placement" ),
395 array( "workflow_id" => $id,
396 "version" => 0 ),
397 array( "placement" => "asc" ),
398 array( "offset" => $index - 1,
399 "length" => 1 ),
400 false );
401
402 eZDebugSetting::writeDebug( 'workflow-event', $list, "event indexed" );
403 if ( count( $list ) > 0 )
404 return $list[$index - 1]["id"];
405 return null;
406 }
407
408 function fetchEvents( $asObject = true, $version = false )
409 {
410 if ( $version === false )
411 {
412 $version = $this->Version;
413 }
414 return eZWorkflowEvent::fetchFilteredList( array( "workflow_id" => $this->ID,
415 "version" => $version ),
416 $asObject );
417 }
418
419 static function fetchEventsByWorkflowID( $id, $asObject = true, $version = 0 )
420 {
421 return eZWorkflowEvent::fetchFilteredList( array( "workflow_id" => $id,
422 "version" => $version ),
423 $asObject );
424 }
425
426 function fetchEventCount( $version = false )
427 {
428 if ( $version === false )
429 {
430 $version = $this->Version;
431 }
432 $list = eZPersistentObject::fetchObjectList( eZWorkflowEvent::definition(),
433 array(),
434 array( 'version' => $version,
435 'workflow_id' => $id ),
436 false,
437 null,
438 false,
439 false,
440 array( array( 'operation' => 'count( id )',
441 'name' => 'count' ) ) );
442 return $list[0]["count"];
443 }
444
445 static function fetchEventCountByWorkflowID( $id, $version = 0 )
446 {
447 $list = eZPersistentObject::fetchObjectList( eZWorkflowEvent::definition(),
448 array(),
449 array( 'version' => $version,
450 'workflow_id' => $id ),
451 false,
452 null,
453 false,
454 false,
455 array( array( 'operation' => 'count( id )',
456 'name' => 'count' ) ) );
457 return $list[0]["count"];
458 }
459
460 function creator()
461 {
462 if ( isset( $this->CreatorID ) and $this->CreatorID )
463 {
464 return eZUser::fetch( $this->CreatorID );
465 }
466
467 return null;
468 }
469
470 function modifier()
471 {
472 if ( isset( $this->ModifierID ) and $this->ModifierID )
473 {
474 return eZUser::fetch( $this->ModifierID );
475 }
476
477 return null;
478 }
479
480 function ingroupList()
481 {
482 $this->InGroups = eZWorkflowGroupLink::fetchGroupList( $this->attribute("id"),
483 $this->attribute("version"),
484 true );
485 return $this->InGroups;
486 }
487
488 function ingroupIDList()
489 {
490 $list = eZWorkflowGroupLink::fetchGroupList( $this->attribute("id"),
491 $this->attribute("version"),
492 false );
493
494 $this->InGroupIDs = array();
495 foreach ( $list as $item )
496 {
497 $this->InGroupIDs[] = $item['group_id'];
498 }
499 return $this->InGroupIDs;
500 }
501
502 function groupList()
503 {
504 $this->AllGroups = eZWorkflowGroup::fetchList();
505 return $this->AllGroups;
506 }
507
508 function workflowType()
509 {
510 return eZWorkflowType::createType( $this->WorkflowTypeString );
511 }
512
517 function cleanupWorkFlowProcess()
518 {
519 $db = eZDB::instance();
520 $workflowID = $this->attribute( 'id' );
521 $event_list = $this->fetchEvents();
522 if ( $event_list != null )
523 {
524 $existEventIDArray = array();
525 foreach ( $event_list as $event )
526 {
527 $eventID = $event->attribute( 'id' );
528 $existEventIDArray[] = $eventID;
529 }
530 $existEventIDString = implode( ',', $existEventIDArray );
531 $db->query( "DELETE FROM ezworkflow_process
532 WHERE workflow_id=$workflowID
533 AND event_id not in ( $existEventIDString )" );
534 }
535 else
536 {
537 $db->query( "DELETE FROM ezworkflow_process WHERE workflow_id=$workflowID" );
538 }
539 }
540
546 static function statusNameMap()
547 {
548 return array( eZWorkflow::STATUS_NONE => ezpI18n::tr( 'kernel/classes', 'No state yet' ),
549 eZWorkflow::STATUS_BUSY => ezpI18n::tr( 'kernel/classes', 'Workflow running' ),
550 eZWorkflow::STATUS_DONE => ezpI18n::tr( 'kernel/classes', 'Workflow done' ),
551 eZWorkflow::STATUS_FAILED => ezpI18n::tr( 'kernel/classes', 'Workflow failed an event' ),
552 eZWorkflow::STATUS_DEFERRED_TO_CRON => ezpI18n::tr( 'kernel/classes', 'Workflow event deferred to cron job' ),
553 eZWorkflow::STATUS_CANCELLED => ezpI18n::tr( 'kernel/classes', 'Workflow was canceled' ),
554 eZWorkflow::STATUS_FETCH_TEMPLATE => ezpI18n::tr( 'kernel/classes', 'Workflow fetches template' ),
555 eZWorkflow::STATUS_REDIRECT => ezpI18n::tr( 'kernel/classes', 'Workflow redirects user view' ),
556 eZWorkflow::STATUS_RESET => ezpI18n::tr( 'kernel/classes', 'Workflow was reset for reuse' ) );
557 }
558
560 public $ID;
561 public $Name;
562 public $WorkflowTypeString;
563 public $Version;
564 public $IsEnabled;
565 public $CreatorID;
566 public $ModifierID;
567 public $Created;
568 public $Modified;
569 public $InGroups;
570 public $InGroupIDs;
571 public $AllGroups;
572 }
573
574 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\updateObjectList
static updateObjectList( $parameters)
Definition: ezpersistentobject.php:1209
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZWorkflowEvent\definition
static definition()
Definition: ezworkflowevent.php:35
eZWorkflowEvent\fetchFilteredList
static fetchFilteredList( $cond, $asObject=true)
Definition: ezworkflowevent.php:154
eZWorkflowGroupLink\fetchGroupList
static fetchGroupList( $workflow_id, $workflow_version, $asObject=true)
Definition: ezworkflowgrouplink.php:112
eZWorkflowGroup\fetchList
static fetchList( $asObject=true)
Definition: ezworkflowgroup.php:82
eZWorkflowType\createType
static createType( $typeString)
Definition: ezworkflowtype.php:81
eZWorkflow
Definition: ezworkflow.php:18
eZWorkflow\$InGroupIDs
$InGroupIDs
Definition: ezworkflow.php:570
eZWorkflow\$ModifierID
$ModifierID
Definition: ezworkflow.php:566
eZWorkflow\cleanupWorkFlowProcess
cleanupWorkFlowProcess()
Definition: ezworkflow.php:517
eZWorkflow\setVersion
setVersion( $version, $set_childs=false)
Definition: ezworkflow.php:282
eZWorkflow\STATUS_CANCELLED
const STATUS_CANCELLED
Definition: ezworkflow.php:24
eZWorkflow\fetchLimited
static fetchLimited( $moduleName, $functionName, $connectType)
Definition: ezworkflow.php:321
eZWorkflow\adjustEventPlacements
static adjustEventPlacements( $events)
Definition: ezworkflow.php:218
eZWorkflow\$ID
$ID
Definition: ezworkflow.php:560
eZWorkflow\fetchEventCount
fetchEventCount( $version=false)
Definition: ezworkflow.php:426
eZWorkflow\STATUS_BUSY
const STATUS_BUSY
Definition: ezworkflow.php:20
eZWorkflow\workflowType
workflowType()
Definition: ezworkflow.php:508
eZWorkflow\$Created
$Created
Definition: ezworkflow.php:567
eZWorkflow\creator
creator()
Definition: ezworkflow.php:460
eZWorkflow\fetchEvents
fetchEvents( $asObject=true, $version=false)
Definition: ezworkflow.php:408
eZWorkflow\statusNameMap
static statusNameMap()
Definition: ezworkflow.php:546
eZWorkflow\$CreatorID
$CreatorID
Definition: ezworkflow.php:565
eZWorkflow\definition
static definition()
Definition: ezworkflow.php:31
eZWorkflow\fetch
static fetch( $id, $asObject=true, $version=0)
Definition: ezworkflow.php:302
eZWorkflow\$WorkflowTypeString
$WorkflowTypeString
Definition: ezworkflow.php:562
eZWorkflow\removeThis
removeThis( $remove_childs=false)
Definition: ezworkflow.php:142
eZWorkflow\create
static create( $user_id)
Definition: ezworkflow.php:100
eZWorkflow\$AllGroups
$AllGroups
Definition: ezworkflow.php:571
eZWorkflow\STATUS_DEFERRED_TO_CRON
const STATUS_DEFERRED_TO_CRON
Definition: ezworkflow.php:23
eZWorkflow\$Name
$Name
Definition: ezworkflow.php:561
eZWorkflow\fetchEventsByWorkflowID
static fetchEventsByWorkflowID( $id, $asObject=true, $version=0)
Definition: ezworkflow.php:419
eZWorkflow\fetchEventCountByWorkflowID
static fetchEventCountByWorkflowID( $id, $version=0)
Definition: ezworkflow.php:445
eZWorkflow\STATUS_WAITING_PARENT
const STATUS_WAITING_PARENT
Definition: ezworkflow.php:28
eZWorkflow\fetchList
static fetchList( $version=0, $enabled=1, $asObject=true)
Definition: ezworkflow.php:364
eZWorkflow\modifier
modifier()
Definition: ezworkflow.php:470
eZWorkflow\STATUS_FAILED
const STATUS_FAILED
Definition: ezworkflow.php:22
eZWorkflow\fetchListCount
static fetchListCount( $version=0, $enabled=1)
Definition: ezworkflow.php:374
eZWorkflow\isAllowed
isAllowed( $moduleName, $functionName, $connectType)
Definition: ezworkflow.php:348
eZWorkflow\STATUS_DONE
const STATUS_DONE
Definition: ezworkflow.php:21
eZWorkflow\STATUS_FETCH_TEMPLATE
const STATUS_FETCH_TEMPLATE
Definition: ezworkflow.php:25
eZWorkflow\removeWorkflow
static removeWorkflow( $id, $version)
Definition: ezworkflow.php:131
eZWorkflow\removeEvents
static removeEvents( $events=false, $id=false, $version=false)
Definition: ezworkflow.php:190
eZWorkflow\$Modified
$Modified
Definition: ezworkflow.php:568
eZWorkflow\store
store( $store_childs=false)
Definition: ezworkflow.php:233
eZWorkflow\STATUS_FETCH_TEMPLATE_REPEAT
const STATUS_FETCH_TEMPLATE_REPEAT
Definition: ezworkflow.php:29
eZWorkflow\$IsEnabled
$IsEnabled
Definition: ezworkflow.php:564
eZWorkflow\setIsEnabled
static setIsEnabled( $enabled, $id, $version=0)
Definition: ezworkflow.php:116
eZWorkflow\fetchEventIndexed
fetchEventIndexed( $index)
Definition: ezworkflow.php:389
eZWorkflow\$Version
$Version
Definition: ezworkflow.php:563
eZWorkflow\ingroupIDList
ingroupIDList()
Definition: ezworkflow.php:488
eZWorkflow\ingroupList
ingroupList()
Definition: ezworkflow.php:480
eZWorkflow\STATUS_RESET
const STATUS_RESET
Definition: ezworkflow.php:27
eZWorkflow\removeTemporary
static removeTemporary()
Definition: ezworkflow.php:170
eZWorkflow\STATUS_REDIRECT
const STATUS_REDIRECT
Definition: ezworkflow.php:26
eZWorkflow\groupList
groupList()
Definition: ezworkflow.php:502
eZWorkflow\storeDefined
storeDefined( $store_childs=false)
Definition: ezworkflow.php:259
eZWorkflow\$InGroups
$InGroups
Definition: ezworkflow.php:569
eZWorkflow\statusName
static statusName( $status)
Definition: ezworkflow.php:92
eZWorkflow\STATUS_NONE
const STATUS_NONE
Definition: ezworkflow.php:19
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+.