2013-07-12 12:06:06 +00:00
< ? php
2013-09-12 04:13:28 +00:00
/**
* Class that handles the logging . The logging will be used when a ticket is created , a reply is added , if someone views a ticket ,
* if someone assigns a ticket to him or if someone forwards a ticket . This class provides functions to get retrieve those logs and also make them .
2014-09-03 02:46:08 +00:00
*
2013-09-12 04:13:28 +00:00
*- the Action IDs being used are :
* - # User X Created ticket
* - # Admin X created ticket for arg
* - # Read ticket
* - # Added Reply ID: arg to ticket
* - # Changed status to arg
* - # Changed Priority to arg
* - # assigned to the ticket
* - # forwarded ticket to support group arg
* - # unassigned to the ticket
2014-09-05 07:50:07 +00:00
* - # added attachment to the ticket
2013-09-12 04:13:28 +00:00
*
* @ author Daan Janssens , mentored by Matthew Lagoe
*/
2013-07-12 12:06:06 +00:00
class Ticket_Log {
2014-09-03 02:46:08 +00:00
private $tLogId ; /**< The id of the log entry */
private $timestamp ; /**< The timestamp of the log entry */
private $query ; /**< The query (json encoded array containing action id & argument) */
private $author ; /**< author of the log */
private $ticket ; /**< the id of the ticket related to the log entry */
2013-07-12 17:43:33 +00:00
/****************************************
* 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
2014-09-05 07:50:07 +00:00
* 10 : added attachment to the ticket
2013-07-12 17:43:33 +00:00
*
****************************************/
2014-09-03 02:46:08 +00:00
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* return all log entries related to a ticket .
* @ param $ticket_id the id of the ticket of which we want all related log entries returned .
* @ return an array of ticket_log objects , be aware that the author in the ticket_log object is a ticket_user object on its own ( so not a simple integer ) .
*/
2013-07-13 01:46:15 +00:00
public static function getLogsOfTicket ( $ticket_id ) {
$dbl = new DBLayer ( " lib " );
2013-08-02 17:43:43 +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 ORDER BY ticket_log.TLogId ASC " , array ( 'id' => $ticket_id ));
2013-07-13 01:46:15 +00:00
$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 ;
}
2014-09-03 02:46:08 +00:00
return $result ;
2013-07-13 01:46:15 +00:00
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* create a new log entry .
* It will check if the $TICKET_LOGGING global var is true , this var is used to turn logging on and off . In case it ' s on , the log message will be stored .
* the action id and argument ( which is - 1 by default ), will be json encoded and stored in the query field in the db .
* @ param $ticket_id the id of the ticket related to the new log entry
* @ param $author_id the id of the user that instantiated the logging .
* @ param $action the action id ( see the list in the class description )
* @ param $arg argument for the action ( default = - 1 )
*/
2013-07-12 17:43:33 +00:00
public static function createLogEntry ( $ticket_id , $author_id , $action , $arg = - 1 ) {
global $TICKET_LOGGING ;
if ( $TICKET_LOGGING ){
$dbl = new DBLayer ( " lib " );
2014-09-03 02:46:08 +00:00
$values = Array ( 'Query' => json_encode ( array ( $action , $arg )), 'Ticket' => $ticket_id , 'Author' => $author_id );
$dbl -> insert ( " ticket_log " , $values , array ( 'Timestamp' => 'now()' ));
2013-07-12 17:43:33 +00:00
}
2013-07-12 12:06:06 +00:00
}
2013-09-12 04:13:28 +00:00
/**
* return constructed element based on TLogId
2013-09-13 22:39:03 +00:00
* @ param $id ticket_log id of the entry that we want to load into our object .
2013-09-12 04:13:28 +00:00
* @ return constructed ticket_log object .
*/
2013-07-12 17:43:33 +00:00
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 ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* return all log entries related to a ticket .
* @ param $ticket_id the id of the ticket of which we want all related log entries returned .
* @ return an array of ticket_log objects , here the author is an integer .
* @ todo only use one of the 2 comparable functions in the future and make the other depricated .
*/
2013-07-12 17:43:33 +00:00
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 ;
}
2014-09-03 02:46:08 +00:00
return $result ;
2013-07-12 12:06:06 +00:00
}
2014-09-03 02:46:08 +00:00
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Methods////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* A constructor .
* Empty constructor
*/
2013-07-12 12:06:06 +00:00
public function __construct () {
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* sets the object ' s attributes .
* @ param $values should be an array .
*/
2013-07-12 17:43:33 +00:00
public function set ( $values ) {
$this -> setTLogId ( $values [ 'TLogId' ]);
$this -> setTimestamp ( $values [ 'Timestamp' ]);
$this -> setQuery ( $values [ 'Query' ]);
$this -> setTicket ( $values [ 'Ticket' ]);
$this -> setAuthor ( $values [ 'Author' ]);
2014-09-03 02:46:08 +00:00
}
2013-07-12 12:06:06 +00:00
2013-09-12 04:13:28 +00:00
/**
* loads the object ' s attributes .
* loads the object ' s attributes by giving a ticket_log entries ID ( TLogId ) .
2014-08-18 01:43:15 +00:00
* @ param $id the id of the ticket_log entry that should be loaded
2013-09-12 04:13:28 +00:00
*/
2013-07-12 17:43:33 +00:00
public function load_With_TLogId ( $id ) {
2013-07-12 12:06:06 +00:00
$dbl = new DBLayer ( " lib " );
2014-05-27 22:18:44 +00:00
$dbl -> select ( " ticket_log " , array ( 'id' => $id ), " TLogId=: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
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* update attributes of the object to the DB .
*/
2013-07-12 12:06:06 +00:00
public function update (){
$dbl = new DBLayer ( " lib " );
2014-09-03 02:46:08 +00:00
2014-05-27 22:18:44 +00:00
$values = Array ( 'timestamp' => $this -> getTimestamp (), 'query' => $this -> getQuery (), 'author' => $this -> getAuthor (), 'ticket' => $this -> getTicket () );
$dbl -> update ( " ticket_log " , $values , " TLogId = $this->getTLogId () " );
2014-09-03 02:46:08 +00:00
2013-07-12 12:06:06 +00:00
}
2014-09-03 02:46:08 +00:00
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get tLogId attribute of the object .
*/
2013-07-12 17:43:33 +00:00
public function getTLogId (){
return $this -> tLogId ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get timestamp attribute of the object .
*/
2013-07-12 17:43:33 +00:00
public function getTimestamp (){
2013-07-19 14:30:58 +00:00
return Helpers :: outputTime ( $this -> timestamp );
2013-07-12 17:43:33 +00:00
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get query attribute of the object .
*/
2013-07-12 17:43:33 +00:00
public function getQuery (){
return $this -> query ;
2013-07-12 12:06:06 +00:00
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get author attribute of the object .
*/
2013-07-12 17:43:33 +00:00
public function getAuthor (){
return $this -> author ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get ticket attribute of the object .
*/
2013-07-12 17:43:33 +00:00
public function getTicket (){
return $this -> ticket ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get the action id out of the query by decoding it .
*/
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
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get the argument out of the query by decoding it .
*/
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 ];
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* get the action text ( string ) array .
* this is being read from the language . ini files .
*/
2013-10-24 01:26:59 +00:00
public static 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 ;
}
2014-09-03 02:46:08 +00:00
2013-07-12 12:06:06 +00:00
////////////////////////////////////////////Setters////////////////////////////////////////////////////
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* set tLogId attribute of the object .
* @ param $id integer id of the log entry
*/
2013-07-12 17:43:33 +00:00
public function setTLogId ( $id ){
$this -> tLogId = $id ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* set timestamp attribute of the object .
* @ param $t timestamp of the log entry
*/
2013-07-12 17:43:33 +00:00
public function setTimestamp ( $t ){
$this -> timestamp = $t ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* set query attribute of the object .
* @ param $q the encoded query
*/
2013-07-12 17:43:33 +00:00
public function setQuery ( $q ){
$this -> query = $q ;
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* set author attribute of the object .
* @ param $a integer id of the user who created the log entry
*/
2013-07-12 17:43:33 +00:00
public function setAuthor ( $a ){
$this -> author = $a ;
2013-07-12 12:06:06 +00:00
}
2014-09-03 02:46:08 +00:00
2013-09-12 04:13:28 +00:00
/**
* set ticket attribute of the object .
* @ param $t integer id of ticket of which the log entry is related to .
*/
2013-07-12 17:43:33 +00:00
public function setTicket ( $t ){
$this -> ticket = $t ;
2013-07-12 12:06:06 +00:00
}
2014-09-03 02:46:08 +00:00
2014-05-27 22:18:44 +00:00
}