Exemple #1
0
 function team_get()
 {
     // check that the id is at least a valid number
     $this->_check_id();
     // get the single team by id
     $team = new Team();
     $team->where('id', $this->get('id'))->limit(1)->get();
     if ($team->result_count() == 1) {
         $result = $team->to_array();
         $members = new Membership();
         // get members gives an actual object with ->profile_othervariable
         $memb = $members->get_members($team->id);
         // we have to select the user array manually because... we don't want to expose password hashes
         foreach ($memb->all as $key => $mem) {
             $result['members'][$key] = $mem->to_array(array('id', 'username'));
             $result['members'][$key]['display_name'] = $mem->profile_display_name;
             $result['members'][$key]['twitter'] = $mem->profile_twitter;
             $result['members'][$key]['bio'] = $mem->profile_bio;
         }
         // all good
         $this->response($result, 200);
         // 200 being the HTTP response code
     } else {
         // no team for this id
         $this->response(array('error' => _('Team could not be found')), 404);
     }
 }
Exemple #2
0
	public function team($stub = NULL) {
		if (is_null($stub))
			show_404();
		$team = new Team();
		$team->where('stub', $stub)->get();
		if ($team->result_count() < 1)
			show_404();

		$memberships = new Membership();
		$members = $memberships->get_members($team->id);

		$this->template->title(_('Team'));
		$this->template->set('team', $team);
		$this->template->set('members', $members);
		$this->template->build('team');
	}
Exemple #3
0
	function team_get() {
		if (!$this->get('id') || !is_numeric($this->get('id'))) {
			$this->response(NULL, 400);
		}

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

		if ($team->result_count() == 1) {
			$result = $team->to_array();
			$members = new Membership();
			$memb = $members->get_members($team->id);
			foreach($memb->all as $key => $mem) {
				$result['members'][$key] = $memb->to_array(array('id','username'));
				$result['members'][$key]['display_name'] = $memb->profile_display_name;
				$result['members'][$key]['twitter'] = $memb->profile_twitter;
				$result['members'][$key]['bio'] = $memb->profile_bio;
			}
			$this->response($result, 200); // 200 being the HTTP response code
		} else {
			$this->response(array('error' => _('Team could not be found')), 404);
		}
	}
Exemple #4
0
	/**
	 * Checks if there's a leader between the members of a team
	 *
	 * @author Woxxy
	 * @param int $team_id
	 * @return bool
	 */
	function has_leader($team_id) {
		$members = new Membership();
		$members_result = $members->get_members($team_id);
		foreach ($members_result as $key => $member) {
			if ($member->is_leader)
				return TRUE;
		}
		return FALSE;
	}
Exemple #5
0
	function teams($stub = "") {
		if ($stub == "") {
			$this->viewdata["function_title"] = "Team list";
			$teams = new Team();
			$teams->order_by('name', 'ASC')->get_iterated();
			$rows = array();
			foreach ($teams as $team) {
				$rows[] = array('title' => '<a href="' . site_url('admin/members/teams/' . $team->stub) . '">' . $team->name . '</a>');
			}
			$data['list'] = lister($rows);
			$this->viewdata["main_content_view"] = $this->load->view('admin/members/users', $data, TRUE);
			$this->load->view("admin/default", $this->viewdata);
		}
		else {
			$team = new Team();
			$team->where('stub', $stub)->get();

			if ($this->tank_auth->is_admin() || $this->tank_auth->is_group('mod'))
				$can_edit = true;
			else
				$can_edit = false;

			if ($this->tank_auth->is_team_leader($team->id) && !$can_edit)
				$can_edit_limited = true;
			else
				$can_edit_limited = false;

			if (($post = $this->input->post()) && ($can_edit || $can_edit_limited)) {
				$team = new Team();
				$team->where('stub', $stub)->get();
				$post["id"] = $team->id;
				if ($can_edit_limited) {
					unset($post['name']);
				}
				$team->update_team($post, TRUE);
				set_notice('notice', _('Saved.'));
			}


			$this->viewdata["function_title"] = "Team";
			$this->viewdata["extra_title"][] = $team->name;

			if ($can_edit_limited)
				$team->validation['name']['disabled'] = 'true';

			$result = ormer($team);

			$result = tabler($result, TRUE, ($can_edit || $can_edit_limited));
			$data['table'] = $result;
			$data['team'] = $team;

			$members = new Membership();
			$users = $members->get_members($team->id);

			$users_arr = array();
			foreach ($users->all as $key => $item) {
				$users_arr[$key][] = '<a href="' . site_url('/admin/members/member/' . $item->id) . '">' . $item->username . '</a>';
				if ($can_edit)
					$users_arr[$key][] = $item->email;
				$users_arr[$key][] = $item->last_login;
				$users_arr[$key][] = ($item->is_leader) ? _('Leader') : _('Member');
				if ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed()) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Remove member"),
						'href' => site_url('/admin/members/reject_application/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to remove this team member?')
					);
				}
				$users_arr[$key][] = (isset($buttoner) && !empty($buttoner)) ? buttoner($buttoner) : '';
				if (!$item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Make leader"),
						'href' => site_url('/admin/members/make_team_leader/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to make this user a team leader?')
					);
				}
				if ($item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Remove leader"),
						'href' => site_url('/admin/members/remove_team_leader/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to remove this user from the team leadership?')
					);
				}
				$users_arr[$key][] = (isset($buttoner) && !empty($buttoner)) ? buttoner($buttoner) : '';
			}

			// Spawn the form for adding a team leader
			$data["no_leader"] = FALSE;
			if ($this->tank_auth->is_allowed())
				$data["no_leader"] = TRUE;

			$data['members'] = tabler($users_arr, TRUE, FALSE);

			$this->viewdata["main_content_view"] = $this->load->view('admin/members/team', $data, TRUE);
			$this->load->view("admin/default", $this->viewdata);
		}
	}
Exemple #6
0
 function teams($stub = "")
 {
     // no team selected
     if ($stub == "") {
         // set subtitle
         $this->viewdata["function_title"] = _('Teams');
         // we can use get_iterated on teams
         $teams = new Team();
         // support filtering via search
         if ($this->input->post()) {
             $teams->ilike('name', $this->input->post('search'));
             $this->viewdata['extra_title'][] = _('Searching') . " : " . $this->input->post('search');
         }
         $teams->order_by('name', 'ASC')->get_iterated();
         $rows = array();
         // produce links for each team
         foreach ($teams as $team) {
             $rows[] = array('title' => '<a href="' . site_url('admin/members/teams/' . $team->stub) . '">' . $team->name . '</a>');
         }
         // put in a list the teams
         $data['form_title'] = _('Teams');
         $data['table'] = lister($rows);
         // print out
         $this->viewdata["main_content_view"] = $this->load->view('admin/members/users', $data, TRUE);
         $this->load->view("admin/default", $this->viewdata);
     } else {
         // team was selected, let's grab it and create a form for it
         $team = new Team();
         $team->where('stub', $stub)->get();
         // if the team was not found return 404
         if ($team->result_count() != 1) {
             show_404();
         }
         // if admin or mod allow full editing rights
         if ($this->tank_auth->is_allowed()) {
             $can_edit = true;
         } else {
             $can_edit = false;
         }
         // if it's a team leader, but not admin or mod, allow him to change data but not the team name
         if ($this->tank_auth->is_team_leader($team->id) && !$can_edit) {
             $can_edit_limited = true;
         } else {
             $can_edit_limited = false;
         }
         // if allowed in any way to edit,
         if (($post = $this->input->post()) && ($can_edit || $can_edit_limited)) {
             $post["id"] = $team->id;
             // save the stub in case it's changed
             $old_stub = $team->stub;
             // don't allow editing of name for team leaders
             if ($can_edit_limited) {
                 unset($post['name']);
             }
             // send the data to database
             $team->update_team($post);
             // green box to tell data is saved
             set_notice('notice', _('Saved.'));
             if ($team->stub != $old_stub) {
                 flash_notice('notice', _('Saved.'));
                 redirect('admin/members/teams/' . $team->stub);
             }
         }
         // subtitle
         $this->viewdata["function_title"] = '<a href="' . site_url("admin/members/teams") . '">' . _('Teams') . '</a>';
         // subsubtitle!
         $this->viewdata["extra_title"][] = $team->name;
         // gray out the name field for team leaders by editing directly the validation array
         if ($can_edit_limited) {
             $team->validation['name']['disabled'] = 'true';
         }
         // convert the team information to an array
         $result = ormer($team);
         // convert the array to a form
         $result = tabler($result, TRUE, $can_edit || $can_edit_limited);
         $data['table'] = $result;
         $data['team'] = $team;
         // get the team's members
         $members = new Membership();
         $users = $members->get_members($team->id);
         // the team members' array needs lots of buttons and links
         $users_arr = array();
         foreach ($users->all as $key => $item) {
             $users_arr[$key][] = '<a href="' . site_url('/admin/members/member/' . $item->id) . '">' . $item->username . '</a>';
             // show the email only to admins and mods
             if ($can_edit) {
                 $users_arr[$key][] = $item->email;
             }
             $users_arr[$key][] = $item->last_login;
             // leader of normal member?
             $users_arr[$key][] = $item->is_leader ? _('Leader') : _('Member');
             if ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed()) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Remove member"), 'href' => site_url('/admin/members/reject_application/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to remove this team member?'));
             }
             // add button to array or stay silent if there's no button
             $users_arr[$key]['action'] = isset($buttoner) && !empty($buttoner) ? buttoner($buttoner) : '';
             if (!$item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Make leader"), 'href' => site_url('/admin/members/make_team_leader/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to make this user a team leader?'));
             }
             if ($item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Remove leader"), 'href' => site_url('/admin/members/remove_team_leader/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to remove this user from the team leadership?'));
             }
             // add button to array or stay silent if there's no button
             $users_arr[$key]['action'] .= isset($buttoner) && !empty($buttoner) ? buttoner($buttoner) : '';
         }
         // Spawn the form for adding a team leader
         $data["no_leader"] = FALSE;
         if ($this->tank_auth->is_allowed()) {
             $data["no_leader"] = TRUE;
         }
         // make a form out of the array of members
         $data['members'] = tabler($users_arr, TRUE, FALSE);
         // print out
         $this->viewdata["main_content_view"] = $this->load->view('admin/members/team', $data, TRUE);
         $this->load->view("admin/default", $this->viewdata);
     }
 }