/** * Static function to save content likes and dislikes in the database. * TODO: Resource intensive, needs to be optimized. * @param integer $cid Content ID of the liked/disliked content. * @param integer $uid User ID who liked/disliked content. * @param integer $like User Preference (1:Like | -1:Dislike) * @return integer Like ID identifying the User, Content and Preference (like/dislike) */ public static function like($cid,$uid,$like) { activity::removelike($cid,$uid); $sql="Insert into content_like(cl_cid,cl_uid,cl_value) values('".$cid."','".$uid."','".$like."') returning cl_id"; $likeid=pg_fetch_result(dbquery($sql),0,0); if($likeid) { if($like==1) $sql="Update content set cn_likes=cn_likes+1 where cn_id=$cid"; else if($like==-1) $sql="Update content set cn_dislikes=cn_dislikes+1 where cn_id=$cid"; dbquery($sql); } return $likeid; }