public function like($post_id) { if ($this->user->data['user_type'] != 1 and $this->user->data['user_type'] != 2) { $json_response = new \phpbb\json_response(); $user_id = $this->user->data['user_id']; if ($post_id and $user_id) { $this->db->sql_query("INSERT INTO " . $this->table_prefix . "post_likes (`post_id`, `user_id`)\n\t\t\t\t\tVALUES ('" . $post_id . "', '" . $user_id . "')"); $err = $this->db->get_sql_error_returned(); if ($err['code'] == 1062) { $json_response->send(['status' => 'already liked']); } } $json_response->send(['status' => 'ok', 'postId' => $post_id, 'message' => $this->getLikeMessage($this->request->variable('like_opt', 'opt2'))]); } }
/** * Wrapper for running queries to generate user feedback on updates * * @param string $sql SQL query to run on the database * @return mixed Query result from db->sql_query() */ protected function sql_query($sql) { $this->queries[] = $sql; $this->db->sql_return_on_error(true); if ($sql === 'begin') { $result = $this->db->sql_transaction('begin'); } else { if ($sql === 'commit') { $result = $this->db->sql_transaction('commit'); } else { $result = $this->db->sql_query($sql); if ($this->db->get_sql_error_triggered()) { $this->errors[] = array('sql' => $this->db->get_sql_error_sql(), 'code' => $this->db->get_sql_error_returned()); } } } $this->db->sql_return_on_error(false); return $result; }