[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZContentBrowseRecent class 4 // 5 // Created on: <30-Apr-2003 13:04:11 sp> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezcontentbrowserecent.php 30 */ 31 32 /*! 33 \class eZContentBrowseRecent ezcontentbrowserecent.php 34 \brief Handles recent nodes for users 35 36 Allows the creation and fetching of recent lists for users. 37 The recent list is used in the browse page to allow quick navigation and selection. 38 39 Creating a new recent item is done with 40 \code 41 $userID = eZUser::currentUserID(); 42 $nodeID = 2; 43 $nodeName = 'Node'; 44 eZContentBrowseRecent::createNew( $userID, $nodeID, $nodeName ) 45 \endcode 46 47 Fetching the list is done with 48 \code 49 $userID = eZUser::currentUserID(); 50 eZContentBrowseRecent::fetchListForUser( $userID ) 51 \endcode 52 53 */ 54 55 include_once ( "lib/ezdb/classes/ezdb.php" ); 56 include_once ( "lib/ezutils/classes/ezdebug.php" ); 57 include_once ( "kernel/classes/ezpersistentobject.php" ); 58 59 class eZContentBrowseRecent extends eZPersistentObject 60 { 61 /*! 62 \reimp 63 */ 64 function eZContentBrowseRecent( $row ) 65 { 66 $this->eZPersistentObject( $row ); 67 } 68 69 /*! 70 \reimp 71 */ 72 function definition() 73 { 74 return array( "fields" => array( "id" => array( 'name' => 'ID', 75 'datatype' => 'integer', 76 'default' => 0, 77 'required' => true ), 78 "user_id" => array( 'name' => 'UserID', 79 'datatype' => 'integer', 80 'default' => 0, 81 'required' => true, 82 'foreign_class' => 'eZUser', 83 'foreign_attribute' => 'contentobject_id', 84 'multiplicity' => '1..*' ), 85 "node_id" => array( 'name' => "NodeID", 86 'datatype' => 'integer', 87 'default' => 0, 88 'required' => true, 89 'foreign_class' => 'eZContentObjectTreeNode', 90 'foreign_attribute' => 'node_id', 91 'multiplicity' => '1..*' ), 92 "created" => array( 'name' => 'Created', 93 'datatype' => 'integer', 94 'default' => 0, 95 'required' => true ), 96 "name" => array( 'name' => "Name", 97 'datatype' => 'string', 98 'default' => '', 99 'required' => true ) ), 100 "keys" => array( "id" ), 101 "function_attributes" => array( 'node' => 'fetchNode', 102 'contentobject_id' => 'contentObjectID' ), 103 "increment_key" => "id", 104 "sort" => array( "id" => "asc" ), 105 "class_name" => "eZContentBrowseRecent", 106 "name" => "ezcontentbrowserecent" ); 107 108 } 109 110 /*! 111 \static 112 \return the recent item \a $recentID 113 */ 114 function fetch( $recentID ) 115 { 116 return eZPersistentObject::fetchObject( eZContentBrowseRecent::definition(), 117 null, array( 'id' => $recentID ), true ); 118 } 119 120 /*! 121 \static 122 \return the recent list for the user identifier by \a $userID. 123 */ 124 function fetchListForUser( $userID ) 125 { 126 return eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(), 127 null, array( 'user_id' => $userID ), 128 array( 'created' => 'desc' ), null, true ); 129 } 130 131 /*! 132 \static 133 \return the maximum number of recent items for user \a $userID. 134 The default value is read from MaximumRecentItems from group BrowseSettings in browse.ini. 135 \note Currently all users get the same default maximum amount 136 */ 137 function maximumRecentItems( $userID ) 138 { 139 include_once ( 'lib/ezutils/classes/ezini.php' ); 140 $ini =& eZINI::instance( 'browse.ini' ); 141 $maximum = $ini->variable( 'BrowseSettings', 'MaximumRecentItems' ); 142 return $maximum; 143 } 144 145 /*! 146 \static 147 Tries to create a new recent item and returns it. 148 If the node ID \a $nodeID already exists as a recent item nothing is done and the old item is returned. 149 150 It will also remove items when the maximum number of items for the user \a $userID is exceeded. 151 \sa maximumRecentItems 152 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 153 the calls within a db transaction; thus within db->begin and db->commit. 154 */ 155 function &createNew( $userID, $nodeID, $nodeName ) 156 { 157 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(), 158 array(), 159 array( 'user_id' => $userID ), 160 false, 161 null, 162 false, 163 array( 'user_id' ), 164 array( array( 'operation' => 'count( * )', 165 'name' => 'count' ) ) ); 166 $matchingRecentList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(), 167 null, 168 array( 'user_id' => $userID, 169 'node_id' => $nodeID ), 170 null, 171 null, 172 true ); 173 // If we already have the node in the list just return 174 if ( count( $matchingRecentList ) > 0 ) 175 { 176 $oldItem =& $matchingRecentList[0]; 177 $oldItem->setAttribute( 'created', mktime() ); 178 $oldItem->store(); 179 return $oldItem; 180 } 181 $recentCount = 0; 182 if ( isset( $recentCountList[0] ) and count( $recentCountList[0] ) > 0 ) 183 $recentCount = $recentCountList[0]['count']; 184 $maximumCount = eZContentBrowseRecent::maximumRecentItems( $userID ); 185 // Remove oldest item 186 187 $db =& eZDB::instance(); 188 $db->begin(); 189 if ( $recentCount > $maximumCount ) 190 { 191 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(), 192 null, 193 array( 'user_id' => $userID ), 194 array( 'created' => 'asc' ), 195 array( 'length' => ( $recentCount - $maximumCount ), 'offset' => 0 ), 196 true ); 197 foreach($recentCountList as $countList) 198 { 199 $eldest = $countList; 200 $eldest->remove(); 201 } 202 203 } 204 205 $recent = new eZContentBrowseRecent( array( 'user_id' => $userID, 206 'node_id' => $nodeID, 207 'name' => $nodeName, 208 'created' => time() ) ); 209 $recent->store(); 210 $db->commit(); 211 return $recent; 212 } 213 214 /*! 215 \return the tree node which this item refers to. 216 */ 217 function &fetchNode() 218 { 219 $node = eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) ); 220 return $node; 221 } 222 223 /*! 224 \return the content object ID of the tree node which this item refers to. 225 */ 226 function &contentObjectID() 227 { 228 $node =& $this->fetchNode(); 229 if ( $node ) 230 $objectID = $node->attribute( 'contentobject_id' ); 231 else 232 $objectID = false; 233 return $objectID; 234 } 235 236 /*! 237 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 238 the calls within a db transaction; thus within db->begin and db->commit. 239 */ 240 function removeRecentByNodeID( $nodeID ) 241 { 242 $db =& eZDB::instance(); 243 $nodeID =(int) $nodeID; 244 $db->query( "DELETE FROM ezcontentbrowserecent WHERE node_id=$nodeID" ); 245 } 246 247 /*! 248 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 249 the calls within a db transaction; thus within db->begin and db->commit. 250 */ 251 function updateNodeID( $oldNodeID, $newNodeID ) 252 { 253 $db =& eZDB::instance(); 254 $oldNodeID =(int) $oldNodeID; 255 $newNodeID =(int) $newNodeID; 256 $db->query( "UPDATE ezcontentbrowserecent SET node_id=$newNodeID WHERE node_id=$oldNodeID" ); 257 } 258 259 /*! 260 \static 261 Removes all recent entries for all users. 262 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 263 the calls within a db transaction; thus within db->begin and db->commit. 264 */ 265 function cleanup() 266 { 267 $db =& eZDB::instance(); 268 $db->query( "DELETE FROM ezcontentbrowserecent" ); 269 } 270 } 271 272 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |