Skip to content
Snippets Groups Projects
Commit ffa94642 authored by PavelBegunkov's avatar PavelBegunkov
Browse files

sql stored fn: @CurrentSemesterID annihilation

parent d989fd18
Branches
Tags
No related merge requests found
...@@ -1125,10 +1125,12 @@ CREATE FUNCTION `BindStudent` ( ...@@ -1125,10 +1125,12 @@ CREATE FUNCTION `BindStudent` (
) RETURNS int(11) ) RETURNS int(11)
NO SQL NO SQL
BEGIN BEGIN
DECLARE vChecker, vGroupID, vTemp INT DEFAULT -1; DECLARE vChecker, vGroupID, vTemp, vSemesterID INT DEFAULT -1;
DECLARE vInGroup BOOLEAN DEFAULT FALSE; DECLARE vInGroup BOOLEAN DEFAULT FALSE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
SET vSemesterID = GetDisciplineSemesterID(pDisciplineID);
# 1. check if AccessedTeacher is author # 1. check if AccessedTeacher is author
IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN
RETURN -1; RETURN -1;
...@@ -1142,7 +1144,7 @@ BEGIN ...@@ -1142,7 +1144,7 @@ BEGIN
INNER JOIN `disciplines_groups` ON disciplines_groups.DisciplineID = pDisciplineID AND INNER JOIN `disciplines_groups` ON disciplines_groups.DisciplineID = pDisciplineID AND
disciplines_groups.GroupID = students_groups.GroupID disciplines_groups.GroupID = students_groups.GroupID
WHERE students_groups.StudentID = pStudentID AND WHERE students_groups.StudentID = pStudentID AND
students_groups.SemesterID = @CurrentSemesterID students_groups.SemesterID = vSemesterID
LIMIT 1 LIMIT 1
); );
...@@ -1213,12 +1215,14 @@ CREATE FUNCTION `UnbindStudent` ( ...@@ -1213,12 +1215,14 @@ CREATE FUNCTION `UnbindStudent` (
) RETURNS int(11) ) RETURNS int(11)
NO SQL NO SQL
BEGIN BEGIN
DECLARE vInGroup INT DEFAULT -1; DECLARE vInGroup, vSemesterID INT DEFAULT -1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN
RETURN -1; RETURN -1;
END IF; END IF;
SET vSemesterID = GetDisciplineSemesterID(pDisciplineID);
# TODO: extract method - GetDisciplineSemesterID # TODO: extract method - GetDisciplineSemesterID
# TODO: join students_groups by discipline SemesterID # TODO: join students_groups by discipline SemesterID
...@@ -1226,7 +1230,7 @@ BEGIN ...@@ -1226,7 +1230,7 @@ BEGIN
SELECT disciplines_groups.ID INTO vInGroup SELECT disciplines_groups.ID INTO vInGroup
FROM `students` FROM `students`
INNER JOIN `students_groups` ON students_groups.StudentID = students.ID AND INNER JOIN `students_groups` ON students_groups.StudentID = students.ID AND
students_groups.SemesterID = @CurrentSemesterID students_groups.SemesterID = vSemesterID
INNER JOIN `disciplines_groups` ON disciplines_groups.DisciplineID = pDisciplineID AND INNER JOIN `disciplines_groups` ON disciplines_groups.DisciplineID = pDisciplineID AND
disciplines_groups.GroupID = students_groups.GroupID disciplines_groups.GroupID = students_groups.GroupID
WHERE students.ID = pStudentID WHERE students.ID = pStudentID
...@@ -1433,7 +1437,8 @@ DROP FUNCTION IF EXISTS RestrictAfterMilestoneForCredits// ...@@ -1433,7 +1437,8 @@ DROP FUNCTION IF EXISTS RestrictAfterMilestoneForCredits//
CREATE FUNCTION `RestrictAfterMilestoneForCredits` ( CREATE FUNCTION `RestrictAfterMilestoneForCredits` (
`pTeacherID` INT, `pTeacherID` INT,
`pFacultyID` INT, `pFacultyID` INT,
`pMilestone` INT `pMilestone` INT,
`pSemesterID` INT
) RETURNS int(11) ) RETURNS int(11)
NO SQL NO SQL
BEGIN BEGIN
...@@ -1441,7 +1446,7 @@ BEGIN ...@@ -1441,7 +1446,7 @@ BEGIN
SET disciplines.MilestoneDate = CURDATE(), SET disciplines.MilestoneDate = CURDATE(),
disciplines.Milestone = pMilestone disciplines.Milestone = pMilestone
WHERE disciplines.FacultyID= pFacultyID AND WHERE disciplines.FacultyID= pFacultyID AND
disciplines.SemesterID = @CurrentSemesterID AND disciplines.SemesterID = pSemesterID AND
( disciplines.ExamType = 'credit' OR disciplines.ExamType = 'grading_credit'); ( disciplines.ExamType = 'credit' OR disciplines.ExamType = 'grading_credit');
RETURN 0; RETURN 0;
END // END //
...@@ -2125,18 +2130,19 @@ CREATE FUNCTION `SetStudentRate` ( ...@@ -2125,18 +2130,19 @@ CREATE FUNCTION `SetStudentRate` (
) RETURNS int(11) ) RETURNS int(11)
NO SQL NO SQL
BEGIN BEGIN
DECLARE vDisciplineID, vMaxRate, vModuleType INT DEFAULT -1; DECLARE vDisciplineID, vMaxRate, vModuleType, vSemesterID INT DEFAULT -1;
DECLARE vIsOver, vIsLocked, vIsUsed BOOLEAN DEFAULT FALSE; DECLARE vIsOver, vIsLocked, vIsUsed BOOLEAN DEFAULT FALSE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
SET vIsOver = TRUE; SET vIsOver = TRUE;
SELECT disciplines.ID, SELECT disciplines.ID,
disciplines.SemesterID,
disciplines.isLocked, disciplines.isLocked,
disciplines.Milestone, disciplines.Milestone,
submodules.IsUsed, submodules.IsUsed,
submodules.maxRate, submodules.maxRate,
modules.Type modules.Type
INTO vDisciplineID, vIsLocked, vIsOver, vIsUsed, vMaxRate, vModuleType INTO vDisciplineID, vSemesterID, vIsLocked, vIsOver, vIsUsed, vMaxRate, vModuleType
FROM `submodules` FROM `submodules`
INNER JOIN `modules` ON submodules.ModuleID = modules.ID INNER JOIN `modules` ON submodules.ModuleID = modules.ID
INNER JOIN `disciplines` ON modules.DisciplineID = disciplines.ID INNER JOIN `disciplines` ON modules.DisciplineID = disciplines.ID
...@@ -2151,7 +2157,7 @@ BEGIN ...@@ -2151,7 +2157,7 @@ BEGIN
# 1) check rights # 1) check rights
# 2) check, you can't rate regular and bonus after milestone # 2) check, you can't rate regular and bonus after milestone
# 3) check, max rate exceeding # 3) check, max rate exceeding
IF NOT InternalIsStudentAttached(pStudentID, vDisciplineID, @CurrentSemesterID) OR IF NOT InternalIsStudentAttached(pStudentID, vDisciplineID, vSemesterID) OR
NOT InternalIsTeacherBound(pTeacherID, vDisciplineID) OR NOT InternalIsTeacherBound(pTeacherID, vDisciplineID) OR
pRate > vMaxRate OR pRate > vMaxRate OR
(vIsOver AND (vModuleType = 1 OR vModuleType = 3)) # 1 - regular, 3 - bonus (vIsOver AND (vModuleType = 1 OR vModuleType = 3)) # 1 - regular, 3 - bonus
......
...@@ -223,7 +223,8 @@ class Model_Discipline extends Model implements JsonSerializable, ArrayAccess ...@@ -223,7 +223,8 @@ class Model_Discipline extends Model implements JsonSerializable, ArrayAccess
* @return Database_Result * @return Database_Result
*/ */
public static function setMilestoneForCredits($teacherID, $facultyID, $milestone) { public static function setMilestoneForCredits($teacherID, $facultyID, $milestone) {
$sql = "SELECT `RestrictAfterMilestoneForCredits`('$teacherID', '$facultyID', '$milestone') AS 'Num'"; $semesterID = User::instance()->offsetGet('SemesterID');
$sql = "SELECT `RestrictAfterMilestoneForCredits`('$teacherID', '$facultyID', '$milestone', $semesterID) AS 'Num'";
return DB::query(Database::SELECT, $sql)->execute(); return DB::query(Database::SELECT, $sql)->execute();
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment