mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 21:56:13 +00:00
refactor queue's part 1
This commit is contained in:
parent
dbe6e82945
commit
b515b42223
5 changed files with 98 additions and 123 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,34 +1,42 @@
|
|||
<?php
|
||||
class Ticket_Queue{
|
||||
|
||||
protected $queueElements;
|
||||
private $query;
|
||||
private $params;
|
||||
|
||||
public function loadAllNotAssignedTickets(){
|
||||
$dbl = new DBLayer("lib");
|
||||
$statement = $dbl->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){
|
||||
|
@ -73,64 +81,11 @@ class Ticket_Queue{
|
|||
$this->setQueue($rows);
|
||||
}
|
||||
|
||||
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 getQuery(){
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTickets(){
|
||||
return $this->queueElements;
|
||||
public function getParams(){
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
$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();
|
||||
|
||||
|
||||
|
||||
return $queue->getTickets();
|
||||
}
|
||||
|
||||
public static function CreateQueue($userid, $groupid, $what, $how, $who){
|
||||
|
|
|
@ -6,16 +6,14 @@ 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);
|
||||
|
||||
//if queue_view is a valid parameter value
|
||||
if ($queueArray != "ERROR"){
|
||||
|
||||
|
||||
$queueArray = array();
|
||||
$queue_handler = new Ticket_Queue_handler();
|
||||
|
||||
//if an action is set
|
||||
if(isset($_POST['action'])){
|
||||
switch($_POST['action']){
|
||||
case "assignTicket":
|
||||
|
@ -34,7 +32,7 @@ function show_queue(){
|
|||
$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);
|
||||
$result['ACTION_RESULT'] = $queue_handler->CreateQueue($userid, $groupid, $what, $how, $who);
|
||||
if ($result['ACTION_RESULT'] != "ERROR"){
|
||||
$queueArray = $result['ACTION_RESULT'];
|
||||
}
|
||||
|
@ -43,6 +41,14 @@ function show_queue(){
|
|||
}
|
||||
}
|
||||
|
||||
//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"){
|
||||
|
||||
$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){
|
||||
|
|
Loading…
Reference in a new issue