eZ Publish  [4.0]
eztipafriendrequest.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTipafriendRequest class
00004 //
00005 // Created on: <16-Dec-2004 17:25:49 sp>
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 eztipafriendrequest.php
00032 */
00033 
00034 /*!
00035   \class eZTipafriendRequest eztipafriendrequest.php
00036   \brief The class eZTipafriendRequest does
00037 
00038 */
00039 //include_once( "lib/ezdb/classes/ezdb.php" );
00040 
00041 class eZTipafriendRequest extends eZPersistentObject
00042 {
00043     /*!
00044      Constructor
00045     */
00046     function eZTipafriendRequest( $row )
00047     {
00048         $this->eZPersistentObject( $row );
00049     }
00050 
00051     static function definition()
00052     {
00053         return array( "fields" => array( 'email_receiver' => array( 'name' => 'EmailReceiver',
00054                                                                     'datatype' => 'string',
00055                                                                     'default' => '',
00056                                                                     'required' => true ),
00057                                          'created' => array( 'name' => 'Created',
00058                                                              'datatype' => 'integer',
00059                                                              'default' => 0,
00060                                                              'required' => true ) ),
00061                       'keys' => array( 'email_receiver' ),
00062                       'class_name' => 'eZTipafriendRequest',
00063                       'sort' => array( 'created' => 'desc' ),
00064                       'name' => 'eztipafriend_request' );
00065     }
00066 
00067     static function create( $receiver )
00068     {
00069         $row = array( "email_receiver" => $receiver,
00070                       "created" => time() );
00071         return new eZTipafriendRequest( $row );
00072     }
00073 
00074     static function checkReceiver( $receiver )
00075     {
00076         eZTipafriendRequest::cleanup();
00077         $ini = eZINI::instance();
00078         $timeFrame = 1;
00079         if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
00080             $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
00081         $time = time() - $timeFrame * 3600;
00082         $requestsPerTimeframe = 1;
00083         if ( $ini->hasVariable( 'TipAFriend', 'MaxRequestsPerTimeframe' ) )
00084             $requestsPerTimeframe = $ini->variable( 'TipAFriend', 'MaxRequestsPerTimeframe' );
00085 
00086         $db = eZDB::instance();
00087         $receiver = $db->escapeString( $receiver );
00088         $countResult = $db->arrayQuery( "SELECT count(*) as count
00089                                          FROM eztipafriend_request
00090                                          WHERE email_receiver = '$receiver'
00091                                            AND created > $time " );
00092         $count = 0;
00093         if ( isset(  $countResult[0]['count'] ) )
00094             $count = $countResult[0]['count'];
00095         if ( $count >= $requestsPerTimeframe )
00096             return false;
00097         return true;
00098     }
00099 
00100     /*!
00101      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00102      the calls within a db transaction; thus within db->begin and db->commit.
00103      */
00104     static function cleanup()
00105     {
00106         $ini = eZINI::instance();
00107         $db = eZDB::instance();
00108         $timeFrame = 1;
00109         if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
00110             $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
00111         $time = time() - $timeFrame * 3600;
00112 
00113         $db->query( "DELETE FROM eztipafriend_request
00114                       WHERE created < $time " );
00115     }
00116 
00117 }
00118 
00119 ?>