diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql index 2830737b4cab7c7d0302df5f9364916e8631ec5e..91afd606bde802e406e8d3362e2b691c4f4e7885 100644 --- a/db/StoredProcedures.sql +++ b/db/StoredProcedures.sql @@ -434,6 +434,18 @@ BEGIN END // +DROP FUNCTION IF EXISTS SetSemesterID// +CREATE FUNCTION `SetSemesterID` ( `SemesterID` INT + ) RETURNS int(11) + NO SQL +BEGIN + SET @CurrentSemesterID = SemesterID; + RETURN 0; +END // + + + + DROP FUNCTION IF EXISTS SetCurSemesterID// CREATE FUNCTION `SetCurSemesterID` ( `SemesterID` INT @@ -1922,7 +1934,7 @@ BEGIN INNER JOIN `subjects` ON disciplines.SubjectID = subjects.ID INNER JOIN `teachers` ON disciplines.AuthorID = teachers.ID INNER JOIN `departments` ON teachers.DepartmentID = departments.ID - WHERE GetCurSemesterID() = disciplines.SemesterID AND + WHERE @CurrentSemesterID = disciplines.SemesterID AND disciplines.FacultyID = FacultyID ORDER BY departments.Name ASC; END // @@ -1954,7 +1966,7 @@ BEGIN TeacherID = disciplines_teachers.TeacherID INNER JOIN `subjects` ON subjects.ID = disciplines.SubjectID LEFT JOIN `study_groups` ON study_groups.ID = disciplines_groups.StudyGroupID - WHERE disciplines.SemesterID = GetCurSemesterID() + WHERE disciplines.SemesterID = @CurrentSemesterID ORDER BY grades.ID ASC, subjects.Name ASC, disciplines.ID ASC, @@ -1980,7 +1992,7 @@ BEGIN FROM `disciplines` INNER JOIN `subjects` ON disciplines.SubjectID = subjects.ID INNER JOIN `teachers` ON disciplines.AuthorID = teachers.ID - WHERE GetCurSemesterID() = disciplines.SemesterID AND + WHERE @CurrentSemesterID = disciplines.SemesterID AND InternalIsStudentAttached(StudentID, disciplines.ID) ORDER BY disciplines.ExamType ASC, Rate DESC; END // @@ -2203,7 +2215,7 @@ BEGIN disciplines.SemesterID, disciplines.FacultyID ) - VALUES ( TeacherID, GradeID, SubjectID, ExamType, LectionCount, PracticeCount, LabCount, GetCurSemesterID(), FacultyID ); + VALUES ( TeacherID, GradeID, SubjectID, ExamType, LectionCount, PracticeCount, LabCount, @CurrentSemesterID, FacultyID ); SET DisciplineID = LAST_INSERT_ID(); INSERT INTO `disciplines_teachers` @@ -2873,7 +2885,7 @@ CREATE FUNCTION `RestrictAfterMilestoneForCredits` ( `TeacherID` INT, BEGIN DECLARE semID INT; - SET semID = GetCurSemesterID(); + SET semID = @CurrentSemesterID; UPDATE `disciplines` SET disciplines.MilestoneDate = CURDATE(), @@ -4175,7 +4187,7 @@ CREATE PROCEDURE `GetFinalFormInfo` ( IN `DisciplineID` INT, NO SQL BEGIN DECLARE curSem INT; - SET curSem = GetCurSemesterID(); + SET curSem = @CurrentSemesterID; SELECT study_groups.GroupNum AS 'GroupNum', study_groups.Name AS 'GroupName', diff --git a/~dev_rating/application/classes/Controller/Handler/Settings.php b/~dev_rating/application/classes/Controller/Handler/Settings.php index c86f4a317c368bde88d71e6edeb784d45188d079..6fa77af8abb2d8626f32a85a3de21f8ef00dff3e 100644 --- a/~dev_rating/application/classes/Controller/Handler/Settings.php +++ b/~dev_rating/application/classes/Controller/Handler/Settings.php @@ -94,4 +94,13 @@ class Controller_Handler_Settings extends Controller_Handler { { } + + public function action_setSemesterID() + { + $this->post + ->rule('semesterID', 'not_empty') + ->rule('semesterID', 'digit'); + $semesterID = $this->post->offsetGet('semesterID'); + User::instance()->SetSemester($semesterID); + } } \ No newline at end of file diff --git a/~dev_rating/modules/account/classes/Kohana/User.php b/~dev_rating/modules/account/classes/Kohana/User.php index 90bc1fba127723ddc527871575ac40e2e82ab8da..c6b647045025c054177e25ec53e968a51b0fcbb0 100644 --- a/~dev_rating/modules/account/classes/Kohana/User.php +++ b/~dev_rating/modules/account/classes/Kohana/User.php @@ -33,17 +33,36 @@ class Kohana_User implements ArrayAccess { $this->_config['hash_key'] = $this->_model->getHashKey(); $this->_config['hash_method'] = 'sha256'; $isSignedIn = $this->isSignedIn(); + $this->_PrepareSemester($isSignedIn); + if($isSignedIn) { $id = $this->_session->get('ID'); - $this->_userInfo = $this->_getInfoFromDB($id); + $this->_userInfo = $this->_getInfoFromDB($id); + if (self::$_flag != true) { $this->_session->regenerate(); $this->_session->set('start_time', time()); } } + } + + protected function _PrepareSemester($isSignedIn) { + if ($isSignedIn) { + $semesterID = $this->_session->get("SemesterID"); + } else { + $semesterID = $this->_model->GetCurSemesterID(); + } + $this->SetSemester($semesterID); + } + + public function SetSemester($semesterID) { + $this->_model->SetSemesterID($semesterID); + $this->_session->set("SemesterID", $semesterID); + } + /** * Регистрирует нового пользователя и осуществляет вход. * Проверяет корректность кода активации и существование аккаунтов с такими же авторизационными данными. diff --git a/~dev_rating/modules/account/classes/Model/Kohana/Account.php b/~dev_rating/modules/account/classes/Model/Kohana/Account.php index 8c35309cbb00cdcb3b2d2b10d5f237573ddb4009..1ac848c066f4fa94ec252af4f2658e63493b53e8 100644 --- a/~dev_rating/modules/account/classes/Model/Kohana/Account.php +++ b/~dev_rating/modules/account/classes/Model/Kohana/Account.php @@ -160,4 +160,24 @@ class Model_Kohana_Account extends Model } return $id; } + + public function GetCurSemesterID() + { + $sql = "SELECT `GetCurSemesterID`() AS `Num`; "; + $res = DB::query(Database::SELECT, $sql)->execute(); + foreach ($res as $value) { + $id = $value['Num']; + } + return $id; + } + + public function SetSemesterID($semesterID) + { + $sql = "SELECT `SetSemesterID`('$semesterID') AS `Num`; "; + $res = DB::query(Database::SELECT, $sql)->execute(); + foreach ($res as $value) { + $id = $value['Num']; + } + return $id; + } } \ No newline at end of file