From 394293203b561b76a1c68cf5c5fe4c89d2b969bd Mon Sep 17 00:00:00 2001 From: PavelBegunkov <asml.Silence@gmail.com> Date: Sat, 23 Aug 2014 14:01:58 +0400 Subject: [PATCH] exam modules --- db/StoredProcedures.sql | 68 +++++++++++++++++++++++++++++++++++++++++ db/Structure.sql | 3 +- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql index f0f2217d9..a2d93d3c4 100644 --- a/db/StoredProcedures.sql +++ b/db/StoredProcedures.sql @@ -1779,6 +1779,48 @@ BEGIN ); +END // + +DROP FUNCTION IF EXISTS AddModule// +CREATE FUNCTION `AddModuleExam` ( `TeacherID` INT, + `DisciplineID` INT + ) RETURNS int(11) + NO SQL +BEGIN + DECLARE checker INT; + + SELECT disciplines.ID + INTO checker + FROM `disciplines` + INNER JOIN `disciplines_teachers` ON disciplines_teachers.TeacherID = TeacherID AND disciplines_teachers.DisciplineID = disciplines.ID + WHERE disciplines.ID = DisciplineID + LIMIT 1; + IF NOT (checker > 0) THEN + RETURN -1; + END IF; + + SET checker = -1; + SELECT modules.ID + INTO checker + FROM `modules` + WHERE modules.DisciplineID = DisciplineID AND + modules.isExam = 1; + IF checker > 0 THEN + RETURN -2; + END IF; + + + INSERT INTO `modules` ( modules.Name, modules.OrderNum, modules.DisciplineID, modules.isExam ) + VALUES ( 'Ркзамен' , 666 , DisciplineID, 1 ); + + + RETURN ( SELECT modules.ID + FROM `modules` + WHERE modules.DisciplineID = DisciplineID AND + modules.isExam = 1 + ); + + END // -- Добавление РЅРѕРІРѕРіРѕ подмодуля Рє данному модулю @@ -1822,6 +1864,32 @@ BEGIN RETURN 0; END // +DROP FUNCTION IF EXISTS DeleteModule// +CREATE FUNCTION `DeleteModuleExam` ( `TeacherID` INT, + `DisciplineID` INT + ) RETURNS int(11) + NO SQL +BEGIN + + DECLARE checker INT; + + SELECT disciplines.ID + INTO checker + FROM `disciplines_teachers` + WHERE disciplines_teachers.TeacherID = TeacherID AND + disciplines_teachers.DisciplineID = DisciplineID + LIMIT 1; + IF NOT (checker > 0) THEN + RETURN -1; + END IF; + + + DELETE FROM `modules` + WHERE modules.isExam = 1 + LIMIT 1; + + RETURN 0; +END // diff --git a/db/Structure.sql b/db/Structure.sql index 329f4449b..8b14fc777 100644 --- a/db/Structure.sql +++ b/db/Structure.sql @@ -191,10 +191,11 @@ CREATE TABLE IF NOT EXISTS `modules` ( `Name` varchar(50) NOT NULL, `OrderNum` int(11) NOT NULL, `DisciplineID` int(11) NOT NULL, + `isExam` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `OrderNum` (`OrderNum`,`DisciplineID`), KEY `DisciplineID` (`DisciplineID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- -- GitLab