Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezmultiplexertype.php
Go to the documentation of this file.
1 <?php
23 class eZMultiplexerType extends eZWorkflowEventType
24 {
25 const WORKFLOW_TYPE_STRING = "ezmultiplexer";
26 const VERSION_OPTION_FIRST_ONLY = 1;
27 const VERSION_OPTION_EXCEPT_FIRST = 2;
28 const VERSION_OPTION_ALL = 3;
29
33 public function __construct()
34 {
35 parent::__construct( eZMultiplexerType::WORKFLOW_TYPE_STRING, ezpI18n::tr( 'kernel/workflow/event', 'Multiplexer' ) );
36 }
37
38 function attributeDecoder( $event, $attr )
39 {
40 switch ( $attr )
41 {
42 case 'selected_sections':
43 {
44 $attributeValue = trim( $event->attribute( 'data_text1' ) );
45 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
46 }break;
47
48 case 'selected_classes':
49 {
50 $attributeValue = trim( $event->attribute( 'data_text5' ) );
51 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
52 }break;
53
54 case 'selected_usergroups':
55 {
56 $attributeValue = trim( $event->attribute('data_text2') );
57 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
58 }break;
59
60 case 'selected_workflow':
61 {
62 $returnValue = $event->attribute( 'data_int1' );
63 }break;
64
65 case 'language_list':
66 {
67 $returnValue = array();
68 $attributeValue = $event->attribute( 'data_int2' );
69 if ( $attributeValue != 0 )
70 {
71 $languages = eZContentLanguage::languagesByMask( $attributeValue );
72 foreach ( $languages as $language )
73 {
74 $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' );
75 }
76 }
77 }break;
78
79 case 'version_option':
80 {
81 $returnValue = eZMultiplexerType::VERSION_OPTION_ALL & $event->attribute( 'data_int3' );
82 }break;
83
84 default:
85 $returnValue = null;
86 }
87 return $returnValue;
88 }
89
90 function typeFunctionalAttributes()
91 {
92 return array( 'selected_sections',
93 'selected_usergroups',
94 'selected_classes',
95 'selected_workflow',
96 'language_list',
97 'version_option' );
98 }
99
100 function attributes()
101 {
102 return array_merge( array( 'sections',
103 'languages',
104 'contentclass_list',
105 'workflow_list',
106 'usergroups' ),
107 eZWorkflowEventType::attributes() );
108 }
109
110 function hasAttribute( $attr )
111 {
112 return in_array( $attr, $this->attributes() );
113 }
114
115 function attribute( $attr )
116 {
117 switch( $attr )
118 {
119 case 'sections':
120 {
121 $sections = eZSection::fetchList( false );
122 foreach ( $sections as $key => $section )
123 {
124 $sections[$key]['Name'] = $section['name'];
125 $sections[$key]['value'] = $section['id'];
126 }
127 return $sections;
128 }
129 break;
130
131 case 'languages':
132 {
133 return eZContentLanguage::fetchList();
134 }break;
135
136 case 'usergroups':
137 {
138 $groups = eZPersistentObject::fetchObjectList(
139 eZContentObject::definition(),
140 array( 'id', 'name' ),
141 array( 'contentclass_id' => 3, 'status' => eZContentObject::STATUS_PUBLISHED ),
142 null,
143 null,
144 false
145 );
146
147 foreach ( $groups as $key => $group )
148 {
149 $groups[$key]['Name'] = $group['name'];
150 $groups[$key]['value'] = $group['id'];
151 }
152 return $groups;
153 }
154 break;
155
156 case 'contentclass_list':
157 {
158 $classes = eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true, false, array( 'name' => 'asc' ) );
159 $classList = array();
160 for ( $i = 0; $i < count( $classes ); $i++ )
161 {
162 $classList[$i]['Name'] = $classes[$i]->attribute( 'name' );
163 $classList[$i]['value'] = $classes[$i]->attribute( 'id' );
164 }
165 return $classList;
166 }
167 break;
168
169 case 'workflow_list':
170 {
171 $workflows = eZWorkflow::fetchList();
172 $workflowList = array();
173 for ( $i = 0; $i < count( $workflows ); $i++ )
174 {
175 $workflowList[$i]['Name'] = $workflows[$i]->attribute( 'name' );
176 $workflowList[$i]['value'] = $workflows[$i]->attribute( 'id' );
177 }
178 return $workflowList;
179 }
180 break;
181 }
182 return eZWorkflowEventType::attribute( $attr );
183 }
184
185 function execute( $process, $event )
186 {
187 $processParameters = $process->attribute( 'parameter_list' );
188 $storeProcessParameters = false;
189 $classID = false;
190 $object = false;
191 $sectionID = false;
192 $languageID = 0;
193
194 if ( isset( $processParameters['object_id'] ) )
195 {
196 $object = eZContentObject::fetch( $processParameters['object_id'] );
197 }
198 else if ( isset( $processParameters['node_id'] ) )
199 {
200 $object = eZContentObject::fetchByNodeID( $processParameters['node_id'] );
201 }
202
203 if ( $object instanceof eZContentObject )
204 {
205 // Examine if the published version contains one of the languages we
206 // match for.
207 if ( isset( $processParameters['version'] ) )
208 {
209 $versionID = $processParameters['version'];
210 $version = $object->version( $versionID );
211
212 if ( is_object( $version ) )
213 {
214 $version_option = $event->attribute( 'version_option' );
215 if ( ( $version_option == eZMultiplexerType::VERSION_OPTION_FIRST_ONLY and $processParameters['version'] > 1 ) or
216 ( $version_option == eZMultiplexerType::VERSION_OPTION_EXCEPT_FIRST and $processParameters['version'] == 1 ) )
217 {
218 return eZWorkflowType::STATUS_ACCEPTED;
219 }
220
221 // If the language ID is part of the mask the result is non-zero.
222 $languageID = (int)$version->attribute( 'initial_language_id' );
223 }
224 }
225 $sectionID = $object->attribute( 'section_id' );
226 $class = $object->attribute( 'content_class' );
227 if ( $class )
228 {
229 $classID = $class->attribute( 'id' );
230 }
231 }
232
233 $userArray = explode( ',', $event->attribute( 'data_text2' ) );
234 $classArray = explode( ',', $event->attribute( 'data_text5' ) );
235 $languageMask = $event->attribute( 'data_int2' );
236
237 if ( !isset( $processParameters['user_id'] ) )
238 {
239 $user = eZUser::currentUser();
240 $userID = $user->id();
241 $processParameters['user_id'] = $userID;
242 $storeProcessParameters = true;
243 }
244 else
245 {
246 $userID = $processParameters['user_id'];
247 $user = eZUser::fetch( $userID );
248 if ( !( $user instanceof eZUser ) )
249 {
250 $user = eZUser::currentUser();
251 $userID = $user->id();
252 $processParameters['user_id'] = $userID;
253 $storeProcessParameters = true;
254 }
255 }
256 $userGroups = $user->attribute( 'groups' );
257 $inExcludeGroups = count( array_intersect( $userGroups, $userArray ) ) != 0;
258
259 if ( $storeProcessParameters )
260 {
261 $process->setParameters( $processParameters );
262 $process->store();
263 }
264
265 // All languages match by default
266 $hasLanguageMatch = true;
267 if ( $languageMask != 0 )
268 {
269 // Match ID with mask.
270 $hasLanguageMatch = (bool)( $languageMask & $languageID );
271 }
272
273 if ( $hasLanguageMatch &&
274 ( !$inExcludeGroups ) &&
275 ( in_array( -1, $classArray ) ||
276 in_array( $classID, $classArray ) ) )
277 {
278 $sectionArray = explode( ',', $event->attribute( 'data_text1' ) );
279
280 if ( in_array( $sectionID, $sectionArray ) ||
281 in_array( -1, $sectionArray ) )
282 {
283 $workflowToRun = $event->attribute( 'data_int1' );
284
285 $childParameters = array_merge( $processParameters,
286 array( 'workflow_id' => $workflowToRun,
287 'user_id' => $userID,
288 'parent_process_id' => $process->attribute( 'id' )
289 ) );
290
291 $childProcessKey = eZWorkflowProcess::createKey( $childParameters );
292
293 $childProcessArray = eZWorkflowProcess::fetchListByKey( $childProcessKey );
294 $childProcess =& $childProcessArray[0];
295 if ( $childProcess == null )
296 {
297 $childProcess = eZWorkflowProcess::create( $childProcessKey, $childParameters );
298 $childProcess->store();
299 }
300
301 $workflow = eZWorkflow::fetch( $childProcess->attribute( "workflow_id" ) );
302 $workflowEvent = null;
303
304 if ( $childProcess->attribute( "event_id" ) != 0 )
305 $workflowEvent = eZWorkflowEvent::fetch( $childProcess->attribute( "event_id" ) );
306
307 $childStatus = $childProcess->run( $workflow, $workflowEvent, $eventLog );
308 $childProcess->store();
309
310 if ( $childStatus == eZWorkflow::STATUS_DEFERRED_TO_CRON )
311 {
312 $this->setActivationDate( $childProcess->attribute( 'activation_date' ) );
313 $childProcess->setAttribute( "status", eZWorkflow::STATUS_WAITING_PARENT );
314 $childProcess->store();
315 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
316 }
317 else if ( $childStatus == eZWorkflow::STATUS_FETCH_TEMPLATE or $childStatus == eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT )
318 {
319 $process->Template =& $childProcess->Template;
320 return eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT;
321 }
322 else if ( $childStatus == eZWorkflow::STATUS_REDIRECT )
323 {
324 $process->RedirectUrl =& $childProcess->RedirectUrl;
325 return eZWorkflowType::STATUS_REDIRECT_REPEAT;
326 }
327 else if ( $childStatus == eZWorkflow::STATUS_DONE )
328 {
329 $childProcess->removeThis();
330 return eZWorkflowType::STATUS_ACCEPTED;
331 }
332 else if ( $childStatus == eZWorkflow::STATUS_CANCELLED )
333 {
334 $childProcess->removeThis();
335 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
336 }
337 else if ( $childStatus == eZWorkflow::STATUS_FAILED )
338 {
339 $childProcess->removeThis();
340 return eZWorkflowType::STATUS_REJECTED;
341 }
342 return $childProcess->attribute( 'event_status' );
343 }
344 }
345 return eZWorkflowType::STATUS_ACCEPTED;
346 }
347
348 function initializeEvent( $event )
349 {
350 }
351
352
353 function fetchHTTPInput( $http, $base, $event )
354 {
355 if ( !$http->hasPostVariable( "StoreButton" ) )
356 {
357 return;
358 }
359
360 $sectionsVar = $base . "_event_ezmultiplexer_section_ids_" . $event->attribute( "id" );
361 if ( $http->hasPostVariable( $sectionsVar ) )
362 {
363 $sectionsArray = $http->postVariable( $sectionsVar );
364 if ( in_array( '-1', $sectionsArray ) )
365 {
366 $sectionsArray = array( -1 );
367 }
368 $sectionsString = implode( ',', $sectionsArray );
369 $event->setAttribute( "data_text1", $sectionsString );
370 }
371
372 $languageVar = $base . "_event_ezmultiplexer_languages_" . $event->attribute( "id" );
373 if ( $http->hasPostVariable( $languageVar ) )
374 {
375 $languageArray = $http->postVariable( $languageVar );
376 if ( in_array( '-1', $languageArray ) )
377 {
378 $languageArray = array();
379 }
380 $languageMask = 0;
381 foreach ( $languageArray as $languageID )
382 {
383 $languageMask |= $languageID;
384 }
385 $event->setAttribute( "data_int2", $languageMask );
386 }
387
388 $usersVar = $base . "_event_ezmultiplexer_not_run_ids_" . $event->attribute( "id" );
389 if ( $http->hasPostVariable( $usersVar ) )
390 {
391 $usersArray = $http->postVariable( $usersVar );
392 $usersString = implode( ',', $usersArray );
393 $event->setAttribute( "data_text2", $usersString );
394 }
395 else
396 {
397 $event->setAttribute( "data_text2", '' );
398 }
399
400 $classesVar = $base . "_event_ezmultiplexer_class_ids_" . $event->attribute( "id" );
401 if ( $http->hasPostVariable( $classesVar ) )
402 {
403 $classesArray = $http->postVariable( $classesVar );
404 if ( in_array( '-1', $classesArray ) )
405 {
406 $classesArray = array( -1 );
407 }
408 $classesString = implode( ',', $classesArray );
409 $event->setAttribute( "data_text5", $classesString );
410 }
411
412 $workflowVar = $base . "_event_ezmultiplexer_workflow_id_" . $event->attribute( "id" );
413 if ( $http->hasPostVariable( $workflowVar ) )
414 {
415 $workflowID = $http->postVariable( $workflowVar );
416 $event->setAttribute( "data_int1", $workflowID );
417 }
418
419 $versionOptionVar = $base . "_event_ezmultiplexer_version_option_" . $event->attribute( "id" );
420 if ( $http->hasPostVariable( $versionOptionVar ) )
421 {
422 $versionOptionArray = $http->postVariable( $versionOptionVar );
423 $versionOption = 0;
424 if ( is_array( $versionOptionArray ) )
425 {
426 foreach ( $versionOptionArray as $vv )
427 {
428 $versionOption = $versionOption | $vv;
429 }
430 }
431 $versionOption = $versionOption & eZMultiplexerType::VERSION_OPTION_ALL;
432 $event->setAttribute( 'data_int3', $versionOption );
433 }
434 }
435 }
436
437 eZWorkflowEventType::registerEventType( eZMultiplexerType::WORKFLOW_TYPE_STRING, 'eZMultiplexerType' );
438
439 ?>
eZContentClass\fetchList
static fetchList( $version=eZContentClass::VERSION_STATUS_DEFINED, $asObject=true, $user_id=false, $sorts=null, $fields=null, $classFilter=false, $limit=null)
Definition: ezcontentclass.php:1238
eZContentClass\VERSION_STATUS_DEFINED
const VERSION_STATUS_DEFINED
Definition: ezcontentclass.php:22
eZContentLanguage\fetchList
static fetchList( $forceReloading=false)
Definition: ezcontentlanguage.php:163
eZContentLanguage\languagesByMask
static languagesByMask( $mask)
Definition: ezcontentlanguage.php:432
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobject.php:20
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZContentObject\fetchByNodeID
static fetchByNodeID( $nodeID, $asObject=true)
Definition: ezcontentobject.php:1072
eZContentObject\definition
static definition()
Definition: ezcontentobject.php:100
eZMultiplexerType
The class eZMultiplexerType does.
Definition: ezmultiplexertype.php:24
eZMultiplexerType\execute
execute( $process, $event)
Definition: ezmultiplexertype.php:185
eZMultiplexerType\initializeEvent
initializeEvent( $event)
Definition: ezmultiplexertype.php:348
eZMultiplexerType\hasAttribute
hasAttribute( $attr)
Definition: ezmultiplexertype.php:110
eZMultiplexerType\VERSION_OPTION_EXCEPT_FIRST
const VERSION_OPTION_EXCEPT_FIRST
Definition: ezmultiplexertype.php:27
eZMultiplexerType\fetchHTTPInput
fetchHTTPInput( $http, $base, $event)
Definition: ezmultiplexertype.php:353
eZMultiplexerType\attributes
attributes()
Definition: ezmultiplexertype.php:100
eZMultiplexerType\VERSION_OPTION_ALL
const VERSION_OPTION_ALL
Definition: ezmultiplexertype.php:28
eZMultiplexerType\VERSION_OPTION_FIRST_ONLY
const VERSION_OPTION_FIRST_ONLY
Definition: ezmultiplexertype.php:26
eZMultiplexerType\attributeDecoder
attributeDecoder( $event, $attr)
Definition: ezmultiplexertype.php:38
eZMultiplexerType\WORKFLOW_TYPE_STRING
const WORKFLOW_TYPE_STRING
Definition: ezmultiplexertype.php:25
eZMultiplexerType\attribute
attribute( $attr)
Definition: ezmultiplexertype.php:115
eZMultiplexerType\__construct
__construct()
Definition: ezmultiplexertype.php:33
eZMultiplexerType\typeFunctionalAttributes
typeFunctionalAttributes()
Definition: ezmultiplexertype.php:90
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
eZSection\fetchList
static fetchList( $asObject=true)
Definition: ezsection.php:139
eZUser
eZUser handles eZ Publish user accounts
Definition: ezuser.php:19
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
eZWorkflowEventType
Definition: ezworkfloweventtype.php:18
eZWorkflowEventType\registerEventType
static registerEventType( $typeString, $class_name)
Definition: ezworkfloweventtype.php:40
eZWorkflowEvent\fetch
static fetch( $id, $asObject=true, $version=0, $field_filters=null)
Definition: ezworkflowevent.php:138
eZWorkflowProcess\create
static create( $processKey, $parameters)
Definition: ezworkflowprocess.php:134
eZWorkflowProcess\createKey
static createKey( $parameters, $keys=null)
Definition: ezworkflowprocess.php:454
eZWorkflowProcess\fetchListByKey
static fetchListByKey( $searchKey, $asObject=true)
Definition: ezworkflowprocess.php:485
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\STATUS_REDIRECT_REPEAT
const STATUS_REDIRECT_REPEAT
Definition: ezworkflowtype.php:31
eZWorkflowType\STATUS_FETCH_TEMPLATE_REPEAT
const STATUS_FETCH_TEMPLATE_REPEAT
Definition: ezworkflowtype.php:28
eZWorkflowType\attributes
attributes()
Definition: ezworkflowtype.php:225
eZWorkflowType\STATUS_REJECTED
const STATUS_REJECTED
Definition: ezworkflowtype.php:22
eZWorkflowType\setActivationDate
setActivationDate( $date)
Definition: ezworkflowtype.php:309
eZWorkflowType\STATUS_WORKFLOW_CANCELLED
const STATUS_WORKFLOW_CANCELLED
Definition: ezworkflowtype.php:26
eZWorkflow\STATUS_CANCELLED
const STATUS_CANCELLED
Definition: ezworkflow.php:24
eZWorkflow\fetch
static fetch( $id, $asObject=true, $version=0)
Definition: ezworkflow.php:302
eZWorkflow\STATUS_DEFERRED_TO_CRON
const STATUS_DEFERRED_TO_CRON
Definition: ezworkflow.php:23
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\STATUS_FAILED
const STATUS_FAILED
Definition: ezworkflow.php:22
eZWorkflow\STATUS_DONE
const STATUS_DONE
Definition: ezworkflow.php:21
eZWorkflow\STATUS_FETCH_TEMPLATE
const STATUS_FETCH_TEMPLATE
Definition: ezworkflow.php:25
eZWorkflow\STATUS_FETCH_TEMPLATE_REPEAT
const STATUS_FETCH_TEMPLATE_REPEAT
Definition: ezworkflow.php:29
eZWorkflow\STATUS_REDIRECT
const STATUS_REDIRECT
Definition: ezworkflow.php:26
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+.