2013-07-06 04:09:47 +00:00
< ? php
class Ticket {
private $tId ;
private $timestamp ;
private $title ;
private $status ;
private $queue ;
private $ticket_category ;
private $author ;
2013-07-11 18:31:34 +00:00
private $priority ;
2013-07-06 04:09:47 +00:00
2013-07-11 18:31:34 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
2013-07-08 12:49:03 +00:00
2013-07-11 18:31:34 +00:00
/* FUNCTION : getStatusArray
* returns all possible statusses
*
*/
2013-07-11 00:39:52 +00:00
public static function getStatusArray () {
return Array ( " Waiting on user reply " , " Waiting on support " , " Waiting on Dev reply " , " Closed " );
}
2013-07-11 18:31:34 +00:00
/* FUNCTION : getPriorityArray
* returns all possible statusses
*
*/
public static function getPriorityArray () {
return Array ( " Low " , " Normal " , " High " , " Super Dupa High " );
}
/* FUNCTION : getEntireTicket
* return all ticket of the given author ' s id .
*
*/
2013-07-10 10:36:14 +00:00
public static function getEntireTicket ( $id ) {
$ticket = new Ticket ();
2013-07-10 00:41:03 +00:00
$ticket -> load_With_TId ( $id );
2013-07-10 10:36:14 +00:00
$reply_array = Ticket_Reply :: getRepliesOfTicket ( $id );
2013-07-10 00:41:03 +00:00
return Array ( 'ticket_obj' => $ticket , 'reply_array' => $reply_array );
}
/* FUNCTION : getTicketTitlesOf
2013-07-08 23:03:49 +00:00
* return all ticket of the given author ' s id .
*
*/
2013-07-10 10:36:14 +00:00
public static function getTicketsOf ( $author ) {
$dbl = new DBLayer ( " lib " );
2013-07-08 23:03:49 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket_user.ExternId=:id " , array ( 'id' => $author ));
$row = $statement -> fetchAll ();
$result = Array ();
foreach ( $row as $ticket ){
2013-07-10 10:36:14 +00:00
$instance = new self ();
2013-07-09 14:03:52 +00:00
$instance -> setTId ( $ticket [ 'TId' ]);
2013-07-08 23:03:49 +00:00
$instance -> setTimestamp ( $ticket [ 'Timestamp' ]);
$instance -> setTitle ( $ticket [ 'Title' ]);
$instance -> setStatus ( $ticket [ 'Status' ]);
$instance -> setQueue ( $ticket [ 'Queue' ]);
$instance -> setTicket_Category ( $ticket [ 'Ticket_Category' ]);
$instance -> setAuthor ( $ticket [ 'Author' ]);
$result [] = $instance ;
}
return $result ;
}
2013-07-08 12:49:03 +00:00
/* FUNCTION : create_Ticket ()
* creates a ticket + first initial reply and fills in the content of it !
*
*/
2013-07-12 17:43:33 +00:00
public static function create_Ticket ( $title , $content , $category , $author , $real_author ) {
2013-07-08 12:49:03 +00:00
2013-07-10 10:36:14 +00:00
$ticket = new Ticket ();
2013-07-11 18:31:34 +00:00
$ticket -> set ( $title , 1 , 0 , $category , $author , 0 );
2013-07-08 12:49:03 +00:00
$ticket -> create ();
$ticket_id = $ticket -> getTId ();
2013-07-11 18:31:34 +00:00
2013-07-12 17:43:33 +00:00
Ticket_Reply :: createReply ( $content , $author , $ticket_id );
if ( $author == $real_author ){
Ticket_Log :: createLogEntry ( $ticket_id , $author , 1 );
} else {
Ticket_Log :: createLogEntry ( $ticket_id , $real_author , 2 , $author );
}
2013-07-10 00:41:03 +00:00
return $ticket_id ;
2013-07-08 12:49:03 +00:00
}
2013-07-12 17:43:33 +00:00
/* FUNCTION : updateTicketStatusAndPriority ()
* creates a ticket + first initial reply and fills in the content of it !
*
*/
public static function updateTicketStatusAndPriority ( $ticket_id , $newStatus , $newPriority , $author ) {
$ticket = new Ticket ();
$ticket -> load_With_TId ( $ticket_id );
if ( $ticket -> getStatus () != $newStatus ){
$ticket -> setStatus ( $newStatus );
Ticket_Log :: createLogEntry ( $ticket_id , $author , 5 , $newStatus );
}
if ( $ticket -> getPriority () != $newPriority ){
$ticket -> setPriority ( $newPriority );
Ticket_Log :: createLogEntry ( $ticket_id , $author , 6 , $newPriority );
}
$ticket -> update ();
}
2013-07-12 18:10:17 +00:00
//return the latest reply.
2013-07-11 18:31:34 +00:00
public static function getLatestReply ( $ticket_id ) {
$dbl = new DBLayer ( " lib " );
$statement = $dbl -> execute ( " SELECT * FROM ticket_reply WHERE Ticket =:id ORDER BY TReplyId DESC LIMIT 1 " , array ( 'id' => $ticket_id ));
$reply = new Ticket_Reply ();
$reply -> set ( $statement -> fetch ());
return $reply ;
}
2013-07-12 18:10:17 +00:00
public static function createReply ( $content , $author , $ticket_id ){
if ( $content != " " ){
$ticket = new Ticket ();
$ticket -> load_With_TId ( $ticket_id );
//if status is not closed
if ( $ticket -> getStatus () != 3 ){
Ticket_Reply :: createReply ( $content , $author , $ticket_id );
} else {
//TODO: Show error message that ticket is closed
}
} else {
//TODO: Show error content is empty
}
}
2013-07-11 18:31:34 +00:00
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Methods////////////////////////////////////////////////////
2013-07-10 10:36:14 +00:00
public function __construct () {
2013-07-06 04:09:47 +00:00
}
//Set ticket object
2013-07-11 18:31:34 +00:00
public function set ( $t , $s , $q , $t_c , $a , $p ){
2013-07-06 04:09:47 +00:00
$this -> title = $t ;
$this -> status = $s ;
$this -> queue = $q ;
$this -> ticket_category = $t_c ;
$this -> author = $a ;
2013-07-11 18:31:34 +00:00
$this -> priority = $p ;
2013-07-06 04:09:47 +00:00
}
//create ticket by writing private data to DB.
public function create (){
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-11 18:31:34 +00:00
$query = " INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author, Priority) VALUES (now(), :title, :status, :queue, :tcat, :author, :priority) " ;
$values = Array ( 'title' => $this -> title , 'status' => $this -> status , 'queue' => $this -> queue , 'tcat' => $this -> ticket_category , 'author' => $this -> author , 'priority' => $this -> priority );
2013-07-08 07:40:48 +00:00
$this -> tId = $dbl -> executeReturnId ( $query , $values ); ;
2013-07-06 04:09:47 +00:00
}
//return constructed element based on TId
public function load_With_TId ( $id ) {
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-06 04:09:47 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket WHERE TId=:id " , array ( 'id' => $id ));
$row = $statement -> fetch ();
$this -> tId = $row [ 'TId' ];
$this -> timestamp = $row [ 'Timestamp' ];
$this -> title = $row [ 'Title' ];
$this -> status = $row [ 'Status' ];
$this -> queue = $row [ 'Queue' ];
$this -> ticket_category = $row [ 'Ticket_Category' ];
$this -> author = $row [ 'Author' ];
2013-07-11 18:31:34 +00:00
$this -> priority = $row [ 'Priority' ];
2013-07-06 04:09:47 +00:00
}
//update private data to DB.
public function update (){
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-11 18:31:34 +00:00
$query = " UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author, Priority = :priority WHERE TId=:id " ;
$values = Array ( 'id' => $this -> tId , 'timestamp' => $this -> timestamp , 'title' => $this -> title , 'status' => $this -> status , 'queue' => $this -> queue , 'tcat' => $this -> ticket_category , 'author' => $this -> author , 'priority' => $this -> priority );
2013-07-06 04:09:47 +00:00
$statement = $dbl -> execute ( $query , $values );
}
2013-07-11 18:31:34 +00:00
/* FUNCTION : postreply
* returns all possible statusses
*
*
public function postReply () {
return Array ( " Waiting on user reply " , " Waiting on support " , " Waiting on Dev reply " , " Closed " );
} */
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-07-08 07:40:48 +00:00
public function getTId (){
return $this -> tId ;
2013-07-06 04:09:47 +00:00
}
2013-07-08 12:49:03 +00:00
public function getTimestamp (){
return $this -> timestamp ;
}
public function getTitle (){
return $this -> title ;
}
public function getStatus (){
return $this -> status ;
}
2013-07-09 14:03:52 +00:00
public function getStatusText (){
2013-07-11 00:39:52 +00:00
$statusArray = Ticket :: getStatusArray ();
return $statusArray [ $this -> getStatus ()];
2013-07-09 14:03:52 +00:00
}
public function getCategoryName (){
2013-07-10 10:36:14 +00:00
$category = Ticket_Category :: constr_TCategoryId ( $this -> getTicket_Category ());
2013-07-09 14:03:52 +00:00
return $category -> getName ();
}
2013-07-08 12:49:03 +00:00
public function getQueue (){
return $this -> queue ;
}
public function getTicket_Category (){
return $this -> ticket_category ;
}
public function getAuthor (){
return $this -> author ;
}
2013-07-11 18:31:34 +00:00
public function getPriority (){
return $this -> priority ;
}
public function getPriorityText (){
$priorityArray = Ticket :: getPriorityArray ();
return $priorityArray [ $this -> getPriority ()];
}
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Setters////////////////////////////////////////////////////
2013-07-08 07:40:48 +00:00
public function setTId ( $id ){
$this -> tId = $id ;
2013-07-06 04:09:47 +00:00
}
2013-07-08 12:49:03 +00:00
public function setTimestamp ( $ts ){
$this -> timestamp = $ts ;
}
public function setTitle ( $t ){
$this -> title = $t ;
}
public function setStatus ( $s ){
$this -> status = $s ;
}
public function setQueue ( $q ){
$this -> queue = $q ;
}
public function setTicket_Category ( $tc ){
$this -> ticket_category = $tc ;
}
public function setAuthor ( $a ){
$this -> author = $a ;
}
2013-07-11 18:31:34 +00:00
public function setPriority ( $p ){
$this -> priority = $p ;
}
2013-07-06 04:09:47 +00:00
}