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

    public function action_index() {
        $student_id = $this->UserInfo['StudentID'];
        $disciplines = Model_Disciplines::ofStudent($student_id);
        $colorsList = array('Undefined', 'ECTS-F', 'ECTS-FX', 'ECTS-E', 'ECTS-D', 'ECTS-C', 'ECTS-B', 'ECTS-A');

        $list = array();
        foreach ($disciplines as $row) {
            $row['Title'] = $row['SubjectName'];
            $row['Teachers'] = $this->getTeachersForDiscipline($row['ID']);
            $row['Control'] = ($row['ExamType'] == 'exam') ? 'Экзамен' : 'Зачет';
            $row['ColorScheme'] = $colorsList[$this->getColor($row['Rate'], $row['MaxCurrentRate'], $row['ExamRate'])];
            $list[] = $row;
        }

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

    protected function getTeachersForDiscipline($id) {
        $teachers = Model_Teachers::ofDiscipline($id);
        $teachersHandled = array(); $i = 0;
        foreach ($teachers as $teacher)
        {
            $i++;
            $teachersHandled[$i] = $teacher['LastName'].' '.UTF8::substr($teacher['FirstName'], 0, 1).'. ';
            if(!empty($teacher['SecondName']))
            {
                $teachersHandled[$i] .= UTF8::substr($teacher['SecondName'], 0, 1).'.';
            }
        }
        return $teachersHandled;
    }
    
    protected function getColor($rate, $current, $examRate)
    {
        if($current > 0)
        {
            $percent = $rate / $current;
            if($percent < 0.31)
                $color = 1;
            elseif($percent >= 0.31 AND $percent <= 0.59)
                $color = 2;
            elseif($percent >= 0.60 AND $percent <= 0.64)
                $color = 3;
            elseif($percent >= 0.65 AND $percent <= 0.70)
                $color = 4;
            elseif($percent >= 0.71 AND $percent <= 0.84)
                $color = 5;
            elseif($percent >= 0.85 AND $percent <= 0.94)
                $color = 6;
            elseif($percent >= 0.95)
                $color = 7;
            if($examRate !== NULL AND $examRate < 22)
                $color = 2;
        }
        else
        {
            $color = 0;
        }
        return $color;
    }


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