khanat-opennel-code/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_queue.php

89 lines
3.7 KiB
PHP
Raw Normal View History

2013-07-14 14:38:36 +00:00
<?php
class Ticket_Queue{
2013-08-05 20:35:22 +00:00
private $query;
private $params;
2013-07-14 14:38:36 +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();
}
public function loadAllTickets(){
2013-08-05 20:35:22 +00:00
$this->query = "SELECT * FROM `ticket`";
$this->params = array();
}
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
}
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();
}
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);
2013-07-14 14:38:36 +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";
if ($how == "assigned"){
$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";
if ($how == "assigned"){
$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";
}else if ($what == "waiting_for_user"){
$status = "t.Status = 0";
}else if ($what == "closed"){
$status = "t.Status = 3";
}
$query = $selectfrom ." WHERE " . $assign;
if(isset($status)){
$query = $query . " AND " . $status;
}
if($who == "user"){
$params = array('id' => $userid);
}else if ($who == "support_group"){
$params = array('id' => $groupid);
}
$this->query = $query;
$this->params = $params;
2013-08-05 20:35:22 +00:00
}
2013-07-21 13:38:22 +00:00
2013-08-05 20:35:22 +00:00
public function getQuery(){
return $this->query;
2013-07-14 14:38:36 +00:00
}
2013-08-05 20:35:22 +00:00
public function getParams(){
return $this->params;
2013-07-14 14:38:36 +00:00
}
}