Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezuserdiscountrule.php
Go to the documentation of this file.
1 <?php
17 class eZUserDiscountRule extends eZPersistentObject
18 {
19 public $ContentobjectID;
20 static function definition()
21 {
22 return array( "fields" => array( "id" => array( 'name' => 'ID',
23 'datatype' => 'integer',
24 'default' => 0,
25 'required' => true ),
26 "discountrule_id" => array( 'name' => "DiscountRuleID",
27 'datatype' => 'integer',
28 'default' => 0,
29 'required' => true,
30 'foreign_class' => 'eZDiscountRule',
31 'foreign_attribute' => 'id',
32 'multiplicity' => '1..*' ),
33 "contentobject_id" => array( 'name' => "ContentobjectID",
34 'datatype' => 'integer',
35 'default' => 0,
36 'required' => true,
37 'foreign_class' => 'eZContentObject',
38 'foreign_attribute' => 'id',
39 'multiplicity' => '1..*' ) ),
40 "keys" => array( "id" ),
41 "increment_key" => "id",
42 "relations" => array( "discountrule_id" => array( "class" => "eZDiscountRule",
43 "field" => "id" ),
44 "contentobject_id" => array( "class" => "eZContentObject",
45 "field" => "id" ) ),
46 "class_name" => "eZUserDiscountRule",
47 "name" => "ezuser_discountrule" );
48 }
49
50 function store( $fieldFilters = null )
51 {
52 if ( $this->ContentobjectID == eZUser::anonymousId() )
53 {
54 eZUser::purgeUserCacheByAnonymousId();
55 }
56 else
57 {
58 $handler = eZExpiryHandler::instance();
59 $handler->setTimestamp( 'user-discountrules-cache', time() );
60 $handler->store();
61 }
62 parent::store( $fieldFilters );
63 }
64
65 static function fetch( $id, $asObject = true )
66 {
67 return eZPersistentObject::fetchObject( eZUserDiscountRule::definition(),
68 null,
69 array( "id" => $id
70 ),
71 $asObject );
72 }
73
74 static function fetchByUserID( $userID, $asObject = true )
75 {
76 return eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(),
77 null,
78 array( "contentobject_id" => $userID ),
79 null,
80 null,
81 $asObject );
82 }
83
84 static function fetchIDListByUserID( $userID )
85 {
86 if ( $userID == eZUser::anonymousId() )
87 {
88 $userCache = eZUSer::getUserCacheByAnonymousId();
89 $ruleArray = $userCache['discount_rules'];
90 }
91 else
92 {
93 $http = eZHTTPTool::instance();
94
95 $handler = eZExpiryHandler::instance();
96 $expiredTimeStamp = 0;
97 if ( $handler->hasTimestamp( 'user-discountrules-cache' ) )
98 $expiredTimeStamp = $handler->timestamp( 'user-discountrules-cache' );
99
100 $ruleTimestamp =& $http->sessionVariable( 'eZUserDiscountRulesTimestamp' );
101
102 $ruleArray = false;
103 // check for cached version in session
104 if ( $ruleTimestamp > $expiredTimeStamp )
105 {
106 if ( $http->hasSessionVariable( 'eZUserDiscountRules' . $userID ) )
107 {
108 $ruleArray =& $http->sessionVariable( 'eZUserDiscountRules' . $userID );
109 }
110 }
111
112 if ( !is_array( $ruleArray ) )
113 {
114 $ruleArray = self::generateIDListByUserID( (int) $userID );
115 $http->setSessionVariable( 'eZUserDiscountRules' . $userID, $ruleArray );
116 $http->setSessionVariable( 'eZUserDiscountRulesTimestamp', time() );
117 }
118 }
119
120 $rules = array();
121 foreach ( $ruleArray as $ruleRow )
122 {
123 $rules[] = $ruleRow['id'];
124 }
125 return $rules;
126 }
127
135 static public function generateIDListByUserID( $userId )
136 {
137 $db = eZDB::instance();
138 $query = "SELECT DISTINCT ezdiscountrule.id
139 FROM ezdiscountrule,
140 ezuser_discountrule
141 WHERE ezuser_discountrule.contentobject_id = $userId AND
142 ezuser_discountrule.discountrule_id = ezdiscountrule.id";
143 return $db->arrayQuery( $query );
144 }
145
153 static function &fetchByUserIDArray( $idArray )
154 {
155 $db = eZDB::instance();
156 $inString = $db->generateSQLINStatement( $idArray, 'ezuser_discountrule.contentobject_id', false, false, 'int' );
157 $query = "SELECT DISTINCT ezdiscountrule.id,
158 ezdiscountrule.name
159 FROM ezdiscountrule,
160 ezuser_discountrule
161 WHERE $inString AND
162 ezuser_discountrule.discountrule_id = ezdiscountrule.id";
163 $ruleArray = $db->arrayQuery( $query );
164
165 $rules = array();
166 foreach ( $ruleArray as $ruleRow )
167 {
168 $rules[] = new eZDiscountRule( $ruleRow );
169 }
170 return $rules;
171 }
172
173 static function &fetchUserID( $discountRuleID )
174 {
175 $userList = eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(),
176 null,
177 array( "discountrule_id" => $discountRuleID ),
178 null,
179 null,
180 false );
181 $idArray = array();
182 foreach ( $userList as $user )
183 {
184
185 $idArray[] = $user['contentobject_id'];
186 }
187 return $idArray;
188 }
189
190 static function &fetchByRuleID( $discountRuleID, $asObject = true )
191 {
192 $objectList = eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(),
193 null,
194 array( "discountrule_id" => $discountRuleID ),
195 null,
196 null,
197 $asObject );
198 return $objectList;
199 }
200
201 static function create( $discountRuleID, $contentobjectID )
202 {
203 $row = array(
204 "id" => null,
205 "discountrule_id" => $discountRuleID,
206 "contentobject_id" => $contentobjectID );
207 return new eZUserDiscountRule( $row );
208 }
209
210 static function removeUser( $userID )
211 {
212 eZPersistentObject::removeObject( eZUserDiscountRule::definition(),
213 array( "contentobject_id" => $userID ) );
214 }
215 function removeByID( $id )
216 {
217 eZPersistentObject::removeObject( eZUserDiscountRule::definition(),
218 array( "id" => $id ) );
219 }
220 }
221 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDiscountRule
The class eZDiscountRule does.
Definition: ezdiscountrule.php:18
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZUserDiscountRule
The class eZUserDiscountRule does.
Definition: ezuserdiscountrule.php:18
eZUserDiscountRule\fetchByUserIDArray
static & fetchByUserIDArray( $idArray)
Definition: ezuserdiscountrule.php:153
eZUserDiscountRule\fetch
static fetch( $id, $asObject=true)
Definition: ezuserdiscountrule.php:65
eZUserDiscountRule\store
store( $fieldFilters=null)
Definition: ezuserdiscountrule.php:50
eZUserDiscountRule\fetchIDListByUserID
static fetchIDListByUserID( $userID)
Definition: ezuserdiscountrule.php:84
eZUserDiscountRule\removeByID
removeByID( $id)
Definition: ezuserdiscountrule.php:215
eZUserDiscountRule\$ContentobjectID
$ContentobjectID
Definition: ezuserdiscountrule.php:19
eZUserDiscountRule\create
static create( $discountRuleID, $contentobjectID)
Definition: ezuserdiscountrule.php:201
eZUserDiscountRule\definition
static definition()
Definition: ezuserdiscountrule.php:20
eZUserDiscountRule\fetchUserID
static & fetchUserID( $discountRuleID)
Definition: ezuserdiscountrule.php:173
eZUserDiscountRule\fetchByRuleID
static & fetchByRuleID( $discountRuleID, $asObject=true)
Definition: ezuserdiscountrule.php:190
eZUserDiscountRule\generateIDListByUserID
static generateIDListByUserID( $userId)
Definition: ezuserdiscountrule.php:135
eZUserDiscountRule\fetchByUserID
static fetchByUserID( $userID, $asObject=true)
Definition: ezuserdiscountrule.php:74
eZUserDiscountRule\removeUser
static removeUser( $userID)
Definition: ezuserdiscountrule.php:210
eZUser\anonymousId
static anonymousId()
Definition: ezuser.php:2898
eZUser\purgeUserCacheByAnonymousId
static purgeUserCacheByAnonymousId()
Definition: ezuser.php:1334
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.