[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZViewCounter class
   4  //
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  //!! eZKernel
  29  //! The class eZViewCounter
  30  /*!
  31  
  32  */
  33  
  34  include_once ( "lib/ezdb/classes/ezdb.php" );
  35  include_once ( "kernel/classes/ezpersistentobject.php" );
  36  include_once ( "kernel/classes/ezcontentclassgroup.php" );
  37  
  38  class eZViewCounter extends eZPersistentObject
  39  {
  40      function eZViewCounter( $row )
  41      {
  42          $this->eZPersistentObject( $row );
  43      }
  44  
  45      function definition()
  46      {
  47          return array( "fields" => array( "node_id" => array( 'name' => "NodeID",
  48                                                               'datatype' => 'integer',
  49                                                               'default' => 0,
  50                                                               'required' => true,
  51                                                               'foreign_class' => 'eZContentObjectTreeNode',
  52                                                               'foreign_attribute' => 'node_id',
  53                                                               'multiplicity' => '1..*' ),
  54                                           "count" => array( 'name' => "Count",
  55                                                             'datatype' => 'integer',
  56                                                             'default' => 0,
  57                                                             'required' => true ) ),
  58                        "keys" => array( "node_id" ),
  59                        'relations' => array( 'node_id' => array( 'class' => 'ezcontentobjecttreenode',
  60                                                                  'field' => 'node_id' ) ),
  61                        "class_name" => "eZViewCounter",
  62                        "sort" => array( "count" => "desc" ),
  63                        "name" => "ezview_counter" );
  64      }
  65  
  66      function create( $node_id )
  67      {
  68          $row = array("node_id" => $node_id,
  69                       "count" => 0 );
  70          return new eZViewCounter( $row );
  71      }
  72  
  73      /*!
  74       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  75       the calls within a db transaction; thus within db->begin and db->commit.
  76       */
  77      function remove( $node_id )
  78      {
  79          eZPersistentObject::removeObject( eZViewCounter::definition(),
  80                                            array("node_id" => $node_id ) );
  81      }
  82  
  83      /*!
  84       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  85       the calls within a db transaction; thus within db->begin and db->commit.
  86       */
  87      function clear( $node_id )
  88      {
  89          $counter = eZViewCounter::fetch( $node_id );
  90          if ( $counter != null )
  91          {
  92              $counter->setAttribute( 'count', 0 );
  93              $counter->store();
  94          }
  95      }
  96  
  97      /*!
  98       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  99       the calls within a db transaction; thus within db->begin and db->commit.
 100       */
 101      function increase()
 102      {
 103          $currentCount = $this->attribute( 'count' );
 104          $newCount = $currentCount + 1;
 105          $this->setAttribute( 'count', $newCount );
 106          $this->store();
 107      }
 108  
 109      function fetch( $node_id, $asObject = true )
 110      {
 111          return eZPersistentObject::fetchObject( eZViewCounter::definition(),
 112                                                  null,
 113                                                  array("node_id" => $node_id ),
 114                                                  $asObject );
 115      }
 116  
 117      function fetchTopList( $classID = false, $sectionID = false, $offset = false, $limit = false )
 118      {
 119          if ( !$classID && !$sectionID )
 120          {
 121  
 122              return  eZPersistentObject::fetchObjectList( eZViewCounter::definition(),
 123                                                           null,
 124                                                           null,
 125                                                           null,
 126                                                           array( 'length' => $limit, 'offset' => $offset ),
 127                                                           false );
 128          }
 129  
 130          $queryPart = "";
 131          if ( $classID != false )
 132          {
 133              $classID = (int)$classID;
 134              $queryPart .= "ezcontentobject.contentclass_id=$classID AND ";
 135          }
 136  
 137          if ( $sectionID != false )
 138          {
 139              $sectionID = (int)$sectionID;
 140              $queryPart .= "ezcontentobject.section_id=$sectionID AND ";
 141          }
 142  
 143          $db =& eZDB::instance();
 144          $query = "SELECT ezview_counter.*
 145                    FROM
 146                           ezcontentobject_tree,
 147                           ezcontentobject,
 148                           ezview_counter
 149                    WHERE
 150                           ezview_counter.node_id=ezcontentobject_tree.node_id AND
 151                           $queryPart
 152                           ezcontentobject_tree.contentobject_id=ezcontentobject.id
 153                    ORDER BY ezview_counter.count DESC";
 154  
 155          if ( !$offset && !$limit )
 156          {
 157              $countListArray = $db->arrayQuery( $query );
 158          }
 159          else
 160          {
 161              $countListArray = $db->arrayQuery( $query, array( "offset" => $offset,
 162                                                                 "limit" => $limit ) );
 163          }
 164          return $countListArray;
 165      }
 166  
 167      /// \privatesection
 168      var $NodeID;
 169      var $Count;
 170  }
 171  
 172  ?>


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