public function saveMessage($messageID, $message, $userID = 0) { // Is this a new message? if (!$messageID) { // Message data $message = array('user_id' => $userID, 'poster_id' => session::item('user_id'), 'message' => $message, 'post_date' => date_helper::now()); // Insert message $messageID = $this->db->insert('timeline_messages', $message); // Save timeline action timeline_helper::save('timeline_message_post', $userID, $messageID, 1, 1, false, array(), session::item('user_id'), session::item('timeline_message_post', 'config') === false || session::item('timeline_message_post', 'config') ? 1 : 0); // Action hook hook::action('timeline/messages/insert', session::item('user_id'), $userID, $message['message']); // Do we have user id? if ($userID && $userID != session::item('user_id')) { // Save notification timeline_helper::notice('timeline_message_post', $userID, session::item('user_id')); } } else { // Message data $message = array('message' => $message); $this->db->update('timeline_messages', $message, array('message_id' => $messageID), 1); // Action hook hook::action('timeline/messages/update', $messageID, $message['message']); } return $messageID; }
public function saveComment($commentID, $comment, $resource = '', $userID = 0, $itemID = 0, $table = '', $column = '') { // Is this a new comment? if (!$commentID) { // Get resource ID if (!($resourceID = config::item('resources', 'core', $resource, 'resource_id'))) { return false; } // Comment data $comment['resource_id'] = $resourceID; $comment['user_id'] = $userID; $comment['item_id'] = $itemID; $comment['poster_id'] = session::item('user_id'); $comment['post_date'] = date_helper::now(); // Get table and column names $table = $table ? $table : config::item('resources', 'core', $resource, 'table'); $column = $column ? $column : config::item('resources', 'core', $resource, 'column'); // Insert comment if ($commentID = $this->db->insert('core_comments', $comment)) { // Update comment count $this->db->query("UPDATE `:prefix:" . $table . "` SET `total_comments`=`total_comments`+1 WHERE `" . $column . "`=? LIMIT 1", array($itemID)); // Action hook hook::action('comments/insert', session::item('user_id'), $resourceID, $userID, $itemID, $comment); // Do we have user id? if ($userID && $userID != session::item('user_id')) { // Save notification timeline_helper::notice($resource . '_comment', $userID, session::item('user_id'), $itemID); } } } else { $this->db->update('core_comments', $comment, array('comment_id' => $commentID), 1); // Action hook hook::action('comments/update', $commentID, $comment); } return $commentID; }
public function saveLike($resource, $userID, $itemID, $like, $table = '', $column = '') { // Get resource ID if (!($resourceID = config::item('resources', 'core', $resource, 'resource_id'))) { return false; } // Get table and column names $table = $table ? $table : config::item('resources', 'core', $resource, 'table'); $column = $column ? $column : config::item('resources', 'core', $resource, 'column'); $data = array('resource_id' => $resourceID, 'item_id' => $itemID, 'user_id' => session::item('user_id')); // Like if ($like) { $data['post_date'] = date_helper::now(); // Update total likes if ($retval = $this->db->query("UPDATE `:prefix:" . $table . "` SET `total_likes`=`total_likes`+1 WHERE `" . $column . "`=? LIMIT 1", array($itemID))) { // Save like $this->db->insert('core_likes', $data); // Action hook hook::action('likes/insert', session::item('user_id'), $resourceID, $itemID); // Do we have user id? if ($userID && $userID != session::item('user_id')) { // Save notification timeline_helper::notice($resource . '_like', $userID, session::item('user_id'), $itemID); } } } else { // Update total likes if ($retval = $this->db->query("UPDATE `:prefix:" . $table . "` SET `total_likes`=`total_likes`-1 WHERE `" . $column . "`=? LIMIT 1", array($itemID))) { // Save like if ($this->db->delete('core_likes', $data, 1)) { // Action hook hook::action('likes/unlike', session::item('user_id'), $resourceID, $itemID); // Delete notification timeline_helper::unnotice($resource . '_like', $userID, session::item('user_id'), $itemID); } } } return $retval; }
public function saveVote($resource, $userID, $itemID, $score, $table = '', $column = '') { // Get resource ID if (!($resourceID = config::item('resources', 'core', $resource, 'resource_id'))) { return false; } // Get table and column names $table = $table ? $table : config::item('resources', 'core', $resource, 'table'); $column = $column ? $column : config::item('resources', 'core', $resource, 'column'); $data = array('resource_id' => $resourceID, 'item_id' => $itemID, 'user_id' => session::item('user_id'), 'score' => $score, 'post_date' => date_helper::now()); // Update total votes and score $retval = $this->db->query("UPDATE `:prefix:" . $table . "`\n\t\t\tSET `total_votes`=`total_votes`+1, `total_score`=`total_score`+?, `total_rating`=`total_score`/`total_votes`\n\t\t\tWHERE `" . $column . "`=? LIMIT 1", array($score, $itemID)); if ($retval) { // Save vote $this->db->insert('core_votes', $data); // Action hook hook::action('votes/insert', session::item('user_id'), $resourceID, $itemID, $score); // Do we have user id? if ($userID != session::item('user_id')) { // Save notification timeline_helper::notice($resource . '_vote', $userID, session::item('user_id'), $itemID); } } return $retval; }