Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ViewsDAO.inc.php
1 <?php
2 
16 define('RECORD_VIEW_RESULT_FAIL', 0);
17 define('RECORD_VIEW_RESULT_EXISTING', 1);
18 define('RECORD_VIEW_RESULT_INSERTED', 2);
19 
20 class ViewsDAO extends DAO {
24  function ViewsDAO() {
25  parent::DAO();
26  }
27 
35  function recordView($assocType, $assocId, $userId) {
36  return $this->replace(
37  'item_views',
38  array(
39  'date_last_viewed' => strftime('%Y-%m-%d %H:%M:%S'),
40  'assoc_type' => (int) $assocType,
41  'assoc_id' => $assocId,
42  'user_id' => (int) $userId
43  ),
44  array('assoc_type', 'assoc_id', 'user_id')
45  );
46  }
47 
55  function getLastViewDate($assocType, $assocId, $userId = null) {
56  $params = array((int)$assocType, $assocId);
57  if ($userId) $params[] = (int)$userId;
58  $result = $this->retrieve(
59  'SELECT date_last_viewed
60  FROM item_views
61  WHERE assoc_type = ?
62  AND assoc_id = ?' .
63  ($userId ? ' AND user_id = ?' : ''),
64  $params
65  );
66  return (isset($result->fields[0])) ? $result->fields[0] : false;
67  }
68 
75  function moveViews($assocType, $oldAssocId, $newAssocId) {
76  return $this->update(
77  'UPDATE item_views SET assoc_id = ? WHERE assoc_type = ? AND assoc_id = ?',
78  array($newAssocId, (int)$assocType, $oldAssocId)
79  );
80  }
81 
87  function deleteViews($assocType, $assocId) {
88  return $this->update(
89  'DELETE FROM item_views WHERE assoc_type = ? AND assoc_id = ?',
90  array((int)$assocType, $assocId)
91  );
92  }
93 }
94 
95 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteViews($assocType, $assocId)
getLastViewDate($assocType, $assocId, $userId=null)
Class for keeping track of item views.
moveViews($assocType, $oldAssocId, $newAssocId)
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:237
recordView($assocType, $assocId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208