From 819d7dfb48730b060e4d5efacc07fb4e7b818248 Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.Silence@gmail.com>
Date: Mon, 22 Sep 2014 01:25:43 +0400
Subject: [PATCH] max 100 restriction

---
 db/StoredProcedures.sql                       | 23 +++++++++++++++----
 .../classes/Controller/Handler/Map.php        |  6 ++---
 .../media/js/discipline/EditSettings.js       |  7 +++++-
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index 1ed31ecbe..106db0124 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -2258,15 +2258,19 @@ BEGIN
 
 	IF 	(checker != ExamType) 		
 	THEN
-		UPDATE `disciplines`
-		SET 	disciplines.ExamType = ExamType
-		WHERE 	DisciplineID = disciplines.ID;
-
 		IF ExamType = 'exam' THEN
+			SET checker = GetDisciplineMaxRate(DisciplineID);
+			IF checker > 60 THEN
+				RETURN 1;
+			END IF;
 			SET checker = AddModuleExam(TeacherID, DisciplineID);
 		ELSE
 			SET checker = DeleteModuleExam(TeacherID, DisciplineID);
 		END IF;
+
+		UPDATE `disciplines`
+		SET 	disciplines.ExamType = ExamType
+		WHERE 	DisciplineID = disciplines.ID;
 	END IF;
 	RETURN 0;
 END //
@@ -2712,7 +2716,6 @@ END //
 
 
 
--- Добавление нового подмодуля к данному модулю
 DROP FUNCTION IF EXISTS DeleteModule//
 CREATE FUNCTION `DeleteModule`	(	`TeacherID` INT,
 									`ModuleID` 	INT 
@@ -2760,6 +2763,8 @@ BEGIN
 	RETURN 0;
 END //
 
+
+
 DROP FUNCTION IF EXISTS DeleteModuleExam//
 CREATE FUNCTION `DeleteModuleExam`		(	`TeacherID` INT,
 											`DisciplineID` 	INT 
@@ -2943,6 +2948,8 @@ END //
 
 
 -- Внесение изменений в подмодуль (MaxRate, TItle, Description, Order и т.д.), который неявно прикреплен к преподавателю
+-- TODO delete 
+-- deprecated
 DROP FUNCTION IF EXISTS ChangeSubmodule//
 CREATE FUNCTION `ChangeSubmodule`	(	`TeacherID` 	INT, 
 										`SubmoduleID` 	INT, 
@@ -2991,6 +2998,9 @@ BEGIN
 	RETURN 0;
 END //
 
+
+-- TODO delete 
+-- deprecated
 DROP FUNCTION IF EXISTS ChangeSubmoduleControlType//
 CREATE FUNCTION `ChangeSubmoduleControlType`(	`TeacherID` 	INT, 
 												`SubmoduleID` 	INT, 
@@ -3021,6 +3031,9 @@ BEGIN
 	RETURN 0;
 END //
 
+
+-- TODO delete 
+-- deprecated
 DROP FUNCTION IF EXISTS ChangeSubmoduleMaxRate//
 CREATE FUNCTION `ChangeSubmoduleMaxRate`	(	`TeacherID` 	INT, 
 												`SubmoduleID` 	INT, 
diff --git a/~dev_rating/application/classes/Controller/Handler/Map.php b/~dev_rating/application/classes/Controller/Handler/Map.php
index 5a20998ca..1d50b8174 100644
--- a/~dev_rating/application/classes/Controller/Handler/Map.php
+++ b/~dev_rating/application/classes/Controller/Handler/Map.php
@@ -119,7 +119,6 @@ class Controller_Handler_Map extends Controller_Handler {
 		
 		// Изменение контроля
 		public function action_ChangeDisciplineControl() {
-			$data['success'] = false;
             $this->post -> rule('DisciplineID', 'not_empty')
                         -> rule('DisciplineID', 'digit')
 						-> rule('Control', 'not_empty');
@@ -129,9 +128,10 @@ class Controller_Handler_Map extends Controller_Handler {
 					$this->post->offsetGet('DisciplineID'),
 					$this->post->offsetGet('Control')		
 				);
-				if ($result[0]['Num'] == 0)
-					$data['success'] = true;
+				$data['success'] = $result[0]['Num'];
 			}
+			else
+				$data['success'] = 0;
 			$this->response->body(json_encode($data));
 		}
 		
diff --git a/~dev_rating/media/js/discipline/EditSettings.js b/~dev_rating/media/js/discipline/EditSettings.js
index d2ce4b58b..b0db67a92 100644
--- a/~dev_rating/media/js/discipline/EditSettings.js
+++ b/~dev_rating/media/js/discipline/EditSettings.js
@@ -59,6 +59,7 @@ $(function() {
 	
 	// Изменение контроля
 	$('input.ExamType').change(function(){
+		var thisObj = $(this);
 		$.post(
 			URLdir + 'handler/map/ChangeDisciplineControl',
 			{
@@ -67,8 +68,12 @@ $(function() {
 			},
 			function(data) {
 				data = $.parseJSON(data);
-				if(data.success === true)
+				if(data.success == 0)
 					EventInspector_ShowMsg('Форма контроля изменена', 'success');
+				else if (data.success > 0) {
+					EventInspector_ShowMsg('Превышено максимальное кол-во баллов', 'error');
+					thisObj.parent().children('.ExamType[value="credit"]').prop('checked', true);
+				}
 				else EventInspector_ShowMsg('Ошибка: Изменение формы контроля', 'error');
 			}
 		);
-- 
GitLab