00001 <?php
00002
00015 import('classes.views.ViewsDAO');
00016
00017 class ViewsDAO extends DAO {
00021 function ViewsDAO() {
00022 parent::DAO();
00023 }
00024
00032 function recordView($assocType, $assocId, $userId) {
00033 $this->Replace(
00034 'item_views',
00035 array(
00036 'date_last_viewed' => strftime('%Y-%m-%d %H:%M:%S'),
00037 'assoc_type' => (int) $assocType,
00038 'assoc_id' => $assocId,
00039 'user_id' => (int) $userId
00040 ),
00041 array('assoc_type', 'assoc_id', 'user_id')
00042 );
00043 }
00044
00052 function getLastViewDate($assocType, $assocId, $userId = null) {
00053 $params = array((int)$assocType, $assocId);
00054 if ($userId) $params[] = (int)$userId;
00055 $result = $this->retrieve(
00056 'SELECT date_last_viewed
00057 FROM item_views
00058 WHERE assoc_type = ?
00059 AND assoc_id = ?' .
00060 ($userId ? ' AND user_id = ?' : ''),
00061 $params
00062 );
00063 return (isset($result->fields[0])) ? $result->fields[0] : false;
00064 }
00065
00072 function moveViews($assocType, $oldAssocId, $newAssocId) {
00073 return $this->update(
00074 'UPDATE item_views SET assoc_id = ? WHERE assoc_type = ? AND assoc_id = ?',
00075 array($newAssocId, (int)$assocType, $oldAssocId)
00076 );
00077 }
00078
00084 function deleteViews($assocType, $assocId) {
00085 return $this->update(
00086 'DELETE FROM item_views WHERE assoc_type = ? AND assoc_id = ?',
00087 array((int)$assocType, $assocId)
00088 );
00089 }
00090 }
00091
00092 ?>