示例#1
0
 /**
  * Returns the chapter
  * 
  * Available filters: id (required)
  *
  * @author Woxxy
  */
 function chapter_get()
 {
     if ($this->get('comic_stub') || is_numeric($this->get('comic_id')) || is_numeric($this->get('volume')) || is_numeric($this->get('chapter')) || is_numeric($this->get('subchapter')) || is_numeric($this->get('team_id')) || is_numeric($this->get('joint_id'))) {
         $chapter = new Chapter();
         if ($this->get('comic_stub')) {
             $chapter->where_related('comic', 'stub', $this->get('comic_stub'));
         }
         // this mess is a complete search system through integers!
         if (is_numeric($this->get('comic_id'))) {
             $chapter->where('comic_id', $this->get('comic_id'));
         }
         if (is_numeric($this->get('volume'))) {
             $chapter->where('volume', $this->get('volume'));
         }
         if (is_numeric($this->get('chapter'))) {
             $chapter->where('chapter', $this->get('chapter'));
         }
         if (is_numeric($this->get('subchapter'))) {
             $chapter->where('subchapter', $this->get('subchapter'));
         }
         if (is_numeric($this->get('team_id'))) {
             $chapter->where('team_id', $this->get('team_id'));
         }
         if (is_numeric($this->get('joint_id'))) {
             $chapter->where('joint_id', $this->get('joint_id'));
         }
         // and we'll still give only one result
         $chapter->limit(1)->get();
     } else {
         // check that the id is at least a valid number
         $this->_check_id();
         $chapter = new Chapter();
         // get the single chapter by id
         $chapter->where('id', $this->get('id'))->limit(1)->get();
     }
     if ($chapter->result_count() == 1) {
         $chapter->get_comic();
         $chapter->get_teams();
         // the pretty array gets pages too: [comic][chapter][teams][pages]
         $result = array();
         $result['comic'] = $chapter->comic->to_array();
         $result['chapter'] = $chapter->to_array();
         $result['teams'] = array();
         foreach ($chapter->teams as $team) {
             $result['teams'][] = $team->to_array();
         }
         // this time we get the pages
         $result['pages'] = $chapter->get_pages();
         // all good
         $this->response($result, 200);
         // 200 being the HTTP response code
     } else {
         // the chapter with that id doesn't exist
         $this->response(array('error' => _('Chapter could not be found')), 404);
     }
 }