eZ Publish  [4.0]
eztipafriendcounter.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTipafriendCounter class
00004 //
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 //!! eZKernel
00031 //! The class eZTipafriendCounter
00032 /*!
00033 
00034 */
00035 
00036 //include_once( "lib/ezdb/classes/ezdb.php" );
00037 //include_once( "kernel/classes/ezpersistentobject.php" );
00038 //include_once( "kernel/classes/ezcontentclassgroup.php" );
00039 
00040 class eZTipafriendCounter extends eZPersistentObject
00041 {
00042     function eZTipafriendCounter( $row )
00043     {
00044         $this->eZPersistentObject( $row );
00045     }
00046 
00047     static function definition()
00048     {
00049         return array( 'fields' => array( 'node_id' => array( 'name' => 'NodeID',
00050                                                              'datatype' => 'integer',
00051                                                              'default' => 0,
00052                                                              'required' => true ),
00053                                          'count' => array( 'name' => 'Count', // deprecated column, must not be used
00054                                                            'datatype' => 'integer',
00055                                                            'default' => 0,
00056                                                            'required' => true ),
00057                                          'requested' => array( 'name' => 'Requested',
00058                                                                'datatype' => 'integer',
00059                                                                'default' => 0,
00060                                                                'required' => true ) ),
00061                       'keys' => array( 'node_id', 'requested' ),
00062                       'relations' => array( 'node_id' => array( 'class' => 'eZContentObjectTreeNode',
00063                                                                 'field' => 'node_id' ) ),
00064                       'class_name' => 'eZTipafriendCounter',
00065                       'sort' => array( 'count' => 'desc' ),
00066                       'name' => 'eztipafriend_counter' );
00067     }
00068 
00069     static function create( $nodeID )
00070     {
00071         return new eZTipafriendCounter( array( 'node_id' => $nodeID,
00072                                                'count' => 0,
00073                                                'requested' => time() ) );
00074     }
00075 
00076     /*!
00077      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00078      the calls within a db transaction; thus within db->begin and db->commit.
00079      */
00080     static function removeForNode( $nodeID )
00081     {
00082         eZPersistentObject::removeObject( eZTipafriendCounter::definition(),
00083                                           array( 'node_id' => $nodeID ) );
00084     }
00085 
00086     /*!
00087      \deprecated
00088      Use removeForNode instead
00089      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00090      the calls within a db transaction; thus within db->begin and db->commit.
00091      */
00092     function clear( $nodeID )
00093     {
00094         eZTipafriendCounter::removeForNode( $nodeID );
00095     }
00096 
00097     /*!
00098      \deprecated, will be removed in future versions of eZP
00099      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00100      the calls within a db transaction; thus within db->begin and db->commit.
00101      */
00102     function increase()
00103     {
00104     }
00105 
00106     static function fetch( $nodeID, $asObject = true )
00107     {
00108         return eZPersistentObject::fetchObject( eZTipafriendCounter::definition(),
00109                                                 null,
00110                                                 array( 'node_id' => $nodeID ),
00111                                                 $asObject );
00112     }
00113 
00114     /*!
00115      \static
00116      Removes all counters for tipafriend functionality.
00117      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00118      the calls within a db transaction; thus within db->begin and db->commit.
00119     */
00120     static function cleanup()
00121     {
00122         $db = eZDB::instance();
00123         $db->query( "DELETE FROM eztipafriend_counter" );
00124     }
00125 
00126     /// \privatesection
00127     public $NodeID;
00128     public $Count;
00129 }
00130 
00131 ?>