public function testFree() { $this->client->shouldReceive('baseUrl')->once(); $this->client->shouldReceive('request')->with('v1.2/champion', ['freeToPlay' => 'true', 'api_key' => 'key'])->once()->andReturn(file_get_contents('tests/Json/champion.free.json')); Api::setKey('key', $this->client); $free = Champion::free(); $this->assertEquals(10, count($free->champions)); }
public function indexAction() { // Get all champions in database, don't need champion ids $results = Champion::find(array("columns" => "champion_name", "order" => "champion_name")); // Make array for champion list $champions = array(); // Push each champion onto array foreach ($results as $result) { array_push($champions, $result->champion_name); } $this->view->setVar('champions', $champions); }
public function updateChampionVSAction() { print "Finding champions: "; $champion_list = Champion::find(array("columns" => "champion_id"))->toArray(); $vs_list = Champion::find(array("columns" => "champion_id"))->toArray(); print "Champion list: " . $champion_list; print "VS Champion list: " . $vs_list; foreach ($champion_list as $champion) { $champion_id = $champion["champion_id"]; foreach ($vs_list as $vs_champion) { $vs_id = $vs_champion["champion_id"]; $vs_phql = "SELECT c1.id as matchId, c1.assigned_id as assignedId, CONCAT(IFNULL(stat.item0,''),' ',IFNULL(stat.item1,''),' ',IFNULL(stat.item2,''),' ',IFNULL(stat.item3,''),' ',IFNULL(stat.item4,''),' ',IFNULL(stat.item5,'')) AS items\n FROM MatchParticipant c1 \n JOIN MatchParticipant c2 ON c1.id = c2.id\n JOIN ParticipantStats stat ON c1.id = stat.id AND c1.player_id = stat.player_id WHERE c1.champion_id = :champion_id: AND c2.champion_id = :vs_id: AND c1.team_id != c2.team_id AND stat.winner = 1"; print "Executing query for" . $champion_id . "and" . $vs_id . ": "; print $vs_phql; $games = $this->modelsManager->executeQuery($vs_phql, array("champion_id" => $champion_id, "vs_id" => $vs_id)); $all_item_sets = array(); print "Analyzing "; foreach ($games as $game) { // Gets item list and sorts $items_as_array = explode(' ', $game->items); sort($items_as_array, SORT_NUMERIC); $game_items = implode(' ', $items_as_array); // If item set exists then increment, otherwise add in item set if (array_key_exists($game_items, $all_item_sets)) { $all_item_sets[$game_items] += 1; } else { $all_item_sets += array($game_items => 1); } } // Get item set with most wins $winningest_item_set = array_search(max($all_item_sets), $all_item_sets); print $winningest_item_set; $vs_item_set = new CachedData(); $vs_item_set->save(array("type" => "vs_item_set", "conditionals" => json_encode(array("champion_id" => $champion_id, "vs_id" => $vs_id)), "value" => $winningest_item_set, "updated_at" => date("Y-m-d H:I:s"))); /** print("Inserting vs skill set into CachedData"); $vs_skill_set = new CachedData(); $vs_skill_set->save( array( "type" => "vs_skill_set", "conditionals" => json_encode(array("champion_id" => $champion_id, "vs_id" => $vs_id)), "value" => "", "updated_at" => time() ) ); **/ } } }
$this->get('/{id}', function ($req, $res, $args) { $champion = \Champion::find($args['id']); if ($champion) { return $res->withStatus(200)->write($champion->toJson()); } 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
public function getAction($champion_name) { // Get the user chosen options from POST data $item_set = $this->request->getPost("item_set"); /** $skill_set = $this->request->getPost("skill_set"); **/ $combined_set = $this->request->getPost("combined_set"); if ($combined_set !== '') { $item_set = $combined_set; /** $skill_set = $combined_set; **/ } // Get the kind of set type to find $item_type = $item_set == "Overall" ? "overall" : "vs"; /** $skill_type = ($skill_set == "Overall") ? "overall" : "vs"; **/ // Convert champion names into IDs, to be used for CachedData conditionals $champion_result = Champion::findFirst("champion_name = '" . $champion_name . "'"); $champion_id = $champion_result->champion_id; $item_set_result = Champion::findFirst("champion_name = '" . $item_set . "'"); $vs_item_id = $item_set == "Overall" ? "overall" : $item_set_result->champion_id; /** $vs_skill_id = ($skill_set == "Overall") ? "overall" : Champion::find(array("champion_name" => $skill_set))->champion_id; **/ $find_item_set = CachedData::findFirst(array("conditionals = '" . json_encode(array("champion_id" => $champion_id, "vs_id" => $vs_item_id)) . "'")); $item_set_array = explode(' ', $find_item_set->value); /** $find_skill_set = CachedData::find( array( "type" => $skill_type . "_skill_set", "conditionals" => json_encode(array("champion_id" => $champion_id, "vs_id" => $vs_skill_id)) ) ); // Insert skill set into item set $json = json_decode($find_item_set->value, true); $json[blocks][0][type] = $find_skill_set->value; $json_data = json_encode($json); **/ $compiled_item_set = array("title" => $champion_name . " vs " . $item_set, "type" => "custom", "map" => "any", "mode" => "any", "priority" => false, "sortrank" => 1, "blocks" => array(array("type" => "Basic Items", "recMath" => false, "minSummonerLevel" => -1, "maxSummonerLevel" => -1, "showIfSummonerSpell" => "", "hideIfSummonerSpell" => "", "items" => array(array("id" => "2003", "count" => 1), array("id" => "3340", "count" => 1), array("id" => "3341", "count" => 1), array("id" => "3342", "count" => 1), array("id" => "2044", "count" => 1), array("id" => "2043", "count" => 1))), array("type" => "Item Set", "recMath" => false, "minSummonerLevel" => -1, "maxSummonerLevel" => -1, "showIfSummonerSpell" => "", "hideIfSummonerSpell" => "", "items" => array(array("id" => $item_set_array[0], "count" => 1), array("id" => $item_set_array[1], "count" => 1), array("id" => $item_set_array[2], "count" => 1), array("id" => $item_set_array[3], "count" => 1), array("id" => $item_set_array[4], "count" => 1), array("id" => $item_set_array[5], "count" => 1))))); // Get JSON data and location to be sent to user $filename = $champion_name . "VS" . $item_set . ".json"; $json_string = json_encode($compiled_item_set); // Send data back to user forwarding through setAction $this->dispatcher->forward(array("action" => "set", "params" => array($champion_name, $filename, $json_string))); }