|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZWaitUntilDateType class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZWaitUntilDateType ezwaituntildatetype.php 00013 \brief The class eZWaitUntilDateType does 00014 00015 */ 00016 class eZWaitUntilDateType extends eZWorkflowEventType 00017 { 00018 const WORKFLOW_TYPE_STRING = "ezwaituntildate"; 00019 00020 /*! 00021 Constructor 00022 */ 00023 function eZWaitUntilDateType() 00024 { 00025 $this->eZWorkflowEventType( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, ezpI18n::tr( 'kernel/workflow/event', "Wait until date" ) ); 00026 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before', 00027 'after' ) ) ) ); 00028 } 00029 00030 function execute( $process, $event ) 00031 { 00032 $parameters = $process->attribute( 'parameter_list' ); 00033 $object = eZContentObject::fetch( $parameters['object_id'] ); 00034 00035 if ( !$object ) 00036 { 00037 eZDebugSetting::writeError( 'kernel-workflow-waituntildate','The object with ID '.$parameters['object_id'].' does not exist.', 'eZApproveType::execute() object is unavailable' ); 00038 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00039 } 00040 00041 $version = $object->version( $parameters['version'] ); 00042 $objectAttributes = $version->attribute( 'contentobject_attributes' ); 00043 $waitUntilDateObject = $this->workflowEventContent( $event ); 00044 $waitUntilDateEntryList = $waitUntilDateObject->attribute( 'classattribute_id_list' ); 00045 $modifyPublishDate = $event->attribute( 'data_int1' ); 00046 00047 foreach ( array_keys( $objectAttributes ) as $key ) 00048 { 00049 $objectAttribute = $objectAttributes[$key]; 00050 $contentClassAttributeID = $objectAttribute->attribute( 'contentclassattribute_id' ); 00051 if ( in_array( $objectAttribute->attribute( 'contentclassattribute_id' ), $waitUntilDateEntryList ) ) 00052 { 00053 $dateTime = $objectAttribute->attribute( 'content' ); 00054 if ( $dateTime instanceof eZDateTime or 00055 $dateTime instanceof eZTime or 00056 $dateTime instanceof eZDate ) 00057 { 00058 if ( time() < $dateTime->timeStamp() ) 00059 { 00060 $this->setInformation( "Event delayed until " . $dateTime->toString( true ) ); 00061 $this->setActivationDate( $dateTime->timeStamp() ); 00062 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; 00063 } 00064 else if ( $dateTime->isValid() and $modifyPublishDate ) 00065 { 00066 $object->setAttribute( 'published', $dateTime->timeStamp() ); 00067 $object->store(); 00068 } 00069 else 00070 { 00071 return eZWorkflowType::STATUS_ACCEPTED; 00072 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00073 } 00074 } 00075 else 00076 { 00077 return eZWorkflowType::STATUS_ACCEPTED; 00078 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00079 } 00080 } 00081 } 00082 return eZWorkflowType::STATUS_ACCEPTED; 00083 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00084 } 00085 00086 function attributes() 00087 { 00088 return array_merge( array( 'contentclass_list', 00089 'contentclassattribute_list', 00090 'has_class_attributes' ), 00091 eZWorkflowEventType::attributes() ); 00092 } 00093 00094 function hasAttribute( $attr ) 00095 { 00096 return in_array( $attr, $this->attributes() ); 00097 } 00098 00099 function attribute( $attr ) 00100 { 00101 switch( $attr ) 00102 { 00103 case 'contentclass_list' : 00104 { 00105 return eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true ); 00106 }break; 00107 case 'contentclassattribute_list' : 00108 { 00109 // $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); and $http->hasPostVariable( $postvarname ) 00110 if ( isset ( $GLOBALS['eZWaitUntilDateSelectedClass'] ) ) 00111 { 00112 $classID = $GLOBALS['eZWaitUntilDateSelectedClass']; 00113 } 00114 else 00115 { 00116 // if nothing was preselected, we will use the first one: 00117 // POSSIBLE ENHANCEMENT: in the common case, the contentclass_list fetch will be called twice 00118 $classList = eZWaitUntilDateType::attribute( 'contentclass_list' ); 00119 if ( isset( $classList[0] ) ) 00120 $classID = $classList[0]->attribute( 'id' ); 00121 else 00122 $classID = false; 00123 } 00124 if ( $classID ) 00125 { 00126 return eZContentClassAttribute::fetchListByClassID( $classID ); 00127 } 00128 return array(); 00129 }break; 00130 case 'has_class_attributes' : 00131 { 00132 // for the backward compatibility: 00133 return 1; 00134 }break; 00135 default: 00136 return eZWorkflowEventType::attribute( $attr ); 00137 } 00138 } 00139 00140 function customWorkflowEventHTTPAction( $http, $action, $workflowEvent ) 00141 { 00142 $id = $workflowEvent->attribute( "id" ); 00143 switch ( $action ) 00144 { 00145 case "new_classelement" : 00146 { 00147 $waitUntilDate = $workflowEvent->content( ); 00148 00149 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'class_' . $workflowEvent->attribute( 'id' ) ); 00150 $classAttributeIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'classattribute_' . $workflowEvent->attribute( 'id' ) ); 00151 00152 $waitUntilDate->addEntry( $classAttributeIDList[0], $classIDList[0] ); 00153 $workflowEvent->setContent( $waitUntilDate ); 00154 }break; 00155 case "remove_selected" : 00156 { 00157 $version = $workflowEvent->attribute( "version" ); 00158 $postvarname = "WorkflowEvent" . "_data_waituntildate_remove_" . $workflowEvent->attribute( "id" ); 00159 $arrayRemove = $http->postVariable( $postvarname ); 00160 $waitUntilDate = $workflowEvent->content( ); 00161 00162 foreach( $arrayRemove as $entryID ) 00163 { 00164 $waitUntilDate->removeEntry( $id, $entryID, $version ); 00165 } 00166 }break; 00167 case "load_class_attribute_list" : 00168 { 00169 $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); 00170 if ( $http->hasPostVariable( $postvarname ) ) 00171 { 00172 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ) ); 00173 $GLOBALS['eZWaitUntilDateSelectedClass'] = $classIDList[0]; 00174 } 00175 else 00176 { 00177 eZDebug::writeError( "no class selected" ); 00178 } 00179 }break; 00180 default : 00181 { 00182 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZEnumType" ); 00183 }break; 00184 } 00185 00186 } 00187 00188 function fetchHTTPInput( $http, $base, $event ) 00189 { 00190 $modifyDateVariable = $base . "_data_waituntildate_modifydate_" . $event->attribute( "id" ); 00191 if ( $http->hasPostVariable( $modifyDateVariable ) ) 00192 { 00193 $modifyDateValue = (int)$http->postVariable( $modifyDateVariable ); 00194 $event->setAttribute( 'data_int1', $modifyDateValue ); 00195 } 00196 } 00197 00198 function workflowEventContent( $event ) 00199 { 00200 $id = $event->attribute( "id" ); 00201 $version = $event->attribute( "version" ); 00202 return new eZWaitUntilDate( $id, $version ); 00203 } 00204 00205 function storeEventData( $event, $version ) 00206 { 00207 $event->content()->setVersion( $version ); 00208 } 00209 00210 function storeDefinedEventData( $event ) 00211 { 00212 $id = $event->attribute( 'id' ); 00213 $version = 1; 00214 $waitUntilDateVersion1 = new eZWaitUntilDate( $id, $version ); 00215 $waitUntilDateVersion1->setVersion( 0 ); //strange name but we are creating version 0 here 00216 eZWaitUntilDate::removeWaitUntilDateEntries( $id, 1 ); 00217 } 00218 00219 } 00220 00221 eZWorkflowEventType::registerEventType( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, "eZWaitUntilDateType" ); 00222 00223 00224 ?>