[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezproductcollection.php (source)

   1  <?php
   2  //
   3  // Definition of eZProductCollection class
   4  //
   5  // Created on: <04-Jul-2002 13:40:41 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30    \class eZProductCollection ezproductcollection.php
  31    \brief eZProductCollection is a container class which handles groups of products
  32    \ingroup eZKernel
  33  
  34  */
  35  
  36  include_once ( "kernel/classes/ezpersistentobject.php" );
  37  include_once ( "lib/ezdb/classes/ezdb.php" );
  38  
  39  class eZProductCollection extends eZPersistentObject
  40  {
  41      function eZProductCollection( $row )
  42      {
  43          $this->eZPersistentObject( $row );
  44      }
  45  
  46      function definition()
  47      {
  48          return array( "fields" => array( "id" => array( 'name' => 'ID',
  49                                                          'datatype' => 'integer',
  50                                                          'default' => 0,
  51                                                          'required' => true ),
  52                                           "created" => array( 'name' => "Created",
  53                                                               'datatype' => 'integer',
  54                                                               'default' => 0,
  55                                                               'required' => true ),
  56                                           'currency_code' => array( 'name' => 'CurrencyCode',
  57                                                                     'datatype' => 'string',
  58                                                                     'default' => '',
  59                                                                     'required' => true ) ),
  60                        "keys" => array( "id" ),
  61                        "increment_key" => "id",
  62                        "class_name" => "eZProductCollection",
  63                        "name" => "ezproductcollection" );
  64      }
  65  
  66      /*!
  67       Creates a new empty collection and returns it.
  68      */
  69      function create( )
  70      {
  71          $row = array( "created" => time() );
  72          return new eZProductCollection( $row );
  73      }
  74  
  75      /*!
  76       Clones the collection object and returns it. The ID of the clone is erased.
  77      */
  78      function clone()
  79      {
  80          $collection = $this;
  81          $collection->setAttribute( 'id', null );
  82          return $collection;
  83      }
  84  
  85      /*!
  86       Copies the collection object, the collection items and options.
  87       \return the new collection object.
  88       \note The new collection will already be present in the database.
  89       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  90       the calls within a db transaction; thus within db->begin and db->commit.
  91      */
  92      function &copy()
  93      {
  94          $collection = $this->clone();
  95  
  96          $db =& eZDB::instance();
  97          $db->begin();
  98          $collection->store();
  99  
 100          $oldItems =& $this->itemList();
 101          foreach ( array_keys( $oldItems ) as $oldItemKey )
 102          {
 103              $oldItem =& $oldItems[$oldItemKey];
 104              $item =& $oldItem->copy( $collection->attribute( 'id' ) );
 105          }
 106          $db->commit();
 107          return $collection;
 108      }
 109  
 110      /*!
 111       \return the product collection with ID \a $productCollectionID.
 112      */
 113      function fetch( $productCollectionID, $asObject = true )
 114      {
 115          return eZPersistentObject::fetchObject( eZProductCollection::definition(),
 116                                                  null,
 117                                                  array( 'id' => $productCollectionID ),
 118                                                  $asObject );
 119      }
 120  
 121      /*!
 122       \return all production collection items as an array.
 123      */
 124      function &itemList( $asObject = true )
 125      {
 126          $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
 127                                                                null, array( "productcollection_id" => $this->ID ),
 128                                                                null,
 129                                                                null,
 130                                                                $asObject );
 131          return $productItems;
 132      }
 133  
 134      function &verify( $id )
 135      {
 136          $invalidItemArray = array();
 137          $collection = eZProductCollection::fetch( $id );
 138          if ( !is_object( $collection ) )
 139               return $invalidItemArray;
 140  
 141          $currency =& $collection->attribute( 'currency_code' );
 142          $productItemList = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
 143                                                                   null, array( "productcollection_id" => $id ),
 144                                                                   null,
 145                                                                   null,
 146                                                                   true );
 147          $isValid = true;
 148  
 149          foreach ( array_keys( $productItemList ) as $key )
 150          {
 151              $productItem =& $productItemList[$key];
 152  
 153              if ( !$productItem->verify( $currency ) )
 154              {
 155                  $invalidItemArray[] =& $productItem;
 156                  //  eZDebug::writeDebug( $productItem , "invalid item" );
 157                  $isValid = false;
 158              }
 159          }
 160          if ( !$isValid )
 161          {
 162              return $invalidItemArray;
 163          }
 164          return $isValid;
 165      }
 166  
 167      /*!
 168       \static
 169       \return a count of the number of product collections that exists.
 170      */
 171      function count()
 172      {
 173          $db =& eZDB::instance();
 174          $rows = $db->arrayQuery( "SELECT count( id ) as count FROM ezproductcollection_item" );
 175          return $rows[0]['count'];
 176      }
 177  
 178      /*!
 179       \static
 180       Removes all product collections which are specified in the array \a $productCollectionIDList.
 181       Will also remove the product collection items.
 182       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 183       the calls within a db transaction; thus within db->begin and db->commit.
 184      */
 185      function cleanupList( $productCollectionIDList )
 186      {
 187          $db =& eZDB::instance();
 188          $db->begin();
 189  
 190          // Purge shipping information associated with product collections being removed.
 191          require_once ( 'kernel/classes/ezshippingmanager.php' );
 192          foreach ( $productCollectionIDList as $productCollectionID )
 193              eZShippingManager::purgeShippingInfo( $productCollectionID );
 194  
 195          include_once ( 'kernel/classes/ezproductcollectionitem.php' );
 196          eZProductCollectionItem::cleanupList( $productCollectionIDList );
 197          $idText = $db->implodeWithTypeCast( ', ', $productCollectionIDList, 'int' );
 198          $db->query( "DELETE FROM ezproductcollection WHERE id IN ( $idText )" );
 199          $db->commit();
 200      }
 201  }
 202  
 203  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7