From 1071f906f63782917d20459cd04db29a82128a5a Mon Sep 17 00:00:00 2001 From: PavelBegunkov <asml.Silence@gmail.com> Date: Wed, 1 Jul 2015 20:16:16 +0300 Subject: [PATCH] Changed rating page behavior: clear cell to delete mark (fix #17) --- db/StoredFunctions.sql | 14 ++++++++++ db/fix.sql | 28 ------------------- deploy/scripts/status => status | 0 .../classes/Controller/Handler/Rating.php | 16 +++++------ .../application/classes/Model/Rating.php | 2 -- 5 files changed, 22 insertions(+), 38 deletions(-) delete mode 100644 db/fix.sql rename deploy/scripts/status => status (100%) diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql index a66e0a0e7..ef9983480 100644 --- a/db/StoredFunctions.sql +++ b/db/StoredFunctions.sql @@ -2075,6 +2075,20 @@ BEGIN DECLARE vIsOver, vIsLocked, vIsUsed BOOLEAN DEFAULT FALSE; DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; + IF pRate < 0 THEN + INSERT INTO `logs_rating` + (StudentID, SubmoduleID, TeacherID, Rate, Action ) + VALUES (pStudentID, pSubModuleID, pTeacherID, pRate, 'delete'); + + # TODO: extract method log rate + DELETE FROM `rating_table` + WHERE rating_table.StudentID = pStudentID AND + rating_table.SubmoduleID = pSubmoduleID + LIMIT 1; + + RETURN ROW_COUNT()-1; + END IF; + SET vIsOver = TRUE; SELECT disciplines.ID, disciplines.SemesterID, diff --git a/db/fix.sql b/db/fix.sql deleted file mode 100644 index 64e31b1f7..000000000 --- a/db/fix.sql +++ /dev/null @@ -1,28 +0,0 @@ -# 03.06.15 - -DROP TABLE `session_options`; -CREATE TABLE IF NOT EXISTS `exam_period_options` ( - `ID` int(11) NOT NULL AUTO_INCREMENT, - `SubmoduleID` int(11) NOT NULL, - `StudentID` int(11) NOT NULL, - `Type` enum('absence','pass'), - PRIMARY KEY (`ID`), - UNIQUE KEY `SubmoduleID` (`SubmoduleID`,`StudentID`), - KEY `SubmoduleID_2` (`SubmoduleID`), - KEY `StudentID` (`StudentID`), - KEY `StudentID_2` (`StudentID`), - KEY `StudentID_3` (`StudentID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; - - -ALTER TABLE `exam_period_options` -ADD CONSTRAINT `exam_period_options_ibfk_2` FOREIGN KEY (`StudentID`) REFERENCES `students` (`ID`), -ADD CONSTRAINT `exam_period_options_ibfk_1` FOREIGN KEY (`SubmoduleID`) REFERENCES `submodules` (`ID`); - -UPDATE `subjects` SET `Name`= "Научная исследовательская работа", `Abbr` = "Курсовая" WHERE `ID` = 346; - - -# 13.05.15 - -DROP TABLE `page_access`; -DROP TABLE `general_settings`; diff --git a/deploy/scripts/status b/status similarity index 100% rename from deploy/scripts/status rename to status diff --git a/~dev_rating/application/classes/Controller/Handler/Rating.php b/~dev_rating/application/classes/Controller/Handler/Rating.php index bf2ad78ba..d64696af9 100644 --- a/~dev_rating/application/classes/Controller/Handler/Rating.php +++ b/~dev_rating/application/classes/Controller/Handler/Rating.php @@ -4,7 +4,7 @@ class Controller_Handler_Rating extends Controller_Handler { /** @var Model_Rating */ protected $model; - + public function before() { parent::before(); @@ -14,19 +14,19 @@ class Controller_Handler_Rating extends Controller_Handler public function action_SetRate() { - $data['success'] = false; + $data['success'] = false; $this->post -> rule('studentID', 'not_empty') -> rule('studentID', 'digit') -> rule('submoduleID', 'not_empty') -> rule('submoduleID', 'digit') - -> rule('rate', 'digit') - -> rule('rate', 'range', array(':value', -1, 100)); + -> rule('rate', 'numeric') + -> rule('rate', 'range', array(':value', -2, 100)); if($this->post->check()) { $result = Model_Rating::SetStudentRate( $this->user->TeacherID, $this->post['studentID'], $this->post['submoduleID'], $this->post['rate']); - $data['success'] = ($result[0]['Num'] == 0); + $data['success'] = ($result->get('Num') == 0); } $this->response->body(json_encode($data)); } @@ -40,10 +40,10 @@ class Controller_Handler_Rating extends Controller_Handler if($this->post->check()) { //$SGID = Cookie::get('SGID', null); $SG_json = json_decode(Cookie::get('SGID', null), true); - + $SG_json[$this->post['disciplineID']] = $this->post['groupSelected']; - Cookie::set('SGID', json_encode($SG_json), '2592000'); + Cookie::set('SGID', json_encode($SG_json), '2592000'); $data['success'] = true; } $this->response->body(json_encode($data)); @@ -75,4 +75,4 @@ class Controller_Handler_Rating extends Controller_Handler } $this->response->body(json_encode($data)); } -} \ No newline at end of file +} diff --git a/~dev_rating/application/classes/Model/Rating.php b/~dev_rating/application/classes/Model/Rating.php index da4438a4c..93ad75891 100644 --- a/~dev_rating/application/classes/Model/Rating.php +++ b/~dev_rating/application/classes/Model/Rating.php @@ -53,8 +53,6 @@ class Model_Rating extends Model } public static function SetStudentRate($teacher, $student, $submodule, $rate) { - if ($rate == -1) $rate = null; # fixme: kind of shit - $sql = "SELECT `SetStudentRate`(:teacher, :student, :submodule, :rate) AS `Num`"; return DB::query(Database::SELECT, $sql) ->parameters([ -- GitLab