|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZDiscountSubRule class 00004 // 00005 // Created on: <27-Nov-2002 13:05:59 wy> 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 ezdiscountrule.php 00032 */ 00033 00034 /*! 00035 \class eZDiscountSubRule ezdiscountsubrule.php 00036 \brief The class eZDiscountSubRule does 00037 00038 */ 00039 00040 //include_once( "kernel/classes/ezpersistentobject.php" ); 00041 00042 class eZDiscountSubRule extends eZPersistentObject 00043 { 00044 /*! 00045 Constructor 00046 */ 00047 function eZDiscountSubRule( $row ) 00048 { 00049 $this->eZPersistentObject( $row ); 00050 } 00051 00052 static function definition() 00053 { 00054 return array( "fields" => array( "id" => array( 'name' => 'ID', 00055 'datatype' => 'integer', 00056 'default' => 0, 00057 'required' => true ), 00058 "name" => array( 'name' => "Name", 00059 'datatype' => 'string', 00060 'default' => '', 00061 'required' => true ), 00062 "discountrule_id" => array( 'name' => "DiscountRuleID", 00063 'datatype' => 'integer', 00064 'default' => 0, 00065 'required' => true, 00066 'foreign_class' => 'eZDiscountRule', 00067 'foreign_attribute' => 'id', 00068 'multiplicity' => '1..*' ), 00069 "discount_percent" => array( 'name' => "DiscountPercent", 00070 'datatype' => 'float', 00071 'default' => 0, 00072 'required' => true ), 00073 "limitation" => array( 'name' => "Limitation", 00074 'datatype' => 'string', 00075 'default' => '', 00076 'required' => true ) ), 00077 "keys" => array( "id" ), 00078 "increment_key" => "id", 00079 "class_name" => "eZDiscountSubRule", 00080 "name" => "ezdiscountsubrule" ); 00081 } 00082 00083 /*! 00084 \reimp 00085 */ 00086 function setAttribute( $attr, $val ) 00087 { 00088 switch( $attr ) 00089 { 00090 case 'discount_percent': 00091 { 00092 //include_once( 'lib/ezlocale/classes/ezlocale.php' ); 00093 $locale = eZLocale::instance(); 00094 00095 $val = $locale->internalNumber( $val ); 00096 if ( $val < 0.0 ) 00097 $val = 0.0; 00098 if ( $val > 100.0 ) 00099 $val = 100.0; 00100 eZPersistentObject::setAttribute( $attr, $val ); 00101 } break; 00102 00103 default: 00104 { 00105 eZPersistentObject::setAttribute( $attr, $val ); 00106 } break; 00107 } 00108 } 00109 00110 static function fetch( $id, $asObject = true ) 00111 { 00112 return eZPersistentObject::fetchObject( eZDiscountSubRule::definition(), 00113 null, 00114 array( "id" => $id ), 00115 $asObject ); 00116 } 00117 00118 static function fetchList( $asObject = true ) 00119 { 00120 return eZPersistentObject::fetchObjectList( eZDiscountSubRule::definition(), 00121 null, null, null, null, 00122 $asObject ); 00123 } 00124 00125 static function fetchByRuleID( $discountRuleID, $asObject = true ) 00126 { 00127 return eZPersistentObject::fetchObjectList( eZDiscountSubRule::definition(), 00128 null, 00129 array( "discountrule_id" => $discountRuleID ), 00130 null, 00131 null, 00132 $asObject ); 00133 } 00134 00135 static function create( $discountRuleID ) 00136 { 00137 $row = array( 00138 "id" => null, 00139 "name" => ezi18n( 'kernel/shop/discountgroup', "New Discount Rule" ), 00140 "discountrule_id" => $discountRuleID, 00141 "discount_percent" => "", 00142 "limitation" => "*" ); 00143 return new eZDiscountSubRule( $row ); 00144 } 00145 00146 /*! 00147 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00148 the calls within a db transaction; thus within db->begin and db->commit. 00149 */ 00150 function remove ( $id = null, $dumb = null ) 00151 { 00152 eZPersistentObject::removeObject( eZDiscountSubRule::definition(), 00153 array( "id" => $id ) ); 00154 } 00155 } 00156 ?>