<?php

use PSU\TeacherCert;
respond('/[i:sgs_id]/[*]', function ($request, $response, $app) {
    $sgs_id = $request->param('sgs_id');
    $app->populate(TeacherCert\Student\GateSystem::get($sgs_id));
    $app->populate('schools', new TeacherCert\Schools());
    $app->populate('school_model', new TeacherCert\Model\Student\School());
    $app->populate('teacher_model', new TeacherCert\Model\Student\CooperatingTeacher());
    $app->populate('cancel_url', $app->resolver($app->student_gate_system));
    $app->breadcrumbs->push(new PSU\Template\Breadcrumb($app->student_gate_system->gate_system()->name, $app->resolver($app->gate_system)));
    $app->breadcrumbs->push(new PSU\Template\Breadcrumb(sprintf('%s (%s)', $app->student_gate_system->student()->person()->formatName('f l'), $app->student_gate_system->student()->person()->id), $app->resolver($app->student_gate_system)));
    $app->populate_constituents = function () use($app) {
        $rc = TeacherCert\ActiveRecord::$rowcache = new TeacherCert\RowCache();
        $where = sprintf('id IN (SELECT constituent_id FROM psu_teacher_cert.constituent_schools WHERE school_id = %d)', $app->student_school->school_id);
        $rc->cache('PSU\\TeacherCert\\Constituent', 'id', $where);
        $constituent_schools = new TeacherCert\CooperatingTeachers($app->student_school->school_id);
        $schools_options = TeacherCert\Model::collection($constituent_schools, 'name=constituent_name');
        usort($schools_options, function ($a, $b) {
            return strnatcasecmp($a[1], $b[1]);
        });
        $app->teacher_model->constituent_school_id->options = $schools_options;
    };
});
respond('GET', '/[i:sgs_id]/[add|edit|delete:action]/[i:ss_id]?', function ($request, $response, $app) {
    $ss_id = $request->param('ss_id');
    if ('edit' === $request->param('action')) {
        $app->populate('student_school', TeacherCert\Student\School::get($ss_id));
        $app->populate_constituents();
        // populate form with existing school data
        $f = get_object_vars($app->student_school);
Пример #2
0
        $redirect .= '/gate/' . $gate->slug;
    }
    //end if
    if ($app->gate_system->level_code == 'ug' && !$person->student->ug) {
        $_SESSION['errors'][] = "{$person->formatName('l, f m')} is not an active UG student!";
        $response->redirect($redirect, 400);
    } elseif ($app->gate_system->level_code == 'gr' && !$person->student->gr) {
        $_SESSION['errors'][] = "{$person->formatName('l, f m')} is not an active GR student!";
        $response->redirect($redirect, 400);
    }
    //end if
    $student = new TeacherCert\Student($person->pidm);
    $in_system = false;
    if (!$student->gate_systems($app->gate_system)) {
        $data = array('the_id' => 9999, 'pidm' => $person->pidm, 'gate_system_id' => $app->gate_system->id, 'approve_date' => time());
        $system = new TeacherCert\Student\GateSystem($data);
        if ($system->save()) {
            $_SESSION['successes'][] = "{$person->formatName('l, f m')} has been added to the {$app->gate_system->name} Gate System!";
        } else {
            $_SESSION['errors'][] = "{$person->formatName('l, f m')} could not be added to the {$app->gate_system->name} Gate System. Please contact ITS.";
        }
        //end else
    } else {
        $_SESSION['errors'][] = "{$person->formatName('l, f m')} is already a member of the {$app->gate_system->name} Gate System.";
    }
    //end else
    $response->redirect($redirect);
});
respond('/[:gate_system]/[search:action]', function ($request, $response, $app) {
    $action = $request->param('action');
    if ('search' === $action) {