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 include_once( 'kernel/classes/workflowtypes/event/ezwaituntildate/ezwaituntildate.php' );
00040 define( "EZ_WORKFLOW_TYPE_WAIT_UNTIL_DATE_ID", "ezwaituntildate" );
00041
00042 class eZWaitUntilDateType extends eZWorkflowEventType
00043 {
00044
00045
00046
00047 function eZWaitUntilDateType()
00048 {
00049 $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_WAIT_UNTIL_DATE_ID, ezi18n( 'kernel/workflow/event', "Wait until date" ) );
00050 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before',
00051 'after' ) ) ) );
00052 }
00053
00054 function execute( &$process, &$event )
00055 {
00056 $parameters = $process->attribute( 'parameter_list' );
00057 $object =& eZContentObject::fetch( $parameters['object_id'] );
00058
00059 if ( !$object )
00060 {
00061 eZDebugSetting::writeError( 'kernel-workflow-waituntildate','The object with ID '.$parameters['object_id'].' does not exist.', 'eZApproveType::execute() object is unavailable' );
00062 return EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED;
00063 }
00064
00065 $version =& $object->version( $parameters['version'] );
00066 $objectAttributes = $version->attribute( 'contentobject_attributes' );
00067 $waitUntilDateObject =& $this->workflowEventContent( $event );
00068 $waitUntilDateEntryList = $waitUntilDateObject->attribute( 'classattribute_id_list' );
00069 $modifyPublishDate = $event->attribute( 'data_int1' );
00070 eZDebug::writeDebug( 'executing publish on time event' );
00071
00072
00073
00074 foreach ( array_keys( $objectAttributes ) as $key )
00075 {
00076 $objectAttribute =& $objectAttributes[$key];
00077 $contentClassAttributeID = $objectAttribute->attribute( 'contentclassattribute_id' );
00078
00079 if ( in_array( $objectAttribute->attribute( 'contentclassattribute_id' ), $waitUntilDateEntryList ) )
00080 {
00081 $dateTime =& $objectAttribute->attribute( 'content' );
00082 if ( get_class( $dateTime ) == 'ezdatetime' or
00083 get_class( $dateTime ) == 'eztime' or
00084 get_class( $dateTime ) == 'ezdate' )
00085 {
00086 if ( time() < $dateTime->timeStamp() )
00087 {
00088 $this->setInformation( "Event delayed until " . $dateTime->toString( true ) );
00089 $this->setActivationDate( $dateTime->timeStamp() );
00090
00091 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT;
00092 }
00093 else if ( $dateTime->isValid() and $modifyPublishDate )
00094 {
00095 $object->setAttribute( 'published', $dateTime->timeStamp() );
00096 $object->store();
00097 }
00098 else
00099 {
00100 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00101
00102 }
00103 }
00104 else
00105 {
00106 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00107
00108 }
00109 }
00110 }
00111 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00112
00113 }
00114
00115 function attributes()
00116 {
00117 return array_merge( array( 'contentclass_list',
00118 'contentclassattribute_list',
00119 'has_class_attributes' ),
00120 eZWorkflowEventType::attributes() );
00121 }
00122
00123 function hasAttribute( $attr )
00124 {
00125 return in_array( $attr, $this->attributes() );
00126 }
00127
00128 function &attribute( $attr )
00129 {
00130 switch( $attr )
00131 {
00132 case 'contentclass_list' :
00133 {
00134 $classList = eZContentClass::fetchList( EZ_CLASS_VERSION_STATUS_DEFINED, true );
00135 return $classList;
00136
00137 }break;
00138 case 'contentclassattribute_list' :
00139 {
00140
00141 if ( isset ( $GLOBALS['eZWaitUntilDateSelectedClass'] ) )
00142 {
00143 $classID = $GLOBALS['eZWaitUntilDateSelectedClass'];
00144 }
00145 else
00146 {
00147
00148
00149 $classList = eZWaitUntilDateType::attribute( 'contentclass_list' );
00150 if ( isset( $classList[0] ) )
00151 $classID = $classList[0]->attribute( 'id' );
00152 else
00153 $classID = false;
00154 }
00155 if ( $classID )
00156 {
00157 $attributeList = eZContentClassAttribute::fetchListByClassID( $classID );
00158 }
00159 else
00160 $attributeList = array();
00161 return $attributeList;
00162 }break;
00163 case 'has_class_attributes' :
00164 {
00165
00166 $hasClassAttribute = 1;
00167 return $hasClassAttribute;
00168 }break;
00169 default:
00170 return eZWorkflowEventType::attribute( $attr );
00171 }
00172 }
00173
00174 function customWorkflowEventHTTPAction( &$http, $action, &$workflowEvent )
00175 {
00176 $id = $workflowEvent->attribute( "id" );
00177 switch ( $action )
00178 {
00179 case "new_classelement" :
00180 {
00181 $waitUntilDate =& $workflowEvent->content( );
00182
00183 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'class_' . $workflowEvent->attribute( 'id' ) );
00184
00185 $classAttributeIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'classattribute_' . $workflowEvent->attribute( 'id' ) );
00186
00187
00188 $waitUntilDate->addEntry( $classAttributeIDList[0], $classIDList[0] );
00189 $workflowEvent->setContent( $waitUntilDate );
00190 }break;
00191 case "remove_selected" :
00192 {
00193 $version = $workflowEvent->attribute( "version" );
00194 $postvarname = "WorkflowEvent" . "_data_waituntildate_remove_" . $workflowEvent->attribute( "id" );
00195 $arrayRemove = $http->postVariable( $postvarname );
00196 eZDebug::writeDebug( $arrayRemove, 'remove params 0' );
00197
00198 foreach( $arrayRemove as $entryID )
00199 {
00200 eZDebug::writeDebug( "$id - $entryID - $version ", 'remove params' );
00201 eZWaitUntilDate::removeEntry( $id, $entryID, $version );
00202 }
00203 }break;
00204 case "load_class_attribute_list" :
00205 {
00206 $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' );
00207 if ( $http->hasPostVariable( $postvarname ) )
00208 {
00209 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ) );
00210 eZDebug::writeDebug($classIDList, "classIDLIst" );
00211
00212 $GLOBALS['eZWaitUntilDateSelectedClass'] = $classIDList[0];
00213 }
00214 else
00215 {
00216 eZDebug::writeDebug( "no class selected" );
00217 }
00218 }break;
00219 default :
00220 {
00221 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZEnumType" );
00222 }break;
00223 }
00224
00225 }
00226
00227 function fetchHTTPInput( &$http, $base, &$event )
00228 {
00229 $modifyDateVariable = $base . "_data_waituntildate_modifydate_" . $event->attribute( "id" );
00230 if ( $http->hasPostVariable( $modifyDateVariable ) )
00231 {
00232 $modifyDateValue = (int)$http->postVariable( $modifyDateVariable );
00233 $event->setAttribute( 'data_int1', $modifyDateValue );
00234 }
00235 }
00236
00237 function &workflowEventContent( &$event )
00238 {
00239 $id = $event->attribute( "id" );
00240 $version = $event->attribute( "version" );
00241 $waitUntilDate = new eZWaitUntilDate( $id, $version );
00242 return $waitUntilDate;
00243 }
00244
00245 function storeEventData( &$event, $version )
00246 {
00247 $waitUntilDate =& $event->content();
00248 $waitUntilDate->setVersion( $version );
00249 }
00250
00251 function storeDefinedEventData( $event )
00252 {
00253 $id = $event->attribute( 'id' );
00254 $version = 1;
00255 $waitUntilDateVersion1 = new eZWaitUntilDate( $id, $version );
00256 $waitUntilDateVersion1->setVersion( 0 );
00257 eZWaitUntilDate::removeWaitUntilDateEntries( $id, 1 );
00258 }
00259
00260 }
00261
00262 eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_WAIT_UNTIL_DATE_ID, "ezwaituntildatetype" );
00263
00264
00265 ?>