function reportscenarios_get() { if (!$this->get('type') || !$this->get('pfsnumber')) { $this->response(NULL, 400); } // Get the player $player = new Person(); $player->get_by_pfsnumber($this->get('pfsnumber')); // Determine what kind of content we need to get if ($this->get('type') != 'overview') { // Normal content if (is_numeric(substr($this->get('type'), 1, 1))) { // Season $season = substr($this->get('type'), 1, 1); // Get all the scenarios played for this player in this season $played_scenarios = $player->scenarios->where('season', $season)->include_join_fields()->get(); } else { // Module or Adventure path $content = $this->get('type'); // Get all the modules and adventure paths played for this player $played_scenarios = $player->scenarios->where('type', $content)->include_join_fields()->get(); } $state = array(); foreach ($played_scenarios as $played_scenario) { $state[$played_scenario->id]['pfs'] = (bool) $played_scenario->join_pfs; $state[$played_scenario->id]['core'] = (bool) $played_scenario->join_core; $state[$played_scenario->id]['pfs_gm'] = (bool) $played_scenario->join_pfs_gm; $state[$played_scenario->id]['core_gm'] = (bool) $played_scenario->join_core_gm; } $scenarios = new Scenario(); if (is_numeric(substr($this->get('type'), 1, 1))) { $scenarios->order_by('cast(number as unsigned)', 'asc')->get_by_season($season); } else { $scenarios->order_by('name', 'asc')->get_by_type($content); } $scenarios_array = $scenarios->all_to_array(); foreach ($scenarios_array as $index => $scenario) { if (array_key_exists($scenario['id'], $state)) { $scenarios_array[$index]['state'] = $state[$scenario['id']]; } else { $scenarios_array[$index]['state'] = array('pfs' => false, 'core' => false, 'pfs_gm' => false, 'core_gm' => false); } } $this->response($scenarios_array, 200); } }