Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezwaituntildatetype.php
Go to the documentation of this file.
1 <?php
16 class eZWaitUntilDateType extends eZWorkflowEventType
17 {
18 const WORKFLOW_TYPE_STRING = "ezwaituntildate";
19
20 public function __construct()
21 {
22 parent::__construct( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, ezpI18n::tr( 'kernel/workflow/event', "Wait until date" ) );
23 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before',
24 'after' ) ) ) );
25 }
26
27 function execute( $process, $event )
28 {
29 $parameters = $process->attribute( 'parameter_list' );
30 $object = eZContentObject::fetch( $parameters['object_id'] );
31
32 if ( !$object )
33 {
34 eZDebugSetting::writeError( 'kernel-workflow-waituntildate','The object with ID '.$parameters['object_id'].' does not exist.', 'eZApproveType::execute() object is unavailable' );
35 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
36 }
37
38 $version = $object->version( $parameters['version'] );
39 $objectAttributes = $version->attribute( 'contentobject_attributes' );
40 $waitUntilDateObject = $this->workflowEventContent( $event );
41 $waitUntilDateEntryList = $waitUntilDateObject->attribute( 'classattribute_id_list' );
42 $modifyPublishDate = $event->attribute( 'data_int1' );
43
44 foreach ( array_keys( $objectAttributes ) as $key )
45 {
46 $objectAttribute = $objectAttributes[$key];
47 $contentClassAttributeID = $objectAttribute->attribute( 'contentclassattribute_id' );
48 if ( in_array( $objectAttribute->attribute( 'contentclassattribute_id' ), $waitUntilDateEntryList ) )
49 {
50 $dateTime = $objectAttribute->attribute( 'content' );
51 if ( $dateTime instanceof eZDateTime or
52 $dateTime instanceof eZTime or
53 $dateTime instanceof eZDate )
54 {
55 if ( time() < $dateTime->timeStamp() )
56 {
57 $this->setInformation( "Event delayed until " . $dateTime->toString( true ) );
58 $this->setActivationDate( $dateTime->timeStamp() );
59 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
60 }
61 else if ( $dateTime->isValid() and $modifyPublishDate )
62 {
63 $object->setAttribute( 'published', $dateTime->timeStamp() );
64 $object->store();
65 }
66 else
67 {
68 return eZWorkflowType::STATUS_ACCEPTED;
69 // return eZWorkflowType::STATUS_WORKFLOW_DONE;
70 }
71 }
72 else
73 {
74 return eZWorkflowType::STATUS_ACCEPTED;
75 // return eZWorkflowType::STATUS_WORKFLOW_DONE;
76 }
77 }
78 }
79 return eZWorkflowType::STATUS_ACCEPTED;
80 // return eZWorkflowType::STATUS_WORKFLOW_DONE;
81 }
82
83 function attributes()
84 {
85 return array_merge( array( 'contentclass_list',
86 'contentclassattribute_list',
87 'has_class_attributes' ),
88 eZWorkflowEventType::attributes() );
89 }
90
91 function hasAttribute( $attr )
92 {
93 return in_array( $attr, $this->attributes() );
94 }
95
96 function attribute( $attr )
97 {
98 switch( $attr )
99 {
100 case 'contentclass_list' :
101 {
102 return eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true );
103 }break;
104 case 'contentclassattribute_list' :
105 {
106 // $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ); and $http->hasPostVariable( $postvarname )
107 if ( isset ( $GLOBALS['eZWaitUntilDateSelectedClass'] ) )
108 {
109 $classID = $GLOBALS['eZWaitUntilDateSelectedClass'];
110 }
111 else
112 {
113 // if nothing was preselected, we will use the first one:
114 // POSSIBLE ENHANCEMENT: in the common case, the contentclass_list fetch will be called twice
115 $classList = eZWaitUntilDateType::attribute( 'contentclass_list' );
116 if ( isset( $classList[0] ) )
117 $classID = $classList[0]->attribute( 'id' );
118 else
119 $classID = false;
120 }
121 if ( $classID )
122 {
123 return eZContentClassAttribute::fetchListByClassID( $classID );
124 }
125 return array();
126 }break;
127 case 'has_class_attributes' :
128 {
129 // for the backward compatibility:
130 return 1;
131 }break;
132 default:
133 return eZWorkflowEventType::attribute( $attr );
134 }
135 }
136
137 function customWorkflowEventHTTPAction( $http, $action, $workflowEvent )
138 {
139 $id = $workflowEvent->attribute( "id" );
140 switch ( $action )
141 {
142 case "new_classelement" :
143 {
144 $waitUntilDate = $workflowEvent->content( );
145
146 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'class_' . $workflowEvent->attribute( 'id' ) );
147 $classAttributeIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' . 'classattribute_' . $workflowEvent->attribute( 'id' ) );
148
149 $waitUntilDate->addEntry( $classAttributeIDList[0], $classIDList[0] );
150 $workflowEvent->setContent( $waitUntilDate );
151 }break;
152 case "remove_selected" :
153 {
154 $version = $workflowEvent->attribute( "version" );
155 $postvarname = "WorkflowEvent" . "_data_waituntildate_remove_" . $workflowEvent->attribute( "id" );
156 $arrayRemove = $http->postVariable( $postvarname );
157 $waitUntilDate = $workflowEvent->content( );
158
159 foreach( $arrayRemove as $entryID )
160 {
161 $waitUntilDate->removeEntry( $id, $entryID, $version );
162 }
163 }break;
164 case "load_class_attribute_list" :
165 {
166 $postvarname = 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' );
167 if ( $http->hasPostVariable( $postvarname ) )
168 {
169 $classIDList = $http->postVariable( 'WorkflowEvent' . '_event_ezwaituntildate_' .'class_' . $workflowEvent->attribute( 'id' ) );
170 $GLOBALS['eZWaitUntilDateSelectedClass'] = $classIDList[0];
171 }
172 else
173 {
174 eZDebug::writeError( "no class selected" );
175 }
176 }break;
177 default :
178 {
179 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZEnumType" );
180 }break;
181 }
182
183 }
184
185 function fetchHTTPInput( $http, $base, $event )
186 {
187 $modifyDateVariable = $base . "_data_waituntildate_modifydate_" . $event->attribute( "id" );
188 if ( $http->hasPostVariable( $modifyDateVariable ) )
189 {
190 $modifyDateValue = (int)$http->postVariable( $modifyDateVariable );
191 $event->setAttribute( 'data_int1', $modifyDateValue );
192 }
193 }
194
195 function workflowEventContent( $event )
196 {
197 $id = $event->attribute( "id" );
198 $version = $event->attribute( "version" );
199 return new eZWaitUntilDate( $id, $version );
200 }
201
202 function storeEventData( $event, $version )
203 {
204 $event->content()->setVersion( $version );
205 }
206
207 function storeDefinedEventData( $event )
208 {
209 $id = $event->attribute( 'id' );
210 $version = 1;
211 $waitUntilDateVersion1 = new eZWaitUntilDate( $id, $version );
212 $waitUntilDateVersion1->setVersion( 0 ); //strange name but we are creating version 0 here
213 eZWaitUntilDate::removeWaitUntilDateEntries( $id, 1 );
214 }
215
216 }
217
218 eZWorkflowEventType::registerEventType( eZWaitUntilDateType::WORKFLOW_TYPE_STRING, "eZWaitUntilDateType" );
219
220
221 ?>
eZContentClassAttribute\fetchListByClassID
static fetchListByClassID( $classID, $version=eZContentClass::VERSION_STATUS_DEFINED, $asObject=true)
Definition: ezcontentclassattribute.php:450
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
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZDateTime
Locale aware date and time handler.
Definition: ezdatetime.php:62
eZDate
Locale aware date handler.
Definition: ezdate.php:58
eZDebugSetting\writeError
static writeError( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:113
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZTime
Locale aware time handler.
Definition: eztime.php:59
eZWaitUntilDateType
The class eZWaitUntilDateType does.
Definition: ezwaituntildatetype.php:17
eZWaitUntilDateType\customWorkflowEventHTTPAction
customWorkflowEventHTTPAction( $http, $action, $workflowEvent)
Definition: ezwaituntildatetype.php:137
eZWaitUntilDateType\attribute
attribute( $attr)
Definition: ezwaituntildatetype.php:96
eZWaitUntilDateType\hasAttribute
hasAttribute( $attr)
Definition: ezwaituntildatetype.php:91
eZWaitUntilDateType\__construct
__construct()
Definition: ezwaituntildatetype.php:20
eZWaitUntilDateType\attributes
attributes()
Definition: ezwaituntildatetype.php:83
eZWaitUntilDateType\fetchHTTPInput
fetchHTTPInput( $http, $base, $event)
Definition: ezwaituntildatetype.php:185
eZWaitUntilDateType\workflowEventContent
workflowEventContent( $event)
Definition: ezwaituntildatetype.php:195
eZWaitUntilDateType\WORKFLOW_TYPE_STRING
const WORKFLOW_TYPE_STRING
Definition: ezwaituntildatetype.php:18
eZWaitUntilDateType\storeEventData
storeEventData( $event, $version)
Definition: ezwaituntildatetype.php:202
eZWaitUntilDateType\storeDefinedEventData
storeDefinedEventData( $event)
Definition: ezwaituntildatetype.php:207
eZWaitUntilDateType\execute
execute( $process, $event)
Definition: ezwaituntildatetype.php:27
eZWaitUntilDate
The class eZWaitUntilDate does.
Definition: ezwaituntildate.php:17
eZWaitUntilDate\removeWaitUntilDateEntries
static removeWaitUntilDateEntries( $workflowEventID, $workflowEventVersion)
Definition: ezwaituntildate.php:69
eZWorkflowEventType
Definition: ezworkfloweventtype.php:18
eZWorkflowEventType\registerEventType
static registerEventType( $typeString, $class_name)
Definition: ezworkfloweventtype.php:40
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\setInformation
setInformation( $inf)
Definition: ezworkflowtype.php:314
eZWorkflowType\attributes
attributes()
Definition: ezworkflowtype.php:225
eZWorkflowType\setActivationDate
setActivationDate( $date)
Definition: ezworkflowtype.php:309
eZWorkflowType\setTriggerTypes
setTriggerTypes( $allowedTypes)
Definition: ezworkflowtype.php:276
eZWorkflowType\STATUS_WORKFLOW_CANCELLED
const STATUS_WORKFLOW_CANCELLED
Definition: ezworkflowtype.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+.