Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentbrowserecent.php
Go to the documentation of this file.
1 <?php
33 class eZContentBrowseRecent extends eZPersistentObject
34 {
35 static function definition()
36 {
37 return array( "fields" => array( "id" => array( 'name' => 'ID',
38 'datatype' => 'integer',
39 'default' => 0,
40 'required' => true ),
41 "user_id" => array( 'name' => 'UserID',
42 'datatype' => 'integer',
43 'default' => 0,
44 'required' => true,
45 'foreign_class' => 'eZUser',
46 'foreign_attribute' => 'contentobject_id',
47 'multiplicity' => '1..*' ),
48 "node_id" => array( 'name' => "NodeID",
49 'datatype' => 'integer',
50 'default' => 0,
51 'required' => true,
52 'foreign_class' => 'eZContentObjectTreeNode',
53 'foreign_attribute' => 'node_id',
54 'multiplicity' => '1..*' ),
55 "created" => array( 'name' => 'Created',
56 'datatype' => 'integer',
57 'default' => 0,
58 'required' => true ),
59 "name" => array( 'name' => "Name",
60 'datatype' => 'string',
61 'default' => '',
62 'required' => true ) ),
63 "keys" => array( "id" ),
64 "function_attributes" => array( 'node' => 'fetchNode',
65 'contentobject_id' => 'contentObjectID' ),
66 "increment_key" => "id",
67 "sort" => array( "id" => "asc" ),
68 "class_name" => "eZContentBrowseRecent",
69 "name" => "ezcontentbrowserecent" );
70
71 }
72
77 static function fetch( $recentID )
78 {
79 return eZPersistentObject::fetchObject( eZContentBrowseRecent::definition(),
80 null, array( 'id' => $recentID ), true );
81 }
82
87 static function fetchListForUser( $userID )
88 {
89 return eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
90 null, array( 'user_id' => $userID ),
91 array( 'created' => 'desc' ), null, true );
92 }
93
100 static function maximumRecentItems( $userID )
101 {
102 $ini = eZINI::instance( 'browse.ini' );
103 $maximum = $ini->variable( 'BrowseSettings', 'MaximumRecentItems' );
104 return $maximum;
105 }
106
117 static function createNew( $userID, $nodeID, $nodeName )
118 {
119 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
120 array(),
121 array( 'user_id' => $userID ),
122 false,
123 null,
124 false,
125 false,
126 array( array( 'operation' => 'count( * )',
127 'name' => 'count' ) ) );
128 $matchingRecentList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
129 null,
130 array( 'user_id' => $userID,
131 'node_id' => $nodeID ),
132 null,
133 null,
134 true );
135 // If we already have the node in the list just return
136 if ( count( $matchingRecentList ) > 0 )
137 {
138 $oldItem = $matchingRecentList[0];
139 $oldItem->setAttribute( 'created', time() );
140 $oldItem->store();
141 return $oldItem;
142 }
143 $recentCount = 0;
144 if ( isset( $recentCountList[0] ) and count( $recentCountList[0] ) > 0 )
145 $recentCount = $recentCountList[0]['count'];
146 $maximumCount = eZContentBrowseRecent::maximumRecentItems( $userID );
147 // Remove oldest item
148
149 $db = eZDB::instance();
150 $db->begin();
151 if ( $recentCount > $maximumCount )
152 {
153 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
154 null,
155 array( 'user_id' => $userID ),
156 array( 'created' => 'asc' ),
157 array( 'length' => ( $recentCount - $maximumCount ), 'offset' => 0 ),
158 true );
159 foreach($recentCountList as $countList)
160 {
161 $eldest = $countList;
162 $eldest->remove();
163 }
164
165 }
166
167 $recent = new eZContentBrowseRecent( array( 'user_id' => $userID,
168 'node_id' => $nodeID,
169 'name' => $nodeName,
170 'created' => time() ) );
171 $recent->store();
172 $db->commit();
173 return $recent;
174 }
175
179 function fetchNode()
180 {
181 return eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) );
182 }
183
187 function contentObjectID()
188 {
189 $node = $this->fetchNode();
190 if ( $node )
191 {
192 return $node->attribute( 'contentobject_id' );
193 }
194
195 return false;
196 }
197
202 static function removeRecentByNodeID( $nodeID )
203 {
204 $db = eZDB::instance();
205 $nodeID =(int) $nodeID;
206 $db->query( "DELETE FROM ezcontentbrowserecent WHERE node_id=$nodeID" );
207 }
208
213 static function updateNodeID( $oldNodeID, $newNodeID )
214 {
215 $db = eZDB::instance();
216 $oldNodeID =(int) $oldNodeID;
217 $newNodeID =(int) $newNodeID;
218 $db->query( "UPDATE ezcontentbrowserecent SET node_id=$newNodeID WHERE node_id=$oldNodeID" );
219 }
220
227 static function cleanup()
228 {
229 $db = eZDB::instance();
230 $db->query( "DELETE FROM ezcontentbrowserecent" );
231 }
232 }
233
234 ?>
eZContentBrowseRecent
Handles recent nodes for users.
Definition: ezcontentbrowserecent.php:34
eZContentBrowseRecent\maximumRecentItems
static maximumRecentItems( $userID)
Definition: ezcontentbrowserecent.php:100
eZContentBrowseRecent\definition
static definition()
Definition: ezcontentbrowserecent.php:35
eZContentBrowseRecent\fetchListForUser
static fetchListForUser( $userID)
Definition: ezcontentbrowserecent.php:87
eZContentBrowseRecent\fetchNode
fetchNode()
Definition: ezcontentbrowserecent.php:179
eZContentBrowseRecent\cleanup
static cleanup()
Definition: ezcontentbrowserecent.php:227
eZContentBrowseRecent\removeRecentByNodeID
static removeRecentByNodeID( $nodeID)
Definition: ezcontentbrowserecent.php:202
eZContentBrowseRecent\contentObjectID
contentObjectID()
Definition: ezcontentbrowserecent.php:187
eZContentBrowseRecent\createNew
static createNew( $userID, $nodeID, $nodeName)
Definition: ezcontentbrowserecent.php:117
eZContentBrowseRecent\updateNodeID
static updateNodeID( $oldNodeID, $newNodeID)
Definition: ezcontentbrowserecent.php:213
eZContentBrowseRecent\fetch
static fetch( $recentID)
Definition: ezcontentbrowserecent.php:77
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
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\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.