function PerformAction($actionName, $championId, $userId) { $error = new Error(); if (strcmp($actionName, "Add") == 0) { $error = ChampionFacade::AddChampionToUser($championId, $userId); } else { if (strcmp($actionName, "Remove") == 0) { $error = ChampionFacade::RemoveChampionFromUser($championId, $userId); } else { $error = new Error(Error::InvalidParameter, "Invalid action: " . $actionName); } } return $error; }
function ValidateParameters($championName, $file) { if (strlen($championName) == 0) { return new Error(Error::InvalidParameter, "Invalid champion name."); } if (ChampionFacade::DoesChampionExists($championName)) { return new Error(Error::NotUniqueValue, "Provided champion already exists."); } if (!isset($file) || $file === null) { return new Error(Error::InvalidFile, "File has not been uploaded."); } $error = ValidateFile($file); if ($error->code != Error::NoError) { return $error; } return new Error(); }
require_once $_SERVER['DOCUMENT_ROOT'] . "/include/header.php"; Site::RequiresLoggedInUser("/log-in.php"); ?> <h1>Add or remove champions owned by you</h1> <form method="post" action="/process/manage-champions.php" accept-charset="UTF-8"> <table class="form-table"> <tr> <td> <?php Form::Label("Champion", "champion"); ?> <br /> <?php Form::Combobox("champion", "champion", ChampionFacade::GetAllChampions()); ?> </td> </tr> <tr> <td class="align-center"> <?php Form::SubmitButton("submit", "Add"); ?> <?php Form::SubmitButton("submit", "Remove"); ?> </td> </tr> </table>
function DisplayMutualChampions() { $selectedPlayerIds = GetSelectedPlayers(); if (array_count_values($selectedPlayerIds)["0"] == 5) { print "<p>Select players to display their mutual champions."; return; } $champions = ChampionFacade::GetMutualChampions($selectedPlayerIds); if ($champions->error->code != Error::NoError) { Site::DisplayError($champions->error, "error-box"); return; } print "<p class=\"align-center\">"; foreach ($champions->result as $champion) { print "<img class=\"champion-image\" alt=\"" . $champion["name"] . "\" src=\"" . $champion["imagePath"] . "\"/>"; } }