From fdef0d55dc46e77d920ebf50682c8f8c4dd90a06 Mon Sep 17 00:00:00 2001 From: Quitta Date: Sun, 21 Jul 2013 03:49:31 +0200 Subject: [PATCH] People can assign and unassign to a ticket --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/assigned.php | 32 +++++++++++--- .../ryzom_ams/ams_lib/autoload/ticket.php | 32 +++++++++++++- .../ryzom_ams/ams_lib/translations/en.ini | 7 ++- .../ryzom_ams/ams_lib/translations/fr.ini | 2 +- .../ryzom_ams/www/html/inc/show_queue.php | 35 +++++++++++---- .../www/html/templates/show_queue.tpl | 44 +++++++++++++++++-- 6 files changed, 131 insertions(+), 21 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php index 32b7ef734..6d2a558c3 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php @@ -8,20 +8,35 @@ class Assigned{ ////////////////////////////////////////////Functions//////////////////////////////////////////////////// //Assigns a ticket to a user or returns error message - public static function AssignTicket( $user_id, $ticket_id) { + public static function assignTicket( $user_id, $ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is already assigned, if so return "ALREADY ASSIGNED" if(! Assigned::isAssigned($ticket_id)){ $assignation = new Assigned(); $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); $assignation->create(); - return "SUCCESS"; + return "SUCCESS_ASSIGNED"; }else{ return "ALREADY_ASSIGNED"; } } + //Unsign a ticket to a user or returns error message + public static function unAssignTicket( $user_id, $ticket_id) { + $dbl = new DBLayer("lib"); + //check if ticket is really assigned to that user + if( Assigned::isAssigned($ticket_id, $user_id)){ + $assignation = new Assigned(); + $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); + $assignation->delete(); + return "SUCCESS_UNASSIGNED"; + }else{ + return "NOT_ASSIGNED"; + } + + } + // Get the id of the user assigned to a ticket public static function getUserAssignedToTicket($ticket_id) { $dbl = new DBLayer("lib"); @@ -33,10 +48,13 @@ class Assigned{ } - public static function isAssigned( $ticket_id ) { + public static function isAssigned( $ticket_id, $user_id = 0) { $dbl = new DBLayer("lib"); //check if ticket is already assigned - if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + + if($user_id == 0 && $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + return true; + }else if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id and `User` = :user_id", array('ticket_id' => $ticket_id, 'user_id' => $user_id) )->rowCount()){ return true; }else{ return false; @@ -51,12 +69,12 @@ class Assigned{ //set values public function set($values) { $this->setUser($values['User']); - $this->setGroup($values['Ticket']); + $this->setTicket($values['Ticket']); } public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `assigned' (`User`,`Ticket`) VALUES (:user, :ticket)"; + $query = "INSERT INTO `assigned` (`User`,`Ticket`) VALUES (:user, :ticket)"; $values = Array('user' => $this->getUser(), 'ticket' => $this->getTicket()); $dbl->execute($query, $values); } @@ -65,7 +83,7 @@ class Assigned{ public function delete() { $dbl = new DBLayer("lib"); $query = "DELETE FROM `assigned` WHERE `User` = :user_id and `Ticket` = :ticket_id"; - $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getGroup()); + $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket()); $dbl->execute($query, $values); } 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 cfcd6f3df..24732f3f4 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 @@ -10,7 +10,21 @@ class Ticket{ private $author; private $priority; - ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + /*FUNCTION: ticketExists + * returns true if ticket exists + * + */ + public static function ticketExists($id) { + $dbl = new DBLayer("lib"); + //check if ticket is already assigned + if( $dbl->execute(" SELECT * FROM `ticket` WHERE `TId` = :ticket_id", array('ticket_id' => $id) )->rowCount() ){ + return true; + }else{ + return false; + } + } /*FUNCTION: getStatusArray * returns all possible statusses @@ -130,7 +144,23 @@ class Ticket{ } } + //returns SUCCESS_ASSIGNED, TICKET_NOT_EXISTING or ALREADY_ASSIGNED + public static function assignTicket($user_id, $ticket_id){ + if(self::ticketExists($ticket_id)){ + return Assigned::assignTicket($user_id, $ticket_id); + }else{ + return "TICKET_NOT_EXISTING"; + } + } + //returns SUCCESS_UNASSIGNED, TICKET_NOT_EXISTING or NOT_ASSIGNED + public static function unAssignTicket($user_id, $ticket_id){ + if(self::ticketExists($ticket_id)){ + return Assigned::unAssignTicket($user_id, $ticket_id); + }else{ + return "TICKET_NOT_EXISTING"; + } + } ////////////////////////////////////////////Methods//////////////////////////////////////////////////// public function __construct() { diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 930ab69f1..8f5613e9f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -30,7 +30,12 @@ t_send = "Send reply" [show_user] [show_queue] -not_assigned = "None" +not_assigned = "Open" +success_assigned = "The ticket was successfully assigned!" +success_unassigned = "The ticket was successfully unassigned!" +ticket_not_existing = "That ticket doesn't exist!" +already_assigned = "That ticket is already assigned to someone!" +not_assigned = "That ticket isn't assigned to you!" [show_sgroup] add_to_group_success = "The user has been added to the group!" diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini index 8a9257305..f3f208a0f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini @@ -30,7 +30,7 @@ t_send = "Envoyer la reponse" [show_user] [show_queue] -not_assigned = "Ne pas" +not_assigned = "Libre" [show_sgroup] add_to_group_success = "ce user est ajoute sur la groupe!" 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 ff8818e4f..097b5c4f7 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 @@ -4,24 +4,43 @@ function show_queue(){ //if logged in & queue id is given if(WebUsers::isLoggedIn() && isset($_GET['get'])){ + if( Ticket_User::isMod($_SESSION['ticket_user'])){ - $result['queue_action'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING); + $result['queue_view'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING); - $queueArray = Ticket_Queue_Handler::getTickets($result['queue_action']); - if ($queueArray != "ERROR"){ + $queueArray = Ticket_Queue_Handler::getTickets($result['queue_view']); + + //if queue_view is a valid parameter value + if ($queueArray != "ERROR"){ + + $user_id = $_SESSION['ticket_user']->getTUserId(); + + 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; + } + } + $result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned")); - $i = 0; foreach( $result['tickets'] as $ticket){ $result['tickets'][$i]['author'] = WebUsers::getUsername($ticket['authorExtern']); $result['tickets'][$i]['assignedText'] = WebUsers::getUsername($ticket['assigned']); $i++; } - if(Ticket_User::isMod($_SESSION['ticket_user'])){ - $result['isMod'] = "TRUE"; - } + $result['user_id'] = $_SESSION['ticket_user']->getTUserId(); return $result; - }else{ + + }else{ + //ERROR: Doesn't exist! $_SESSION['error_code'] = "404"; header("Location: index.php?page=error"); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl index f5f5a2120..df5c2cb7a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl @@ -2,7 +2,7 @@
-

Ticket Queue {$queue_action}

+

Ticket Queue {$queue_view}

@@ -11,6 +11,29 @@
Tickets + + {if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_ASSIGNED"} +
+ {$success_assigned} +
+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_UNASSIGNED"} +
+ {$success_unassigned} +
+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "TICKET_NOT_EXISTING"} +
+ {$ticket_not_existing} +
+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "ALREADY_ASSIGNED"} +
+ {$already_assigned} +
+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "NOT_ASSIGNED"} +
+ {$not_assigned} +
+ {/if} + @@ -20,6 +43,7 @@ + @@ -27,11 +51,25 @@ - + - + {/foreach}
Timestamp Category StatusActions
{$ticket.tId} {$ticket.title}{if $ticket.assignedText neq ""} {$ticket.assignedText} {else} {$not_assigned} {/if}{if $ticket.assignedText neq ""} {$ticket.assignedText} {else} {$not_assigned} {/if} {$ticket.timestamp} {$ticket.category}{if $ticket.status eq 0} {/if} {$ticket.statusText} + {if $ticket.assigned eq 0} +
+ + + +
+ {else if $ticket.assigned eq 1} +
+ + + +
+ {/if} +