From 6fb1a750ef0b8b21e66cf16e07fa5fed7c1977db Mon Sep 17 00:00:00 2001
From: RomanSteinberg <romanofficial@yandex.ru>
Date: Thu, 14 May 2015 15:33:26 +0300
Subject: [PATCH] FIX: extra maxrate calculation

---
 db/StoredFunctions.sql                        | 22 ++++++++++++++-----
 .../Controller/Handler/FileCreator.php        |  2 +-
 .../classes/Controller/Teacher/Rating.php     |  4 ++--
 .../application/views/teacher/exam.twig       |  2 +-
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql
index 96bb91260..079107647 100644
--- a/db/StoredFunctions.sql
+++ b/db/StoredFunctions.sql
@@ -2007,24 +2007,33 @@ CREATE FUNCTION `CalculateMaxRateForExtra`
 ( `pSubmoduleID` INT, `pStudentID` INT) RETURNS int(11)
     NO SQL
 BEGIN
-    DECLARE vExamType INT; # enum('exam', 'credit');# utf8;
+    DECLARE vExamType INT DEFAULT -1; # enum('exam', 'credit');# utf8;
     DECLARE vLim INT;
-    DECLARE vResult INT DEFAULT -1;
+    DECLARE vResult INT DEFAULT 0;
 
-    IF vExamType = 'exam' THEN
+    SELECT  disciplines.ExamType INTO vExamType
+        FROM `submodules`
+        INNER JOIN `modules` ON modules.ID = submodules.ModuleID
+        INNER JOIN `disciplines` ON disciplines.ID = modules.DisciplineID
+        WHERE submodules.ID = pSubmoduleID
+        LIMIT 1;
+
+    IF vExamType = -1 THEN
+        RETURN -1;
+    ELSEIF vExamType = 1 THEN # exam
         SET vLim = 38;
-    ELSE
+    ELSE # credit or grading_credit
         SET vLim = 60;
     END IF;
 
-    SELECT vLim - view_rating_result.RateRegular INTO vResult
+    SELECT  view_rating_result.RateRegular INTO vResult
         FROM `submodules`
         INNER JOIN `modules` ON modules.ID = submodules.ModuleID
         INNER JOIN view_rating_result ON view_rating_result.DisciplineID = modules.DisciplineID AND
                                          view_rating_result.StudentID = pStudentID
         WHERE submodules.ID = pSubmoduleID
         LIMIT 1;
-    RETURN vResult;
+    RETURN vLim - vResult;
 END //
 
 
@@ -2062,6 +2071,7 @@ BEGIN
 
     # 1) check rights
     # 2) check, you can't rate regular and bonus after milestone
+    # 3) check, max rate exceeding
     IF  NOT InternalIsStudentAttached(pStudentID, vDisciplineID) OR
         NOT InternalIsTeacherBounded(pTeacherID, vDisciplineID) OR
         pRate > vMaxRate OR
diff --git a/~dev_rating/application/classes/Controller/Handler/FileCreator.php b/~dev_rating/application/classes/Controller/Handler/FileCreator.php
index 4a7067615..6c1127f42 100644
--- a/~dev_rating/application/classes/Controller/Handler/FileCreator.php
+++ b/~dev_rating/application/classes/Controller/Handler/FileCreator.php
@@ -227,7 +227,7 @@ class Controller_Handler_FileCreator extends Controller_Handler
         $controlDate = "";
         $range = $objPHPExcel->getNamedRange("Date")->getRange();
         if ($disciplineType == 'credit') {
-            $controlDate = "Дата зачета\n".$this->figureOutCreditDate($data['SemesterNum'], $data['Year']);
+            $controlDate = "Дата зачета\n".$this->figureOutCreditDate($data['SemesterNum'], $startYear);
         } elseif ($disciplineType == 'exam') {
             $controlDate = "Дата экзамена\n__________";
         }
diff --git a/~dev_rating/application/classes/Controller/Teacher/Rating.php b/~dev_rating/application/classes/Controller/Teacher/Rating.php
index 0707db72b..e49863990 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Rating.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Rating.php
@@ -29,8 +29,8 @@ class Controller_Teacher_Rating extends Controller_UserEnvironment {
     private function getDisciplineInformation($id) {
         
         $temp = Model_Discipline::getInfo($id);
-        $disciplineInfo = $temp[0];
-        $disciplineInfo['ID'] = $id;
+        $disciplineInfo = $temp;
+//        $disciplineInfo['ID'] = $id;
         $disciplineInfo['GroupID_Filter'] = $this->getGroupID_ForFilter($id);
 
         return $disciplineInfo;
diff --git a/~dev_rating/application/views/teacher/exam.twig b/~dev_rating/application/views/teacher/exam.twig
index a376a8c92..6bdbf7044 100644
--- a/~dev_rating/application/views/teacher/exam.twig
+++ b/~dev_rating/application/views/teacher/exam.twig
@@ -19,7 +19,7 @@
 	{% endif %}
 	</h2>
 
-    {{ HTML.anchor('rate/'~disciplineInfo.ID, 
+    {{ HTML.anchor('rate/'~disciplineInfo.DisciplineID,
             "← Перейти к оцениванию", 
             {'title': 'Оценивание', 'class': 'rate_a'})|raw }}
 
-- 
GitLab