public static function find_popular($link_class = "Itunes", $user_id = 0) { $sql = "SELECT l.* FROM " . $link_class::get_table_name() . " l"; $sql .= " JOIN popular p ON p.id = l.id AND p.type = '" . $link_class::get_table_name() . "' LIMIT 18"; $links = $link_class::find_by_sql($sql); $movies = array(); foreach ($links as $link) { $movie = self::find_by_id($link->id); $movie->link = $link; if ($user_id > 0 && Favorite::find($user_id, $link->id)) { $movie->favorited = true; } $movies[] = $movie; } return !empty($movies) ? $movies : false; }
public function destroyFavorite($id) { $fav = Favorite::find($id); $result = $fav->delete(); return Response::json(['data' => $result], 200); }
if (empty($_POST['user_id']) || empty($_POST['movie_id']) || empty($_POST['type']) || empty($_POST['key'])) { sendResponse(400, "Invalid request. Please provide \"key\", \"user_id\", \"type\", and \"movie_id\" parameters."); } else { if ($_POST['key'] != API_KEY) { sendResponse(403, "Invalid API key."); } else { if ($_POST["type"] == "create") { $favorite = new Favorite(); $favorite->user_id = $_POST['user_id']; $favorite->movie_id = $_POST['movie_id']; if ($favorite->create()) { sendResponse(200, json_encode("Success")); } else { sendResponse(403, "An error occurred."); } } else { if ($_POST["type"] == "delete") { $favorite = Favorite::find($_POST['user_id'], $_POST['movie_id']); if ($favorite->delete()) { sendResponse(200, json_encode("Success")); } else { sendResponse(403, "An error occurred."); } } } } } } else { sendResponse(403, "No request."); } }