Skip to content
Snippets Groups Projects
Forked from it-lab / grade
Source project has a limited visibility.
Index.php 1.98 KiB
<?php defined('SYSPATH') or die('No direct script access.');
 
class Controller_Student_Index extends Controller_UserEnvironment {

    public function action_index() {
        $student_id = $this->user['StudentID'];
        $disciplines = Model_Disciplines::ofStudent($student_id);

        $list = array();
        foreach ($disciplines as $row) {
            $row['Title'] = $row['SubjectName'];

            if ($row['Subtype'] == 'disciplinary_coursework')
                $row['Teachers'] = ['Курсовая'];
            elseif ($row['Subtype'] == 'scientific_coursework')
                $row['Teachers'] = ['Науч. рук.'];
            else
                $row['Teachers'] = self::getTeachersForDiscipline($row['ID']);

            $row['Control'] = DataHelper::LocalizeExamType($row['ExamType']);
            $row['ColorScheme'] = Model_Subjects::getECTSMark($row['Rate'], $row['MaxCurrentRate'], $row['ExamRate']);
            $list[] = $row;
        }

        $twig = Twig::factory('student/index');
        if (count($disciplines) > 0)
            $twig->disciplines = $list;
        $twig->User = $this->user;
        $twig->Semester = $this->SemesterInfo;
        $twig->SemesterList = Model_Semesters::toArray();
        $this->response->body($twig);
    }

    /**
     * @param $id int discipline id
     * @return array list of short-form names
     */
    private static function getTeachersForDiscipline($id) {
        $teachers = Model_Teachers::ofDiscipline($id);

        $list = array();
        foreach ($teachers as $teacher) {
            $name = $teacher['LastName'] . ' ' . UTF8::substr($teacher['FirstName'], 0, 1) . '. ';
            if (!empty($teacher['SecondName']))
                $name .= UTF8::substr($teacher['SecondName'], 0, 1) . '.';
            $list[] = $name;
        }
        return $list;
    }

    public function action_settings() {
        $twig = Twig::factory('settings');
        $twig->User = $this->user;
        $this->response->body($twig);
    }
}