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;
 }
Exemplo n.º 2
0
    include $GLOBALS['BASE_DIR'] . '/debug.php';
}
includes_psu_register('TrainingTracker', $GLOBALS['BASE_DIR'] . '/includes');
require_once 'klein/klein.php';
require_once $GLOBALS['BASE_DIR'] . '/includes/TrainingTrackerAPI.class.php';
IDMObject::authN();
/**
 * Routing provided by klein.php (https://github.com/chriso/klein.php)
 * Make some objects available elsewhere.
 */
//Catch all
respond(function ($request, $response, $app) {
    // get the logged in user
    $app->user = PSUPerson::get($_SESSION['wp_id']);
    $memcache = new \PSUMemcache('training-tracker_teams');
    if (!($cached_results = $memcache->get('is_admin'))) {
        $staff_collection = new TrainingTracker\StaffCollection();
        $staff_collection->load();
        $valid_users = $staff_collection->valid_users();
        $is_valid = false;
        $is_mentor = false;
        $is_admin = false;
        foreach ($valid_users as $user) {
            if ($app->user->wpid == $user->wpid) {
                $is_valid = true;
            }
        }
        if (!$is_valid) {
            die('You do not have access to this app.');
        }
        $teams_data = TrainingTracker::get_teams();