Skip to content
Snippets Groups Projects
Forked from it-lab / grade
Source project has a limited visibility.
Index.php 3.13 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);

        $i = 0;
        $colorsList = array('Undefined', 'ECTS-F', 'ECTS-FX', 'ECTS-E', 'ECTS-D', 'ECTS-C', 'ECTS-B', 'ECTS-A');
        foreach($disciplines as $row)
        {
            $i++;
            $disciplinesHandled[$i]['ID'] = $row['ID'];
            if($row['ExamType'] == 'exam')
            {
                $disciplinesHandled[$i]['Control'] = 'Экзамен';
            }
            elseif($row['ExamType'] == 'credit')
            {
                $disciplinesHandled[$i]['Control'] = 'Зачет';
            }
            $disciplinesHandled[$i]['Teachers'] = $this->getTeachersForDiscipline($row['ID']);
            $disciplinesHandled[$i]['Title'] = $row['SubjectName'];
            $disciplinesHandled[$i]['Rate'] = $row['Rate'];
            $disciplinesHandled[$i]['MaxCurrentRate'] = $row['MaxCurrentRate'];
            $disciplinesHandled[$i]['ColorScheme'] = $colorsList[$this->getColor($row['Rate'], $row['MaxCurrentRate'], $row['ExamRate'])];
        }

        $twig = Twig::factory('student/index');
        if ($i != 0)
            $twig->disciplines = $disciplinesHandled;
        $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);
    }
}