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` (
) RETURNS int(11)
NO SQL
BEGIN
DECLARE vChecker, vGroupID, vTemp INT DEFAULT -1;
DECLARE vChecker, vGroupID, vTemp, vSemesterID INT DEFAULT -1;
DECLARE vInGroup BOOLEAN DEFAULT FALSE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
SET vSemesterID = GetDisciplineSemesterID(pDisciplineID);
# 1. check if AccessedTeacher is author
IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN
RETURN -1;
......@@ -1142,7 +1144,7 @@ BEGIN
INNER JOIN `disciplines_groups` ON disciplines_groups.DisciplineID = pDisciplineID AND
disciplines_groups.GroupID = students_groups.GroupID
WHERE students_groups.StudentID = pStudentID AND
students_groups.SemesterID = @CurrentSemesterID
students_groups.SemesterID = vSemesterID
LIMIT 1
);
......@@ -1213,12 +1215,14 @@ CREATE FUNCTION `UnbindStudent` (
) RETURNS int(11)
NO SQL
BEGIN
DECLARE vInGroup INT DEFAULT -1;
DECLARE vInGroup, vSemesterID INT DEFAULT -1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
IF NOT InternalIsTeacherAuthor(pTeacherID, pDisciplineID) THEN
RETURN -1;
END IF;
SET vSemesterID = GetDisciplineSemesterID(pDisciplineID);
# TODO: extract method - GetDisciplineSemesterID
# TODO: join students_groups by discipline SemesterID
......@@ -1226,7 +1230,7 @@ BEGIN
SELECT disciplines_groups.ID INTO vInGroup
FROM `students`
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
disciplines_groups.GroupID = students_groups.GroupID
WHERE students.ID = pStudentID
......@@ -1433,7 +1437,8 @@ DROP FUNCTION IF EXISTS RestrictAfterMilestoneForCredits//
CREATE FUNCTION `RestrictAfterMilestoneForCredits` (
`pTeacherID` INT,
`pFacultyID` INT,
`pMilestone` INT
`pMilestone` INT,
`pSemesterID` INT
) RETURNS int(11)
NO SQL
BEGIN
......@@ -1441,7 +1446,7 @@ BEGIN
SET disciplines.MilestoneDate = CURDATE(),
disciplines.Milestone = pMilestone
WHERE disciplines.FacultyID= pFacultyID AND
disciplines.SemesterID = @CurrentSemesterID AND
disciplines.SemesterID = pSemesterID AND
( disciplines.ExamType = 'credit' OR disciplines.ExamType = 'grading_credit');
RETURN 0;
END //
......@@ -2125,18 +2130,19 @@ CREATE FUNCTION `SetStudentRate` (
) RETURNS int(11)
NO SQL
BEGIN
DECLARE vDisciplineID, vMaxRate, vModuleType INT DEFAULT -1;
DECLARE vDisciplineID, vMaxRate, vModuleType, vSemesterID INT DEFAULT -1;
DECLARE vIsOver, vIsLocked, vIsUsed BOOLEAN DEFAULT FALSE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
SET vIsOver = TRUE;
SELECT disciplines.ID,
disciplines.SemesterID,
disciplines.isLocked,
disciplines.Milestone,
submodules.IsUsed,
submodules.maxRate,
modules.Type
INTO vDisciplineID, vIsLocked, vIsOver, vIsUsed, vMaxRate, vModuleType
INTO vDisciplineID, vSemesterID, vIsLocked, vIsOver, vIsUsed, vMaxRate, vModuleType
FROM `submodules`
INNER JOIN `modules` ON submodules.ModuleID = modules.ID
INNER JOIN `disciplines` ON modules.DisciplineID = disciplines.ID
......@@ -2151,7 +2157,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, @CurrentSemesterID) OR
IF NOT InternalIsStudentAttached(pStudentID, vDisciplineID, vSemesterID) OR
NOT InternalIsTeacherBound(pTeacherID, vDisciplineID) OR
pRate > vMaxRate OR
(vIsOver AND (vModuleType = 1 OR vModuleType = 3)) # 1 - regular, 3 - bonus
......
......@@ -223,7 +223,8 @@ class Model_Discipline extends Model implements JsonSerializable, ArrayAccess
* @return Database_Result
*/
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();
}
......
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