예제 #1
0
 /**
  * Returns leader team objects, false in case user is not a team leader
  * 
  * @author Woxxy
  * @param int $team_id if NULL returns each team in which this user is leader
  * @return object Teams
  * 
  */
 function is_team_leader($team_id = NULL, $joint_id = NULL)
 {
     // not logged in? get booted
     if (!$this->is_logged_in()) {
         return FALSE;
     }
     // this calls another function in order to cycle each team in the joint with is_team
     if (!is_null($joint_id) && $joint_id != 0) {
         $teams = new Team();
         return $this->is_team_leader_array($teams->get_teams(0, $joint_id));
     }
     // let's get all the memberships
     if (!isset($this->cached['leaderships'])) {
         $memberships = new Membership();
         $memberships->where('user_id', $this->get_user_id())->where('accepted', 1)->where('is_leader', 1)->get();
         $this->cached['leaderships'] = $memberships->get_clone();
     } else {
         $memberships = $this->cached['leaderships'];
     }
     // if not member of any team, return FALSE
     if ($memberships->result_count() < 1) {
         return FALSE;
     }
     // if a team is set, let's grab the team and return the data of the team
     if (is_numeric($team_id)) {
         foreach ($memberships->all as $membership) {
             if ($membership->team_id == $team_id) {
                 return new Team($team_id);
             }
         }
         return FALSE;
     }
     $teams = new Team();
     // Notice that if you remove the result count on $leaderships, this will not run and the user will be leader of any team!
     foreach ($memberships->all as $key => $membership) {
         $teams->or_where('id', $membership->team_id);
     }
     $teams->get();
     return $teams;
 }