diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql index ef998348013b91819a633e0c87696f1c66d0174c..17f173dd4edfe45e541651f7b92ef8e1e32a0cb3 100644 --- a/db/StoredFunctions.sql +++ b/db/StoredFunctions.sql @@ -2197,6 +2197,40 @@ END// +DROP FUNCTION IF EXISTS CreateRequest// +CREATE FUNCTION `CreateRequest` ( + `pRequestID` INT, + `pAccountID` INT, + `pTitle` VARCHAR(50) CHARSET utf8, + `pDescription` TEXT CHARSET utf8, + `pImage` BOOLEAN +) RETURNS int(11) +NO SQL +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN -1; + + IF pRequestID <= 0 THEN + INSERT INTO `requests` + (AccountID, Title, Description, Status, IsImage) + VALUES (pAccountID, pTitle, pDescription, 'opened', pImage); + RETURN LAST_INSERT_ID(); + ELSE + UPDATE `requests` + SET requests.Description = pDescription, + requests.Title = pTitle, + requests.Date = NOW() + WHERE requests.ID = pRequestID AND + requests.AccountID = pAccountID + LIMIT 1; + RETURN ROW_COUNT()-1; + END IF; + + + +END// + + + # ------------------------------------------------------------------------------------------- # Label: recovery @@ -2303,4 +2337,4 @@ BEGIN RETURN LAST_INSERT_ID(); END // -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/Structure.sql b/db/Structure.sql index 5825317b6a282aa7285f8452f0bb03e6c60fd420..1c2ff930d23c3105e1afabfd4ffe55bc9fc39b92 100644 --- a/db/Structure.sql +++ b/db/Structure.sql @@ -261,6 +261,7 @@ CREATE TABLE IF NOT EXISTS `requests` ( `Description` text CHARACTER SET utf8 NOT NULL, `Date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `Status` enum('opened','processed','closed') NOT NULL DEFAULT 'opened', + `IsImage` BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (`ID`), KEY `AccountID` (`AccountID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/db/fixes/15_07_07.sql b/db/fixes/15_07_07.sql new file mode 100644 index 0000000000000000000000000000000000000000..becdfb7fec500d24c3549c9701007368f405f117 --- /dev/null +++ b/db/fixes/15_07_07.sql @@ -0,0 +1 @@ +ALTER TABLE `requests` ADD IsImage BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/~dev_rating/application/classes/Controller/Handler/ErrMessages.php b/~dev_rating/application/classes/Controller/Handler/ErrMessages.php index 18a61358dd91859c2732bfa795ab2beb4be4d77d..79b3a7945dd3e8a4440f6e1a268a1899cadf8de6 100644 --- a/~dev_rating/application/classes/Controller/Handler/ErrMessages.php +++ b/~dev_rating/application/classes/Controller/Handler/ErrMessages.php @@ -36,7 +36,7 @@ class Controller_Handler_ErrMessages extends Controller_Handler $data['requestID'] = $requestID; } } - sleep(2); + // sleep(3); $this->response->body(json_encode($data)); } @@ -54,8 +54,10 @@ class Controller_Handler_ErrMessages extends Controller_Handler if ($requestID <= 0) { $ticket = $this->sendNewRequest($this->user->ID, $title, $text); } else { - // TODO write in to existed record - $ticket = $this->updateExistedRequest($requestID, $this->user->ID, $title, $text); // not implemented + $ticket = $this->updateExistedRequest($requestID, $this->user->ID, $title, $text); + if ($ticket!=$requestID) { + // Error! + } } $subject = "Request {$ticket}: rating system report"; @@ -79,31 +81,15 @@ class Controller_Handler_ErrMessages extends Controller_Handler /** return int number of created ticket */ private function sendNewRequest($accountID, $title, $description) { - $sql = "SELECT `CreateRequest`(:account, :title, :description) AS 'Num';"; - return DB::query(Database::SELECT, $sql) - ->param(':account', (int) $accountID) - ->param(':description', $description) - ->param(':title', $title) - ->execute()->get('Num'); + return Model_Support::newRequest($accountID, $title, $description, false); } - private function updateExistedRequest($requestID,$accountID, $title, $description) { - // TODO: implement - return $requestID; + private function updateExistedRequest($requestID, $accountID, $title, $description) { + return Model_Support::updateRequest($requestID, $accountID, $title, $description); } private function createRequestWithImg($accountID) { - // TODO: implement - /* - $sql = "SELECT `CreateRequest`(:account, :title, :description, :isImage) AS 'Num';"; - return DB::query(Database::SELECT, $sql) - ->param(':account', (int) $accountID) - ->param(':description', "") - ->param(':title', "") - ->param(':isImage',true) - ->execute()->get('Num'); - */ - return 165; + return Model_Support::newRequest($accountID); } } diff --git a/~dev_rating/application/classes/Model/Support.php b/~dev_rating/application/classes/Model/Support.php new file mode 100644 index 0000000000000000000000000000000000000000..e5493eee988b2914956019453db5f041fdf0dbe3 --- /dev/null +++ b/~dev_rating/application/classes/Model/Support.php @@ -0,0 +1,26 @@ +<?php defined('SYSPATH') or die('No direct script access.'); + +class Model_Support extends Model +{ + public static function newRequest($accountID, $description = '', $title = '', $isImg = false) { + $sql = "SELECT `CreateRequest`(0, :account, :title, :description, :isImg) AS 'Num';"; + return DB::query(Database::SELECT, $sql) + ->param(':account', (int) $accountID) + ->param(':description', $description) + ->param(':title', $title) + ->param(':isImg', $isImg) + ->execute()->get('Num'); + } + + + public static function updateRequest($requestID, $accountID, $description, $title) { + $sql = "SELECT `CreateRequest`(:requestID, :account, :title, :description, :isImg) AS 'Num';"; + return DB::query(Database::SELECT, $sql) + ->param(':requestID', (int) $requestID) + ->param(':account', (int) $accountID) + ->param(':description', $description) + ->param(':title', $title) + ->param(':isImg', true) + ->execute()->get('Num'); + } +}