diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql index 2f0784b2a3cd6f11fc1eb2984ab9c98480badca3..93ea46dcc94820a7fe6c4a42aa50669cb4046381 100644 --- a/db/StoredFunctions.sql +++ b/db/StoredFunctions.sql @@ -948,7 +948,7 @@ CREATE FUNCTION `ChangeDisciplineControl` ( NO SQL BEGIN DECLARE vChecker, vExtraMax, vExtraID INT DEFAULT -1; - DECLARE vOldExamType enum('exam', 'credit', 'grading_credit') DEFAULT -1; + DECLARE vOldExamType enum('exam', 'credit', 'grading_credit'); DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; IF InternalIsMapLocked(pDisciplineID) OR @@ -968,42 +968,40 @@ BEGIN RETURN -1; END IF; + # check type changing: exam <-> credit/grading_credit + IF NOT (vOldExamType = 'exam' XOR pExamType != 'exam') THEN + + # TODO: extract method addExtraModule + IF pExamType = 'exam' THEN # change to exam + SET vExtraMax = 7; + # count discipline's current max rate + SELECT view_disciplines_results.DisciplineRateMax INTO vChecker + FROM `view_disciplines_results` + WHERE view_disciplines_results.DisciplineID = pDisciplineID + LIMIT 1; + + IF vChecker >= 61 THEN # can't add exam module ( > 100 points) + RETURN 1; + END IF; + SET vChecker = AddModuleExam(pTeacherID, pDisciplineID); + + # delete extra submodules(only 1 extra for exam) + DELETE FROM `submodules` + WHERE submodules.OrderNum > 1 AND submodules.ModuleID = vExtraID; + ELSE # change to credit + SET vExtraMax = 29; + SET vChecker = DeleteModuleExam(pTeacherID, pDisciplineID); + # 2 extra submodules (1 already created for exam) + SET vChecker = AddSubmodule(pTeacherID, vExtraID, vExtraMax, '', NULL, 'LandmarkControl'); + END IF; + END IF; + # set new exam type UPDATE `disciplines` SET disciplines.ExamType = pExamType WHERE disciplines.ID = pDisciplineID LIMIT 1; - # check type changing: exam <-> credit/grading_credit - IF vOldExamType = 'exam' XOR pExamType != 'exam' THEN - RETURN 0; - END IF; - - - # TODO: extract method addExtraModule - IF pExamType = 'exam' THEN # change to exam - SET vExtraMax = 7; - # count discipline's current max rate - SELECT view_disciplines_results.DisciplineRateMax INTO vChecker - FROM `view_disciplines_results` - WHERE view_disciplines_results.DisciplineID = pDisciplineID - LIMIT 1; - - IF vChecker >= 61 THEN # can't add exam module ( > 100 points) - RETURN 1; - END IF; - SET vChecker = AddModuleExam(pTeacherID, pDisciplineID); - - # delete extra submodules(only 1 extra for exam) - DELETE FROM `submodules` - WHERE submodules.OrderNum > 1 AND submodules.ModuleID = vExtraID; - ELSE # change to credit - SET vExtraMax = 29; - SET vChecker = DeleteModuleExam(pTeacherID, pDisciplineID); - # 2 extra submodules (1 already created for exam) - SET vChecker = AddSubmodule(pTeacherID, vExtraID, vExtraMax, '', NULL, 'LandmarkControl'); - END IF; - # set max rate for extra UPDATE `submodules` SET submodules.MaxRate = vExtraMax @@ -1074,18 +1072,19 @@ BEGIN ON DUPLICATE KEY UPDATE disciplines_groups.ID = ( @isAttached := LAST_INSERT_ID(disciplines_groups.ID) ); - IF @isAttached < 0 THEN # group was attached + IF @isAttached > 0 THEN # group was attached SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); # 3. delete students of this group which were bound to discipline before - DELETE FROM `disciplines_students` - WHERE disciplines_students.DisciplineID = pDisciplineID AND - disciplines_students.StudentID IN ( - SELECT students_groups.StudentID - FROM `students_groups` - WHERE students_groups.GroupID = pGroupID AND - students_groups.SemesterID = vSemesterID - ); + DELETE FROM `disciplines_students` + WHERE disciplines_students.DisciplineID = pDisciplineID AND + disciplines_students.StudentID IN ( + SELECT students_groups.StudentID + FROM `students_groups` + WHERE students_groups.GroupID = pGroupID AND + students_groups.SemesterID = vSemesterID + ); + RETURN 1; END IF; RETURN 0; diff --git a/~dev_rating/application/classes/Model/Teacher.php b/~dev_rating/application/classes/Model/Teacher.php index b7b6a91d091e2c7f32f0304a925373de2c916d73..15bf9281e953ddb6ef2a8e57e16308e11644e9c1 100644 --- a/~dev_rating/application/classes/Model/Teacher.php +++ b/~dev_rating/application/classes/Model/Teacher.php @@ -16,17 +16,17 @@ class Model_Teacher extends Model public function changeInfo($lastName, $firstName, $secondName, $degreeID, $departmentID) { - $sql = "SELECT `ChangeTeacherInfo`(:id, :last, :first, :second, :degree, :department) AS `UserID`;"; - return DB::query(Database::SELECT, $sql) + $sql = "SELECT `ChangeTeacherInfo`(:id, :last, :first, :second, :degree, :department) AS `Num`;"; + $res = DB::query(Database::SELECT, $sql) ->parameters([ ':id' => $this->ID, ':last' => $lastName, ':first' => $firstName, ':second' => $secondName, ':degree' => $degreeID, - 'department' => $departmentID, - ])->execute()->get('UserID'); - // todo: what does it return? + ':department' => $departmentID, + ])->execute()->get('Num'); + return ( $res == 0 ); } /** @return Model_Discipline[] */ diff --git a/~dev_rating/application/classes/User.php b/~dev_rating/application/classes/User.php index 47b60f6b6b84af868c1e6b68a02e72022c43a04b..f086804bb58720eace809897689a6e0f9eb355b5 100644 --- a/~dev_rating/application/classes/User.php +++ b/~dev_rating/application/classes/User.php @@ -68,7 +68,7 @@ class User implements ArrayAccess } - private function __construct($config = array()) { + private function __construct($config = []) { $this->_config = $config; $this->_general = Model_System::loadConfig("general.json"); @@ -132,17 +132,17 @@ class User implements ArrayAccess $id = Model_Account::activateAccount($login, $password, $email, $code); switch ($id) { case -1: - return array(false, 'something wrong!'); + return [false, 'something wrong!']; case -2: - return array(false, 'invalid_code'); + return [false, 'invalid_code']; case -3: - return array(false, 'mail_exists'); + return [false, 'mail_exists']; case -4: - return array(false, 'login_exists'); + return [false, 'login_exists']; } $this->completeSignIn($id, $this->hash($password)); - return array(true, 'ok'); + return [true, 'ok']; } /** @@ -262,7 +262,11 @@ class User implements ArrayAccess return false; $res = (int)Model_Account::changeAccountData($this->ID, $login, 'login'); - return ( $res === 0 ); + if ( $res === 0 ) { + $this->Login = $login; + return true; + } + return false; } public function changeMail($email) { @@ -287,12 +291,19 @@ class User implements ArrayAccess // } public function changeProfile($data) { - if ($this->Type == 'teacher') { - Model_Teacher::with($this['TeacherID'])->changeInfo( - $data['lastName'], $data['firstName'], $data['secondName'], - $data['jobPositionID'], $data['departmentID'] - ); + if ($this->Type != 'teacher') + return false; + + $res = Model_Teacher::with($this['TeacherID'])->changeInfo( + $data['lastName'], $data['firstName'], $data['secondName'], + $data['jobPositionID'], $data['departmentID'] + ); + if ( $res ) { + $this->LastName = $data['lastName']; + $this->FirstName = $data['firstName']; + $this->SecondName = $data['secondName']; } + return $res; } /* Info */ @@ -306,7 +317,7 @@ class User implements ArrayAccess if ($this->isSignedIn()) { return $this->_session->as_array(); } else { - return array(); + return []; } } diff --git a/~dev_rating/application/views/teacher/exam.twig b/~dev_rating/application/views/teacher/exam.twig index d258181de14c8fba62f1a97705c4372aeb85b4b8..0573d9b11689e452736388d431f1444222196cee 100644 --- a/~dev_rating/application/views/teacher/exam.twig +++ b/~dev_rating/application/views/teacher/exam.twig @@ -201,7 +201,7 @@ <span id="maxRate">Максимальный балл: <b></b></span> </div> </div> - <div id="hidden_div"> + <div id="hidden_div" style="display: none;"> {{ Discipline_JSON|raw }} </div> <input type="hidden" id="pageType" value="exam"/>