Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezworkflowtype.php
Go to the documentation of this file.
1 <?php
13
17 class eZWorkflowType
18 {
19 public $Attributes;
20 const STATUS_NONE = 0;
21 const STATUS_ACCEPTED = 1;
22 const STATUS_REJECTED = 2;
23 const STATUS_DEFERRED_TO_CRON = 3;
24 const STATUS_DEFERRED_TO_CRON_REPEAT = 4;
25 const STATUS_RUN_SUB_EVENT = 5;
26 const STATUS_WORKFLOW_CANCELLED = 6;
27 const STATUS_FETCH_TEMPLATE = 7;
28 const STATUS_FETCH_TEMPLATE_REPEAT = 8;
29 const STATUS_REDIRECT = 10;
30 const STATUS_WORKFLOW_DONE = 9;
31 const STATUS_REDIRECT_REPEAT = 11;
32 const STATUS_WORKFLOW_RESET = 12;
33
42 public function __construct( $group, $type, $groupName, $name )
43 {
44 $this->Group = $group;
45 $this->Type = $type;
46 $this->TypeString = $group . "_" . $type;
47 $this->GroupName = $groupName;
48 $this->Name = $name;
49 $this->Information = "";
50 $this->ActivationDate = false;
51 $this->Attributes = array();
52 $this->Attributes["group"] =& $this->Group;
53 $this->Attributes["type"] =& $this->Type;
54 $this->Attributes["type_string"] =& $this->TypeString;
55 $this->Attributes["group_name"] =& $this->GroupName;
56 $this->Attributes["name"] =& $this->Name;
57 $this->Attributes["information"] =& $this->Information;
58 $this->Attributes["activation_date"] =& $this->ActivationDate;
59 }
60
68 public function eZWorkflowType( $group, $type, $groupName, $name )
69 {
70 self::__construct( $group, $type, $groupName, $name );
71 }
72
73 static function statusName( $status )
74 {
75 $statusNameMap = self::statusNameMap();
76 if ( isset( $statusNameMap[$status] ) )
77 return $statusNameMap[$status];
78 return false;
79 }
80
81 static function createType( $typeString )
82 {
83 $types =& $GLOBALS["eZWorkflowTypes"];
84 if ( !isset( $types[$typeString] ) )
85 {
86 $result = eZWorkflowType::loadAndRegisterType( $typeString );
87 if ( $result === false )
88 return null;
89 }
90
91 if ( isset( $types[$typeString] ) )
92 {
93 $class_name = $types[$typeString]["class_name"];
94
95 if ( !isset( $GLOBALS["eZWorkflowTypeObjects"][$typeString] ) )
96 {
97 if ( class_exists( $class_name ) )
98 {
99 $GLOBALS["eZWorkflowTypeObjects"][$typeString] = new $class_name();
100 }
101 else
102 {
103 eZDebug::writeError( "Undefined event type class: $class_name", __METHOD__ );
104 }
105 }
106 return $GLOBALS["eZWorkflowTypeObjects"][$typeString];
107 }
108 else
109 {
110 eZDebug::writeError( "Undefined type: $typeString", __METHOD__ );
111 }
112 return null;
113 }
114
115 static function fetchRegisteredTypes()
116 {
117 eZWorkflowType::loadAndRegisterAllTypes();
118 $types = $GLOBALS["eZWorkflowTypes"];
119 if ( is_array( $types ) )
120 {
121 foreach ( $types as $typeString => $type_def )
122 {
123 $class_name = $type_def["class_name"];
124 $def =& $definition_objects[$typeString];
125 if ( !isset( $GLOBALS["eZWorkflowTypeObjects"][$typeString] ) )
126 {
127 if ( class_exists( $class_name ) )
128 {
129 $GLOBALS["eZWorkflowTypeObjects"][$typeString] = new $class_name();
130 }
131 else
132 {
133 eZDebug::writeError( "Undefined event type class: $class_name", __METHOD__ );
134 }
135 }
136 }
137 }
138 return $GLOBALS["eZWorkflowTypeObjects"];
139 }
140
141 static function allowedTypes()
142 {
143 if ( !isset( $GLOBALS["eZWorkflowAllowedTypes"] ) ||
144 !is_array( $GLOBALS["eZWorkflowAllowedTypes"] ) )
145 {
146 $wfINI = eZINI::instance( 'workflow.ini' );
147 $eventTypes = $wfINI->variable( "EventSettings", "AvailableEventTypes" );
148 $GLOBALS["eZWorkflowAllowedTypes"] = array_unique( $eventTypes );
149 }
150 return $GLOBALS["eZWorkflowAllowedTypes"];
151 }
152
153 static function loadAndRegisterAllTypes()
154 {
155 $allowedTypes = eZWorkflowType::allowedTypes();
156 foreach( $allowedTypes as $type )
157 {
158 eZWorkflowType::loadAndRegisterType( $type );
159 }
160 }
161
162 static function registerType( $group, $type, $class_name )
163 {
164 $typeString = $group . "_" . $type;
165 if ( !isset( $GLOBALS["eZWorkflowTypes"] ) || !is_array( $GLOBALS["eZWorkflowTypes"] ) )
166 {
167 $GLOBALS["eZWorkflowTypes"] = array();
168 }
169 if ( isset( $GLOBALS["eZWorkflowTypes"][$typeString] ) )
170 {
171 eZDebug::writeError( "Type already registered: $typeString", __METHOD__ );
172 }
173 else
174 {
175 $GLOBALS["eZWorkflowTypes"][$typeString] = array( "class_name" => $class_name );
176 }
177 }
178
179 static function loadAndRegisterType( $typeString )
180 {
181 $typeElements = explode( "_", $typeString );
182 if ( count( $typeElements ) < 2 )
183 {
184 eZDebug::writeError( "Workflow type not found: $typeString", __METHOD__ );
185 return false;
186 }
187
188 $types =& $GLOBALS["eZWorkflowTypes"];
189 if ( isset( $types[ $typeString ] ) and
190 isset( $types[ $typeString ][ 'class_name' ] ) and
191 class_exists( $types[ $typeString ][ 'class_name' ] ) )
192 {
193 return true;
194 }
195
196 $group = $typeElements[0];
197 $type = $typeElements[1];
198
199 $baseDirectory = eZExtension::baseDirectory();
200 $wfINI = eZINI::instance( 'workflow.ini' );
201 $repositoryDirectories = $wfINI->variable( 'EventSettings', 'RepositoryDirectories' );
202 $extensionDirectories = $wfINI->variable( 'EventSettings', 'ExtensionDirectories' );
203 foreach ( $extensionDirectories as $extensionDirectory )
204 {
205 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/eventtypes';
206 if ( file_exists( $extensionPath ) )
207 $repositoryDirectories[] = $extensionPath;
208 }
209
210 foreach ( $repositoryDirectories as $repositoryDirectory )
211 {
212 $includeFile = "$repositoryDirectory/$group/$type/" . $type . "type.php";
213 if ( file_exists( $includeFile ) )
214 {
215 include_once( $includeFile );
216 return true;
217 }
218 }
219
220 eZDebug::writeError( "Workflow type not found: $typeString, searched in these directories: " . implode( ', ', $repositoryDirectories ), __METHOD__ );
221 return false;
222 }
223
224
225 function attributes()
226 {
227 return array_merge( array( 'description',
228 'allowed_triggers' ),
229 array_keys( $this->Attributes ) );
230 }
231
232 function hasAttribute( $attr )
233 {
234 return in_array( $attr, $this->attributes() );
235 }
236
237 function attribute( $attr )
238 {
239 switch( $attr )
240 {
241 case 'description':
242 {
243 return $this->eventDescription();
244 } break;
245
246 case 'allowed_triggers':
247 {
248 return $this->TriggerTypes;
249 } break;
250
251 default:
252 {
253 if ( isset( $this->Attributes[$attr] ) )
254 return $this->Attributes[$attr];
255 } break;
256 }
257
258 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
259 return null;
260 }
261
262 function setAttribute( $attr, $value )
263 {
264 if ( array_key_exists( $attr, $this->Attributes ) )
265 $this->Attributes[$attr] = $value;
266 }
267
276 function setTriggerTypes( $allowedTypes )
277 {
278 $this->TriggerTypes = $allowedTypes;
279 }
280
281 function eventDescription()
282 {
283 return $this->Attributes["name"];
284 }
285
286 function execute( $process, $event )
287 {
288 return eZWorkflowType::STATUS_NONE;
289 }
290
291 function initializeEvent( $event )
292 {
293 }
294
295 function validateHTTPInput( $http, $base, $event, &$validation )
296 {
297 return eZInputValidator::STATE_ACCEPTED;
298 }
299
300 function fixupHTTPInput( $http, $base, $event )
301 {
302 return true;
303 }
304
305 function fetchHTTPInput( $http, $base, $event )
306 {
307 }
308
309 function setActivationDate( $date )
310 {
311 $this->ActivationDate = $date;
312 }
313
314 function setInformation( $inf )
315 {
316 $this->Information = $inf;
317 }
318
319 function needCleanup()
320 {
321 return false;
322 }
323
324 function cleanupAfterRemoving( $attr = array() )
325 {
326 }
327
328 function cleanup( $process, $event )
329 {
330 }
331
332 function attributeDecoder( $event, $attr )
333 {
334 return null;
335 }
336
337 function typeFunctionalAttributes( )
338 {
339 return array();
340 }
341
342 function customWorkflowEventHTTPAction( $http, $action, $workflowEvent )
343 {
344 }
345
346 function workflowEventContent( $event )
347 {
348 return "";
349 }
350 function storeEventData( $event, $version )
351 {
352 }
353 function storeDefinedEventData( $event )
354 {
355 }
365 function isAllowed( $moduleName, $functionName, $connectType )
366 {
367 if ( isset( $this->TriggerTypes['*'] ) )
368 {
369 return true;
370 }
371 else if ( isset( $this->TriggerTypes[$moduleName] ) )
372 {
373 if ( isset( $this->TriggerTypes[$moduleName][$functionName] ) )
374 {
375 if ( in_array( $connectType, $this->TriggerTypes[$moduleName][$functionName] ) )
376 {
377 return true;
378 }
379 }
380 }
381
382 return false;
383 }
384
390 static function statusNameMap()
391 {
392 return array( self::STATUS_NONE => ezpI18n::tr( 'kernel/classes', 'No state yet' ),
393 self::STATUS_ACCEPTED => ezpI18n::tr( 'kernel/classes', 'Accepted event' ),
394 self::STATUS_REJECTED => ezpI18n::tr( 'kernel/classes', 'Rejected event' ),
395 self::STATUS_DEFERRED_TO_CRON => ezpI18n::tr( 'kernel/classes', 'Event deferred to cron job' ),
396 self::STATUS_DEFERRED_TO_CRON_REPEAT => ezpI18n::tr( 'kernel/classes', 'Event deferred to cron job, event will be rerun' ),
397 self::STATUS_RUN_SUB_EVENT => ezpI18n::tr( 'kernel/classes', 'Event runs a sub event' ),
398 self::STATUS_WORKFLOW_CANCELLED => ezpI18n::tr( 'kernel/classes', 'Canceled whole workflow' ),
399 self::STATUS_WORKFLOW_RESET => ezpI18n::tr( 'kernel/classes', 'Workflow was reset for reuse' ) );
400 }
401
403 public $Group;
404 public $Type;
405 public $TypeString;
406 public $GroupName;
407 public $Name;
408 public $ActivationDate;
409 public $Information;
410 public $TriggerTypes = array( '*' => true );
411 }
412
413 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZWorkflowType
Definition: ezworkflowtype.php:18
eZWorkflowType\setAttribute
setAttribute( $attr, $value)
Definition: ezworkflowtype.php:262
eZWorkflowType\__construct
__construct( $group, $type, $groupName, $name)
Definition: ezworkflowtype.php:42
eZWorkflowType\eventDescription
eventDescription()
Definition: ezworkflowtype.php:281
eZWorkflowType\cleanupAfterRemoving
cleanupAfterRemoving( $attr=array())
Definition: ezworkflowtype.php:324
eZWorkflowType\STATUS_DEFERRED_TO_CRON_REPEAT
const STATUS_DEFERRED_TO_CRON_REPEAT
Definition: ezworkflowtype.php:24
eZWorkflowType\cleanup
cleanup( $process, $event)
Definition: ezworkflowtype.php:328
eZWorkflowType\typeFunctionalAttributes
typeFunctionalAttributes()
Definition: ezworkflowtype.php:337
eZWorkflowType\$ActivationDate
$ActivationDate
Definition: ezworkflowtype.php:408
eZWorkflowType\fixupHTTPInput
fixupHTTPInput( $http, $base, $event)
Definition: ezworkflowtype.php:300
eZWorkflowType\fetchHTTPInput
fetchHTTPInput( $http, $base, $event)
Definition: ezworkflowtype.php:305
eZWorkflowType\initializeEvent
initializeEvent( $event)
Definition: ezworkflowtype.php:291
eZWorkflowType\$Information
$Information
Definition: ezworkflowtype.php:409
eZWorkflowType\fetchRegisteredTypes
static fetchRegisteredTypes()
Definition: ezworkflowtype.php:115
eZWorkflowType\STATUS_REDIRECT
const STATUS_REDIRECT
Definition: ezworkflowtype.php:29
eZWorkflowType\STATUS_ACCEPTED
const STATUS_ACCEPTED
Definition: ezworkflowtype.php:21
eZWorkflowType\attributeDecoder
attributeDecoder( $event, $attr)
Definition: ezworkflowtype.php:332
eZWorkflowType\eZWorkflowType
eZWorkflowType( $group, $type, $groupName, $name)
Definition: ezworkflowtype.php:68
eZWorkflowType\isAllowed
isAllowed( $moduleName, $functionName, $connectType)
Definition: ezworkflowtype.php:365
eZWorkflowType\attribute
attribute( $attr)
Definition: ezworkflowtype.php:237
eZWorkflowType\STATUS_REDIRECT_REPEAT
const STATUS_REDIRECT_REPEAT
Definition: ezworkflowtype.php:31
eZWorkflowType\$TriggerTypes
$TriggerTypes
Definition: ezworkflowtype.php:410
eZWorkflowType\STATUS_WORKFLOW_DONE
const STATUS_WORKFLOW_DONE
Definition: ezworkflowtype.php:30
eZWorkflowType\STATUS_FETCH_TEMPLATE
const STATUS_FETCH_TEMPLATE
Definition: ezworkflowtype.php:27
eZWorkflowType\STATUS_RUN_SUB_EVENT
const STATUS_RUN_SUB_EVENT
Definition: ezworkflowtype.php:25
eZWorkflowType\STATUS_WORKFLOW_RESET
const STATUS_WORKFLOW_RESET
Definition: ezworkflowtype.php:32
eZWorkflowType\registerType
static registerType( $group, $type, $class_name)
Definition: ezworkflowtype.php:162
eZWorkflowType\needCleanup
needCleanup()
Definition: ezworkflowtype.php:319
eZWorkflowType\setInformation
setInformation( $inf)
Definition: ezworkflowtype.php:314
eZWorkflowType\STATUS_FETCH_TEMPLATE_REPEAT
const STATUS_FETCH_TEMPLATE_REPEAT
Definition: ezworkflowtype.php:28
eZWorkflowType\statusName
static statusName( $status)
Definition: ezworkflowtype.php:73
eZWorkflowType\storeDefinedEventData
storeDefinedEventData( $event)
Definition: ezworkflowtype.php:353
eZWorkflowType\attributes
attributes()
Definition: ezworkflowtype.php:225
eZWorkflowType\workflowEventContent
workflowEventContent( $event)
Definition: ezworkflowtype.php:346
eZWorkflowType\loadAndRegisterAllTypes
static loadAndRegisterAllTypes()
Definition: ezworkflowtype.php:153
eZWorkflowType\hasAttribute
hasAttribute( $attr)
Definition: ezworkflowtype.php:232
eZWorkflowType\validateHTTPInput
validateHTTPInput( $http, $base, $event, &$validation)
Definition: ezworkflowtype.php:295
eZWorkflowType\STATUS_REJECTED
const STATUS_REJECTED
Definition: ezworkflowtype.php:22
eZWorkflowType\allowedTypes
static allowedTypes()
Definition: ezworkflowtype.php:141
eZWorkflowType\STATUS_NONE
const STATUS_NONE
Definition: ezworkflowtype.php:20
eZWorkflowType\STATUS_DEFERRED_TO_CRON
const STATUS_DEFERRED_TO_CRON
Definition: ezworkflowtype.php:23
eZWorkflowType\$Type
$Type
Definition: ezworkflowtype.php:404
eZWorkflowType\loadAndRegisterType
static loadAndRegisterType( $typeString)
Definition: ezworkflowtype.php:179
eZWorkflowType\statusNameMap
static statusNameMap()
Definition: ezworkflowtype.php:390
eZWorkflowType\setActivationDate
setActivationDate( $date)
Definition: ezworkflowtype.php:309
eZWorkflowType\createType
static createType( $typeString)
Definition: ezworkflowtype.php:81
eZWorkflowType\setTriggerTypes
setTriggerTypes( $allowedTypes)
Definition: ezworkflowtype.php:276
eZWorkflowType\execute
execute( $process, $event)
Definition: ezworkflowtype.php:286
eZWorkflowType\$GroupName
$GroupName
Definition: ezworkflowtype.php:406
eZWorkflowType\$Attributes
$Attributes
Definition: ezworkflowtype.php:19
eZWorkflowType\STATUS_WORKFLOW_CANCELLED
const STATUS_WORKFLOW_CANCELLED
Definition: ezworkflowtype.php:26
eZWorkflowType\$TypeString
$TypeString
Definition: ezworkflowtype.php:405
eZWorkflowType\$Name
$Name
Definition: ezworkflowtype.php:407
eZWorkflowType\$Group
$Group
Definition: ezworkflowtype.php:403
eZWorkflowType\storeEventData
storeEventData( $event, $version)
Definition: ezworkflowtype.php:350
eZWorkflowType\customWorkflowEventHTTPAction
customWorkflowEventHTTPAction( $http, $action, $workflowEvent)
Definition: ezworkflowtype.php:342
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+.