public function get_teams($key = null, $type = null) { $memcache = new \PSUMemcache('training-tracker_teams'); if (!$key and !$type) { if (!($cached_results = $memcache->get('teams'))) { $teams = array(); // get all the mentors from the database $sql = "SELECT DISTINCT mentor FROM teams"; $mentors = \PSU::db('hr')->GetAll($sql); foreach ($mentors as $mentor) { $sql = "SELECT * FROM teams WHERE mentor = ?"; $wpid = $mentor['mentor']; $team = \PSU::db('hr')->GetAll($sql, array($wpid)); foreach ($team as $people) { $mentee_wpid = $people['mentee']; $mentee = \PSUPerson::get($mentee_wpid)->formatName("f l"); $mentor_wpid = $people['mentor']; $mentor_name = PSUPerson::get($mentor_wpid)->formatName("f l"); $teams["{$wpid}"]["mentor"]['mentor_name'] = PSUPerson::get($mentor_wpid)->formatName("f l"); $teams["{$wpid}"]["mentor"]['mentor_wpid'] = $mentor_wpid; $teams["{$wpid}"]["{$mentee_wpid}"]['mentor_name'] = PSUPerson::get($mentor_wpid)->formatName("f l"); $teams["{$wpid}"]["{$mentee_wpid}"]["mentor_wpid"] = $mentor_wpid; $teams["{$wpid}"]["{$mentee_wpid}"]["name"] = PSUPerson::get($mentee_wpid)->formatName("f l"); $teams["{$wpid}"]["{$mentee_wpid}"]["wpid"] = $mentee_wpid; } } $sql = "SELECT p.wpid, CONCAT( p.name_first_formatted, ' ', p.name_last_formatted ) AS name\n\t\t\t\t\t\t\t\tFROM call_log_employee e\n\t\t\t\t\t\t\t\tRIGHT OUTER JOIN phonebook.phonebook p ON p.username = e.user_name\n\t\t\t\t\t\t\t\tLEFT OUTER JOIN hr.teams t ON t.mentee = p.wpid\n\t\t\t\t\t\t\t\tWHERE e.status = ?\n\t\t\t\t\t\t\t\tAND t.mentee IS NULL \n\t\t\t\t\t\t\t\tAND e.user_privileges\n\t\t\t\t\t\t\t\tIN (?, ?)\n\t\t\t\t\t\t\t\tORDER BY p.name_last_formatted, p.name_full ASC"; $unassigned = PSU::db('calllog')->GetAll($sql, array("active", 'trainee', 'sta')); foreach ($unassigned as $loner) { $loner_wpid = $loner['wpid']; $teams["unassigned"]["mentor"]["mentor_name"] = "Unassigned"; $teams["unassigned"]["mentor"]["mentor_wpid"] = "unassigned"; $teams["unassigned"]["{$loner_wpid}"]["mentor_name"] = "unassigned"; $teams["unassigned"]["{$loner_wpid}"]["mentor_wpid"] = "unassigned"; $teams["unassigned"]["{$loner_wpid}"]["name"] = $loner['name']; $teams["unassigned"]["{$loner_wpid}"]["wpid"] = $loner['wpid']; } $memcache->set('teams', $teams, MEMCACHE_COMPRESSED, 60 * 5); $team_array = $memcache->get('teams'); } else { $team_array = $memcache->get('teams'); } } else { if (!$type) { if (!($cached_results = $memcache->get("teams-all-{$key}"))) { $sql = "SELECT * FROM teams WHERE mentor = ? OR mentee = ?"; $team_array = \PSU::db('hr')->GetAll($sql, array($key, $key)); $memcache->set("teams-all-{$key}", $team_array, MEMCACHE_COMPRESSED, 60 * 5); $team_array = $memcache->get("teams-all-{$key}"); } else { $team_array = $memcache->get("teams-all-{$key}"); } } else { // get all where key matches the type $sql = "SELECT * FROM teams WHERE {$type} = ?"; $team_array = \PSU::db('hr')->GetAll($sql, array($key)); $memcache->set("teams-{$key}", $team_array, MEMCACHE_COMPRESSED, 60 * 5); $team_array = $memcache->get("teams-{$key}"); } } return $team_array; }
foreach ($admins as $admin) { if ($app->user->wpid == $admin->wpid) { $is_admin = true; $is_mentor = true; } } if (!$is_mentor) { foreach ($mentors as $mentor) { if ($app->user->wpid == $mentor->wpid) { $is_mentor = true; } } } $active_user_parameters['wpid'] = $wpid; $active_user = new TrainingTracker\Staff($active_user_parameters); $memcache->set('active_user', $active_user, MEMCACHE_COMPRESSED, 60 * 5); $memcache->set('has_team', $has_team, MEMCACHE_COMPRESSED, 60 * 5); $memcache->set('is_admin', $is_admin, MEMCACHE_COMPRESSED, 60 * 5); $memcache->set('is_mentor', $is_mentor, MEMCACHE_COMPRESSED, 60 * 5); $memcache->set('is_valid', $is_valid, MEMCACHE_COMPRESSED, 60 * 5); } else { $active_user = $memcache->get('active_user'); $has_team = $memcache->get('has_team'); $is_admin = $memcache->get('is_admin'); $is_mentor = $memcache->get('is_mentor'); $is_valid = $memcache->get('is_mentor'); } if (!$is_valid) { die('You do not have access to this app.'); } $app->active_user = $active_user;