From 10e88391af960b58f7efdc04e9f8877d8c129d34 Mon Sep 17 00:00:00 2001 From: PavelBegunkov <asml.Silence@gmail.com> Date: Sun, 24 May 2015 13:43:42 +0300 Subject: [PATCH] add sql: absence & auto-pass --- db/StoredFunctions.sql | 18 ++++++++++++++++++ db/StoredProcedures.sql | 7 +++++-- db/Structure.sql | 30 +++++++++++++++++++++++++++++- db/fix.sql | 20 +++++++++++++++++++- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql index 72d147e7c..f3b5df151 100644 --- a/db/StoredFunctions.sql +++ b/db/StoredFunctions.sql @@ -115,6 +115,24 @@ BEGIN END // +DROP FUNCTION IF EXISTS SetRateType// +CREATE FUNCTION `SetRateType` + ( `pStudentID` INT, `pSubmoduleID` INT, + `pType` VARCHAR(30) CHARSET utf8 # enum('absence','pass') + ) RETURNS int(11) + NO SQL +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; + + INSERT INTO `session_options` + (StudentID, SubmoduleID, Type) VALUES(pStudentID, pSubmoduleID, pType) + ON DUPLICATE KEY UPDATE + session_options.Type = pType; + + RETURN 0; +END // + + # check, if any module is created DROP FUNCTION IF EXISTS InternalIsMapCreated// CREATE FUNCTION `InternalIsMapCreated` diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql index 65ab5f2db..8a335f9c5 100644 --- a/db/StoredProcedures.sql +++ b/db/StoredProcedures.sql @@ -760,10 +760,13 @@ BEGIN view_roadmap.SubmoduleType AS 'SubmoduleControl', view_roadmap.ModuleType, rating_table.Rate, - rating_table.Date + rating_table.Date, + session_options.Type FROM `view_roadmap` - LEFT JOIN `rating_table` ON view_roadmap.SubmoduleID = rating_table.SubmoduleID AND + LEFT JOIN `rating_table` ON view_roadmap.SubmoduleID = rating_table.SubmoduleID AND rating_table.StudentID = pStudentID + LEFT JOIN `session_options` ON session_options.StudentID = pStudentID AND + session_options.SubmoduleID = rating_table.SubmoduleID WHERE view_roadmap.DisciplineID = pDisciplineID AND ( view_roadmap.ModuleType != 'exam' OR diff --git a/db/Structure.sql b/db/Structure.sql index 50de4f99c..e88e11cb9 100644 --- a/db/Structure.sql +++ b/db/Structure.sql @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS `disciplines` ( `LectureCount` int(11) NOT NULL DEFAULT '0', `LabCount` int(11) NOT NULL DEFAULT '0', `FacultyID` int(11) NOT NULL, - -- isLocked (for editing structure) + -- IsLocked (for editing structure) `IsLocked` tinyint(1) NOT NULL DEFAULT '0', -- Milestone semester time (or is session time) @@ -536,6 +536,26 @@ CREATE TABLE IF NOT EXISTS `students_groups` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- -------------------------------------------------------- + +-- +-- Структура таблицы `session_options` +-- + +CREATE TABLE IF NOT EXISTS `session_options` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `SubmoduleID` int(11) NOT NULL, + `StudentID` int(11) NOT NULL, + `Type` enum('absence','pass') NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `SubmoduleID` (`SubmoduleID`,`StudentID`), + KEY `SubmoduleID_2` (`SubmoduleID`), + KEY `StudentID` (`StudentID`), + KEY `StudentID_2` (`StudentID`), + KEY `StudentID_3` (`StudentID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + + -- -- Дамп данных таблицы `user_roles` @@ -736,6 +756,14 @@ ALTER TABLE `students_groups` ADD CONSTRAINT `students_groups_ibfk_3` FOREIGN KEY (`SemesterID`) REFERENCES `semesters` (`ID`); +-- +-- Ограничения внешнего ключа таблицы `session_options` +-- +ALTER TABLE `session_options` + ADD CONSTRAINT `session_options_ibfk_2` FOREIGN KEY (`StudentID`) REFERENCES `students` (`ID`), + ADD CONSTRAINT `session_options_ibfk_1` FOREIGN KEY (`SubmoduleID`) REFERENCES `submodules` (`ID`); + + /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; diff --git a/db/fix.sql b/db/fix.sql index bcc10aba3..2e734d53b 100644 --- a/db/fix.sql +++ b/db/fix.sql @@ -2,4 +2,22 @@ ALTER TABLE `disciplines` CHANGE `ExamType` `ExamType` ENUM( 'exam', 'credit', 'grading_credit' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ; ALTER TABLE `disciplines` ADD `Subtype` ENUM( 'scientific_coursework', 'disciplinary_coursework' ) NULL DEFAULT NULL ; -ALTER TABLE `disciplines` CHANGE `isMilestone` `Milestone` INT( 11 ) NOT NULL DEFAULT '0'; \ No newline at end of file +ALTER TABLE `disciplines` CHANGE `isMilestone` `Milestone` INT( 11 ) NOT NULL DEFAULT '0'; + + +CREATE TABLE IF NOT EXISTS `session_options` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `SubmoduleID` int(11) NOT NULL, + `StudentID` int(11) NOT NULL, + `Type` enum('absence','pass') NOT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `SubmoduleID` (`SubmoduleID`,`StudentID`), + KEY `SubmoduleID_2` (`SubmoduleID`), + KEY `StudentID` (`StudentID`), + KEY `StudentID_2` (`StudentID`), + KEY `StudentID_3` (`StudentID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +ALTER TABLE `session_options` +ADD CONSTRAINT `session_options_ibfk_2` FOREIGN KEY (`StudentID`) REFERENCES `students` (`ID`), +ADD CONSTRAINT `session_options_ibfk_1` FOREIGN KEY (`SubmoduleID`) REFERENCES `submodules` (`ID`); -- GitLab