2013-07-12 12:06:06 +00:00
< ? php
class Ticket_Log {
2013-07-12 17:43:33 +00:00
private $tLogId ;
private $timestamp ;
private $query ;
private $author ;
private $ticket ;
/****************************************
* Action ID ' s :
* 1 : User X Created Ticket
* 2 : Admin X created ticket for arg
* 3 : Read Ticket
* 4 : Added Reply ID : arg to ticket
* 5 : Changed status to arg
* 6 : Changed Priority to arg
2013-07-22 18:33:34 +00:00
* 7 : assigned to the ticket
* 8 : Forwarded ticket to support group arg
* 9 : unassigned to the ticket
2013-07-12 17:43:33 +00:00
*
****************************************/
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
2013-07-13 01:46:15 +00:00
//return all logs that are related to a ticket
public static function getLogsOfTicket ( $ticket_id ) {
$dbl = new DBLayer ( " lib " );
$statement = $dbl -> execute ( " SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id ORDER BY ticket_log.TLogId DESC " , array ( 'id' => $ticket_id ));
$row = $statement -> fetchAll ();
$result = Array ();
foreach ( $row as $log ){
$instanceAuthor = Ticket_User :: constr_TUserId ( $log [ 'Author' ]);
$instanceAuthor -> setExternId ( $log [ 'ExternId' ]);
$instanceAuthor -> setPermission ( $log [ 'Permission' ]);
$instanceLog = new self ();
$instanceLog -> setTLogId ( $log [ 'TLogId' ]);
$instanceLog -> setTimestamp ( $log [ 'Timestamp' ]);
$instanceLog -> setAuthor ( $instanceAuthor );
$instanceLog -> setTicket ( $ticket_id );
$instanceLog -> setQuery ( $log [ 'Query' ]);
$result [] = $instanceLog ;
}
return $result ;
}
2013-07-12 12:06:06 +00:00
2013-07-12 17:43:33 +00:00
//Creates a log entry
public static function createLogEntry ( $ticket_id , $author_id , $action , $arg = - 1 ) {
global $TICKET_LOGGING ;
if ( $TICKET_LOGGING ){
$dbl = new DBLayer ( " lib " );
$query = " INSERT INTO ticket_log (Timestamp, Query, Ticket, Author) VALUES (now(), :query, :ticket, :author ) " ;
$values = Array ( 'ticket' => $ticket_id , 'author' => $author_id , 'query' => json_encode ( array ( $action , $arg )));
$dbl -> execute ( $query , $values );
}
2013-07-12 12:06:06 +00:00
}
2013-07-12 17:43:33 +00:00
//return constructed element based on TLogId
public static function constr_TLogId ( $id ) {
2013-07-12 12:06:06 +00:00
$instance = new self ();
2013-07-12 17:43:33 +00:00
$instance -> setTLogId ( $id );
2013-07-12 12:06:06 +00:00
return $instance ;
}
2013-07-12 17:43:33 +00:00
//returns list of all logs of a ticket
public static function getAllLogs ( $ticket_id ) {
2013-07-12 12:06:06 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-12 17:43:33 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id " , array ( 'id' => $ticket_id ));
2013-07-12 12:06:06 +00:00
$row = $statement -> fetchAll ();
$result = Array ();
2013-07-12 17:43:33 +00:00
foreach ( $row as $log ){
2013-07-12 12:06:06 +00:00
$instance = new self ();
2013-07-12 17:43:33 +00:00
$instance -> set ( $log );
2013-07-12 12:06:06 +00:00
$result [] = $instance ;
}
return $result ;
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct () {
}
2013-07-12 17:43:33 +00:00
//set values
public function set ( $values ) {
$this -> setTLogId ( $values [ 'TLogId' ]);
$this -> setTimestamp ( $values [ 'Timestamp' ]);
$this -> setQuery ( $values [ 'Query' ]);
$this -> setTicket ( $values [ 'Ticket' ]);
$this -> setAuthor ( $values [ 'Author' ]);
}
2013-07-12 12:06:06 +00:00
2013-07-12 17:43:33 +00:00
//Load with tlogId
public function load_With_TLogId ( $id ) {
2013-07-12 12:06:06 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-12 17:43:33 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket_log WHERE TLogId=:id " , array ( 'id' => $id ));
2013-07-12 12:06:06 +00:00
$row = $statement -> fetch ();
2013-07-12 17:43:33 +00:00
$this -> set ( $row );
2013-07-12 12:06:06 +00:00
}
//update private data to DB.
public function update (){
$dbl = new DBLayer ( " lib " );
2013-07-12 17:43:33 +00:00
$query = " UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id " ;
$values = Array ( 'id' => $this -> getTLogId (), 'timestamp' => $this -> getTimestamp (), 'query' => $this -> getQuery (), 'author' => $this -> getAuthor (), 'ticket' => $this -> getTicket () );
2013-07-12 12:06:06 +00:00
$statement = $dbl -> execute ( $query , $values );
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-07-12 17:43:33 +00:00
public function getTLogId (){
return $this -> tLogId ;
}
public function getTimestamp (){
2013-07-19 14:30:58 +00:00
return Helpers :: outputTime ( $this -> timestamp );
2013-07-12 17:43:33 +00:00
}
public function getQuery (){
return $this -> query ;
2013-07-12 12:06:06 +00:00
}
2013-07-12 17:43:33 +00:00
public function getAuthor (){
return $this -> author ;
}
public function getTicket (){
return $this -> ticket ;
}
2013-07-12 12:06:06 +00:00
2013-07-13 01:46:15 +00:00
public function getAction (){
$decodedQuery = json_decode ( $this -> query );
2013-07-12 17:43:33 +00:00
return $decodedQuery [ 0 ];
2013-07-12 12:06:06 +00:00
}
2013-07-12 17:43:33 +00:00
public function getArgument (){
2013-07-13 01:46:15 +00:00
$decodedQuery = json_decode ( $this -> query );
2013-07-12 17:43:33 +00:00
return $decodedQuery [ 1 ];
}
2013-07-12 12:06:06 +00:00
2013-07-13 14:41:52 +00:00
public function getActionTextArray (){
2013-07-13 16:04:40 +00:00
$variables = Helpers :: handle_language ();
2013-07-13 14:41:52 +00:00
$result = array ();
foreach ( $variables [ 'ticket_log' ] as $key => $value ){
$result [ $key ] = $value ;
}
return $result ;
}
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Setters////////////////////////////////////////////////////
2013-07-12 17:43:33 +00:00
public function setTLogId ( $id ){
$this -> tLogId = $id ;
}
public function setTimestamp ( $t ){
$this -> timestamp = $t ;
}
public function setQuery ( $q ){
$this -> query = $q ;
}
public function setAuthor ( $a ){
$this -> author = $a ;
2013-07-12 12:06:06 +00:00
}
2013-07-12 17:43:33 +00:00
public function setTicket ( $t ){
$this -> ticket = $t ;
2013-07-12 12:06:06 +00:00
}
}