|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZUserDiscountRule 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 eZUserDiscountRule ezuserdiscountrule.php 00036 \brief The class eZUserDiscountRule does 00037 00038 */ 00039 00040 //include_once( "kernel/classes/ezpersistentobject.php" ); 00041 //include_once( "kernel/classes/ezdiscountrule.php" ); 00042 00043 class eZUserDiscountRule extends eZPersistentObject 00044 { 00045 /*! 00046 Constructor 00047 */ 00048 function eZUserDiscountRule( $row ) 00049 { 00050 $this->eZPersistentObject( $row ); 00051 } 00052 00053 static function definition() 00054 { 00055 return array( "fields" => array( "id" => array( 'name' => 'ID', 00056 'datatype' => 'integer', 00057 'default' => 0, 00058 'required' => true ), 00059 "discountrule_id" => array( 'name' => "DiscountRuleID", 00060 'datatype' => 'integer', 00061 'default' => 0, 00062 'required' => true, 00063 'foreign_class' => 'eZDiscountRule', 00064 'foreign_attribute' => 'id', 00065 'multiplicity' => '1..*' ), 00066 "contentobject_id" => array( 'name' => "ContentobjectID", 00067 'datatype' => 'integer', 00068 'default' => 0, 00069 'required' => true, 00070 'foreign_class' => 'eZContentObject', 00071 'foreign_attribute' => 'id', 00072 'multiplicity' => '1..*' ) ), 00073 "keys" => array( "id" ), 00074 "increment_key" => "id", 00075 "relations" => array( "discountrule_id" => array( "class" => "eZDiscountRule", 00076 "field" => "id" ), 00077 "contentobject_id" => array( "class" => "eZContentObject", 00078 "field" => "id" ) ), 00079 "class_name" => "eZUserDiscountRule", 00080 "name" => "ezuser_discountrule" ); 00081 } 00082 00083 function store( $fieldFilters = null ) 00084 { 00085 eZExpiryHandler::registerShutdownFunction(); 00086 $handler = eZExpiryHandler::instance(); 00087 $handler->setTimestamp( 'user-discountrules-cache', time() ); 00088 $handler->store(); 00089 eZPersistentObject::store( $fieldFilters ); 00090 } 00091 00092 static function fetch( $id, $asObject = true ) 00093 { 00094 return eZPersistentObject::fetchObject( eZUserDiscountRule::definition(), 00095 null, 00096 array( "id" => $id 00097 ), 00098 $asObject ); 00099 } 00100 00101 static function fetchByUserID( $userID, $asObject = true ) 00102 { 00103 return eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(), 00104 null, 00105 array( "contentobject_id" => $userID ), 00106 null, 00107 null, 00108 $asObject ); 00109 } 00110 00111 static function fetchIDListByUserID( $userID ) 00112 { 00113 $http = eZHTTPTool::instance(); 00114 00115 eZExpiryHandler::registerShutdownFunction(); 00116 $handler = eZExpiryHandler::instance(); 00117 $expiredTimeStamp = 0; 00118 if ( $handler->hasTimestamp( 'user-discountrules-cache' ) ) 00119 $expiredTimeStamp = $handler->timestamp( 'user-discountrules-cache' ); 00120 00121 $ruleTimestamp =& $http->sessionVariable( 'eZUserDiscountRulesTimestamp' ); 00122 00123 $ruleArray = false; 00124 // check for cached version in sesssion 00125 if ( $ruleTimestamp > $expiredTimeStamp ) 00126 { 00127 if ( $http->hasSessionVariable( 'eZUserDiscountRules' . $userID ) ) 00128 { 00129 $ruleArray =& $http->sessionVariable( 'eZUserDiscountRules' . $userID ); 00130 } 00131 } 00132 00133 if ( !is_array( $ruleArray ) ) 00134 { 00135 $userID = (int)$userID; 00136 $db = eZDB::instance(); 00137 $query = "SELECT DISTINCT ezdiscountrule.id 00138 FROM ezdiscountrule, 00139 ezuser_discountrule 00140 WHERE ezuser_discountrule.contentobject_id = $userID AND 00141 ezuser_discountrule.discountrule_id = ezdiscountrule.id"; 00142 $ruleArray = $db->arrayQuery( $query ); 00143 $http->setSessionVariable( 'eZUserDiscountRules' . $userID, $ruleArray ); 00144 $http->setSessionVariable( 'eZUserDiscountRulesTimestamp', time() ); 00145 } 00146 00147 $rules = array(); 00148 foreach ( $ruleArray as $ruleRow ) 00149 { 00150 $rules[] = $ruleRow['id']; 00151 } 00152 return $rules; 00153 } 00154 00155 /** 00156 * Fetches the eZDiscountRules matching an array of eZUserID 00157 * 00158 * @param array(eZUserID) $idArray Array of user ID 00159 * 00160 * @return array(eZDiscountRule) 00161 **/ 00162 static function &fetchByUserIDArray( $idArray ) 00163 { 00164 $db = eZDB::instance(); 00165 $inString = $db->generateSQLINStatement( $idArray, 'ezuser_discountrule.contentobject_id', false, false, 'int' ); 00166 $query = "SELECT DISTINCT ezdiscountrule.id, 00167 ezdiscountrule.name 00168 FROM ezdiscountrule, 00169 ezuser_discountrule 00170 WHERE $inString AND 00171 ezuser_discountrule.discountrule_id = ezdiscountrule.id"; 00172 $ruleArray = $db->arrayQuery( $query ); 00173 00174 $rules = array(); 00175 foreach ( $ruleArray as $ruleRow ) 00176 { 00177 $rules[] = new eZDiscountRule( $ruleRow ); 00178 } 00179 return $rules; 00180 } 00181 00182 static function &fetchUserID( $discountRuleID ) 00183 { 00184 $userList = eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(), 00185 null, 00186 array( "discountrule_id" => $discountRuleID ), 00187 null, 00188 null, 00189 false ); 00190 $idArray = array(); 00191 foreach ( $userList as $user ) 00192 { 00193 00194 $idArray[] = $user['contentobject_id']; 00195 } 00196 return $idArray; 00197 } 00198 00199 static function &fetchByRuleID( $discountRuleID, $asObject = true ) 00200 { 00201 $objectList = eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(), 00202 null, 00203 array( "discountrule_id" => $discountRuleID ), 00204 null, 00205 null, 00206 $asObject ); 00207 return $objectList; 00208 } 00209 00210 static function create( $discountRuleID, $contentobjectID ) 00211 { 00212 $row = array( 00213 "id" => null, 00214 "discountrule_id" => $discountRuleID, 00215 "contentobject_id" => $contentobjectID ); 00216 return new eZUserDiscountRule( $row ); 00217 } 00218 00219 static function removeUser( $userID ) 00220 { 00221 eZPersistentObject::removeObject( eZUserDiscountRule::definition(), 00222 array( "contentobject_id" => $userID ) ); 00223 } 00224 function removeByID( $id ) 00225 { 00226 eZPersistentObject::removeObject( eZUserDiscountRule::definition(), 00227 array( "id" => $id ) ); 00228 } 00229 } 00230 ?>