Exemple #1
0
});
respond('GET', '/list', function ($request, $responce, $app) {
    $teams_array = TrainingTracker::get_teams();
    $app->tpl->assign('teams_array', $teams_array);
    $app->tpl->display('viewteams.tpl');
});
//the axax post part for teams
respond('POST', '/builder', function ($request, $responce, $app) {
    //get the data to variables from the posted data
    $mentee_wpid = $_POST['data'][0];
    $mentor_wpid = $_POST['data'][1];
    if (TrainingTracker::valid_wpid($mentee_wpid)) {
        if (TrainingTracker::valid_wpid($mentor_wpid)) {
            $result = TrainingTracker::get_teams($mentee_wpid, 'mentee');
            if (isset($result[0])) {
                TrainingTracker::team_set_mentee($mentee_wpid, $mentor_wpid);
                // if team exists with that mentee replace mentor
            } else {
                TrainingTracker::team_insert($mentee_wpid, $mentor_wpid);
                //if the mentee isn't in a team make them a team
            }
        } else {
            if ($mentor_wpid == 'unassigned') {
                //if you move the mentee back to the mentee category in the team builder, it removes their database entry.
                TrainingTracker::team_delete($mentee_wpid);
            }
        }
    }
});
//view teams
respond('GET', '/list/[:wpid]', function ($request, $responce, $app) {