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
00039
00040 include_once( "kernel/classes/ezpersistentobject.php" );
00041
00042 class eZDiscountSubRule extends eZPersistentObject
00043 {
00044
00045
00046
00047 function eZDiscountSubRule( $row )
00048 {
00049 $this->eZPersistentObject( $row );
00050 }
00051
00052 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
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 function fetch( $id, $asObject = true )
00111 {
00112 return eZPersistentObject::fetchObject( eZDiscountSubRule::definition(),
00113 null,
00114 array( "id" => $id ),
00115 $asObject );
00116 }
00117
00118 function &fetchList( $asObject = true )
00119 {
00120 $objectList = eZPersistentObject::fetchObjectList( eZDiscountSubRule::definition(),
00121 null, null, null, null,
00122 $asObject );
00123 return $objectList;
00124 }
00125
00126 function fetchByRuleID( $discountRuleID, $asObject = true )
00127 {
00128 return eZPersistentObject::fetchObjectList( eZDiscountSubRule::definition(),
00129 null,
00130 array( "discountrule_id" => $discountRuleID ),
00131 null,
00132 null,
00133 $asObject );
00134 }
00135
00136 function create( $discountRuleID )
00137 {
00138 $row = array(
00139 "id" => null,
00140 "name" => ezi18n( 'kernel/shop/discountgroup', "New Discount Rule" ),
00141 "discountrule_id" => $discountRuleID,
00142 "discount_percent" => "",
00143 "limitation" => "*" );
00144 return new eZDiscountSubRule( $row );
00145 }
00146
00147
00148
00149
00150
00151 function remove ( $id )
00152 {
00153 eZPersistentObject::removeObject( eZDiscountSubRule::definition(),
00154 array( "id" => $id ) );
00155 }
00156 }
00157 ?>