[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZTipafriendRequest class
   4  //
   5  // Created on: <16-Dec-2004 17:25:49 sp>
   6  //
   7  
   8  // SOFTWARE NAME: eZ publish
   9  // SOFTWARE RELEASE: 3.9.0
  10  // BUILD VERSION: 17785
  11  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  12  // SOFTWARE LICENSE: GNU General Public License v2.0
  13  // NOTICE: >
  14  //   This program is free software; you can redistribute it and/or
  15  //   modify it under the terms of version 2.0  of the GNU General
  16  //   Public License as published by the Free Software Foundation.
  17  //
  18  //   This program is distributed in the hope that it will be useful,
  19  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  20  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21  //   GNU General Public License for more details.
  22  //
  23  //   You should have received a copy of version 2.0 of the GNU General
  24  //   Public License along with this program; if not, write to the Free
  25  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  26  //   MA 02110-1301, USA.
  27  //
  28  //
  29  
  30  /*! \file eztipafriendrequest.php
  31  */
  32  
  33  /*!
  34    \class eZTipafriendRequest eztipafriendrequest.php
  35    \brief The class eZTipafriendRequest does
  36  
  37  */
  38  include_once ( "lib/ezdb/classes/ezdb.php" );
  39  
  40  class eZTipafriendRequest extends eZPersistentObject
  41  {
  42      /*!
  43       Constructor
  44      */
  45      function eZTipafriendRequest( $row )
  46      {
  47          $this->eZPersistentObject( $row );
  48      }
  49  
  50      function definition()
  51      {
  52          return array( "fields" => array( 'email_receiver' => array( 'name' => 'EmailReceiver',
  53                                                                      'datatype' => 'string',
  54                                                                      'default' => '',
  55                                                                      'required' => true ),
  56                                           'created' => array( 'name' => 'Created',
  57                                                               'datatype' => 'integer',
  58                                                               'default' => 0,
  59                                                               'required' => true ) ),
  60                        'keys' => array( 'email_receiver' ),
  61                        'class_name' => 'eZTipafriendRequest',
  62                        'sort' => array( 'created' => 'desc' ),
  63                        'name' => 'eztipafriend_request' );
  64      }
  65  
  66      function create( $receiver )
  67      {
  68          $row = array( "email_receiver" => $receiver,
  69                        "created" => time() );
  70          return new eZTipafriendRequest( $row );
  71      }
  72  
  73      function checkReceiver( $receiver )
  74      {
  75          eZTipafriendRequest::cleanup();
  76          $ini = eZINI::instance();
  77          $timeFrame = 1;
  78          if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
  79              $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
  80          $time = time() - $timeFrame * 3600;
  81          $requestsPerTimeframe = 1;
  82          if ( $ini->hasVariable( 'TipAFriend', 'MaxRequestsPerTimeframe' ) )
  83              $requestsPerTimeframe = $ini->variable( 'TipAFriend', 'MaxRequestsPerTimeframe' );
  84  
  85          $db = eZDB::instance();
  86          $receiver = $db->escapeString( $receiver );
  87          $countResult = $db->arrayQuery( "SELECT count(*) as count
  88                                           FROM eztipafriend_request
  89                                           WHERE email_receiver = '$receiver'
  90                                             AND created > $time " );
  91          $count = 0;
  92          if ( isset(  $countResult[0]['count'] ) )
  93              $count = $countResult[0]['count'];
  94          if ( $count >= $requestsPerTimeframe )
  95              return false;
  96          return true;
  97      }
  98  
  99      /*!
 100       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 101       the calls within a db transaction; thus within db->begin and db->commit.
 102       */
 103      function cleanup()
 104      {
 105          $ini = eZINI::instance();
 106          $db = eZDB::instance();
 107          $timeFrame = 1;
 108          if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
 109              $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
 110          $time = time() - $timeFrame * 3600;
 111  
 112          $db->query( "DELETE FROM eztipafriend_request
 113                        WHERE created < $time " );
 114      }
 115  
 116  }
 117  
 118  ?>


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