|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZWaitUntilDateType class 00004 // 00005 // Created on: <09-Jan-2003 15:01:18 sp> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezwaituntildatetype.php 00032 */ 00033 00034 /*! 00035 \class eZWaitUntilDateType ezwaituntildatetype.php 00036 \brief The class eZWaitUntilDateType does 00037 00038 */ 00039 //include_once( 'kernel/classes/workflowtypes/event/ezwaituntildate/ezwaituntildate.php' ); 00040 00041 class eZWaitUntilDateType extends eZWorkflowEventType 00042 { 00043 const WORKFLOW_TYPE_STRING = "ezwaituntildate"; 00044 00045 /*! 00046 Constructor 00047 */ 00048 function eZWaitUntilDateType() 00049 { 00050 $this->eZWorkflowEventType( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, ezi18n( 'kernel/workflow/event', "Wait until date" ) ); 00051 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before', 00052 'after' ) ) ) ); 00053 } 00054 00055 function execute( $process, $event ) 00056 { 00057 $parameters = $process->attribute( 'parameter_list' ); 00058 $object = eZContentObject::fetch( $parameters['object_id'] ); 00059 00060 if ( !$object ) 00061 { 00062 eZDebugSetting::writeError( 'kernel-workflow-waituntildate','The object with ID '.$parameters['object_id'].' does not exist.', 'eZApproveType::execute() object is unavailable' ); 00063 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; 00064 } 00065 00066 $version = $object->version( $parameters['version'] ); 00067 $objectAttributes = $version->attribute( 'contentobject_attributes' ); 00068 $waitUntilDateObject = $this->workflowEventContent( $event ); 00069 $waitUntilDateEntryList = $waitUntilDateObject->attribute( 'classattribute_id_list' ); 00070 $modifyPublishDate = $event->attribute( 'data_int1' ); 00071 00072 foreach ( array_keys( $objectAttributes ) as $key ) 00073 { 00074 $objectAttribute = $objectAttributes[$key]; 00075 $contentClassAttributeID = $objectAttribute->attribute( 'contentclassattribute_id' ); 00076 if ( in_array( $objectAttribute->attribute( 'contentclassattribute_id' ), $waitUntilDateEntryList ) ) 00077 { 00078 $dateTime = $objectAttribute->attribute( 'content' ); 00079 if ( $dateTime instanceof eZDateTime or 00080 $dateTime instanceof eZTime or 00081 $dateTime instanceof eZDate ) 00082 { 00083 if ( time() < $dateTime->timeStamp() ) 00084 { 00085 $this->setInformation( "Event delayed until " . $dateTime->toString( true ) ); 00086 $this->setActivationDate( $dateTime->timeStamp() ); 00087 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; 00088 } 00089 else if ( $dateTime->isValid() and $modifyPublishDate ) 00090 { 00091 $object->setAttribute( 'published', $dateTime->timeStamp() ); 00092 $object->store(); 00093 } 00094 else 00095 { 00096 return eZWorkflowType::STATUS_ACCEPTED; 00097 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00098 } 00099 } 00100 else 00101 { 00102 return eZWorkflowType::STATUS_ACCEPTED; 00103 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00104 } 00105 } 00106 } 00107 return eZWorkflowType::STATUS_ACCEPTED; 00108 // return eZWorkflowType::STATUS_WORKFLOW_DONE; 00109 } 00110 00111 function attributes() 00112 { 00113 return array_merge( array( 'contentclass_list', 00114 'contentclassattribute_list', 00115 'has_class_attributes' ), 00116 eZWorkflowEventType::attributes() ); 00117 } 00118 00119 function hasAttribute( $attr ) 00120 { 00121 return in_array( $attr, $this->attributes() ); 00122 } 00123 00124 function attribute( $attr ) 00125 { 00126 switch( $attr ) 00127 { 00128 case 'contentclass_list' : 00129 { 00130 return eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true ); 00131 }break; 00132 case 'contentclassattribute_list' : 00133 { 00134 // $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); and $http->hasPostVariable( $postvarname ) 00135 if ( isset ( $GLOBALS['eZWaitUntilDateSelectedClass'] ) ) 00136 { 00137 $classID = $GLOBALS['eZWaitUntilDateSelectedClass']; 00138 } 00139 else 00140 { 00141 // if nothing was preselected, we will use the first one: 00142 // POSSIBLE ENHANCEMENT: in the common case, the contentclass_list fetch will be called twice 00143 $classList = eZWaitUntilDateType::attribute( 'contentclass_list' ); 00144 if ( isset( $classList[0] ) ) 00145 $classID = $classList[0]->attribute( 'id' ); 00146 else 00147 $classID = false; 00148 } 00149 if ( $classID ) 00150 { 00151 return eZContentClassAttribute::fetchListByClassID( $classID ); 00152 } 00153 return array(); 00154 }break; 00155 case 'has_class_attributes' : 00156 { 00157 // for the backward compatability: 00158 return 1; 00159 }break; 00160 default: 00161 return eZWorkflowEventType::attribute( $attr ); 00162 } 00163 } 00164 00165 function customWorkflowEventHTTPAction( $http, $action, $workflowEvent ) 00166 { 00167 $id = $workflowEvent->attribute( "id" ); 00168 switch ( $action ) 00169 { 00170 case "new_classelement" : 00171 { 00172 $waitUntilDate = $workflowEvent->content( ); 00173 00174 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'class_' . $workflowEvent->attribute( 'id' ) ); 00175 $classAttributeIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'classattribute_' . $workflowEvent->attribute( 'id' ) ); 00176 00177 $waitUntilDate->addEntry( $classAttributeIDList[0], $classIDList[0] ); 00178 $workflowEvent->setContent( $waitUntilDate ); 00179 }break; 00180 case "remove_selected" : 00181 { 00182 $version = $workflowEvent->attribute( "version" ); 00183 $postvarname = "WorkflowEvent" . "_data_waituntildate_remove_" . $workflowEvent->attribute( "id" ); 00184 $arrayRemove = $http->postVariable( $postvarname ); 00185 $waitUntilDate = $workflowEvent->content( ); 00186 00187 foreach( $arrayRemove as $entryID ) 00188 { 00189 $waitUntilDate->removeEntry( $id, $entryID, $version ); 00190 } 00191 }break; 00192 case "load_class_attribute_list" : 00193 { 00194 $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); 00195 if ( $http->hasPostVariable( $postvarname ) ) 00196 { 00197 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ) ); 00198 $GLOBALS['eZWaitUntilDateSelectedClass'] = $classIDList[0]; 00199 } 00200 else 00201 { 00202 eZDebug::writeError( "no class selected" ); 00203 } 00204 }break; 00205 default : 00206 { 00207 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZEnumType" ); 00208 }break; 00209 } 00210 00211 } 00212 00213 function fetchHTTPInput( $http, $base, $event ) 00214 { 00215 $modifyDateVariable = $base . "_data_waituntildate_modifydate_" . $event->attribute( "id" ); 00216 if ( $http->hasPostVariable( $modifyDateVariable ) ) 00217 { 00218 $modifyDateValue = (int)$http->postVariable( $modifyDateVariable ); 00219 $event->setAttribute( 'data_int1', $modifyDateValue ); 00220 } 00221 } 00222 00223 function workflowEventContent( $event ) 00224 { 00225 $id = $event->attribute( "id" ); 00226 $version = $event->attribute( "version" ); 00227 return new eZWaitUntilDate( $id, $version ); 00228 } 00229 00230 function storeEventData( $event, $version ) 00231 { 00232 $event->content()->setVersion( $version ); 00233 } 00234 00235 function storeDefinedEventData( $event ) 00236 { 00237 $id = $event->attribute( 'id' ); 00238 $version = 1; 00239 $waitUntilDateVersion1 = new eZWaitUntilDate( $id, $version ); 00240 $waitUntilDateVersion1->setVersion( 0 ); //strange name but we are creating version 0 here 00241 eZWaitUntilDate::removeWaitUntilDateEntries( $id, 1 ); 00242 } 00243 00244 } 00245 00246 eZWorkflowEventType::registerEventType( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, "eZWaitUntilDateType" ); 00247 00248 00249 ?>