[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZUserDiscountRule class
   4  //
   5  // Created on: <27-Nov-2002 13:05:59 wy>
   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  /*! \file ezdiscountrule.php
  30  */
  31  
  32  /*!
  33    \class eZUserDiscountRule ezuserdiscountrule.php
  34    \brief The class eZUserDiscountRule does
  35  
  36  */
  37  
  38  include_once ( "kernel/classes/ezpersistentobject.php" );
  39  include_once ( "kernel/classes/ezdiscountrule.php" );
  40  
  41  class eZUserDiscountRule extends eZPersistentObject
  42  {
  43      /*!
  44       Constructor
  45      */
  46      function eZUserDiscountRule( $row )
  47      {
  48          $this->eZPersistentObject( $row );
  49      }
  50  
  51      function definition()
  52      {
  53          return array( "fields" => array( "id" => array( 'name' => 'ID',
  54                                                          'datatype' => 'integer',
  55                                                          'default' => 0,
  56                                                          'required' => true ),
  57                                           "discountrule_id" => array( 'name' => "DiscountRuleID",
  58                                                                       'datatype' => 'integer',
  59                                                                       'default' => 0,
  60                                                                       'required' => true,
  61                                                                       'foreign_class' => 'eZDiscountRule',
  62                                                                       'foreign_attribute' => 'id',
  63                                                                       'multiplicity' => '1..*' ),
  64                                           "contentobject_id" => array( 'name' => "ContentobjectID",
  65                                                                        'datatype' => 'integer',
  66                                                                        'default' => 0,
  67                                                                        'required' => true,
  68                                                                        'foreign_class' => 'eZContentObject',
  69                                                                        'foreign_attribute' => 'id',
  70                                                                        'multiplicity' => '1..*' ) ),
  71                        "keys" => array( "id" ),
  72                        "increment_key" => "id",
  73                        "relations" => array( "discountrule_id" => array( "class" => "ezdiscountrule",
  74                                                                           "field" => "id" ),
  75                                              "contentobject_id" => array( "class" => "ezcontentobject",
  76                                                                           "field" => "id" ) ),
  77                        "class_name" => "eZUserDiscountRule",
  78                        "name" => "ezuser_discountrule" );
  79      }
  80  
  81      function store()
  82      {
  83          include_once ( 'lib/ezutils/classes/ezexpiryhandler.php' );
  84          $handler =& eZExpiryHandler::instance();
  85          $handler->setTimestamp( 'user-discountrules-cache', mktime() );
  86          $handler->store();
  87          eZPersistentObject::store();
  88      }
  89  
  90      function fetch( $id, $asObject = true )
  91      {
  92          return eZPersistentObject::fetchObject( eZUserDiscountRule::definition(),
  93                                                  null,
  94                                                  array( "id" => $id
  95                                                        ),
  96                                                  $asObject );
  97      }
  98  
  99      function fetchByUserID( $userID, $asObject = true )
 100      {
 101          return eZPersistentObject::fetchObjectList( eZUserDiscountRule::definition(),
 102                                                      null,
 103                                                      array( "contentobject_id" => $userID ),
 104                                                      null,
 105                                                      null,
 106                                                      $asObject );
 107      }
 108  
 109      function fetchIDListByUserID( $userID )
 110      {
 111          $http =& eZHTTPTool::instance();
 112  
 113          include_once ( 'lib/ezutils/classes/ezexpiryhandler.php' );
 114          $handler =& eZExpiryHandler::instance();
 115          $expiredTimeStamp = 0;
 116          if ( $handler->hasTimestamp( 'user-discountrules-cache' ) )
 117              $expiredTimeStamp = $handler->timestamp( 'user-discountrules-cache' );
 118  
 119          $ruleTimestamp =& $http->sessionVariable( 'eZUserDiscountRulesTimestamp' );
 120  
 121          $ruleArray = false;
 122          // check for cached version in sesssion
 123          if ( $ruleTimestamp > $expiredTimeStamp )
 124          {
 125              if ( $http->hasSessionVariable( 'eZUserDiscountRules' . $userID ) )
 126              {
 127                  $ruleArray =& $http->sessionVariable( 'eZUserDiscountRules' . $userID );
 128              }
 129          }
 130  
 131          if ( !is_array( $ruleArray ) )
 132          {
 133              $userID = (int)$userID;
 134              $db =& eZDB::instance();
 135              $query = "SELECT DISTINCT ezdiscountrule.id
 136                    FROM ezdiscountrule,
 137                         ezuser_discountrule
 138                    WHERE ezuser_discountrule.contentobject_id = $userID AND
 139                          ezuser_discountrule.discountrule_id = ezdiscountrule.id";
 140              $ruleArray = $db->arrayQuery( $query );
 141              $http->setSessionVariable( 'eZUserDiscountRules' . $userID, $ruleArray );
 142              $http->setSessionVariable( 'eZUserDiscountRulesTimestamp', mktime() );
 143          }
 144  
 145          $rules = array();
 146          foreach ( $ruleArray as $ruleRow )
 147          {
 148              $rules[] = $ruleRow['id'];
 149          }
 150          return $rules;
 151      }
 152  
 153      function &fetchByUserIDArray( $idArray )
 154      {
 155          $db =& eZDB::instance();
 156          $groupString = $db->implodeWithTypeCast( ',', $idArray, 'int' );
 157          $query = "SELECT DISTINCT ezdiscountrule.id,
 158                                    ezdiscountrule.name
 159                    FROM ezdiscountrule,
 160                         ezuser_discountrule
 161                    WHERE ezuser_discountrule.contentobject_id IN ( $groupString ) 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      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      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      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      function removeUser( $userID )
 211      {
 212          eZPersistentObject::removeObject( eZUserDiscountRule::definition(),
 213                                            array( "contentobject_id" => $userID ) );
 214      }
 215      function remove( $id )
 216      {
 217          eZPersistentObject::removeObject( eZUserDiscountRule::definition(),
 218                                            array( "id" => $id ) );
 219      }
 220  }
 221  ?>


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