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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 include_once( "lib/ezdb/classes/ezdb.php" );
00058 include_once( "lib/ezutils/classes/ezdebug.php" );
00059 include_once( "kernel/classes/ezpersistentobject.php" );
00060
00061 class eZContentBrowseRecent extends eZPersistentObject
00062 {
00063
00064
00065
00066 function eZContentBrowseRecent( $row )
00067 {
00068 $this->eZPersistentObject( $row );
00069 }
00070
00071
00072
00073
00074 function definition()
00075 {
00076 return array( "fields" => array( "id" => array( 'name' => 'ID',
00077 'datatype' => 'integer',
00078 'default' => 0,
00079 'required' => true ),
00080 "user_id" => array( 'name' => 'UserID',
00081 'datatype' => 'integer',
00082 'default' => 0,
00083 'required' => true,
00084 'foreign_class' => 'eZUser',
00085 'foreign_attribute' => 'contentobject_id',
00086 'multiplicity' => '1..*' ),
00087 "node_id" => array( 'name' => "NodeID",
00088 'datatype' => 'integer',
00089 'default' => 0,
00090 'required' => true,
00091 'foreign_class' => 'eZContentObjectTreeNode',
00092 'foreign_attribute' => 'node_id',
00093 'multiplicity' => '1..*' ),
00094 "created" => array( 'name' => 'Created',
00095 'datatype' => 'integer',
00096 'default' => 0,
00097 'required' => true ),
00098 "name" => array( 'name' => "Name",
00099 'datatype' => 'string',
00100 'default' => '',
00101 'required' => true ) ),
00102 "keys" => array( "id" ),
00103 "function_attributes" => array( 'node' => 'fetchNode',
00104 'contentobject_id' => 'contentObjectID' ),
00105 "increment_key" => "id",
00106 "sort" => array( "id" => "asc" ),
00107 "class_name" => "eZContentBrowseRecent",
00108 "name" => "ezcontentbrowserecent" );
00109
00110 }
00111
00112
00113
00114
00115
00116 function fetch( $recentID )
00117 {
00118 return eZPersistentObject::fetchObject( eZContentBrowseRecent::definition(),
00119 null, array( 'id' => $recentID ), true );
00120 }
00121
00122
00123
00124
00125
00126 function fetchListForUser( $userID )
00127 {
00128 return eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
00129 null, array( 'user_id' => $userID ),
00130 array( 'created' => 'desc' ), null, true );
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 function maximumRecentItems( $userID )
00140 {
00141 include_once( 'lib/ezutils/classes/ezini.php' );
00142 $ini =& eZINI::instance( 'browse.ini' );
00143 $maximum = $ini->variable( 'BrowseSettings', 'MaximumRecentItems' );
00144 return $maximum;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 function &createNew( $userID, $nodeID, $nodeName )
00158 {
00159 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
00160 array(),
00161 array( 'user_id' => $userID ),
00162 false,
00163 null,
00164 false,
00165 array( 'user_id' ),
00166 array( array( 'operation' => 'count( * )',
00167 'name' => 'count' ) ) );
00168 $matchingRecentList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
00169 null,
00170 array( 'user_id' => $userID,
00171 'node_id' => $nodeID ),
00172 null,
00173 null,
00174 true );
00175
00176 if ( count( $matchingRecentList ) > 0 )
00177 {
00178 $oldItem =& $matchingRecentList[0];
00179 $oldItem->setAttribute( 'created', mktime() );
00180 $oldItem->store();
00181 return $oldItem;
00182 }
00183 $recentCount = 0;
00184 if ( isset( $recentCountList[0] ) and count( $recentCountList[0] ) > 0 )
00185 $recentCount = $recentCountList[0]['count'];
00186 $maximumCount = eZContentBrowseRecent::maximumRecentItems( $userID );
00187
00188
00189 $db =& eZDB::instance();
00190 $db->begin();
00191 if ( $recentCount > $maximumCount )
00192 {
00193 $recentCountList = eZPersistentObject::fetchObjectList( eZContentBrowseRecent::definition(),
00194 null,
00195 array( 'user_id' => $userID ),
00196 array( 'created' => 'asc' ),
00197 array( 'length' => ( $recentCount - $maximumCount ), 'offset' => 0 ),
00198 true );
00199 foreach($recentCountList as $countList)
00200 {
00201 $eldest = $countList;
00202 $eldest->remove();
00203 }
00204
00205 }
00206
00207 $recent = new eZContentBrowseRecent( array( 'user_id' => $userID,
00208 'node_id' => $nodeID,
00209 'name' => $nodeName,
00210 'created' => time() ) );
00211 $recent->store();
00212 $db->commit();
00213 return $recent;
00214 }
00215
00216
00217
00218
00219 function &fetchNode()
00220 {
00221 $node = eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) );
00222 return $node;
00223 }
00224
00225
00226
00227
00228 function &contentObjectID()
00229 {
00230 $node =& $this->fetchNode();
00231 if ( $node )
00232 $objectID = $node->attribute( 'contentobject_id' );
00233 else
00234 $objectID = false;
00235 return $objectID;
00236 }
00237
00238
00239
00240
00241
00242 function removeRecentByNodeID( $nodeID )
00243 {
00244 $db =& eZDB::instance();
00245 $nodeID =(int) $nodeID;
00246 $db->query( "DELETE FROM ezcontentbrowserecent WHERE node_id=$nodeID" );
00247 }
00248
00249
00250
00251
00252
00253 function updateNodeID( $oldNodeID, $newNodeID )
00254 {
00255 $db =& eZDB::instance();
00256 $oldNodeID =(int) $oldNodeID;
00257 $newNodeID =(int) $newNodeID;
00258 $db->query( "UPDATE ezcontentbrowserecent SET node_id=$newNodeID WHERE node_id=$oldNodeID" );
00259 }
00260
00261
00262
00263
00264
00265
00266
00267 function cleanup()
00268 {
00269 $db =& eZDB::instance();
00270 $db->query( "DELETE FROM ezcontentbrowserecent" );
00271 }
00272 }
00273
00274 ?>