public function updateAction() { // Connect to Riot Api and get champion data $key = ''; $api = new Api($key); $champions = $api->staticData()->getChampions(); // Create transaction $manager = new \Phalcon\Mvc\Model\Transaction\Manager(); $transaction = $manager->get(); // Insert champion id and champion name into MySQL foreach ($champions as $champion) { // Remove spaces, periods, and apostrophes from names to better correspond with img names $to_remove = array("'", ".", " "); $to_replace = array("", "", ""); $champion_name = $champion->name; $champion_name = str_replace($to_remove, $to_replace, $champion_name); // Insert champion id and name $new_champion = new Champion(); $new_champion->setTransaction($transaction); $new_champion->save(array("champion_id" => $champion->id, "champion_name" => $champion_name)); print "Inserted: " . $champion->id . " " . $champion_name . "<br>"; } $transaction->commit(); }
} else { return $res->withStatus(400)->write($e->getMessage()); } }); /** * @api {post} /champions Create a new champion * @apiName PostChampion * @apiVersion 1.0.0 * @apiSuccess {Object} champion Champion created */ $this->post('', function ($req, $res, $args) { $champion = new \Champion(); $body = $req->getParsedBody(); $champion->name = $body['name']; $champion->slug = $body['slug']; $champion->save(); if ($champion) { return $res->withStatus(200)->write($champion->toJson()); } else { return $res->withStatus(400)->write('{"error":"there was an error processing your request"}'); } }); /** * @api {put} /champions/:id Updates the champion with ID * @apiName UpdateChampion * @apiVersion 1.0.0 * @apiSuccess {Object} champion Champion updated */ $this->put('/{id}', function ($req, $res, $args) { $id = $args['id']; $champion = $req->getParsedBody();