Пример #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;
 }
Пример #2
0
	function check($team_id, $user_id) {
		$member = new Membership();
		$member->where('team_id', $team_id)->where('user_id', $user_id)->get();
		return ($member->result_count() == 1);
	}
Пример #3
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) {
		if (!$this->is_logged_in())
			return FALSE;

		$leaderships = new Membership();
		$leaderships->where('user_id', $this->get_user_id())->where('accepted', 1)->where('is_leader', 1);

		if (is_numeric($team_id)) {
			$leaderships->where('team_id', $team_id);
			$leaderships->get();
			if ($leaderships->result_count() != 1)
				return FALSE;
			$team = new Team();
			$team->where('id', $team_id)->get();
			return $team;
		}

		$leaderships->get();
		if ($leaderships->result_count() < 1)
			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 ($leaderships->all as $key => $leadership) {
			$teams->or_where('id', $leadership->team_id);
		}
		$teams->get();
		return $teams;
	}