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); } }
function get_home_team() { $CI = & get_instance(); if (isset($CI->fs_loaded->home_team)) return $CI->fs_loaded->home_team; $hometeam = get_setting('fs_gen_default_team'); $team = new Team(); $team->where('name', $hometeam)->limit(1)->get(); if ($team->result_count() < 1) { $team = new Team(); $team->limit(1)->get(); } return $team; }
public function add_joint_via_name($teams) { $result = array(); foreach ($teams as $team) { $tea = new Team(); $tea->where('name', $team)->get(); if ($tea->result_count() == 0) { set_notice('error', _('One of the named teams doesn\'t exist.')); log_message('error', 'add_joint_via_name: team does not exist'); return false; } $result[] = $tea->id; } return $this->add_joint($result); }
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'); }
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); } }
function leave_leadership($team_stub) { $this->viewdata["navbar"] = ""; $team = new Team(); $team->where('stub', $team_stub)->get(); if ($team->result_count() != 1) { show_404(); } if (!$this->tank_auth->is_team_leader($team->id) && !$this->tank_auth->is_allowed()) { show_404(); } if ($this->input->post()) { $member = new Membership(); if (!$member->remove_team_leader($team->id)) { return show_404(); } redirect('/account/teams/'); } $this->viewdata["function_title"] = _("Leave team leadership"); $data["team_name"] = $team->name; $data["team_id"] = $team->id; $this->viewdata["main_content_view"] = $this->load->view('account/profile/leave_leadership', $data, TRUE); $this->load->view("account/default.php", $this->viewdata); }
public function get_teams_id($array, $create_joint = FALSE) { if (count($array) < 1) { set_notice('error', _('There were no groups selected.')); log_message('error', 'get_groups: input array empty'); return false; } if (count($array) == 1) { $team = new Team(); $team->where("name", $array[0])->get(); if ($team->result_count() < 1) { set_notice('error', _('There\'s no team under this ID.')); log_message('error', 'get_groups: team not found'); return false; } $result = array("team_id" => $team->id, "joint_id" => 0); return $result; } if (count($array) > 1) { $id_array = array(); foreach ($array as $key => $arra) { $team = new Team(); $team->where('name', $arra[$key])->get(); if ($team->result_count() < 1) { set_notice('error', _('There\'s no teams under this ID.')); log_message('error', 'get_groups: team not found'); return false; } $id_array[$key] = $team->id; } $joint = new Joint(); if (!$joint->check_joint($id_array) && $create_joint) { if (!$joint->add_joint($id_array)) { log_message('error', 'get_groups: could not create new joint'); return false; } } return array("team_id" => 0, "joint_id" => $joint->joint_id); } set_notice('error', _('There\'s no group found with this ID.')); log_message('error', 'get_groups: no case matched'); return false; }
/** * Handles both creating of new chapters in the database and editing old ones. * It determines if it should update or not by checking if $this->id has * been set. It can get the values from both the $data array and direct * variable assignation. Be aware that array > variables. The latter ones * will be overwritten. Particularly, the variables that the user isn't * allowed to set personally are unset and reset with the automated values. * It's quite safe to throw stuff at it. * * @author Woxxy * @param array $data contains the minimal data * @return object the comic the chapter derives from. */ public function update_chapter_db($data = array()) { // Check if we're updating or creating a new chapter by looking at $data["id"]. // False is returned if the chapter ID was not found. if (isset($data["id"]) && $data['id'] != "") { $this->where("id", $data["id"])->get(); if ($this->result_count() == 0) { set_notice('error', _('The chapter you tried to edit doesn\'t exist.')); log_message('error', 'update_chapter_db: failed to find requested id'); return false; } // Save the stub in case it gets changed (different chapter number/name etc.) // Stub is always automatized. $old_stub = $this->stub; } else { // if we're here, it means that we're creating a new chapter // Set the creator name if it's a new chapter. if (!isset($this->comic_id)) { set_notice('error', 'You didn\'t select a comic to refer to.'); log_message('error', 'update_chapter_db: comic_id was not set'); return false; } // Check that the related comic is defined, and exists. $comic = new Comic($this->comic_id); if ($comic->result_count() == 0) { set_notice('error', _('The comic you were referring to doesn\'t exist.')); log_message('error', 'update_chapter_db: comic_id does not exist in comic database'); return false; } // Set the creator. This happens only on new chapter creation. $this->creator = $this->logged_id(); } // Always set the editor $this->editor = $this->logged_id(); // Unset the sensible variables. // Not even admins should touch these, for database stability. unset($data["creator"]); unset($data["editor"]); unset($data["uniqid"]); unset($data["stub"]); unset($data["team_id"]); unset($data["joint_id"]); // Loop over the array and assign values to the variables. foreach ($data as $key => $value) { $this->$key = $value; } // Double check that we have all the necessary automated variables if (!isset($this->uniqid)) $this->uniqid = uniqid(); if (!isset($this->stub)) $this->stub = $this->stub(); // This is necessary to make the checkbox work. /** * @todo make the checkbox work consistently across the whole framework */ if (!isset($data['hidden']) || $data['hidden'] != 1) $this->hidden = 0; // Prepare a new stub. $this->stub = $this->chapter . '_' . $this->subchapter . '_' . $this->name; // stub() is also able to restub the $this->stub. Already stubbed values won't change. $this->stub = $this->stub(); // If the new stub is different from the old one (if the chapter was // already existing), rename the folder. if (isset($old_stub) && $old_stub != $this->stub) { $this->get_comic(); $dir_old = "content/comics/" . $this->comic->directory() . "/" . $old_stub . "_" . $this->uniqid; $dir_new = "content/comics/" . $this->comic->directory() . "/" . $this->stub . "_" . $this->uniqid; rename($dir_old, $dir_new); } // $data['team'] must be an array of team NAMES if (isset($data['team'])) { // Remove the empty values in the array of team names. // It happens that the POST contains extra empty values. if (is_array($data['team'])) { foreach ($data['team'] as $key => $value) { if ($value == "") { unset($data['team'][$key]); } } sort($data["team"]); } // In case there's more than a team name in array, get the joint_id. // The joint model is able to create new joints on the fly, do not worry. // Worry rather that the team names must exist. if (count($data['team']) > 1) { // Set team_id to 0 since it's a joint. $this->team_id = 0; $joint = new Joint(); // If the search returns false, something went wrong. // GUI errors are inside the function. if (!$this->joint_id = $joint->add_joint_via_name($data['team'])) { log_message('error', 'update_chapter_db: error with joint_id'); return false; } } // In case there's only one team in the array, find the team. // return false in case one of the names doesn't exist. else if (count($data['team']) == 1) { // Set joint_id to 0 since it's a single team $this->joint_id = 0; $team = new Team(); $team->where("name", $data['team'][0])->get(); if ($team->result_count() == 0) { set_notice('error', _('The team you were referring this chapter to doesn\'t exist.')); log_message('error', 'update_chapter_db: team_id does not exist in team database'); return false; } $this->team_id = $team->id; } else { set_notice('error', _('You must select at least one team for this chapter')); log_message('error', 'update_chapter_db: team_id not defined'); return false; } } else if (!isset($this->team)) { // If we're here it means that this is a new chapter with no teams assigned. // The system doesn't allow chapters without related teams. It must be at // least "anonymous" or a default anonymous team. set_notice('error', _('You haven\'t selected any team in relation to this chapter.')); log_message('error', 'update_chapter_db: team_id does not defined'); return false; } // Save with validation. Push false if fail, true if good. $success = $this->save(); if (!$success) { if (!$this->valid) { log_message('error', $this->error->string); set_notice('error', _('Check that you have inputted all the required fields.')); log_message('error', 'update_chapter_db: failed validation'); } else { set_notice('error', _('Failed to save to database for unknown reasons.')); log_message('error', 'update_chapter_db: failed to save'); } return false; } else { // Here we go! return true; } }
function team_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; $team = new Team(); $team->where('id', $this->get('id'))->limit(1)->get(); if ($team->result_count() == 1) { $result = array(); $result['team'] = $team->to_array(); // get joints to get also the chapters from joints $joints = new Joint(); $joints->where('team_id', $team->id)->get(); $chapters = new Chapter(); $chapters->where('team_id', $team->id); foreach ($joints->all as $joint) { $chapters->or_where('joint_id', $joint->joint_id); } $chapters->limit(100, $page)->get(); $chapters->get_comic(); $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { if (!$chapter->team_id) { $chapter->get_teams(); foreach ($chapter->teams as $item) { $result['chapters'][$key]['teams'][] = $item->to_array(); } } else { $result['chapters'][$key]['teams'][] = $team->to_array(); } $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); } $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(array('error' => _('Team could not be found')), 404); } }
/** * Returns chapters per page from team ID * Includes releases from joints too * * This is NOT a method light enough to lookup teams. use api/members/team for that * * Available filters: id (required), page, per_page (default:30, max:100), orderby * * @author Woxxy */ function team_get() { // get the single team by id or stub if ($this->get('stub')) { $team = new Team(); $team->where('stub', $this->get('stub'))->limit(1)->get(); } else { // check that the id is at least a valid number $this->_check_id(); $team = new Team(); $team->where('id', $this->get('id'))->limit(1)->get(); } // team found? if ($team->result_count() == 1) { $result = array(); $result['team'] = $team->to_array(); // get joints to get also the chapters from joints $joints = new Joint(); $joints->where('team_id', $team->id)->get(); $chapters = new Chapter(); // get all chapters with the team ID $chapters->where('team_id', $team->id); foreach ($joints->all as $joint) { // get also all chapters with the joints by the team $chapters->or_where('joint_id', $joint->joint_id); } // filter for the page and the order $this->_orderby($chapters); $this->_page_to_offset($chapters); $chapters->get(); $chapters->get_comic(); // let's save some power by reusing the variables we already have for team // and put everything in the usual clean [comic][chapter][teams] $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { if (!$chapter->team_id) { $chapter->get_teams(); foreach ($chapter->teams as $item) { $result['chapters'][$key]['teams'][] = $item->to_array(); } } else { $result['chapters'][$key]['teams'][] = $team->to_array(); } $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); } // all good $this->response($result, 200); // 200 being the HTTP response code } else { // that single team id wasn't found $this->response(array('error' => _('Team could not be found')), 404); } }
function apply_team($team_id) { if (!isAjax()) { return false; } $this->viewdata["function_title"] = "Applying to team..."; $team = new Team($team_id); if ($team->result_count() != 1) return false; $member = new Membership(); $member->apply($team->id, $this->tank_auth->get_user_id()); flash_notice('notice', _('You have applied for membership in this team. Come later to check the status of your application.')); echo json_encode(array('href' => site_url('/admin/members/teams/' . $team->stub))); }
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); }
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); } }