00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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 eZViewCounter extends eZPersistentObject
00041 {
00042 function eZViewCounter( $row )
00043 {
00044 $this->eZPersistentObject( $row );
00045 }
00046
00047 function definition()
00048 {
00049 return array( "fields" => array( "node_id" => array( 'name' => "NodeID",
00050 'datatype' => 'integer',
00051 'default' => 0,
00052 'required' => true,
00053 'foreign_class' => 'eZContentObjectTreeNode',
00054 'foreign_attribute' => 'node_id',
00055 'multiplicity' => '1..*' ),
00056 "count" => array( 'name' => "Count",
00057 'datatype' => 'integer',
00058 'default' => 0,
00059 'required' => true ) ),
00060 "keys" => array( "node_id" ),
00061 'relations' => array( 'node_id' => array( 'class' => 'ezcontentobjecttreenode',
00062 'field' => 'node_id' ) ),
00063 "class_name" => "eZViewCounter",
00064 "sort" => array( "count" => "desc" ),
00065 "name" => "ezview_counter" );
00066 }
00067
00068 function create( $node_id )
00069 {
00070 $row = array("node_id" => $node_id,
00071 "count" => 0 );
00072 return new eZViewCounter( $row );
00073 }
00074
00075
00076
00077
00078
00079 function remove( $node_id )
00080 {
00081 eZPersistentObject::removeObject( eZViewCounter::definition(),
00082 array("node_id" => $node_id ) );
00083 }
00084
00085
00086
00087
00088
00089 function clear( $node_id )
00090 {
00091 $counter = eZViewCounter::fetch( $node_id );
00092 if ( $counter != null )
00093 {
00094 $counter->setAttribute( 'count', 0 );
00095 $counter->store();
00096 }
00097 }
00098
00099
00100
00101
00102
00103 function increase()
00104 {
00105 $currentCount = $this->attribute( 'count' );
00106 $newCount = $currentCount + 1;
00107 $this->setAttribute( 'count', $newCount );
00108 $this->store();
00109 }
00110
00111 function fetch( $node_id, $asObject = true )
00112 {
00113 return eZPersistentObject::fetchObject( eZViewCounter::definition(),
00114 null,
00115 array("node_id" => $node_id ),
00116 $asObject );
00117 }
00118
00119 function fetchTopList( $classID = false, $sectionID = false, $offset = false, $limit = false )
00120 {
00121 if ( !$classID && !$sectionID )
00122 {
00123
00124 return eZPersistentObject::fetchObjectList( eZViewCounter::definition(),
00125 null,
00126 null,
00127 null,
00128 array( 'length' => $limit, 'offset' => $offset ),
00129 false );
00130 }
00131
00132 $queryPart = "";
00133 if ( $classID != false )
00134 {
00135 $classID = (int)$classID;
00136 $queryPart .= "ezcontentobject.contentclass_id=$classID AND ";
00137 }
00138
00139 if ( $sectionID != false )
00140 {
00141 $sectionID = (int)$sectionID;
00142 $queryPart .= "ezcontentobject.section_id=$sectionID AND ";
00143 }
00144
00145 $db =& eZDB::instance();
00146 $query = "SELECT ezview_counter.*
00147 FROM
00148 ezcontentobject_tree,
00149 ezcontentobject,
00150 ezview_counter
00151 WHERE
00152 ezview_counter.node_id=ezcontentobject_tree.node_id AND
00153 $queryPart
00154 ezcontentobject_tree.contentobject_id=ezcontentobject.id
00155 ORDER BY ezview_counter.count DESC";
00156
00157 if ( !$offset && !$limit )
00158 {
00159 $countListArray = $db->arrayQuery( $query );
00160 }
00161 else
00162 {
00163 $countListArray = $db->arrayQuery( $query, array( "offset" => $offset,
00164 "limit" => $limit ) );
00165 }
00166 return $countListArray;
00167 }
00168
00169
00170 var $NodeID;
00171 var $Count;
00172 }
00173
00174 ?>