Ejemplo n.º 1
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);
	}
Ejemplo n.º 2
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;
	}