From 2b4bef2de5c4bff5d891d92b5fdfe5c391721df1 Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.Silence@gmail.com>
Date: Sun, 1 Mar 2015 12:21:34 +0300
Subject: [PATCH] FIX: exam page

---
 .../classes/Controller/Teacher/Rating.php     | 16 +++++-----
 .../application/views/teacher/exam.twig       | 32 ++++++++++---------
 ~dev_rating/media/js/rating.js                | 18 ++++++-----
 3 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/~dev_rating/application/classes/Controller/Teacher/Rating.php b/~dev_rating/application/classes/Controller/Teacher/Rating.php
index 032282708..29f107b7e 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Rating.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Rating.php
@@ -1,6 +1,7 @@
 <?php defined('SYSPATH') or die('No direct script access.');
 
 class Controller_Teacher_Rating extends Controller_UserEnvi {
+    protected $model_rating;
 
     public function before() {
         Cookie::set('fD', 'true'); // Ставим кук fD, чтоб иметь возможность скачать отчет TODO
@@ -112,7 +113,7 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
         return $out;
     }
     
-    private function getRatesForRatingPage($info) 
+    private function getRatesForRatingPage($info)
     {
 
         $rates = array();
@@ -219,15 +220,15 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $rowIndex++;
         }
         
-        $total = $this->model_rating->GetStudentRate($curStudent['ID'], $disciplineID);
-        $total = ($total[0])?$total[0]['Num']:0;
-        if ($total)
-            $total = 0;
+//        $total = $this->model_rating->GetStudentRate($curStudent['ID'], $disciplineID);
+//        $total = ($total[0])?$total[0]['Num']:0;
+//        if ($total)
+//            $total = 0;
 
+        $curStudent['RateResult'] = $curStudent['RateSemesterResult'] + $rateExtra;
         if ($lastExam >= 0) {
             $curStudent['RateResult'] += $curStudent['Rates'][$lastExam]['Rate'];
         }
-        $curStudent['RateResult'] = $total;
         $this->correctExtra($curStudent, $examType, $lastExtraIndex, $firstEmptyExtra, $rateExtra);
     }
 	
@@ -283,7 +284,7 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $i_s++;
         }
         
-		$editRights=$this->get_edit_rights_for_teacher($this->UserInfo['TeacherID']=id, $disciplineInfo['ID']);
+		$editRights=$this->get_edit_rights_for_teacher($this->UserInfo['TeacherID'], $disciplineInfo['ID']);
         if($editRights == 1)
 			$twig->editRights=$editRights;
 		else
@@ -297,7 +298,6 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
         $twig->disciplineInfo = $disciplineInfo;
         $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 d1205bd63..f9d1a3023 100644
--- a/~dev_rating/application/views/teacher/exam.twig
+++ b/~dev_rating/application/views/teacher/exam.twig
@@ -47,8 +47,9 @@
 					{{ headerRate[i].ModuleTitle }}
 				</td>
 			{% endfor %}
-			
-			<td class="subject" rowspan="3">Бонус</td>
+			{% if disciplineInfo.isBonus == false %}
+				<td class="subject" rowspan="3">Бонус</td>
+			{% endif %}
 			<td class="subject" rowspan="3">Итог</td>
 		</tr>
 		
@@ -61,7 +62,7 @@
 				{% for j in 1..headerRate[i].SubmodulesCount if headerRate[i].ModuleType != 'extra' %}
 					{% set col = col + 1 %}
 					{% set colSpan = colSpanGeneral %}
-					{% if j == 1 %}{% set colSpan = colSpan+1 %}{% endif %}
+					{% if j == 1 and i==1 %}{% set colSpan = colSpan+1 %}{% endif %}
 					<td class="subject col_{{ col }}" colspan="{{colSpan}}"> {{ headerRate[i][j].Title }} </td>
 				{% endfor %}
 			{% endfor %}
@@ -69,7 +70,7 @@
 		
 		<tr class="RatingTableSubmodulesHeadMaxRate">
 			{% set columnsCount = 4 %} {# студенты, итог за семестр, бонусы, итог #}
-			{% set col = 1 %}
+			{% set col = 0 %}
 			<td class="title">Макс. балл</td>
 			{% for i in 1..headerRate.ModulesCount %}
 				{% set columnsCount = columnsCount + headerRate[i].SubmodulesCount %}
@@ -87,7 +88,7 @@
 							Неявка
 						</td>
 						
-						{% if j == 1 %}
+						{% if j == 1 and i == 1 %}
 							{% set columnsCount = columnsCount + 1 %}
 							<td class="subject col_autopass_{{ col }}">
 								Автомат
@@ -99,8 +100,8 @@
 		</tr>
 		
 		<tr class="RatingTableSubmodulesInfo">
-			<td class="info"/>
-			<td class="info"/>
+			<td class="info"></td>
+			<td class="info"></td>
 			
 			{% set col = 0 %}			
 			{% for i in 1..headerRate.ModulesCount %}
@@ -108,18 +109,18 @@
 				{% if headerRate[i].ModuleType == 'exam' %}{% set examModule = true %}{% endif %}
 				{% for j in 1..headerRate[i].SubmodulesCount %}
 					{% set col = col + 1 %}
-					<td class="info col_{{ col }}" id="{{ headerRate[i][j].SubmoduleID }}"/>
+					<td class="info col_{{ col }}" id="{{ headerRate[i][j].SubmoduleID }}"></td>
 					{% if examModule %}
-						<td class="info col_absence_{{ col }}" id="absence_{{ headerRate[i][j].SubmoduleID }}"/>
+						<td class="info col_absence_{{ col }}" id="absence_{{ headerRate[i][j].SubmoduleID }}"></td>
 						{% if j == 1 %}
-							<td class="info col_autopass_{{ col }}" id="autopass_{{ headerRate[i][j].SubmoduleID }}"/>
+							<td class="info col_autopass_{{ col }}" id="autopass_{{ headerRate[i][j].SubmoduleID }}"></td>
 						{% endif %}
 					{% endif %}
 				{% endfor %}
 			{% endfor %}
 			
-			<td class="info"/>
-			<td class="info"/>
+			<td class="info"></td>
+			<td class="info"></td>
 		</tr>
 		
 		{% set row = 0 %}
@@ -133,14 +134,14 @@
  
 			{% for student in group.Students %}
 				{% set row = row + 1 %}
-				{% set col = 0 %}
+				{% set col = 1 %}
 				<tr id="row_{{ row }}" class="group_{{ group.GroupID }}">
 					<td id="student_{{ student.ID }}" class="studentCell staticCell">{{ student.Last }} {{ student.First }}</td>
 					<td class="semesterRateResultCell staticCell">{{ student.RateSemesterResult }}</td>
 					
 					{% set autoPassNotAdded = true %}
 					{% for r in student.Rates %}
-						{% set col = col + 1 %}
+
 						
 						{% if r.ModuleType == 'exam' %}
 							{% set td_class = 'attemptCell' %}
@@ -169,6 +170,7 @@
 						{% endif %}
 						
 						{% if r.ModuleType == 'exam' %}
+							{% set col = col + 1 %}
 							<td class="absenceCell {{ td_class }}" id="absence_{{col}}_{{row}}">
 								<input type="checkbox" class="absenceCheck">
 							</td>
@@ -183,7 +185,7 @@
 						
 					{% endfor %}
 
-					<td class="bonus staticCell">{{ student.Bonus }}</td>
+					<td class="bonus staticCell" colspan="2">{% if student.Bonus is null %}0{% else %}{{ student.Bonus }}{% endif %} </td>
 					<td class="rateResultCell staticCell">{% if student.RateResult > 100 %} 100+ {% else %} {{ student.RateResult }} {% endif %}</td>
 				</tr>
 			{% endfor %} 
diff --git a/~dev_rating/media/js/rating.js b/~dev_rating/media/js/rating.js
index 5d95c7dca..806b16cbc 100644
--- a/~dev_rating/media/js/rating.js
+++ b/~dev_rating/media/js/rating.js
@@ -134,17 +134,19 @@ $(function() {
     function TdInfo(jThis) {
 		var disciplineType = json_settings.ExamType;
 		var disciplinePassRate = 60; // credit pass rate
-		if (disciplineType == "exam")
+		if (disciplineType === "exam")
 			disciplinePassRate = 38;
 
         // Получаем подмодуль
-		g_submoduleID = parseInt($(".RatingTableSubmodulesInfo .col_"+g_col+":first").attr("id"));
-        g_submoduleTitle = $(".RatingTableSubmodulesHead .col_"+g_col+":first").text();
-        if ($(".RatingTableSubmodulesHead .col_"+g_col+":first").length < 1 && $(".RatingTableModulesHead .bonus").length > 0 ) 
+        var jCurSubmoduleInfo = $(".RatingTableSubmodulesInfo .col_"+g_col+":first");
+        var jCurSubmoduleHead = $(".RatingTableSubmodulesHead .col_"+g_col+":first");
+
+		g_submoduleID = parseInt(jCurSubmoduleInfo.attr("id"));
+        g_submoduleTitle = jCurSubmoduleHead.text();
+        if (jCurSubmoduleHead.length < 1 && $(".RatingTableModulesHead .bonus").length > 0 )
             g_submoduleTitle = 'Бонусные баллы';
 		g_submoduleMaxRate = parseInt($(".RatingTableSubmodulesHeadMaxRate .col_"+g_col).text());
 
-        //console.log(g_col.toString() + " " + g_submoduleMaxRate.toString() + " " + g_submoduleID.toString());
 		
 		// Проверяем допустимое значение (только для добора)
         if (jThis.attr("class").indexOf("additionalCell") >= 0)
@@ -190,7 +192,7 @@ $(function() {
 		var rateResult = newRate;
 
 		// считаем баллы по строке
-		if ($("#pageType").val() == "exam") //(jThis.attr("class").indexOf("attemptCell") >= 0)
+		if ($("#pageType").val() === "exam") //(jThis.attr("class").indexOf("attemptCell") >= 0)
 		{
 			// страница сессии		
 			rateResult += parseInt(jThis.siblings(".semesterRateResultCell").text());
@@ -200,7 +202,7 @@ $(function() {
 					rateResult += parseInt($(this).children("input").val());
 			});
 		} 
-		else if ($("#pageType").val() == "rating")
+		else if ($("#pageType").val() === "rating")
 		{
 			// страница оценивания
 			jThis.siblings(".commonCell").each(function(){ // добавим сумму баллов в соседних ячейках
@@ -323,7 +325,7 @@ $(function() {
         $(this).select();
     });
     
-    // При нажатие на элемент commonCell дочерный input получает фокус
+    // При нажатии на элемент commonCell дочерный input получает фокус
     $(".commonCell ").click(function(){
         $(this).children("input").focus();
     } );
-- 
GitLab