function playerprogress_get() { if (!$this->get('pfsnumber') || !$this->get('type')) { $this->response(NULL, 400); } $scenario = new Scenario(); $scenario->select('season, type')->distinct()->get(); $types = array(); foreach ($scenario as $s) { $types[] = $s->season; } $types[] = 'mod'; $types[] = 'ap'; $response = array(); $playerprogress = new Person(); $scen = new Scenario(); $playerprogress->where('pfsnumber', $this->get('pfsnumber'))->get(); foreach ($scenario as $s) { if ($s->type == 'mod') { // Modules $response['mod'] = array('season' => 'Modules', 'total' => 0, 'completed' => 0); $response['mod']['completed'] = $playerprogress->scenarios->where_join_field('players', $this->get('type') . ' IS NOT NULL', NULL)->where('type', 'mod')->where('archived IS NULL', NULL)->get()->result_count(); $response['mod']['total'] = $scen->where('type', 'mod')->where('archived IS NULL', NULL)->count(); } elseif ($s->type == 'ap') { // Adventure paths $response['ap'] = array('season' => 'APs', 'total' => 0, 'completed' => 0); $response['ap']['completed'] = $playerprogress->scenarios->where_join_field('players', $this->get('type') . ' IS NOT NULL', NULL)->where('type', 'ap')->where('archived IS NULL', NULL)->get()->result_count(); $response['ap']['total'] = $scen->where('type', 'ap')->where('archived IS NULL', NULL)->count(); } else { // Seasons $response[$s->season] = array('season' => $s->season, 'total' => 0, 'completed' => 0, 'contenttype' => $s->type); $response[$s->season]['completed'] = $playerprogress->scenarios->where_join_field('players', $this->get('type') . ' IS NOT NULL', NULL)->where('season', $s->season)->where('archived IS NULL', NULL)->get()->result_count(); $response[$s->season]['total'] = $scen->where('season', $s->season)->where('archived IS NULL', NULL)->count(); } } $this->response($response, 200); }