Exemple #1
0
	function team_get() {
		if (!$this->get('id') || !is_numeric($this->get('id'))) {
			$this->response(NULL, 400);
		}

		if (!$this->get('page') || !is_numeric($this->get('page')) || $this->get('page') < 1)
			$page = 1;
		else
			$page = (int) $this->get('page');

		$page = ($page * 100) - 100;

		$team = new Team();
		$team->where('id', $this->get('id'))->limit(1)->get();

		if ($team->result_count() == 1) {
			$result = array();
			$result['team'] = $team->to_array();

			// get joints to get also the chapters from joints
			$joints = new Joint();
			$joints->where('team_id', $team->id)->get();


			$chapters = new Chapter();
			$chapters->where('team_id', $team->id);
			foreach ($joints->all as $joint) {
				$chapters->or_where('joint_id', $joint->joint_id);
			}
			$chapters->limit(100, $page)->get();
			$chapters->get_comic();

			$result['chapters'] = array();
			foreach ($chapters->all as $key => $chapter) {
				if (!$chapter->team_id) {
					$chapter->get_teams();
					foreach ($chapter->teams as $item) {
						$result['chapters'][$key]['teams'][] = $item->to_array();
					}
				} else {
						$result['chapters'][$key]['teams'][] = $team->to_array();
				}
				$result['chapters'][$key]['comic'] = $chapter->comic->to_array();
				$result['chapters'][$key]['chapter'] = $chapter->to_array();
			}

			$this->response($result, 200); // 200 being the HTTP response code
		} else {
			$this->response(array('error' => _('Team could not be found')), 404);
		}
	}
Exemple #2
0
 /**
  * Returns chapters per page from team ID
  * Includes releases from joints too
  * 
  * This is NOT a method light enough to lookup teams. use api/members/team for that
  * 
  * Available filters: id (required), page, per_page (default:30, max:100), orderby
  * 
  * @author Woxxy
  */
 function team_get()
 {
     // get the single team by id or stub
     if ($this->get('stub')) {
         $team = new Team();
         $team->where('stub', $this->get('stub'))->limit(1)->get();
     } else {
         // check that the id is at least a valid number
         $this->_check_id();
         $team = new Team();
         $team->where('id', $this->get('id'))->limit(1)->get();
     }
     // team found?
     if ($team->result_count() == 1) {
         $result = array();
         $result['team'] = $team->to_array();
         // get joints to get also the chapters from joints
         $joints = new Joint();
         $joints->where('team_id', $team->id)->get();
         $chapters = new Chapter();
         // get all chapters with the team ID
         $chapters->where('team_id', $team->id);
         foreach ($joints->all as $joint) {
             // get also all chapters with the joints by the team
             $chapters->or_where('joint_id', $joint->joint_id);
         }
         // filter for the page and the order
         $this->_orderby($chapters);
         $this->_page_to_offset($chapters);
         $chapters->get();
         $chapters->get_comic();
         // let's save some power by reusing the variables we already have for team
         // and put everything in the usual clean [comic][chapter][teams]
         $result['chapters'] = array();
         foreach ($chapters->all as $key => $chapter) {
             if (!$chapter->team_id) {
                 $chapter->get_teams();
                 foreach ($chapter->teams as $item) {
                     $result['chapters'][$key]['teams'][] = $item->to_array();
                 }
             } else {
                 $result['chapters'][$key]['teams'][] = $team->to_array();
             }
             $result['chapters'][$key]['comic'] = $chapter->comic->to_array();
             $result['chapters'][$key]['chapter'] = $chapter->to_array();
         }
         // all good
         $this->response($result, 200);
         // 200 being the HTTP response code
     } else {
         // that single team id wasn't found
         $this->response(array('error' => _('Team could not be found')), 404);
     }
 }