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

Big chunk of fixes.

1) exam page: hide hidden div with ( json data )
2) update session info on profile/settings changes (User.php)
3) fix profile page model ( Model_Teacher )
4) fix change discipline's control type ( sql )
5) fix sql response in bind group ( repeated binding problem )
parent cf9563f9
Branches
Tags
No related merge requests found
...@@ -948,7 +948,7 @@ CREATE FUNCTION `ChangeDisciplineControl` ( ...@@ -948,7 +948,7 @@ CREATE FUNCTION `ChangeDisciplineControl` (
NO SQL NO SQL
BEGIN BEGIN
DECLARE vChecker, vExtraMax, vExtraID INT DEFAULT -1; 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; DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1;
IF InternalIsMapLocked(pDisciplineID) OR IF InternalIsMapLocked(pDisciplineID) OR
...@@ -968,42 +968,40 @@ BEGIN ...@@ -968,42 +968,40 @@ BEGIN
RETURN -1; RETURN -1;
END IF; 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 # set new exam type
UPDATE `disciplines` UPDATE `disciplines`
SET disciplines.ExamType = pExamType SET disciplines.ExamType = pExamType
WHERE disciplines.ID = pDisciplineID WHERE disciplines.ID = pDisciplineID
LIMIT 1; 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 # set max rate for extra
UPDATE `submodules` UPDATE `submodules`
SET submodules.MaxRate = vExtraMax SET submodules.MaxRate = vExtraMax
...@@ -1074,18 +1072,19 @@ BEGIN ...@@ -1074,18 +1072,19 @@ BEGIN
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
disciplines_groups.ID = ( @isAttached := LAST_INSERT_ID(disciplines_groups.ID) ); 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'); SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester');
# 3. delete students of this group which were bound to discipline before # 3. delete students of this group which were bound to discipline before
DELETE FROM `disciplines_students` DELETE FROM `disciplines_students`
WHERE disciplines_students.DisciplineID = pDisciplineID AND WHERE disciplines_students.DisciplineID = pDisciplineID AND
disciplines_students.StudentID IN ( disciplines_students.StudentID IN (
SELECT students_groups.StudentID SELECT students_groups.StudentID
FROM `students_groups` FROM `students_groups`
WHERE students_groups.GroupID = pGroupID AND WHERE students_groups.GroupID = pGroupID AND
students_groups.SemesterID = vSemesterID students_groups.SemesterID = vSemesterID
); );
RETURN 1;
END IF; END IF;
RETURN 0; RETURN 0;
......
...@@ -16,17 +16,17 @@ class Model_Teacher extends Model ...@@ -16,17 +16,17 @@ class Model_Teacher extends Model
public function changeInfo($lastName, $firstName, $secondName, $degreeID, $departmentID) { public function changeInfo($lastName, $firstName, $secondName, $degreeID, $departmentID) {
$sql = "SELECT `ChangeTeacherInfo`(:id, :last, :first, :second, :degree, :department) AS `UserID`;"; $sql = "SELECT `ChangeTeacherInfo`(:id, :last, :first, :second, :degree, :department) AS `Num`;";
return DB::query(Database::SELECT, $sql) $res = DB::query(Database::SELECT, $sql)
->parameters([ ->parameters([
':id' => $this->ID, ':id' => $this->ID,
':last' => $lastName, ':last' => $lastName,
':first' => $firstName, ':first' => $firstName,
':second' => $secondName, ':second' => $secondName,
':degree' => $degreeID, ':degree' => $degreeID,
'department' => $departmentID, ':department' => $departmentID,
])->execute()->get('UserID'); ])->execute()->get('Num');
// todo: what does it return? return ( $res == 0 );
} }
/** @return Model_Discipline[] */ /** @return Model_Discipline[] */
......
...@@ -68,7 +68,7 @@ class User implements ArrayAccess ...@@ -68,7 +68,7 @@ class User implements ArrayAccess
} }
private function __construct($config = array()) { private function __construct($config = []) {
$this->_config = $config; $this->_config = $config;
$this->_general = Model_System::loadConfig("general.json"); $this->_general = Model_System::loadConfig("general.json");
...@@ -132,17 +132,17 @@ class User implements ArrayAccess ...@@ -132,17 +132,17 @@ class User implements ArrayAccess
$id = Model_Account::activateAccount($login, $password, $email, $code); $id = Model_Account::activateAccount($login, $password, $email, $code);
switch ($id) { switch ($id) {
case -1: case -1:
return array(false, 'something wrong!'); return [false, 'something wrong!'];
case -2: case -2:
return array(false, 'invalid_code'); return [false, 'invalid_code'];
case -3: case -3:
return array(false, 'mail_exists'); return [false, 'mail_exists'];
case -4: case -4:
return array(false, 'login_exists'); return [false, 'login_exists'];
} }
$this->completeSignIn($id, $this->hash($password)); $this->completeSignIn($id, $this->hash($password));
return array(true, 'ok'); return [true, 'ok'];
} }
/** /**
...@@ -262,7 +262,11 @@ class User implements ArrayAccess ...@@ -262,7 +262,11 @@ class User implements ArrayAccess
return false; return false;
$res = (int)Model_Account::changeAccountData($this->ID, $login, 'login'); $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) { public function changeMail($email) {
...@@ -287,12 +291,19 @@ class User implements ArrayAccess ...@@ -287,12 +291,19 @@ class User implements ArrayAccess
// } // }
public function changeProfile($data) { public function changeProfile($data) {
if ($this->Type == 'teacher') { if ($this->Type != 'teacher')
Model_Teacher::with($this['TeacherID'])->changeInfo( return false;
$data['lastName'], $data['firstName'], $data['secondName'],
$data['jobPositionID'], $data['departmentID'] $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 */ /* Info */
...@@ -306,7 +317,7 @@ class User implements ArrayAccess ...@@ -306,7 +317,7 @@ class User implements ArrayAccess
if ($this->isSignedIn()) { if ($this->isSignedIn()) {
return $this->_session->as_array(); return $this->_session->as_array();
} else { } else {
return array(); return [];
} }
} }
......
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
<span id="maxRate">Максимальный балл: <b></b></span> <span id="maxRate">Максимальный балл: <b></b></span>
</div> </div>
</div> </div>
<div id="hidden_div"> <div id="hidden_div" style="display: none;">
{{ Discipline_JSON|raw }} {{ Discipline_JSON|raw }}
</div> </div>
<input type="hidden" id="pageType" value="exam"/> <input type="hidden" id="pageType" value="exam"/>
......
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