eZ Publish  [4.0]
ezproductcollectionitemoption.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZProductCollectionItemOption class
00004 //
00005 // Created on: <10-ζΕΧ-2003 16:04: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 class eZProductCollectionItemOption extends eZPersistentObject
00032 {
00033     /**
00034      * Initialized an eZProductCollectionItemOption object with the given
00035      * attribute array
00036      *
00037      * @param array $row Array of object attributes
00038      **/
00039     function eZProductCollectionItemOption( $row )
00040     {
00041         $this->eZPersistentObject( $row );
00042 
00043     }
00044 
00045     static function definition()
00046     {
00047         return array( "fields" => array( "id" => array( 'name' => 'ID',
00048                                                         'datatype' => 'integer',
00049                                                         'default' => 0,
00050                                                         'required' => true ),
00051                                          'item_id' => array( 'name' => 'ItemID',
00052                                                              'datatype' => 'integer',
00053                                                              'default' => 0,
00054                                                              'required' => true,
00055                                                              'foreign_class' => 'eZProductCollectionItem',
00056                                                              'foreign_attribute' => 'id',
00057                                                              'multiplicity' => '1..*' ),
00058                                          'option_item_id' => array( 'name' => 'OptionItemID',
00059                                                                     'datatype' => 'integer',
00060                                                                     'default' => 0,
00061                                                                     'required' => true,
00062                                                                     'foreign_class' => 'eZProductCollectionItemOption',
00063                                                                     'foreign_attribute' => 'id',
00064                                                                     'multiplicity' => '1..*' ),
00065                                          'object_attribute_id' => array( 'name' => 'ObjectAttributeID',
00066                                                                          'datatype' => 'integer',
00067                                                                          'default' => 0,
00068                                                                          'required' => true,
00069                                                                          'foreign_class' => 'eZContentObjectAttribute',
00070                                                                          'foreign_attribute' => 'id',
00071                                                                          'multiplicity' => '1..*' ),
00072                                          'name' => array( 'name' => 'Name',
00073                                                           'datatype' => 'string',
00074                                                           'default' => '',
00075                                                           'required' => true ),
00076                                          'value' => array( 'name' => 'Value',
00077                                                            'datatype' => 'string',
00078                                                            'default' => '',
00079                                                            'required' => true ),
00080                                          'price' => array( 'name' => 'Price',
00081                                                            'datatype' => 'float',
00082                                                            'default' => 0,
00083                                                            'required' => true ) ),
00084                       "keys" => array( "id" ),
00085                       "increment_key" => "id",
00086                       "class_name" => "eZProductCollectionItemOption",
00087                       "name" => "ezproductcollection_item_opt" );
00088     }
00089 
00090     /**
00091      * Creates an eZProductCollectionItem
00092      *
00093      * @param int $productCollectionItemID
00094      * @param int $optionItemID
00095      * @param string $optionName
00096      * @param string $optionValue
00097      * @param string $optionPrice
00098      * @param int $attributeID
00099      **/
00100     static function create( $productCollectionItemID, $optionItemID, $optionName, $optionValue, $optionPrice, $attributeID )
00101     {
00102         $row = array( 'item_id' => $productCollectionItemID,
00103                       'option_item_id' => $optionItemID,
00104                       'name' => $optionName,
00105                       'value' => $optionValue,
00106                       'price' => $optionPrice,
00107                       'object_attribute_id' => $attributeID );
00108         return new eZProductCollectionItemOption( $row );
00109     }
00110 
00111     /**
00112      * Clones the collection item option object and returns it.
00113      * The ID of the clone is reset so that the clone can be saved
00114      **/
00115     function __clone()
00116     {
00117         $this->setAttribute( 'id', null );
00118     }
00119 
00120     /**
00121      * Copies the collection object item option. The copy will point to the
00122      * collection item parameter $collectionItemID.
00123      *
00124      * @param int $collectionItemID Collection item ID to match the option to
00125      *
00126      * @return eZProductCollectionItemOption The new object
00127      **/
00128     function copy( $collectionItemID )
00129     {
00130         $item = clone $this;
00131         $item->setAttribute( 'item_id', $collectionItemID );
00132         $item->store();
00133         return $item;
00134     }
00135 
00136     /**
00137      * Fetches eZProductCollectionItemOption items that match the given item ID,
00138      * sorted by ascending order of option ID
00139      *
00140      * @param int $productCollectionItemID
00141      * @param bool $asObject
00142      *
00143      * @return array(eZProductCollectionItemOption)
00144      **/
00145     static function fetchList( $productCollectionItemID, $asObject = true )
00146     {
00147         return eZPersistentObject::fetchObjectList( eZProductCollectionItemOption::definition(),
00148                                                     null, array( "item_id" => $productCollectionItemID ),
00149                                                     array( "id" => "ASC"  ),
00150                                                     null,
00151                                                     $asObject );
00152     }
00153 
00154     /**
00155      * Removes all product collections options which are related to the
00156      * collection items specified in the parameter array
00157      *
00158      * @param array $itemIDList Array of eZProductCollectionItem IDs
00159      *
00160      * @return void
00161      **/
00162     static function cleanupList( $itemIDList )
00163     {
00164         $db = eZDB::instance();
00165         $inText = $db->generateSQLINStatement( $itemIDList, 'item_id', false, false, 'int' );
00166         $db->query( $q = "DELETE FROM ezproductcollection_item_opt WHERE $inText" );
00167     }
00168 
00169 }
00170 
00171 ?>