Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezviewcounter.php
Go to the documentation of this file.
1 <?php
11 class eZViewCounter extends eZPersistentObject
12 {
13 static function definition()
14 {
15 return array( "fields" => array( "node_id" => array( 'name' => "NodeID",
16 'datatype' => 'integer',
17 'default' => 0,
18 'required' => true,
19 'foreign_class' => 'eZContentObjectTreeNode',
20 'foreign_attribute' => 'node_id',
21 'multiplicity' => '1..*' ),
22 "count" => array( 'name' => "Count",
23 'datatype' => 'integer',
24 'default' => 0,
25 'required' => true ) ),
26 "keys" => array( "node_id" ),
27 'relations' => array( 'node_id' => array( 'class' => 'eZContentObjectTreeNode',
28 'field' => 'node_id' ) ),
29 "class_name" => "eZViewCounter",
30 "sort" => array( "count" => "desc" ),
31 "name" => "ezview_counter" );
32 }
33
34 static function create( $node_id )
35 {
36 $row = array("node_id" => $node_id,
37 "count" => 0 );
38 return new eZViewCounter( $row );
39 }
40
45 public static function removeCounter( $node_id )
46 {
47 eZPersistentObject::removeObject( eZViewCounter::definition(),
48 array("node_id" => $node_id ) );
49 }
50
55 static function clear( $node_id )
56 {
57 $counter = eZViewCounter::fetch( $node_id );
58 if ( $counter != null )
59 {
60 $counter->setAttribute( 'count', 0 );
61 $counter->store();
62 }
63 }
64
70 public function increase( $count = 1 )
71 {
72 // The attribute is naively incremented, despite possible updates in the DB.
73 $this->setAttribute( 'count', $this->attribute( 'count' ) + $count );
74 // However, we are not using ->store() here so that we atomatically update
75 // the value of the counter in case it has been updated in parallel.
76 eZDB::instance()->query(
77 "UPDATE ezview_counter " .
78 "SET count = count + " . (int)$count . " " .
79 "WHERE node_id=" . $this->attribute( "node_id" )
80 );
81 }
82
83 static function fetch( $node_id, $asObject = true )
84 {
85 return eZPersistentObject::fetchObject( eZViewCounter::definition(),
86 null,
87 array("node_id" => $node_id ),
88 $asObject );
89 }
90
91 static function fetchTopList( $classID = false, $sectionID = false, $offset = false, $limit = false )
92 {
93 if ( !$classID && !$sectionID )
94 {
95
96 return eZPersistentObject::fetchObjectList( eZViewCounter::definition(),
97 null,
98 null,
99 null,
100 array( 'length' => $limit, 'offset' => $offset ),
101 false );
102 }
103
104 $queryPart = "";
105 if ( $classID != false )
106 {
107 $classID = (int)$classID;
108 $queryPart .= "ezcontentobject.contentclass_id=$classID AND ";
109 }
110
111 if ( $sectionID != false )
112 {
113 $sectionID = (int)$sectionID;
114 $queryPart .= "ezcontentobject.section_id=$sectionID AND ";
115 }
116
117 $db = eZDB::instance();
118 $query = "SELECT ezview_counter.*
119 FROM
120 ezcontentobject_tree,
121 ezcontentobject,
122 ezview_counter
123 WHERE
124 ezview_counter.node_id=ezcontentobject_tree.node_id AND
125 $queryPart
126 ezcontentobject_tree.contentobject_id=ezcontentobject.id
127 ORDER BY ezview_counter.count DESC";
128
129 if ( !$offset && !$limit )
130 {
131 $countListArray = $db->arrayQuery( $query );
132 }
133 else
134 {
135 $countListArray = $db->arrayQuery( $query, array( "offset" => $offset,
136 "limit" => $limit ) );
137 }
138 return $countListArray;
139 }
140
142 public $NodeID;
143 public $Count;
144 }
145
146 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZViewCounter
Definition: ezviewcounter.php:12
eZViewCounter\clear
static clear( $node_id)
Definition: ezviewcounter.php:55
eZViewCounter\definition
static definition()
Definition: ezviewcounter.php:13
eZViewCounter\fetchTopList
static fetchTopList( $classID=false, $sectionID=false, $offset=false, $limit=false)
Definition: ezviewcounter.php:91
eZViewCounter\create
static create( $node_id)
Definition: ezviewcounter.php:34
eZViewCounter\removeCounter
static removeCounter( $node_id)
Definition: ezviewcounter.php:45
eZViewCounter\$NodeID
$NodeID
Definition: ezviewcounter.php:142
eZViewCounter\fetch
static fetch( $node_id, $asObject=true)
Definition: ezviewcounter.php:83
eZViewCounter\increase
increase( $count=1)
Definition: ezviewcounter.php:70
eZViewCounter\$Count
$Count
Definition: ezviewcounter.php:143
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.