Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezorderstatus.php
Go to the documentation of this file.
1 <?php
46 class eZOrderStatus extends eZPersistentObject
47 {
48 public $StatusID;
49 // Define for statuses that doesn't really exist (DB error)
50 const UNDEFINED = 0;
51
52 // Some predefined statuses, they will also appear in the database.
53 const PENDING = 1;
54 const PROCESSING = 2;
55 const DELIVERED = 3;
56
57 // All custom order statuses have this value or higher
58 const CUSTOM = 1000;
59
63 static function definition()
64 {
65 return array( "fields" => array( "id" => array( 'name' => 'ID',
66 'datatype' => 'integer',
67 'default' => 0,
68 'required' => true ),
69 "status_id" => array( 'name' => 'StatusID',
70 'datatype' => 'integer',
71 'default' => 0,
72 'required' => true ),
73 "name" => array( 'name' => "Name",
74 'datatype' => 'string',
75 'default' => '',
76 'required' => true ),
77 "is_active" => array( 'name' => "IsActive",
78 'datatype' => 'bool',
79 'default' => true,
80 'required' => true ) ),
81 "keys" => array( "id" ),
82 'function_attributes' => array( 'is_internal' => 'isInternal' ),
83 "increment_key" => "id",
84 "class_name" => "eZOrderStatus",
85 "name" => "ezorder_status" );
86 }
87
91 function isInternal()
92 {
93 return $this->StatusID < eZOrderStatus::CUSTOM;
94 }
95
100 static function flush()
101 {
102 unset( $GLOBALS['eZOrderStatusList'],
103 $GLOBALS['eZOrderStatusOList'],
104 $GLOBALS['eZOrderStatusMap'],
105 $GLOBALS['eZOrderStatusUndefined'] );
106 }
107
111 static function fetch( $id, $asObject = true )
112 {
113 return eZPersistentObject::fetchObject( eZOrderStatus::definition(),
114 null,
115 array( "id" => $id ),
116 $asObject );
117 }
118
124 static function fetchByStatus( $statusID, $asObject = true )
125 {
126 if ( $statusID == 0 )
127 return eZOrderStatus::createUndefined();
128 return eZPersistentObject::fetchObject( eZOrderStatus::definition(),
129 null,
130 array( "status_id" => $statusID ),
131 $asObject );
132 }
133
140 static function fetchMap( $asObject = true, $showInactive = false )
141 {
142 if ( empty( $GLOBALS['eZOrderStatusMap'][$asObject][$showInactive] ) )
143 {
144 $conds = array();
145 if ( !$showInactive )
146 $conds['is_active'] = 1;
147 $list = eZPersistentObject::fetchObjectList( eZOrderStatus::definition(),
148 null,
149 $conds,
150 null,
151 null,
152 $asObject );
153 $map = array();
154 if ( $asObject )
155 {
156 // Here we access member variables directly since it is of the same class
157 foreach ( $list as $statusItem )
158 {
159 $map[$statusItem->StatusID] = $statusItem;
160 }
161 }
162 else
163 {
164 foreach ( $list as $statusItem )
165 {
166 $map[$statusItem['status_id']] = $statusItem;
167 }
168 }
169 $GLOBALS['eZOrderStatusMap'][$asObject][$showInactive] = $map;
170 }
171
172 return $GLOBALS['eZOrderStatusMap'][$asObject][$showInactive];
173 }
174
180 static function fetchList( $asObject = true, $showInactive = false )
181 {
182 if ( empty( $GLOBALS['eZOrderStatusList'][$asObject][$showInactive] ) )
183 {
184 $conds = array();
185 if ( !$showInactive )
186 $conds['is_active'] = 1;
187 $GLOBALS['eZOrderStatusList'][$asObject][$showInactive] = eZPersistentObject::fetchObjectList( eZOrderStatus::definition(),
188 null,
189 $conds,
190 array( 'status_id' => false ),
191 null,
192 $asObject );
193 }
194 return $GLOBALS['eZOrderStatusList'][$asObject][$showInactive];
195 }
196
202 static function fetchPolicyList( $showInactive = false )
203 {
204 $db = eZDB::instance();
205
206 $conditionText = '';
207 if ( !$showInactive )
208 $conditionText = ' WHERE is_active = 1';
209
210 $rows = $db->arrayQuery( "SELECT status_id AS id, name FROM ezorder_status$conditionText" );
211 return $rows;
212 }
213
219 static function fetchOrderedList( $asObject = true, $showInactive = false )
220 {
221 if ( empty( $GLOBALS['eZOrderStatusOList'][$asObject][$showInactive] ) )
222 {
223 $conds = array();
224 if ( !$showInactive )
225 $conds['is_active'] = 1;
226 $GLOBALS['eZOrderStatusOList'][$asObject][$showInactive] = eZPersistentObject::fetchObjectList( eZOrderStatus::definition(),
227 null,
228 $conds,
229 array( 'name' => false ),
230 null,
231 $asObject );
232 }
233 return $GLOBALS['eZOrderStatusOList'][$asObject][$showInactive];
234 }
235
239 static function orderStatusCount( $showInactive = false )
240 {
241 $db = eZDB::instance();
242
243 $condText = '';
244 if ( !$showInactive )
245 $condText = " WHERE is_active = 1";
246 $countArray = $db->arrayQuery( "SELECT count( * ) AS count FROM ezorder_status$condText" );
247 return $countArray[0]['count'];
248 }
249
250
255 function removeThis()
256 {
257 $db = eZDB::instance();
258 $db->begin();
259
260 // Set all elements using this status to 0 (undefined).
261 $statusID = (int)$this->StatusID;
262 $db->query( "UPDATE ezorder SET status_id = 0 WHERE status_id = $statusID" );
263 $db->query( "UPDATE ezorder_status_history SET status_id = 0 WHERE status_id = $statusID" );
264
265 $id = $this->ID;
266 eZPersistentObject::removeObject( eZOrderStatus::definition(), array( "id" => $id ) );
267
268 $db->commit();
269
270 eZOrderStatus::flush();
271 }
272
277 static function create()
278 {
279 $row = array(
280 'id' => null,
281 'is_active' => true,
282 'name' => ezpI18n::tr( 'kernel/shop', 'Order status' ) );
283 return new eZOrderStatus( $row );
284 }
285
292 static function createUndefined()
293 {
294 if ( empty( $GLOBALS['eZOrderStatusUndefined'] ) )
295 {
296 $row = array(
297 'id' => null,
298 'status_id' => eZOrderStatus::UNDEFINED,
299 'is_active' => true,
300 'name' => ezpI18n::tr( 'kernel/shop', 'Undefined' ) );
301 $GLOBALS['eZOrderStatusUndefined'] = new eZOrderStatus( $row );
302 }
303 return $GLOBALS['eZOrderStatusUndefined'];
304 }
305
312 function storeCustom()
313 {
314 if ( $this->StatusID )
315 {
316 eZOrderStatus::flush();
317 $this->store();
318 }
319 else
320 {
321 // Lock the table while we find the highest number
322 $db = eZDB::instance();
323 $db->lock( 'ezorder_status' );
324
325 $rows = $db->arrayQuery( "SELECT max( status_id ) as status_id FROM ezorder_status" );
326 $statusID = $rows[0]['status_id'];
327
328 // If the max ID is below the custom one we set as the first
329 // custom ID, if not we increase it by one.
330 if ( $statusID < eZOrderStatus::CUSTOM )
331 {
332 $statusID = eZOrderStatus::CUSTOM;
333 }
334 else
335 {
336 ++$statusID;
337 }
338
339 $this->StatusID = $statusID;
340 $this->store();
341
342 $db->unlock();
343
344 eZOrderStatus::flush();
345 }
346 }
347 }
348
349 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZOrderStatus
Handles statuses which can be used on orders.
Definition: ezorderstatus.php:47
eZOrderStatus\definition
static definition()
Definition: ezorderstatus.php:63
eZOrderStatus\removeThis
removeThis()
Definition: ezorderstatus.php:255
eZOrderStatus\flush
static flush()
Definition: ezorderstatus.php:100
eZOrderStatus\createUndefined
static createUndefined()
Definition: ezorderstatus.php:292
eZOrderStatus\UNDEFINED
const UNDEFINED
Definition: ezorderstatus.php:50
eZOrderStatus\fetchOrderedList
static fetchOrderedList( $asObject=true, $showInactive=false)
Definition: ezorderstatus.php:219
eZOrderStatus\$StatusID
$StatusID
Definition: ezorderstatus.php:48
eZOrderStatus\DELIVERED
const DELIVERED
Definition: ezorderstatus.php:55
eZOrderStatus\orderStatusCount
static orderStatusCount( $showInactive=false)
Definition: ezorderstatus.php:239
eZOrderStatus\isInternal
isInternal()
Definition: ezorderstatus.php:91
eZOrderStatus\PROCESSING
const PROCESSING
Definition: ezorderstatus.php:54
eZOrderStatus\fetchByStatus
static fetchByStatus( $statusID, $asObject=true)
Definition: ezorderstatus.php:124
eZOrderStatus\create
static create()
Definition: ezorderstatus.php:277
eZOrderStatus\fetch
static fetch( $id, $asObject=true)
Definition: ezorderstatus.php:111
eZOrderStatus\fetchPolicyList
static fetchPolicyList( $showInactive=false)
Definition: ezorderstatus.php:202
eZOrderStatus\PENDING
const PENDING
Definition: ezorderstatus.php:53
eZOrderStatus\fetchList
static fetchList( $asObject=true, $showInactive=false)
Definition: ezorderstatus.php:180
eZOrderStatus\fetchMap
static fetchMap( $asObject=true, $showInactive=false)
Definition: ezorderstatus.php:140
eZOrderStatus\CUSTOM
const CUSTOM
Definition: ezorderstatus.php:58
eZOrderStatus\storeCustom
storeCustom()
Definition: ezorderstatus.php:312
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\$ID
$ID
Definition: ezpersistentobject.php:1448
eZPersistentObject\store
store( $fieldFilters=null)
Definition: ezpersistentobject.php:304
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
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+.