From b515b422237292bb1eaa585b20a6f408ceee9945 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 5 Aug 2013 22:35:22 +0200 Subject: [PATCH] refactor queue's part 1 --- .../ryzom_ams/ams_lib/autoload/pagination.php | 6 +- .../ryzom_ams/ams_lib/autoload/ticket.php | 15 +-- .../ams_lib/autoload/ticket_queue.php | 107 +++++------------- .../ams_lib/autoload/ticket_queue_handler.php | 23 +++- .../ryzom_ams/www/html/inc/show_queue.php | 70 ++++++------ 5 files changed, 98 insertions(+), 123 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/pagination.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/pagination.php index a4890f980..3c4473170 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/pagination.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/pagination.php @@ -7,7 +7,7 @@ class Pagination{ private $current; private $amountOfRows; - function __construct($query,$db,$nrDisplayed,$resultClass) { + function __construct($query, $db, $nrDisplayed, $resultClass, $params = array()) { if (!(isset($_GET['pagenum']))){ $this->current= 1; }else{ @@ -16,7 +16,7 @@ class Pagination{ //Here we count the number of results $db = new DBLayer($db); - $rows = $db->executeWithoutParams($query)->rowCount(); + $rows = $db->execute($query, $params)->rowCount(); $this->amountOfRows = $rows; //the array hat will contain all users @@ -39,7 +39,7 @@ class Pagination{ $max = 'limit ' .($this->current- 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it - $data = $db->executeWithoutParams($query . " " . $max); + $data = $db->execute($query . " " . $max, $params); $this->element_array = Array(); //This is where we put the results in a resultArray to be sent to smarty diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php index c9703d232..26c131e33 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php @@ -213,13 +213,14 @@ class Ticket{ //Set ticket object - public function set($t,$s,$q,$t_c,$a,$p){ - $this->title = $t; - $this->status = $s; - $this->queue = $q; - $this->ticket_category = $t_c; - $this->author = $a; - $this->priority = $p; + public function set($values){ + $this->tId = $values['TId']; + $this->title = $values['Title']; + $this->status = $values['Status']; + $this->queue = $values['Queue']; + $this->ticket_category = $values['Ticket_Category']; + $this->author = $values['Author']; + $this->priority = $values['Priority']; } //create ticket by writing private data to DB. diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue.php index efcb2f138..9f8fb2ce6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue.php @@ -1,34 +1,42 @@ executeWithoutParams("SELECT ticket . * FROM ticket LEFT JOIN assigned ON ticket.TId = assigned.Ticket WHERE assigned.Ticket IS NULL"); - $rows = $statement->fetchAll(); - $this->setQueue($rows); + $this->query = "SELECT ticket . * FROM ticket LEFT JOIN assigned ON ticket.TId = assigned.Ticket WHERE assigned.Ticket IS NULL"; + $this->params = array(); } public function loadAllTickets(){ - $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM `ticket`"); - $rows = $statement->fetchAll(); - $this->setQueue($rows); + $this->query = "SELECT * FROM `ticket`"; + $this->params = array(); } public function loadAllOpenTickets(){ - $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status!=3"); - $rows = $statement->fetchAll(); - $this->setQueue($rows); + $this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status!=3"; + $this->params = array(); } public function loadAllClosedTickets(){ - $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status=3"); - $rows = $statement->fetchAll(); - $this->setQueue($rows); + $this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status=3"; + $this->params = array(); + } + + public function loadToDoTickets($user_id){ + + //first: find the tickets assigned to the user with status = waiting on support + //second find all not assigned tickets that aren't forwarded yet. + //find all tickets assigned to someone else witht status waiting on support, with timestamp of last reply > 1 day + //find all non-assigned tickets forwarded to the support groups to which that user belongs + $this->query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User LEFT JOIN `forwarded` f ON t.TId = f.Ticket + WHERE (tu.ExternId = :user_id AND t.Status = 1) + OR (a.Ticket IS NULL AND f.Group IS NULL) + OR (tu.ExternId != :user_id AND t.Status = 1 AND (SELECT ticket_reply.Timestamp FROM `ticket_reply` WHERE Ticket =t.TId ORDER BY TReplyId DESC LIMIT 1) < NOW() - INTERVAL 1 DAY ) + OR (a.Ticket IS NULL AND EXISTS (SELECT * FROM `in_support_group` isg JOIN `ticket_user` tu2 ON isg.User = tu2.TUserId WHERE isg.Group = f.Group)) + "; + $this->params = array('user_id' => $user_id); } public function createQueue($userid, $groupid, $what, $how, $who){ @@ -71,66 +79,13 @@ class Ticket_Queue{ $statement = $dbl->execute($query, $params); $rows = $statement->fetchAll(); $this->setQueue($rows); + } + + public function getQuery(){ + return $this->query; } - public function loadToDoTickets($user_id){ - - $dbl = new DBLayer("lib"); - //first: find the tickets assigned to the user with status = waiting on support - //second find all not assigned tickets that aren't forwarded yet. - //find all tickets assigned to someone else witht status waiting on support, with timestamp of last reply > 1 day - //find all non-assigned tickets forwarded to the support groups to which that user belongs - $query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User LEFT JOIN `forwarded` f ON t.TId = f.Ticket - WHERE (tu.ExternId = :user_id AND t.Status = 1) - OR (a.Ticket IS NULL AND f.Group IS NULL) - OR (tu.ExternId != :user_id AND t.Status = 1 AND (SELECT ticket_reply.Timestamp FROM `ticket_reply` WHERE Ticket =t.TId ORDER BY TReplyId DESC LIMIT 1) < NOW() - INTERVAL 1 DAY ) - OR (a.Ticket IS NULL AND EXISTS (SELECT * FROM `in_support_group` isg JOIN `ticket_user` tu2 ON isg.User = tu2.TUserId WHERE isg.Group = f.Group)) - "; - $values = array('user_id' => $user_id); - $statement = $dbl->execute($query,$values); - $rows = $statement->fetchAll(); - $this->setQueue($rows); - - + public function getParams(){ + return $this->params; } - - - - public function getTickets(){ - return $this->queueElements; - } - - protected function setQueue($rows){ - - $result = Array(); - foreach($rows as $ticket){ - $instance = new Ticket(); - $instance->setTId($ticket['TId']); - $instance->setTimestamp($ticket['Timestamp']); - $instance->setTitle($ticket['Title']); - $instance->setStatus($ticket['Status']); - $instance->setQueue($ticket['Queue']); - - $catInstance = new Ticket_Category(); - $catInstance->load_With_TCategoryId($ticket['Ticket_Category']); - $instance->setTicket_Category($catInstance); - - $userInstance = new Ticket_User(); - $userInstance->load_With_TUserId($ticket['Author']); - $instance->setAuthor($userInstance); - - $result[] = $instance; - } - $this->queueElements = $result; - - } - - - - - - - - - } \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue_handler.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue_handler.php index 80a4b5caa..24257c087 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue_handler.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue_handler.php @@ -2,11 +2,12 @@ class Ticket_Queue_Handler{ - public static function getTickets($input, $user_id){ + private $pagination; + + public function getTickets($input, $user_id){ $queue = new Ticket_Queue(); - - + switch ($input){ case "all": $queue->loadAllTickets(); @@ -26,8 +27,20 @@ class Ticket_Queue_Handler{ default: return "ERROR"; } - - return $queue->getTickets(); + $this->pagination = new Pagination($queue->getQuery(),"lib",10,"Ticket",$queue->getParams()); + foreach( $this->pagination->getElements() as $element ){ + $catInstance = new Ticket_Category(); + $catInstance->load_With_TCategoryId($element->getTicket_Category()); + $element->setTicket_Category($catInstance); + + $userInstance = new Ticket_User(); + $userInstance->load_With_TUserId($element->getAuthor()); + $element->setAuthor($userInstance); + } + return $this->pagination->getElements(); + + + } public static function CreateQueue($userid, $groupid, $what, $how, $who){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php index 2c2c1a2fa..136b1941b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php @@ -6,43 +6,49 @@ function show_queue(){ if(WebUsers::isLoggedIn() && isset($_GET['get'])){ if( Ticket_User::isMod($_SESSION['ticket_user'])){ + + //the default queue you want to see. $result['queue_view'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING); - $user_id = $_SESSION['ticket_user']->getTUserId(); - $queueArray = Ticket_Queue_Handler::getTickets($result['queue_view'], $user_id); + $queueArray = array(); + $queue_handler = new Ticket_Queue_handler(); + + //if an action is set + if(isset($_POST['action'])){ + switch($_POST['action']){ + case "assignTicket": + $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); + $result['ACTION_RESULT'] = Ticket::assignTicket($user_id, $ticket_id); + break; + + case "unAssignTicket": + $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); + $result['ACTION_RESULT'] = Ticket::unAssignTicket($user_id, $ticket_id); + break; + + case "create_queue": + $userid = filter_var($_POST['userid'], FILTER_SANITIZE_NUMBER_INT); + $groupid = filter_var($_POST['groupid'], FILTER_SANITIZE_NUMBER_INT); + $what = filter_var($_POST['what'], FILTER_SANITIZE_STRING); + $how = filter_var($_POST['how'], FILTER_SANITIZE_STRING); + $who = filter_var($_POST['who'], FILTER_SANITIZE_STRING); + $result['ACTION_RESULT'] = $queue_handler->CreateQueue($userid, $groupid, $what, $how, $who); + if ($result['ACTION_RESULT'] != "ERROR"){ + $queueArray = $result['ACTION_RESULT']; + } + break; + + } + } + + //if we didn't make a queue ourselves, then use the one specified by the get param + if( ! (isset($_POST['action']) && $_POST['action'] == "create_queue") ){ + $queueArray = $queue_handler->getTickets($result['queue_view'], $user_id); + } //if queue_view is a valid parameter value if ($queueArray != "ERROR"){ - - - - if(isset($_POST['action'])){ - switch($_POST['action']){ - case "assignTicket": - $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); - $result['ACTION_RESULT'] = Ticket::assignTicket($user_id, $ticket_id); - break; - - case "unAssignTicket": - $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); - $result['ACTION_RESULT'] = Ticket::unAssignTicket($user_id, $ticket_id); - break; - - case "create_queue": - $userid = filter_var($_POST['userid'], FILTER_SANITIZE_NUMBER_INT); - $groupid = filter_var($_POST['groupid'], FILTER_SANITIZE_NUMBER_INT); - $what = filter_var($_POST['what'], FILTER_SANITIZE_STRING); - $how = filter_var($_POST['how'], FILTER_SANITIZE_STRING); - $who = filter_var($_POST['who'], FILTER_SANITIZE_STRING); - $result['ACTION_RESULT'] = Ticket_Queue_Handler::CreateQueue($userid, $groupid, $what, $how, $who); - if ($result['ACTION_RESULT'] != "ERROR"){ - $queueArray = $result['ACTION_RESULT']; - } - break; - - } - } - + $result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned","getForwardedGroupName","getForwardedGroupId"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned","forwardedGroupName","forwardedGroupId")); $i = 0; foreach( $result['tickets'] as $ticket){