function comic_get() { if (!$this->get('id') || !is_numeric($this->get('id'))) { $this->response(NULL, 400); } $comic = new Comic(); $comic->where('id', $this->get('id'))->limit(1)->get(); if ($comic->result_count() == 1) { $chapters = new Chapter(); $chapters->where('comic_id', $comic->id)->get(); $chapters->get_teams(); $result = array(); $result["comic"] = $comic->to_array(); $result["chapters"] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key] = $chapter->to_array(); foreach ($chapter->teams as $team) { $result['chapters'][$key]['teams'][] = $team->to_array(); } } $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(array('error' => _('Comic could not be found')), 404); } }
/** * Returns the comic * * Available filters: id (required) * * @author Woxxy */ function comic_get() { if ($this->get('id')) { //// check that the id is at least a valid number $this->_check_id(); // get the comic $comic = new Comic(); $comic->where('id', $this->get('id'))->limit(1)->get(); } else { if ($this->get('stub')) { // mostly used for load balancer $comic = new Comic(); $comic->where('stub', $this->get('stub')); // back compatibility with version 0.7.6, though stub is already an unique key if ($this->get('uniqid')) { $comic->where('uniqid', $this->get('uniqid')); } $comic->limit(1)->get(); } else { $this->response(array('error' => _('You didn\'t use the necessary parameters')), 404); } } if ($comic->result_count() == 1) { $chapters = new Chapter(); $chapters->where('comic_id', $comic->id)->get(); $chapters->get_teams(); $result = array(); $result["comic"] = $comic->to_array(); // order in the beautiful [comic][chapter][teams][page] $result["chapters"] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $result["comic"]; $result['chapters'][$key]['chapter'] = $chapter->to_array(); // if it's requested, throw in also the pages (for load balancer) if ($this->get('chapter_stub') == $chapter->stub && $this->get('chapter_uniqid') == $chapter->uniqid) { $pages = new Page(); $pages->where('chapter_id', $chapter->id)->get(); $result["chapters"][$key]["chapter"]["pages"] = $pages->all_to_array(); } // teams is a normal array, can't use $team->all_to_array() foreach ($chapter->teams as $team) { $result['chapters'][$key]['teams'][] = $team->to_array(); } } // all good $this->response($result, 200); // 200 being the HTTP response code } else { // there's no comic with that id $this->response(array('error' => _('Comic could not be found')), 404); } }