+ public function vote_comment($comment_id, $user_id, $like = TRUE)
+ {
+ if ($like)
+ {
+ $col = 'likes';
+ $action = 'like';
+ }
+ else
+ {
+ $col = 'dislikes';
+ $action = 'dislike';
+ }
+
+ $query = $this->db->query("SELECT * FROM `users_actions`
+ WHERE user_id = $user_id
+ AND target_id = $comment_id
+ AND target_type = 'vcomment'
+ AND action = '$action'
+ AND date = CURDATE()");
+ // User already voted today
+ if ($query->num_rows() > 0)
+ return -1;
+
+ $this->db->query("UPDATE `videos_comments`
+ SET $col = $col + 1
+ WHERE id = $comment_id");
+
+ // Mark this action so that the user cannot repeat it today.
+ $this->db->query("INSERT INTO `users_actions`
+ (user_id, action, target_type, target_id, date)
+ VALUES ( $user_id, '$action', 'vcomment', $comment_id, CURDATE() )");
+
+ $query = $this->db->query("SELECT $col FROM `videos_comments`
+ WHERE id = $comment_id");
+
+ if ($query->num_rows() === 1)
+ {
+ $row = $query->row_array();
+ return $row[ $col ];
+ }
+
+ // Error
+ return FALSE;
+ }
+