00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 define( "EZ_WORKFLOW_TYPE_MULTIPLEXER_ID", "ezmultiplexer" );
00046 define( 'EZ_MULTIPLEXER_VERSION_OPTION_FIRST_ONLY', 1 );
00047 define( 'EZ_MULTIPLEXER_VERSION_OPTION_EXCEPT_FIRST', 2 );
00048 define( 'EZ_MULTIPLEXER_VERSION_OPTION_ALL', EZ_MULTIPLEXER_VERSION_OPTION_FIRST_ONLY | EZ_MULTIPLEXER_VERSION_OPTION_EXCEPT_FIRST );
00049
00050 class eZMultiplexerType extends eZWorkflowEventType
00051 {
00052
00053
00054
00055 function eZMultiplexerType()
00056 {
00057 $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_MULTIPLEXER_ID, ezi18n( 'kernel/workflow/event', 'Multiplexer' ) );
00058 }
00059
00060 function &attributeDecoder( &$event, $attr )
00061 {
00062 switch ( $attr )
00063 {
00064 case 'selected_sections':
00065 {
00066 $attributeValue = trim( $event->attribute( 'data_text1' ) );
00067 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
00068 }break;
00069
00070 case 'selected_classes':
00071 {
00072 $attributeValue = trim( $event->attribute( 'data_text3' ) );
00073 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
00074 }break;
00075
00076 case 'selected_usergroups':
00077 {
00078 $attributeValue = trim( $event->attribute('data_text2') );
00079 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
00080 }break;
00081
00082 case 'selected_workflow':
00083 {
00084 $returnValue = $event->attribute( 'data_int1' );
00085 }break;
00086
00087 case 'language_list':
00088 {
00089 $returnValue = array();
00090 $attributeValue = $event->attribute( 'data_int2' );
00091 if ( $attributeValue != 0 )
00092 {
00093 include_once( 'kernel/classes/ezcontentlanguage.php' );
00094 $languages = eZContentLanguage::languagesByMask( $attributeValue );
00095 foreach ( $languages as $language )
00096 {
00097 $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' );
00098 }
00099 }
00100 }break;
00101
00102 case 'version_option':
00103 {
00104 $returnValue = EZ_MULTIPLEXER_VERSION_OPTION_ALL & $event->attribute( 'data_int3' );
00105 }break;
00106
00107 default:
00108 $returnValue = null;
00109 }
00110 return $returnValue;
00111 }
00112
00113 function typeFunctionalAttributes()
00114 {
00115 return array( 'selected_sections',
00116 'selected_usergroups',
00117 'selected_classes',
00118 'selected_workflow',
00119 'language_list',
00120 'version_option' );
00121 }
00122
00123 function attributes()
00124 {
00125 return array_merge( array( 'sections',
00126 'languages',
00127 'contentclass_list',
00128 'workflow_list',
00129 'usergroups' ),
00130 eZWorkflowEventType::attributes() );
00131 }
00132
00133 function hasAttribute( $attr )
00134 {
00135 return in_array( $attr, $this->attributes() );
00136 }
00137
00138 function &attribute( $attr )
00139 {
00140 switch( $attr )
00141 {
00142 case 'sections':
00143 {
00144 include_once( 'kernel/classes/ezsection.php' );
00145 $sections = eZSection::fetchList( false );
00146 foreach ( array_keys( $sections ) as $key )
00147 {
00148 $section =& $sections[$key];
00149 $section['Name'] = $section['name'];
00150 $section['value'] = $section['id'];
00151 }
00152 return $sections;
00153 }
00154 break;
00155
00156 case 'languages':
00157 {
00158 include_once( 'kernel/classes/ezcontentlanguage.php' );
00159 $languages = eZContentLanguage::fetchList();
00160 return $languages;
00161 }break;
00162
00163 case 'usergroups':
00164 {
00165 $groups = eZPersistentObject::fetchObjectList( eZContentObject::definition(), array( 'id', 'name' ),
00166 array( 'contentclass_id' => 3 ), null, null, false );
00167 foreach ( array_keys( $groups ) as $key )
00168 {
00169 $group =& $groups[$key];
00170 $group['Name'] = $group['name'];
00171 $group['value'] = $group['id'];
00172 }
00173 return $groups;
00174 }
00175 break;
00176
00177 case 'contentclass_list':
00178 {
00179 $classes = eZContentClass::fetchList( EZ_CLASS_VERSION_STATUS_DEFINED, true, false, array( 'name' => 'asc' ) );
00180 $classList = array();
00181 for ( $i = 0; $i < count( $classes ); $i++ )
00182 {
00183 $classList[$i]['Name'] = $classes[$i]->attribute( 'name' );
00184 $classList[$i]['value'] = $classes[$i]->attribute( 'id' );
00185 }
00186 return $classList;
00187 }
00188 break;
00189
00190 case 'workflow_list':
00191 {
00192 $workflows = eZWorkflow::fetchList();
00193 $workflowList = array();
00194 for ( $i = 0; $i < count( $workflows ); $i++ )
00195 {
00196 $workflowList[$i]['Name'] = $workflows[$i]->attribute( 'name' );
00197 $workflowList[$i]['value'] = $workflows[$i]->attribute( 'id' );
00198 }
00199 return $workflowList;
00200 }
00201 break;
00202 }
00203 return eZWorkflowEventType::attribute( $attr );
00204 }
00205
00206 function execute( &$process, &$event )
00207 {
00208 $processParameters = $process->attribute( 'parameter_list' );
00209 $storeProcessParameters = false;
00210 $classID = false;
00211 $objectID = false;
00212 $sectionID = false;
00213 $languageID = 0;
00214
00215 if ( isset( $processParameters['object_id'] ) )
00216 {
00217 $objectID = $processParameters['object_id'];
00218 $object =& eZContentObject::fetch( $objectID );
00219 if ( $object )
00220 {
00221
00222
00223 if ( isset( $processParameters['version'] ) )
00224 {
00225 $versionID = $processParameters['version'];
00226 $version =& $object->version( $versionID );
00227
00228 if ( is_object( $version ) )
00229 {
00230 $version_option = $event->attribute( 'version_option' );
00231 if ( ( $version_option == EZ_MULTIPLEXER_VERSION_OPTION_FIRST_ONLY and $processParameters['version'] > 1 ) or
00232 ( $version_option == EZ_MULTIPLEXER_VERSION_OPTION_EXCEPT_FIRST and $processParameters['version'] == 1 ) )
00233 {
00234 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00235 }
00236
00237
00238 $languageID = (int)$version->attribute( 'initial_language_id' );
00239 }
00240 }
00241 $sectionID = $object->attribute( 'section_id' );
00242 $class =& $object->attribute( 'content_class' );
00243 if ( $class )
00244 {
00245 $classID = $class->attribute( 'id' );
00246 }
00247 }
00248 }
00249
00250 $userArray = explode( ',', $event->attribute( 'data_text2' ) );
00251 $classArray = explode( ',', $event->attribute( 'data_text3' ) );
00252 $languageMask = $event->attribute( 'data_int2' );
00253
00254 if ( !isset( $processParameters['user_id'] ) )
00255 {
00256 $user =& eZUser::currentUser();
00257 $userID = $user->id();
00258 $processParameters['user_id'] = $userID;
00259 $storeProcessParameters = true;
00260 }
00261 else
00262 {
00263 $userID = $processParameters['user_id'];
00264 $user = eZUser::fetch( $userID );
00265 if ( get_class( $user ) != 'ezuser' )
00266 {
00267 $user =& eZUser::currentUser();
00268 $userID = $user->id();
00269 $processParameters['user_id'] = $userID;
00270 $storeProcessParameters = true;
00271 }
00272 }
00273 $userGroups = $user->attribute( 'groups' );
00274 $inExcludeGroups = count( array_intersect( $userGroups, $userArray ) ) != 0;
00275
00276 if ( $storeProcessParameters )
00277 {
00278 $process->setParameters( $processParameters );
00279 $process->store();
00280 }
00281
00282
00283 $hasLanguageMatch = true;
00284 if ( $languageMask != 0 )
00285 {
00286
00287 $hasLanguageMatch = (bool)( $languageMask & $languageID );
00288 }
00289
00290 if ( $hasLanguageMatch &&
00291 ( !$inExcludeGroups ) &&
00292 ( in_array( -1, $classArray ) ||
00293 in_array( $classID, $classArray ) ) )
00294 {
00295 $sectionArray = explode( ',', $event->attribute( 'data_text1' ) );
00296
00297 if ( in_array( $sectionID, $sectionArray ) ||
00298 in_array( -1, $sectionArray ) )
00299 {
00300 $workflowToRun = $event->attribute( 'data_int1' );
00301
00302 $childParameters = array_merge( $processParameters,
00303 array( 'workflow_id' => $workflowToRun,
00304 'user_id' => $userID,
00305 'parent_process_id' => $process->attribute( 'id' )
00306 ) );
00307
00308 $childProcessKey = eZWorkflowProcess::createKey( $childParameters );
00309
00310 $childProcessArray = eZWorkflowProcess::fetchListByKey( $childProcessKey );
00311 $childProcess =& $childProcessArray[0];
00312 if ( $childProcess == null )
00313 {
00314 $childProcess = eZWorkflowProcess::create( $childProcessKey, $childParameters );
00315 $childProcess->store();
00316 }
00317
00318 $workflow = eZWorkflow::fetch( $childProcess->attribute( "workflow_id" ) );
00319 $workflowEvent = null;
00320
00321 if ( $childProcess->attribute( "event_id" ) != 0 )
00322 $workflowEvent = eZWorkflowEvent::fetch( $childProcess->attribute( "event_id" ) );
00323
00324 $childStatus = $childProcess->run( $workflow, $workflowEvent, $eventLog );
00325 $childProcess->store();
00326
00327
00328
00329
00330 if ( $childStatus == EZ_WORKFLOW_STATUS_DEFERRED_TO_CRON )
00331 {
00332 $this->setActivationDate( $childProcess->attribute( 'activation_date' ) );
00333 $childProcess->setAttribute( "status", EZ_WORKFLOW_STATUS_WAITING_PARENT );
00334 $childProcess->store();
00335 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT;
00336 }
00337 else if ( $childStatus == EZ_WORKFLOW_STATUS_FETCH_TEMPLATE )
00338 {
00339 $process->Template =& $childProcess->Template;
00340 return EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT;
00341 }
00342 else if ( $childStatus == EZ_WORKFLOW_STATUS_REDIRECT )
00343 {
00344 $process->RedirectUrl =& $childProcess->RedirectUrl;
00345 return EZ_WORKFLOW_TYPE_STATUS_REDIRECT_REPEAT;
00346 }
00347 else if ( $childStatus == EZ_WORKFLOW_STATUS_DONE )
00348 {
00349 $childProcess->remove();
00350 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00351 }
00352 else if ( $childStatus == EZ_WORKFLOW_STATUS_CANCELLED || $childStatus == EZ_WORKFLOW_STATUS_FAILED )
00353 {
00354 $childProcess->remove();
00355 return EZ_WORKFLOW_TYPE_STATUS_REJECTED;
00356 }
00357 return $childProcess->attribute( 'event_status' );
00358 }
00359 }
00360 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00361 }
00362
00363 function initializeEvent( &$event )
00364 {
00365 }
00366
00367
00368 function fetchHTTPInput( &$http, $base, &$event )
00369 {
00370 $sectionsVar = $base . "_event_ezmultiplexer_section_ids_" . $event->attribute( "id" );
00371 if ( $http->hasPostVariable( $sectionsVar ) )
00372 {
00373 $sectionsArray = $http->postVariable( $sectionsVar );
00374 if ( in_array( '-1', $sectionsArray ) )
00375 {
00376 $sectionsArray = array( -1 );
00377 }
00378 $sectionsString = implode( ',', $sectionsArray );
00379 $event->setAttribute( "data_text1", $sectionsString );
00380 }
00381
00382 $languageVar = $base . "_event_ezmultiplexer_languages_" . $event->attribute( "id" );
00383 if ( $http->hasPostVariable( $languageVar ) )
00384 {
00385 $languageArray = $http->postVariable( $languageVar );
00386 if ( in_array( '-1', $languageArray ) )
00387 {
00388 $languageArray = array();
00389 }
00390 $languageMask = 0;
00391 foreach ( $languageArray as $languageID )
00392 {
00393 $languageMask |= $languageID;
00394 }
00395 $event->setAttribute( "data_int2", $languageMask );
00396 }
00397
00398 $usersVar = $base . "_event_ezmultiplexer_not_run_ids_" . $event->attribute( "id" );
00399 if ( $http->hasPostVariable( $usersVar ) )
00400 {
00401 $usersArray = $http->postVariable( $usersVar );
00402 if ( in_array( '-1', $usersArray ) )
00403 {
00404 $usersArray = array( -1 );
00405 }
00406 $usersString = implode( ',', $usersArray );
00407 $event->setAttribute( "data_text2", $usersString );
00408 }
00409
00410 $classesVar = $base . "_event_ezmultiplexer_class_ids_" . $event->attribute( "id" );
00411 if ( $http->hasPostVariable( $classesVar ) )
00412 {
00413 $classesArray = $http->postVariable( $classesVar );
00414 if ( in_array( '-1', $classesArray ) )
00415 {
00416 $classesArray = array( -1 );
00417 }
00418 $classesString = implode( ',', $classesArray );
00419 $event->setAttribute( "data_text3", $classesString );
00420 }
00421
00422 $workflowVar = $base . "_event_ezmultiplexer_workflow_id_" . $event->attribute( "id" );
00423 if ( $http->hasPostVariable( $workflowVar ) )
00424 {
00425 $workflowID = $http->postVariable( $workflowVar );
00426 $event->setAttribute( "data_int1", $workflowID );
00427 }
00428
00429 $versionOptionVar = $base . "_event_ezmultiplexer_version_option_" . $event->attribute( "id" );
00430 if ( $http->hasPostVariable( $versionOptionVar ) )
00431 {
00432 $versionOptionArray = $http->postVariable( $versionOptionVar );
00433 $versionOption = 0;
00434 if ( is_array( $versionOptionArray ) )
00435 {
00436 foreach ( $versionOptionArray as $vv )
00437 {
00438 $versionOption = $versionOption | $vv;
00439 }
00440 }
00441 $versionOption = $versionOption & EZ_MULTIPLEXER_VERSION_OPTION_ALL;
00442 $event->setAttribute( 'data_int3', $versionOption );
00443 }
00444 }
00445 }
00446
00447 eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_MULTIPLEXER_ID, 'ezmultiplexertype' );
00448
00449 ?>