2013-07-14 14:38:36 +00:00
< ? php
2013-09-12 17:28:56 +00:00
/**
* Data class that holds a lot of queries that load specific tickets .
* These queries are being used by the ticket_queue_handler class . An object of this class holds 2 attributes : the query and the params used for the query .
* @ author Daan Janssens , mentored by Matthew Lagoe
*/
2013-07-14 14:38:36 +00:00
class Ticket_Queue {
2013-09-12 17:28:56 +00:00
private $query ; /**< The query that loads specific tickets */
private $params ; /**< The parameter array that's being needed by the query */
2013-07-14 14:38:36 +00:00
2013-09-12 17:28:56 +00:00
/**
* loads the not yet assigned tickets query into the objects attributes .
*/
2013-07-19 21:36:34 +00:00
public function loadAllNotAssignedTickets (){
2013-08-05 20:35:22 +00:00
$this -> query = " SELECT ticket . * FROM ticket LEFT JOIN assigned ON ticket.TId = assigned.Ticket WHERE assigned.Ticket IS NULL " ;
$this -> params = array ();
2013-07-19 21:36:34 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'all' tickets query into the objects attributes .
*/
2013-07-23 21:38:06 +00:00
public function loadAllTickets (){
2013-08-05 20:35:22 +00:00
$this -> query = " SELECT * FROM `ticket` " ;
$this -> params = array ();
2013-07-23 21:38:06 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'all open' tickets query into the objects attributes .
*/
2013-07-14 14:38:36 +00:00
public function loadAllOpenTickets (){
2013-08-05 20:35:22 +00:00
$this -> query = " SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status!=3 " ;
$this -> params = array ();
2013-07-14 14:38:36 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'closed' tickets query into the objects attributes .
*/
2013-07-14 14:38:36 +00:00
public function loadAllClosedTickets (){
2013-08-05 20:35:22 +00:00
$this -> query = " SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status=3 " ;
$this -> params = array ();
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'todo' tickets query & params into the objects attributes .
* 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
* @ param $user_id the user ' s id to whom the tickets should be assigned
*/
2013-08-05 20:35:22 +00:00
public function loadToDoTickets ( $user_id ){
$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 );
2013-07-14 14:38:36 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'tickets asssigned to a user and waiting on support' query & params into the objects attributes .
* @ param $user_id the user ' s id to whom the tickets should be assigned
*/
2013-08-29 03:01:47 +00:00
public function loadAssignedandWaiting ( $user_id ){
$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
WHERE ( tu . ExternId = : user_id AND t . Status = 1 ) " ;
$this -> params = array ( 'user_id' => $user_id );
}
2013-09-12 17:28:56 +00:00
/**
* loads the 'created' query & params into the objects attributes .
* This function creates dynamically a query based on the selected features .
* @ param $who specifies if we want to user the user_id or group_id to form the query .
2013-09-13 22:39:03 +00:00
* @ param $userid the user ' s id to whom the tickets should be assigned / not assigned
* @ param $groupid the group ' s id to whom the tickets should be forwarded / not forwarded
2013-09-12 17:28:56 +00:00
* @ param $what specifies what kind of tickets we want to return : waiting for support , waiting on user , closed
* @ param $how specifies if the tickets should be or shouldn ' t be assigned / forwarded to the group / user selected .
*/
2013-07-23 21:38:06 +00:00
public function createQueue ( $userid , $groupid , $what , $how , $who ){
if ( $who == " user " ){
$selectfrom = " SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User " ;
2013-10-24 06:58:34 +00:00
if ( $how == " both " ){
$assign = " " ;
} else if ( $how == " assigned " ){
2013-07-23 21:38:06 +00:00
$assign = " tu.TUserId = :id " ;
} else if ( $how == " not_assigned " ){
$assign = " (tu.TUserId != :id OR a.Ticket IS NULL) " ;
}
} else if ( $who == " support_group " ){
$selectfrom = " 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 " ;
2013-10-24 06:58:34 +00:00
if ( $how == " both " ){
$assign = " " ;
} else if ( $how == " assigned " ){
2013-07-23 21:38:06 +00:00
$assign = " f.Group = :id " ;
} else if ( $how == " not_assigned " ){
$assign = " (f.Group != :id OR f.Ticket IS NULL) " ;
}
}
if ( $what == " waiting_for_support " ){
$status = " t.Status = 1 " ;
2013-10-24 06:58:34 +00:00
} else if ( $what == " waiting_for_users " ){
2013-07-23 21:38:06 +00:00
$status = " t.Status = 0 " ;
} else if ( $what == " closed " ){
$status = " t.Status = 3 " ;
}
2013-10-24 06:58:34 +00:00
if ( $assign == " " ) {
$query = $selectfrom ;
if ( isset ( $status )){
$query = $query . " WHERE " . $status ;
}
} else {
$query = $selectfrom . " WHERE " . $assign ;
if ( isset ( $status )){
$query = $query . " AND " . $status ;
}
2013-07-23 21:38:06 +00:00
}
2013-10-24 06:58:34 +00:00
2013-07-23 21:38:06 +00:00
if ( $who == " user " ){
$params = array ( 'id' => $userid );
} else if ( $who == " support_group " ){
$params = array ( 'id' => $groupid );
}
2013-10-24 06:58:34 +00:00
2013-08-05 23:00:17 +00:00
$this -> query = $query ;
$this -> params = $params ;
2013-10-24 06:58:34 +00:00
//print_r($this);
2013-09-12 17:28:56 +00:00
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-07-21 13:38:22 +00:00
2013-09-12 17:28:56 +00:00
/**
* get query attribute of the object .
*/
2013-08-05 20:35:22 +00:00
public function getQuery (){
return $this -> query ;
2013-07-14 14:38:36 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* get params attribute of the object .
*/
2013-08-05 20:35:22 +00:00
public function getParams (){
return $this -> params ;
2013-07-14 14:38:36 +00:00
}
}