|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZOrderStatusHistory class 00004 // 00005 // Created on: <07-Apr-2005 16:27:14 amos> 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 ezorderstatushistory.php 00032 */ 00033 00034 /*! 00035 \class eZOrderStatusHistory ezorderstatushistory.php 00036 \brief Handles a list of status changes to an order item. 00037 00038 This uses the database table ezorder_status_history to store changes 00039 in status for an order item. 00040 Each entry consists of the new status, the time it was done and the 00041 person who did the change. 00042 00043 The \c order_id refers to the external ID of an order (\c order_nr) 00044 and not the internal auto increment value. 00045 00046 To fetch a given history element use fetch() with the history ID. 00047 If you intend to display the history elements for an order item use 00048 the fetchListByOrder() function which returns the history sorted by 00049 date (newest first). 00050 If you are interested in the number of history elements for an order 00051 use the fetchCount() function. 00052 00053 If you intend to create a new history element use the create() function. 00054 00055 */ 00056 00057 //include_once( "kernel/classes/ezpersistentobject.php" ); 00058 00059 class eZOrderStatusHistory extends eZPersistentObject 00060 { 00061 /*! 00062 Initialises the persistent object with \a $row. 00063 If \c status_name is present in \a $row it will cache it in the $StatusName variable. 00064 */ 00065 function eZOrderStatusHistory( $row ) 00066 { 00067 $this->eZPersistentObject( $row ); 00068 $this->Modifier = null; 00069 $this->StatusName = null; 00070 if ( isset( $row['status_name'] ) ) 00071 $this->StatusName = $row['status_name']; 00072 } 00073 00074 /*! 00075 \return the persistent object definition for the eZOrderStatusHistory class. 00076 */ 00077 static function definition() 00078 { 00079 return array( "fields" => array( "id" => array( 'name' => 'ID', 00080 'datatype' => 'integer', 00081 'default' => 0, 00082 'required' => true ), 00083 "order_id" => array( 'name' => 'OrderID', 00084 'datatype' => 'integer', 00085 'default' => 0, 00086 'required' => true, 00087 'foreign_class' => 'eZOrder', 00088 'foreign_attribute' => 'id', 00089 'multiplicity' => '1..*' ), 00090 "status_id" => array( 'name' => 'StatusID', 00091 'datatype' => 'integer', 00092 'default' => 0, 00093 'required' => true, 00094 'foreign_class' => 'eZOrderStatus', 00095 'foreign_attribute' => 'id', 00096 'multiplicity' => '1..*' ), 00097 "modifier_id" => array( 'name' => "ModifierID", 00098 'datatype' => 'integer', 00099 'default' => 0, 00100 'required' => true, 00101 'foreign_class' => 'eZUser', 00102 'foreign_attribute' => 'contentobject_id', 00103 'multiplicity' => '1..*' ), 00104 "modified" => array( 'name' => "Modified", 00105 'datatype' => 'integer', 00106 'default' => 0, 00107 'required' => true ) ), 00108 'function_attributes' => array( 'modifier' => 'modifier', 00109 'status_name' => 'fetchOrderStatusName', 00110 'status' => 'fetchOrderStatus' ), 00111 "keys" => array( "id" ), 00112 "increment_key" => "id", 00113 "class_name" => "eZOrderStatusHistory", 00114 "name" => "ezorder_status_history" ); 00115 } 00116 00117 /*! 00118 \return The user which modified the status, this is returned as a content object. 00119 \note The field \c modified_id is used to find the user, this will contain 00120 the content object ID of the user. 00121 */ 00122 function modifier() 00123 { 00124 if ( $this->Modifier === null ) 00125 { 00126 //include_once( 'kernel/classes/ezcontentobject.php' ); 00127 $this->Modifier = eZContentObject::fetch( $this->ModifierID ); 00128 } 00129 return $this->Modifier; 00130 } 00131 00132 /*! 00133 \return The order status object for this history entry. 00134 \sa fetchOrderStatusName() 00135 */ 00136 function fetchOrderStatus() 00137 { 00138 //include_once( 'kernel/classes/ezorderstatus.php' ); 00139 $statusList = eZOrderStatus::fetchMap( true, true ); 00140 if ( isset( $statusList[$this->StatusID] ) ) 00141 { 00142 return $statusList[$this->StatusID]; 00143 } 00144 return false; 00145 } 00146 00147 /*! 00148 \return The name of the order status for this history entry. 00149 \sa fetchOrderStatus() 00150 */ 00151 function fetchOrderStatusName() 00152 { 00153 if ( $this->StatusName === null ) 00154 { 00155 $status = $this->fetchOrderStatus(); 00156 $this->StatusName = $status->attribute( 'name' ); 00157 } 00158 return $this->StatusName; 00159 } 00160 00161 /*! 00162 \static 00163 \return the status history object with the given DB ID. 00164 */ 00165 function fetch( $id, $asObject = true ) 00166 { 00167 return eZPersistentObject::fetchObject( eZOrderStatusHistory::definition(), 00168 null, 00169 array( "id" => $id ), 00170 $asObject ); 00171 } 00172 00173 /*! 00174 \static 00175 \param $asObject If \c true return them as objects. 00176 \return A list of defined orders sorted by status ID. 00177 */ 00178 static function fetchListByOrder( $orderID, $asObject = true ) 00179 { 00180 $db = eZDB::instance(); 00181 00182 $orderID = (int)$orderID; 00183 $rows = $db->arrayQuery( "SELECT ezorder_status_history.*, ezorder_status.name AS status_name\n" . 00184 "FROM ezorder_status_history, ezorder_status\n" . 00185 "WHERE order_id = $orderID AND\n" . 00186 " ezorder_status.status_id = ezorder_status_history.status_id\n" . 00187 "ORDER BY ezorder_status_history.modified DESC" ); 00188 00189 return eZPersistentObject::handleRows( $rows, 'eZOrderStatusHistory', $asObject ); 00190 } 00191 00192 /*! 00193 \static 00194 \param $asObject If \c true return them as objects. 00195 \return A list of defined orders sorted by status ID. 00196 */ 00197 static function fetchCount( $orderID, $asObject = true ) 00198 { 00199 $db = eZDB::instance(); 00200 00201 $orderID = (int)$orderID; 00202 $countArray = $db->arrayQuery( "SELECT count( * ) AS count FROM ezorder_status_history WHERE order_id = $orderID" ); 00203 return $countArray[0]['count']; 00204 } 00205 00206 /*! 00207 \static 00208 \return A new eZOrderStatusHistory object initialized with the input parameters. 00209 */ 00210 static function create( $orderID, $statusID, $userID = false, $timestamp = false ) 00211 { 00212 if ( $timestamp === false ) 00213 { 00214 $timestamp = time(); 00215 } 00216 if ( $userID === false ) 00217 { 00218 $userID = eZUser::currentUserID(); 00219 } 00220 $row = array( 'id' => null, 00221 'order_id' => $orderID, 00222 'status_id' => $statusID, 00223 'modifier_id' => $userID, 00224 'modified' => $timestamp ); 00225 return new eZOrderStatusHistory( $row ); 00226 } 00227 00228 00229 /// \privatesection 00230 /// This is used for caching the current modifier, 00231 /// it will either contain \c null (uncached) or a content object (cached). 00232 public $Modifier; 00233 } 00234 00235 ?>