From 6c1d8d3215483b302192079f66a1e9bf26b0a30c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A8=D0=B0=D0=BB=D0=B8?=
 =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= <solidovic@gmail.com>
Date: Sun, 28 Dec 2014 14:54:00 +0300
Subject: [PATCH] =?UTF-8?q?HOT=20FIX:=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=8D?=
 =?UTF-8?q?=D0=BA=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD,=20=D1=82=D0=BE=20=D1=81?=
 =?UTF-8?q?=D1=83=D0=BC=D0=BC=D0=B0=20=D0=B1=D0=B0=D0=BB=D0=BB=D0=BE=D0=B2?=
 =?UTF-8?q?=20=D0=B2=20=D1=82=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81?=
 =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D1=81=D1=82=D1=80=D0=B0=20=D0=BD=D0=B5=20?=
 =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B2=D1=8B=D1=88=D0=B0=D0=B5=D1=82=2060=20?=
 =?UTF-8?q?=D0=B1=D0=B0=D0=BB=D0=BB=D0=BE=D0=B2;=20+=20=D0=BE=D0=BF=D1=82?=
 =?UTF-8?q?=D0=B8=D0=BC=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20+=20=D0=B4?=
 =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20json=5Fsettings=20[?=
 =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20?=
 =?UTF-8?q?js],=20=D0=B2=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=BC=20(S?=
 =?UTF-8?q?tudyGroupID=5FFilter=20=D0=B8=20ID=20=D0=B4=D0=B8=D1=81=D1=86?=
 =?UTF-8?q?=D0=B8=D0=BF=D0=BB=D0=B8=D0=BD=D1=8B)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../classes/Controller/Teacher/Rating.php     | 141 +++++++++++-------
 .../application/views/teacher/exam.twig       |   2 +-
 .../application/views/teacher/rating.twig     |   7 +-
 ~dev_rating/media/js/rating.js                |  23 ++-
 4 files changed, 111 insertions(+), 62 deletions(-)

diff --git a/~dev_rating/application/classes/Controller/Teacher/Rating.php b/~dev_rating/application/classes/Controller/Teacher/Rating.php
index 514d80cbf..dea08e8ed 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Rating.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Rating.php
@@ -3,48 +3,65 @@
 class Controller_Teacher_Rating extends Controller_UserEnvi {
 
     public function before() {
-        Cookie::set('fD', 'true'); // Без куки файл качаться не будет, типа защита
+        Cookie::set('fD', 'true'); // Ставим кук fD, чтоб иметь возможность скачать отчет TODO
+
+        $this->model_rating = new Model_Teacher_Rating;
+        $this->model_discipline = new Model_Teacher_Map;
+
         parent::before();
     }
-    
-    // Получить из кука SGID выбранную ранее группу
-    private function GetSGID($id)
+
+    // Получить из кука SGID выбранную ранее группу для данной дисциплины
+    private function getStudyGroupID_ForFilter($id)
     {
         # $id = disciplineID
-        $SG_ar = json_decode(Cookie::get('SGID', null), true);
-        if ($SG_ar !== null) 
+        $SG_array = json_decode(Cookie::get('SGID', null), true);
+        if ($SG_array !== null) 
         {
-            if (array_key_exists($id, $SG_ar))
-                return $SG_ar[$id];
+            if (array_key_exists($id, $SG_array))
+                return $SG_array[$id];
         }
         return 0;
     }
 
+    // Настройки дисциплины и выбранная группа(для фильтра)
+    private function getDisciplineInformation($id) {
+
+        $temp = $this->model_discipline->getDisciplineInfoByID($id);
+        $disciplineInfo['ExamType'] = $temp[0]['ExamType'];
+        $disciplineInfo['ID'] = $id;
+        $disciplineInfo['StudyGroupID_Filter'] = $this->getStudyGroupID_ForFilter($id);
+
+        return $disciplineInfo;
+    }
+
+
+    // Страница оценивания в течение семестра
     public function action_edit()
     {
         $twig = Twig::factory('teacher/rating');
         $twig->User = $this->UserInfo;
         $id = $this->request->param('id');
-        $db = new Model_Teacher_Rating;
-		
+
         // Шапка таблицы: структура УКД (модули и мероприятия)
-		$structure = $db->GetMapForDiscipline($this->UserInfo['TeacherID'], $id);
+		$structure = $this->model_rating->GetMapForDiscipline($this->UserInfo['TeacherID'], $id);
 
         if($structure->count() == 0)
             throw HTTP_Exception::factory (404, "Для дисциплины с ID $id не создана УКД или такой дисциплины не существует!");
         
 		$structureHandled = array();
-        $maxRate = 0; $i = 0; $module = 0;
+        $maxRate = 0; $i = 0; $temp_moduleID = 0;
 
         foreach($structure as $row)
         {
-            if($row['ModuleID'] != $module)
+            if($row['ModuleID'] != $temp_moduleID)
             {
-                $i++;
-                $module = $row['ModuleID'];
+                $i++; // todo
+                $temp_moduleID = $row['ModuleID'];
             }
             if ($i == 1)
-                    $twig->SubjectName = $row['SubjectName'];
+                $twig->SubjectName = $row['SubjectName'];
+
             if(!isset($structureHandled[$i]['SubmodulesCount']))
             {
                 $structureHandled[$i]['SubmodulesCount'] = 0;
@@ -70,14 +87,11 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
         }
         $structureHandled['ModulesCount'] = $i;
         $structureHandled['MaxRate'] = (int) $maxRate; 
-
-        $twig->headerRate = $structureHandled; 
-        //echo debug::vars($structureHandled);
         // end Шапка таблицы
 
 
         // Студенты и их баллы
-        $students = $db->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
+        $students = $this->model_rating->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
 
         $rateHandled = array();
         $groupsHandled = array();
@@ -85,7 +99,8 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
 
         foreach($students as $row) {
             // Группа
-            if ($curGroup !== $row['GroupID']) {
+            if ($curGroup !== $row['GroupID']) 
+            {
                 $curGroup = $row['GroupID'];
                 $i_g++;
                 $rateHandled[$i_g]['GroupID'] = $row['GroupID'];
@@ -104,7 +119,37 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
 
                 $groupsHandled[$curGroup] = $rateHandled[$i_g]['GradeTitle']." ".$row['GroupNum']." РіСЂСѓРїРїР°"; 
             }
+
             // Студенты
+            $curStudent = array();
+            $i_s++;
+            $curStudent['ID'] = $row['ID'];
+            $curStudent['Last'] = $row['Last'];
+            $curStudent['First'] = $row['First'];
+            $curStudent['Second'] = $row['Second'];
+            $curStudent['isAttached'] = $row['isAttached']; // #1
+
+            // Баллы студента
+            $rates = $this->model_rating->getMapForStudent($row['ID'], $id);
+            $i_r = 0;
+            $curStudent['RateResult'] = 0;
+            foreach($rates as $r) {
+                $i_r++;
+                $curStudent['Rates'][$i_r]['Rate'] = $r['Rate'];
+                $curStudent['RateResult'] += $r['Rate'];
+
+                if ($r['ModuleType'] == 'exam')
+                    $curStudent['Rates'][$i_r]['SubmoduleID'] = -1;
+                else if ($r['ModuleType'] == 'extra')
+                    $curStudent['Rates'][$i_r]['SubmoduleID'] = -2;
+                else 
+                    $curStudent['Rates'][$i_r]['SubmoduleID'] = $r['SubmoduleID'];
+
+                $curStudent['Rates'][$i_r]['Type'] = $r['ModuleType'];
+            }
+            $rateHandled[$i_g]['Students'][$i_s] = $curStudent;
+
+            /*
             $i_s++;
             $rateHandled[$i_g]['Students'][$i_s]['ID'] = $row['ID'];
             $rateHandled[$i_g]['Students'][$i_s]['Last'] = $row['Last'];
@@ -113,7 +158,7 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $rateHandled[$i_g]['Students'][$i_s]['isAttached'] = $row['isAttached']; // #1
 
             // Баллы студента
-            $rate = $db->getMapForStudent($row['ID'], $id);
+            $rate = $this->model_rating->getMapForStudent($row['ID'], $id);
             $i_r = 0;
             $rateHandled[$i_g]['Students'][$i_s]['RateResult'] = 0;
             foreach($rate as $r) {
@@ -128,53 +173,49 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
                 else 
                     $rateHandled[$i_g]['Students'][$i_s]['Rates'][$i_r]['SubmoduleID'] = $r['SubmoduleID'];
             }
+            */
         }
 
+        // На вывод
+        $twig->headerRate = $structureHandled; 
         $twig->rateTable = $rateHandled;
         $twig->groups = $groupsHandled;
 
-        $twig->studyGroupID = $this->GetSGID($id);
-
-        $twig->DisciplineID = $id;
+        $twig->disciplineInfo = $this->getDisciplineInformation($id);
+        $twig->disciplineInfo_JSON = json_encode($twig->disciplineInfo);
 
 		$this->response->body($twig);
     }
 
+    // Страница оценивания в сессию
     public function action_exam()
     {
         $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);
+        $structure = $this->model_rating->GetMapForDisciplineExam($this->UserInfo['TeacherID'], $id);
 
         if($structure->count() == 0)
             throw HTTP_Exception::factory (404, "Страница не найдена");
 
         
         $structureHandled = array();
-        $maxRate = 0; $i = 0; $module = 0; $try_1 = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
+        $maxRate = 0; $i = 0; $temp_moduleID = 0; $try_1 = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
         $examRate = 0;
         $try = 0;
 
         foreach($structure as $row)
         {
-            if($row['ModuleID'] != $module)
+            if($row['ModuleID'] != $temp_moduleID)
             {
-               ++$i;
-               $module = $row['ModuleID'];
+               ++$i; // todo
+               $temp_moduleID = $row['ModuleID'];
             }
             if ($i == 1)
-                  $twig->SubjectName = $row['SubjectName'];
+                $twig->SubjectName = $row['SubjectName'];
+
             if(!isset($structureHandled[$i]['SubmodulesCount']))
             {
                 $structureHandled[$i]['SubmodulesCount'] = 0;
@@ -206,12 +247,10 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
         }
         $structureHandled['ModulesCount'] = $i;
         $structureHandled['MaxRate'] = (int) $maxRate; 
-
-        $twig->headerRate = $structureHandled;
         // end Шапка таблицы
 
         // Студенты и их баллы по экзамену
-        $students = $db->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
+        $students = $this->model_rating->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
 
         $rateHandled = array();
         $groupsHandled = array();
@@ -241,9 +280,8 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
                 $groupsHandled[$curGroupID] = $rateHandled[$i_g]['GradeTitle']." ".$row['GroupNum']." РіСЂСѓРїРїР°"; 
                 $i_s = 0;
             }
-            // Студенты
-            
-            
+
+            // Студенты   
             $curStudent = array();
             $curStudent['ID'] = $row['ID'];
             $curStudent['Last'] = $row['Last'];
@@ -256,7 +294,7 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $i_r = 0;
             $examRate = 0;
             $extraNum = 0;
-            $rate = $db->getMapForStudentExam($row['ID'], $id);
+            $rate = $this->model_rating->getMapForStudentExam($row['ID'], $id);
 
             $lastExam = -1;
             $lastExtra = -1;
@@ -304,7 +342,7 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
 
 
             $curStudent['RateResult'] += $examRate;
-            $total = $db->GetStudentRate($row['ID'], $id);
+            $total = $this->model_rating->GetStudentRate($row['ID'], $id);
             $total = $total[0]['Num'];
             if (is_null($total)) $total = 0;
             
@@ -334,14 +372,13 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $i_s++;
         }
 
-        //echo Debug::vars($structureHandled);
-        //echo Debug::vars($rateHandled);	
+        // На вывод
+	    $twig->headerRate = $structureHandled;
         $twig->rateTable = $rateHandled;
         $twig->groups = $groupsHandled;
 
-        $twig->studyGroupID = $this->GetSGID($id);
-
-        $twig->disciplineInfo = $disciplineInfo;
+        $twig->disciplineInfo = $this->getDisciplineInformation($id);
+        $twig->disciplineInfo_JSON = json_encode($twig->disciplineInfo);
 
         $this->response->body($twig);
     }
diff --git a/~dev_rating/application/views/teacher/exam.twig b/~dev_rating/application/views/teacher/exam.twig
index c8b6c5078..096ffba47 100644
--- a/~dev_rating/application/views/teacher/exam.twig
+++ b/~dev_rating/application/views/teacher/exam.twig
@@ -126,6 +126,6 @@
 		</div>
 	</div>
 	<div id="hidden_div">
-		{ "studyGroupID": "{{ studyGroupID }}" }
+		{{ disciplineInfo_JSON|raw }}
 	</div>
 {% endblock %}
\ No newline at end of file
diff --git a/~dev_rating/application/views/teacher/rating.twig b/~dev_rating/application/views/teacher/rating.twig
index 6c63dfc15..d2298cd4f 100644
--- a/~dev_rating/application/views/teacher/rating.twig
+++ b/~dev_rating/application/views/teacher/rating.twig
@@ -15,7 +15,8 @@
 	<h2 class="h2_titleSubject">{{ SubjectName }}</h2>
 
 	<button class="downloadExcel" style="display: none">Скачать в excel формате [dev version]</button>
-    {{ HTML.anchor('exam/'~DisciplineID, 
+
+    {{ HTML.anchor('exam/'~disciplineInfo.ID, 
             "Перейти к сессии →", 
             {'title': 'Сессия', 'class': 'exam_a'})|raw }}
 
@@ -97,7 +98,7 @@
 							</td>
 						{% else %}
 							{% set j = j - 1 %}
-							<td class="staticCell">
+							<td class="staticCell{% if student.Rates[i].Type == 'exam' %} examCell{% endif %}">
 								<p>{{ student.Rates[i].Rate }}</p>
 							</td>
 						{% endif %}
@@ -116,6 +117,6 @@
 		</div>
 	</div>
 	<div id="hidden_div">
-		{ "studyGroupID": "{{ studyGroupID }}" }
+		{{ disciplineInfo_JSON|raw }}
 	</div>
 {% endblock %}
\ No newline at end of file
diff --git a/~dev_rating/media/js/rating.js b/~dev_rating/media/js/rating.js
index 7cfac75c8..c85ab1fde 100644
--- a/~dev_rating/media/js/rating.js
+++ b/~dev_rating/media/js/rating.js
@@ -2,7 +2,7 @@ var $ = jQuery;
 $(function() {
     var g_col;
     var g_row;
-    var g_isFocusCell = false; // Стоит фокус или нет
+    var g_isFocusCell = false; // Стоит фокус на ячейки или нет
     var g_oldRateCell = null;
     var g_submoduleID = null;
     var g_studentID = null;
@@ -15,11 +15,14 @@ $(function() {
     var g_URL = (window.location.href).split("/");
     var g_disciplineID = g_URL[g_URL.length - 1];
 
-    // studyGroupID для фильтра (Эффект памяти)
+    // Настройки дисциплины:
+    // + ID - id дисциплины
+    // + studyGroupID_Filter - studyGroupID для фильтра (Эффект памяти)
     var json_settings = $.parseJSON($("#hidden_div").html());
+    console.log(json_settings);
     $("#hidden_div").remove();
-    filterGroups(json_settings.studyGroupID);
-    $(".groupSelector [value='"+ json_settings.studyGroupID +"']").attr("selected", "selected");
+    filterGroups(json_settings.StudyGroupID_Filter);
+    $(".groupSelector [value='"+ json_settings.StudyGroupID_Filter +"']").attr("selected", "selected");
 
     // Скрываем все остальные группы
     // 0 - показать все
@@ -142,7 +145,7 @@ $(function() {
 
         var rateResult = parseInt(jThis.siblings(".rateResultCell").text()) - oldRate + newRate;
 
-		// exams
+		// страница сессии
 		if (jThis.attr("class").indexOf("attemptCell") >= 0)
 		{
 			//if (jThis.siblings(".semesterRateResultCell ").length > 0) {
@@ -154,7 +157,7 @@ $(function() {
 			});
 			//}
 		}
-		//end exams
+		//end страница сессии
 
         if (rateResult > 100) {
             jThis.children("input").val(oldRate);
@@ -163,6 +166,14 @@ $(function() {
         }
         else 
         {
+          	if ((json_settings.ExamType == "exam") && (rateResult - parseInt(jThis.siblings(".examCell").text())) > 60)
+          	{
+	            jThis.children("input").val(oldRate);
+	            EventInspector_ShowMsg("Сумма баллов не может привышать 60 (т.к. 40 на экзамен)", "error");
+	            jThis.children("input").removeAttr("disabled");
+	            return -1;
+          	}
+
             if (newRate <= g_submoduleMaxRate) 
             {
                 $.ajax({
-- 
GitLab