Skip to content
Snippets Groups Projects
Rating.php 11.9 KiB
Newer Older
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Teacher_Rating extends Controller_UserEnvi {

    public function before() {
        Cookie::set('fD', 'true'); // Без куки файл качаться не будет, типа защита
        parent::before();
    }
    // Получить из кука SGID выбранную ранее группу
    private function GetSGID($id)
    {
        # $id = disciplineID
        $SG_ar = json_decode(Cookie::get('SGID', null), true);
        if ($SG_ar !== null) 
            if (array_key_exists($id, $SG_ar))
                return $SG_ar[$id];
        }
        return 0;
    public function action_edit()
    {
        $twig = Twig::factory('teacher/rating');
        $twig->User = $this->UserInfo;
        $db = new Model_Teacher_Rating;
Антон Шалимов's avatar
Антон Шалимов committed
		
        // Шапка таблицы: структура УКД (модули и мероприятия)
		$structure = $db->GetMapForDiscipline($this->UserInfo['TeacherID'], $id);
        if($structure->count() == 0)
            throw HTTP_Exception::factory (404, "Для дисциплины с ID $id не создана УКД или такой дисциплины не существует!");
		$structureHandled = array();
        foreach($structure as $row)
                    $twig->SubjectName = $row['SubjectName'];
            if(!isset($structureHandled[$i]['SubmodulesCount']))
                $structureHandled[$i]['SubmodulesCount'] = 0;
                $structureHandled[$i]['MaxRate'] = 0;
            $j = $structureHandled[$i]['SubmodulesCount'] += 1;
            $structureHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
            $structureHandled[$i]['ModuleTitle'] = $row['ModuleName'];
            $structureHandled[$i]['ModuleType'] = $row['ModuleType'];
PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['ModuleType'] == "exam") {
                $twig->examSubmoduleID = $row['SubmoduleID'];
PavelBegunkov's avatar
PavelBegunkov committed
            }
            $structureHandled[$i][$j]['SubmoduleID'] = $row['SubmoduleID'];
            $structureHandled[$i][$j]['Title'] = $row['SubModuleName'];
            //$structureHandled[$i][$j]['Description'] = $row['SubmoduleDescription']; // Описание
            $structureHandled[$i][$j]['MaxRate'] = (int) $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed

            if ($row['ModuleType'] == "exam" || $row['ModuleType'] == "extra") {
                $structureHandled[$i][$j]['SubmoduleID'] = -1;
            }
        $structureHandled['ModulesCount'] = $i;
        $structureHandled['MaxRate'] = (int) $maxRate; 
        $twig->headerRate = $structureHandled; 
        //echo debug::vars($structureHandled);
        // end Шапка таблицы


        // Студенты и их баллы
Anton's avatar
Anton committed
        $students = $db->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
PavelBegunkov's avatar
PavelBegunkov committed

        $rateHandled = array();
        $groupsHandled = array();
        $i_g = 0; $i_s = 0; $curGroup = 0;
PavelBegunkov's avatar
PavelBegunkov committed

            // Группа
            if ($curGroup !== $row['GroupID']) {
                $curGroup = $row['GroupID'];
                $i_g++;
                $rateHandled[$i_g]['GroupID'] = $row['GroupID'];
                $rateHandled[$i_g]['GroupNum'] = $row['GroupNum']; // № группы
                $rateHandled[$i_g]['GradeNum'] = $row['GradeNum']; // № курса
                $rateHandled[$i_g]['isAttached'] = $row['isAttached']; // #1

                if ($row['Degree'] == 'bachelor')
                    $rateHandled[$i_g]['GradeTitle'] = $row['GradeNum'].' курс';

                if ($row['Degree'] == 'specialist')
                    $rateHandled[$i_g]['GradeTitle'] = $row['GradeNum'].' курс';

                if ($row['Degree'] == 'master')
                    $rateHandled[$i_g]['GradeTitle'] = 'Магистратура, '.$row['GradeNum'].' год';

                $groupsHandled[$curGroup] = $rateHandled[$i_g]['GradeTitle']." ".$row['GroupNum']." группа"; 
            }
            // Студенты
            $i_s++;
            $rateHandled[$i_g]['Students'][$i_s]['ID'] = $row['ID'];
            $rateHandled[$i_g]['Students'][$i_s]['Last'] = $row['Last'];
            $rateHandled[$i_g]['Students'][$i_s]['First'] = $row['First'];
            $rateHandled[$i_g]['Students'][$i_s]['Second'] = $row['Second'];
            $rateHandled[$i_g]['Students'][$i_s]['isAttached'] = $row['isAttached']; // #1

            // Баллы студента
            $rate = $db->getMapForStudent($row['ID'], $id);
            $i_r = 0;
            $rateHandled[$i_g]['Students'][$i_s]['RateResult'] = 0;
            foreach($rate as $r) {
                $i_r++;
                $rateHandled[$i_g]['Students'][$i_s]['Rates'][$i_r]['Rate'] = $r['Rate'];
                $rateHandled[$i_g]['Students'][$i_s]['RateResult'] += $r['Rate'];
PavelBegunkov's avatar
PavelBegunkov committed

                if ($r['ModuleType'] == 'exam' || $r['ModuleType'] == 'extra')
                    $rateHandled[$i_g]['Students'][$i_s]['Rates'][$i_r]['SubmoduleID'] = -1;
                else
                    $rateHandled[$i_g]['Students'][$i_s]['Rates'][$i_r]['SubmoduleID'] = $r['SubmoduleID'];
        $twig->rateTable = $rateHandled;
        $twig->groups = $groupsHandled;
        $twig->studyGroupID = $this->GetSGID($id);

Антон Шалимов's avatar
Антон Шалимов committed
        $twig->DisciplineID = $id;

Антон Шалимов's avatar
Антон Шалимов committed
    public function action_exam()
Антон Шалимов's avatar
Антон Шалимов committed
    {
        $twig = Twig::factory('teacher/exam');
        $twig->User = $this->UserInfo;
        $id = $this->request->param('id');
        $db = new Model_Teacher_Rating;

        // Узнаем ExamType TODO
        $dbMap = new Model_Teacher_Map;
        $disc_temp = $dbMap->getDisciplineInfoByID($id);
        $disciplineInfo['ExamType'] = $disc_temp[0]['ExamType'];
        $disciplineInfo['ID'] = $id;
        // END TODO
        // Шапка таблицы: структура УКД (модули и мероприятия)
        $structure = $db->GetMapForDisciplineExam($this->UserInfo['TeacherID'], $id);

        if($structure->count() == 0)
            throw HTTP_Exception::factory (404, "Страница не найдена");

        
        $structureHandled = array();
PavelBegunkov's avatar
PavelBegunkov committed
        $maxRate = 0; $i = 0; $module = 0; $try_1 = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
        $examRate = 0;
PavelBegunkov's avatar
PavelBegunkov committed
        $try = 0;

        foreach($structure as $row)
        {
PavelBegunkov's avatar
PavelBegunkov committed
            if($row['ModuleID'] != $module)
            {
               ++$i;
               $module = $row['ModuleID'];
            }
            if ($i == 1)
                  $twig->SubjectName = $row['SubjectName'];
            if(!isset($structureHandled[$i]['SubmodulesCount']))
            {
                $structureHandled[$i]['SubmodulesCount'] = 0;
                $structureHandled[$i]['MaxRate'] = 0;
            }
            $j = $structureHandled[$i]['SubmodulesCount'] += 1;
            $structureHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
            $structureHandled[$i]['ModuleTitle'] = $row['ModuleName'];
            $structureHandled[$i]['ModuleType'] = $row['ModuleType'];
            if ($row['ModuleType'] == "exam")
                $twig->examSubmoduleID = $row['SubmoduleID'];
                    
            $structureHandled[$i][$j]['SubmoduleID'] = $row['SubmoduleID'];
PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['ModuleType'] == 'extra') {
                $structureHandled[$i][$j]['Title'] = 'Добор баллов';
PavelBegunkov's avatar
PavelBegunkov committed
                $maxRate += $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
            }
PavelBegunkov's avatar
PavelBegunkov committed
                if ($try === 0)
                    $structureHandled[$i][$j]['Title'] = 'Основная сдача';
                else
                    $structureHandled[$i][$j]['Title'] = 'Пересдача '.$try;
PavelBegunkov's avatar
PavelBegunkov committed
                $examRate = $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
                $try++;
            //$structureHandled[$i][$j]['Description'] = $row['SubmoduleDescription']; // Описание
            $structureHandled[$i][$j]['MaxRate'] = (int) $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
           
        }
        $structureHandled['ModulesCount'] = $i;
        $structureHandled['MaxRate'] = (int) $maxRate; 

        $twig->headerRate = $structureHandled;
        // end Шапка таблицы

        // Студенты и их баллы по экзамену
        $students = $db->GetStudentsForRating($this->UserInfo['TeacherID'], $id);

        $rateHandled = array();
        $groupsHandled = array();
PavelBegunkov's avatar
PavelBegunkov committed
        $i_g = 0; 
        $i_s = 0; 
        $curGroupID = 0;

        foreach($students as $row) {
PavelBegunkov's avatar
PavelBegunkov committed
            // Группа 
PavelBegunkov's avatar
PavelBegunkov committed
            if ($curGroupID !== $row['GroupID']) {
                $curGroupID = $row['GroupID'];
                $i_g++;
                $rateHandled[$i_g]['GroupID'] = $row['GroupID'];
                $rateHandled[$i_g]['GroupNum'] = $row['GroupNum']; // № группы
                $rateHandled[$i_g]['GradeNum'] = $row['GradeNum']; // № курса
                $rateHandled[$i_g]['isAttached'] = $row['isAttached']; // #1

                if ($row['Degree'] == 'bachelor')
                    $rateHandled[$i_g]['GradeTitle'] = $row['GradeNum'].' курс';

                if ($row['Degree'] == 'specialist')
                    $rateHandled[$i_g]['GradeTitle'] = $row['GradeNum'].' курс';

                if ($row['Degree'] == 'master')
                    $rateHandled[$i_g]['GradeTitle'] = 'Магистратура, '.$row['GradeNum'].' год';

PavelBegunkov's avatar
PavelBegunkov committed
                $groupsHandled[$curGroupID] = $rateHandled[$i_g]['GradeTitle']." ".$row['GroupNum']." группа"; 
            }
            // Студенты
            $i_s++;
PavelBegunkov's avatar
PavelBegunkov committed
            
            $curStudent = $rateHandled[$i_g]['Students'][$i_s];

            $curStudent['ID'] = $row['ID'];
            $curStudent['Last'] = $row['Last'];
            $curStudent['First'] = $row['First'];
            $curStudent['Second'] = $row['Second'];
            $curStudent['isAttached'] = $row['isAttached']; // #1

            // Баллы студента
            $rate = $db->getMapForStudentExam($row['ID'], $id);
            $i_r = 0;
PavelBegunkov's avatar
PavelBegunkov committed
            $curStudent['RateResult'] = 0;
PavelBegunkov's avatar
PavelBegunkov committed
            $examRate = 0;
PavelBegunkov's avatar
mx  
PavelBegunkov committed
            $extraNum = 0;
PavelBegunkov's avatar
PavelBegunkov committed

            foreach($rate as $r) {
                $i_r++;
PavelBegunkov's avatar
PavelBegunkov committed
                $curRate = $curStudent['Rates'][$i_r];
PavelBegunkov's avatar
mx  
PavelBegunkov committed

PavelBegunkov's avatar
PavelBegunkov committed
                $curRate['SubmoduleID'] = $r['SubmoduleID'];
                $curRate['Rate'] = $r['Rate'];
                $curRate['ModuleType'] = $r['ModuleType'];  
                
PavelBegunkov's avatar
PavelBegunkov committed
                if ($r['ModuleType'] == 'exam') {
                    if (!is_null($r['Rate'])) {
                        for ($k = 1; $k < $i_r; $k++)
PavelBegunkov's avatar
PavelBegunkov committed
                            if ($curStudent['Rates'][$k]['ModuleType'] == 'exam')
                                $curStudent['Rates'][$k]['Block'] = 'True';
PavelBegunkov's avatar
PavelBegunkov committed
                        $examRate = $r['Rate'];
PavelBegunkov's avatar
PavelBegunkov committed
                } else {
PavelBegunkov's avatar
PavelBegunkov committed
                    $extraNum = $i_r;
PavelBegunkov's avatar
PavelBegunkov committed
                    $curStudent['RateResult'] += $r['Rate']; 
PavelBegunkov's avatar
PavelBegunkov committed
                }
PavelBegunkov's avatar
PavelBegunkov committed
                $curStudent['Rates'][$i_r] = $curRate;
PavelBegunkov's avatar
PavelBegunkov committed
            $curStudent['RateResult'] += $examRate;
PavelBegunkov's avatar
PavelBegunkov committed
            $total = $db->GetStudentRate($row['ID'], $id);
            $total = $total[0]['Num'];
            if (is_null($total)) $total = 0;
PavelBegunkov's avatar
PavelBegunkov committed
            $curStudent['RateSemesterResult'] = $total - $curStudent['RateResult'];
            $curStudent['RateResult'] = $total;
Антон Шалимов's avatar
Антон Шалимов committed

PavelBegunkov's avatar
PavelBegunkov committed
            $rateHandled[$i_g]['Students'][$i_s] = $curStudent;

        //echo Debug::vars($structureHandled);
Антон Шалимов's avatar
Антон Шалимов committed
        echo Debug::vars($rateHandled);	
        $twig->rateTable = $rateHandled;
        $twig->groups = $groupsHandled;

        $twig->studyGroupID = $this->GetSGID($id);
        $twig->disciplineInfo = $disciplineInfo;
Антон Шалимов's avatar
Антон Шалимов committed

Антон Шалимов's avatar
Антон Шалимов committed
        $this->response->body($twig);
    }