static function createNew($userID, $nodeID, $nodeName) { $recentCountList = eZPersistentObject::fetchObjectList(eZContentBrowseRecent::definition(), array(), array('user_id' => $userID), false, null, false, false, array(array('operation' => 'count( * )', 'name' => 'count'))); $matchingRecentList = eZPersistentObject::fetchObjectList(eZContentBrowseRecent::definition(), null, array('user_id' => $userID, 'node_id' => $nodeID), null, null, true); // If we already have the node in the list just return if (count($matchingRecentList) > 0) { $oldItem = $matchingRecentList[0]; $oldItem->setAttribute('created', time()); $oldItem->store(); return $oldItem; } $recentCount = 0; if (isset($recentCountList[0]) and count($recentCountList[0]) > 0) { $recentCount = $recentCountList[0]['count']; } $maximumCount = eZContentBrowseRecent::maximumRecentItems($userID); // Remove oldest item $db = eZDB::instance(); $db->begin(); if ($recentCount > $maximumCount) { $recentCountList = eZPersistentObject::fetchObjectList(eZContentBrowseRecent::definition(), null, array('user_id' => $userID), array('created' => 'asc'), array('length' => $recentCount - $maximumCount, 'offset' => 0), true); foreach ($recentCountList as $countList) { $eldest = $countList; $eldest->remove(); } } $recent = new eZContentBrowseRecent(array('user_id' => $userID, 'node_id' => $nodeID, 'name' => $nodeName, 'created' => time())); $recent->store(); $db->commit(); return $recent; }