replace( 'item_views', array( 'date_last_viewed' => strftime('%Y-%m-%d %H:%M:%S'), 'assoc_type' => (int) $assocType, 'assoc_id' => $assocId, 'user_id' => (int) $userId ), array('assoc_type', 'assoc_id', 'user_id') ); } /** * Get the timestamp of the last view. * @param $assocType integer * @param $assocId string * @param $userId integer * @return string|boolean Datetime of last view. False if no view found. */ function getLastViewDate($assocType, $assocId, $userId = null) { $params = array((int)$assocType, $assocId); if ($userId) $params[] = (int)$userId; $result = $this->retrieve( 'SELECT date_last_viewed FROM item_views WHERE assoc_type = ? AND assoc_id = ?' . ($userId ? ' AND user_id = ?' : ''), $params ); return (isset($result->fields[0])) ? $result->fields[0] : false; } /** * Move views from one assoc object to another. * @param $assocType integer One of the ASSOC_TYPE_* constants. * @param $oldAssocId string * @param $newAssocId string */ function moveViews($assocType, $oldAssocId, $newAssocId) { return $this->update( 'UPDATE item_views SET assoc_id = ? WHERE assoc_type = ? AND assoc_id = ?', array($newAssocId, (int)$assocType, $oldAssocId) ); } /** * Delete views of an assoc object. * @param $assocType integer One of the ASSOC_TYPE_* constants. * @param $assocId string */ function deleteViews($assocType, $assocId) { return $this->update( 'DELETE FROM item_views WHERE assoc_type = ? AND assoc_id = ?', array((int)$assocType, $assocId) ); } } ?>