public function check_joint($teams) { $teams = array_unique($teams); $size = count($teams); $joints = new Joint(); $joints->where('team_id', $teams[0])->get_iterated(); if ($joints->result_count() < 1) { log_message('debug', 'check_joint: joint not found, result count zero'); return false; } foreach ($joints as $joint) { $join = new Joint(); $join->where('joint_id', $joint->joint_id)->get_iterated(); if ($join->result_count() == $size) { $test = $teams; foreach ($join as $joi) { $key = array_search($joi->team_id, $teams); if ($key === FALSE) { break; } unset($test[$key]); } if (empty($test)) { return $joi->joint_id; } } } log_message('debug', 'check_joint: joint not found'); return false; }
public function get_teams($team_id, $joint_id = 0) { // if it's a joint, let's deal it as a joing if ($joint_id > 0) { // get all the joint entries so we have all the teams $joint = new Joint(); $joint->where("joint_id", $joint_id)->get(); // not an existing joint? if ($joint->result_count() < 1) { log_message('error', 'get_teams: joint -> joint not found'); return false; } // result array $teamarray = array(); foreach ($joint->all as $key => $join) { if (!($team = $this->get_cached($join->team_id))) { $team = new Team(); $team->where('id', $join->team_id); $team->get(); } $teamarray[] = $team->get_clone(); } if (empty($teamarray)) { log_message('error', 'get_teams: joint -> no teams found'); return false; } return $teamarray; } // if we're here, it means it's a simple team if (!($team = $this->get_cached($team_id))) { $team = new Team($team_id); } return array($team); }
/** * Returns chapters per page by joint ID * Also returns the teams * * This is not a method light enough to lookup teams. use api/members/joint for that * * Available filters: id (required), page, per_page (default:30, max:100), orderby * * @author Woxxy */ function joint_get() { // check that the id is at least a valid number $this->_check_id(); // grab by joint_id, id for joints means nothing much $joint = new Joint(); $joint->where('joint_id', $this->get('id'))->limit(1)->get(); if ($joint->result_count() == 1) { // good old get_teams() will give us all Team objects in an array $team = new Team(); $teams = $team->get_teams(0, $this->get('id')); // $teams is a normal array, so we have to do a loop $result = array(); foreach ($teams as $item) { $result['teams'][] = $item->to_array(); } // grab all the chapters from the same joint $chapters = new Chapter(); $chapters->where('joint_id', $joint->joint_id); // apply the limit and orderby filters $this->_orderby($chapters); $this->_page_to_offset($chapters); $chapters->get(); $chapters->get_comic(); // let's put the chapters in a nice [comic][chapter][teams] list $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); $result['chapters'][$key]['teams'] = $result['teams']; } // all good $this->response($result, 200); // 200 being the HTTP response code } else { // nothing for this joint or page $this->response(array('error' => _('Team could not be found')), 404); } }
function joint_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; $joint = new Joint(); $joint->where('joint_id', $this->get('id'))->limit(1)->get(); if ($joint->result_count() == 1) { $team = new Team(); $teams = $team->get_teams(0, $this->get('id')); $result = array(); foreach ($teams as $item) { $result['teams'][] = $item->to_array(); } $chapters = new Chapter(); $chapters->where('joint_id', $joint->joint_id); $chapters->limit(100, $page)->get(); $chapters->get_comic(); $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); $result['chapters'][$key]['teams'] = $result['teams']; } $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(array('error' => _('Team could not be found')), 404); } }
public function get_teams($team_id, $joint_id = 0) { if ($joint_id > 0) { $joint = new Joint(); $joint->where("joint_id", $joint_id)->get(); if ($joint->result_count() < 1) { log_message('error', 'get_teams: joint -> joint not found'); return false; } $teamarray = array(); $team = new Team(); foreach ($joint->all as $key => $join) { $team->where('id', $join->team_id); $team->get(); $teamarray[] = $team->get_clone(); } if ($team->result_count() < 1) { log_message('error', 'get_teams: joint -> no teams found'); return false; } return $teamarray; } $team = new Team($team_id); return array($team); }