00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( "kernel/classes/ezpersistentobject.php" );
00039 include_once( "lib/ezdb/classes/ezdb.php" );
00040
00041 class eZProductCollection extends eZPersistentObject
00042 {
00043 function eZProductCollection( $row )
00044 {
00045 $this->eZPersistentObject( $row );
00046 }
00047
00048 function definition()
00049 {
00050 return array( "fields" => array( "id" => array( 'name' => 'ID',
00051 'datatype' => 'integer',
00052 'default' => 0,
00053 'required' => true ),
00054 "created" => array( 'name' => "Created",
00055 'datatype' => 'integer',
00056 'default' => 0,
00057 'required' => true ),
00058 'currency_code' => array( 'name' => 'CurrencyCode',
00059 'datatype' => 'string',
00060 'default' => '',
00061 'required' => true ) ),
00062 "keys" => array( "id" ),
00063 "increment_key" => "id",
00064 "class_name" => "eZProductCollection",
00065 "name" => "ezproductcollection" );
00066 }
00067
00068
00069
00070
00071 function create( )
00072 {
00073 $row = array( "created" => time() );
00074 return new eZProductCollection( $row );
00075 }
00076
00077
00078
00079
00080 function clone()
00081 {
00082 $collection = $this;
00083 $collection->setAttribute( 'id', null );
00084 return $collection;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094 function ©()
00095 {
00096 $collection = $this->clone();
00097
00098 $db =& eZDB::instance();
00099 $db->begin();
00100 $collection->store();
00101
00102 $oldItems =& $this->itemList();
00103 foreach ( array_keys( $oldItems ) as $oldItemKey )
00104 {
00105 $oldItem =& $oldItems[$oldItemKey];
00106 $item =& $oldItem->copy( $collection->attribute( 'id' ) );
00107 }
00108 $db->commit();
00109 return $collection;
00110 }
00111
00112
00113
00114
00115 function fetch( $productCollectionID, $asObject = true )
00116 {
00117 return eZPersistentObject::fetchObject( eZProductCollection::definition(),
00118 null,
00119 array( 'id' => $productCollectionID ),
00120 $asObject );
00121 }
00122
00123
00124
00125
00126 function &itemList( $asObject = true )
00127 {
00128 $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
00129 null, array( "productcollection_id" => $this->ID ),
00130 null,
00131 null,
00132 $asObject );
00133 return $productItems;
00134 }
00135
00136 function &verify( $id )
00137 {
00138 $invalidItemArray = array();
00139 $collection = eZProductCollection::fetch( $id );
00140 if ( !is_object( $collection ) )
00141 return $invalidItemArray;
00142
00143 $currency =& $collection->attribute( 'currency_code' );
00144 $productItemList = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
00145 null, array( "productcollection_id" => $id ),
00146 null,
00147 null,
00148 true );
00149 $isValid = true;
00150
00151 foreach ( array_keys( $productItemList ) as $key )
00152 {
00153 $productItem =& $productItemList[$key];
00154
00155 if ( !$productItem->verify( $currency ) )
00156 {
00157 $invalidItemArray[] =& $productItem;
00158
00159 $isValid = false;
00160 }
00161 }
00162 if ( !$isValid )
00163 {
00164 return $invalidItemArray;
00165 }
00166 return $isValid;
00167 }
00168
00169
00170
00171
00172
00173 function count()
00174 {
00175 $db =& eZDB::instance();
00176 $rows = $db->arrayQuery( "SELECT count( id ) as count FROM ezproductcollection_item" );
00177 return $rows[0]['count'];
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187 function cleanupList( $productCollectionIDList )
00188 {
00189 $db =& eZDB::instance();
00190 $db->begin();
00191
00192
00193 require_once( 'kernel/classes/ezshippingmanager.php' );
00194 foreach ( $productCollectionIDList as $productCollectionID )
00195 eZShippingManager::purgeShippingInfo( $productCollectionID );
00196
00197 include_once( 'kernel/classes/ezproductcollectionitem.php' );
00198 eZProductCollectionItem::cleanupList( $productCollectionIDList );
00199 $idText = $db->implodeWithTypeCast( ', ', $productCollectionIDList, 'int' );
00200 $db->query( "DELETE FROM ezproductcollection WHERE id IN ( $idText )" );
00201 $db->commit();
00202 }
00203 }
00204
00205 ?>