2013-07-08 07:40:48 +00:00
< ? php
2013-09-12 17:28:56 +00:00
/**
* handles functions related to replies on tickets .
* @ author Daan Janssens , mentored by Matthew Lagoe
*/
2013-07-08 07:40:48 +00:00
class Ticket_Reply {
2013-09-12 17:28:56 +00:00
private $tReplyId ; /**< The id of the reply */
private $ticket ; /**< the ticket id related to the reply */
private $content ; /**< the content of the reply */
private $author ; /**< The id of the user that made the reply */
private $timestamp ; /**< The timestamp of the reply */
private $hidden ; /**< indicates if reply should be hidden for normal users or not */
2013-07-08 07:40:48 +00:00
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
2013-09-12 17:28:56 +00:00
/**
* return constructed element based on TReplyId .
* @ param $id the Id the reply we want to load .
* @ return the loaded object .
*/
2013-07-10 10:36:14 +00:00
public static function constr_TReplyId ( $id ) {
$instance = new self ();
2013-07-08 12:49:03 +00:00
$instance -> setTReplyId ( $id );
return $instance ;
}
2013-07-11 18:31:34 +00:00
2013-09-12 17:28:56 +00:00
/**
* return all replies on a specific ticket .
* @ param $ticket_id the id of the ticket of which we want the replies .
* @ param $view_as_admin if the browsing user is an admin / mod it should be 1 , this will also show the hidden replies .
* @ return an array with ticket_reply objects ( beware the author and content are objects on their own , not integers ! )
*/
2013-07-19 13:59:39 +00:00
public static function getRepliesOfTicket ( $ticket_id , $view_as_admin ) {
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-10 20:40:01 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket_reply INNER JOIN ticket_content INNER JOIN ticket_user ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id and ticket_user.TUserId = ticket_reply.Author ORDER BY ticket_reply.TReplyId ASC " , array ( 'id' => $ticket_id ));
2013-07-10 00:41:03 +00:00
$row = $statement -> fetchAll ();
$result = Array ();
foreach ( $row as $tReply ){
2013-09-12 17:28:56 +00:00
//only add hidden replies if the user is a mod/admin
2013-07-19 13:59:39 +00:00
if ( ! $tReply [ 'Hidden' ] || $view_as_admin ){
2013-09-12 17:28:56 +00:00
//load author
2013-07-19 13:59:39 +00:00
$instanceAuthor = Ticket_User :: constr_TUserId ( $tReply [ 'Author' ]);
$instanceAuthor -> setExternId ( $tReply [ 'ExternId' ]);
$instanceAuthor -> setPermission ( $tReply [ 'Permission' ]);
2013-09-12 17:28:56 +00:00
//load content
2013-07-19 13:59:39 +00:00
$instanceContent = new Ticket_Content ();
$instanceContent -> setTContentId ( $tReply [ 'TContentId' ]);
$instanceContent -> setContent ( $tReply [ 'Content' ]);
2013-09-12 17:28:56 +00:00
//load reply and add the author and content object in it.
2013-07-19 13:59:39 +00:00
$instanceReply = new self ();
$instanceReply -> setTReplyId ( $tReply [ 'TReplyId' ]);
$instanceReply -> setTimestamp ( $tReply [ 'Timestamp' ]);
$instanceReply -> setAuthor ( $instanceAuthor );
$instanceReply -> setTicket ( $ticket_id );
$instanceReply -> setContent ( $instanceContent );
$instanceReply -> setHidden ( $tReply [ 'Hidden' ]);
$result [] = $instanceReply ;
}
2013-07-10 00:41:03 +00:00
}
return $result ;
}
2013-09-12 17:28:56 +00:00
/**
* creates a new reply on a ticket .
* Creates a ticket_content entry and links it with a new created ticket_reply , a log entry will be written about this .
* In case the ticket creator replies on a ticket , he will set the status by default to 'waiting on support' .
* @ param $content the content of the reply
* @ param $author the id of the reply creator .
* @ param $ticket_id the id of the ticket of which we want the replies .
* @ param $hidden should be 0 or 1
* @ param $ticket_creator the ticket ' s starter his id .
*/
2013-07-22 20:58:12 +00:00
public static function createReply ( $content , $author , $ticket_id , $hidden , $ticket_creator ){
2013-07-10 18:46:26 +00:00
$ticket_content = new Ticket_Content ();
$ticket_content -> setContent ( $content );
$ticket_content -> create ();
$content_id = $ticket_content -> getTContentId ();
$ticket_reply = new Ticket_Reply ();
2013-07-19 13:59:39 +00:00
$ticket_reply -> set ( Array ( 'Ticket' => $ticket_id , 'Content' => $content_id , 'Author' => $author , 'Hidden' => $hidden ));
2013-07-10 18:46:26 +00:00
$ticket_reply -> create ();
2013-07-12 17:43:33 +00:00
$reply_id = $ticket_reply -> getTReplyId ();
2013-07-22 20:58:12 +00:00
if ( $ticket_creator == $author ){
Ticket :: updateTicketStatus ( $ticket_id , 1 , $author );
}
2013-07-12 17:43:33 +00:00
Ticket_Log :: createLogEntry ( $ticket_id , $author , 4 , $reply_id );
2013-07-10 18:46:26 +00:00
}
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Methods////////////////////////////////////////////////////
2013-09-12 17:28:56 +00:00
/**
* A constructor .
* Empty constructor
*/
2013-07-10 10:36:14 +00:00
public function __construct () {
2013-07-08 07:40:48 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* sets the object ' s attributes .
* @ param $values should be an array .
*/
2013-07-11 18:31:34 +00:00
public function set ( $values ){
$this -> setTicket ( $values [ 'Ticket' ]);
$this -> setContent ( $values [ 'Content' ]);
$this -> setAuthor ( $values [ 'Author' ]);
if ( isset ( $values [ 'Timestamp' ])){
$this -> setTimestamp ( $values [ 'Timestamp' ]);
}
2013-07-19 13:59:39 +00:00
if ( isset ( $values [ 'Hidden' ])){
$this -> setHidden ( $values [ 'Hidden' ]);
}
2013-07-08 07:40:48 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* creates a new 'ticket_reply' entry .
* this method will use the object 's attributes for creating a new ' ticket_reply ' entry in the database ( the now () function will create the timestamp ) .
*/
2013-07-08 07:40:48 +00:00
public function create (){
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2014-05-27 22:18:44 +00:00
$this -> tReplyId = $dbl -> executeReturnId ( " ticket_reply " , Array ( 'Ticket' => $this -> ticket , 'Content' => $this -> content , 'Author' => $this -> author , 'Timestamp' => now (), 'Hidden' => $this -> hidden ));
2013-07-08 07:40:48 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* loads the object ' s attributes .
* loads the object 's attributes by giving a ticket_reply' s id .
* @ param $id the id of the ticket_reply that should be loaded
*/
2013-07-08 07:40:48 +00:00
public function load_With_TReplyId ( $id ) {
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2014-05-27 22:18:44 +00:00
$statement = $dbl -> select ( " ticket_reply " , array ( 'id' => $id ), " TReplyId=:id " );
2013-07-08 07:40:48 +00:00
$row = $statement -> fetch ();
$this -> tReplyId = $row [ 'TReplyId' ];
$this -> ticket = $row [ 'Ticket' ];
$this -> content = $row [ 'Content' ];
$this -> author = $row [ 'Author' ];
2013-07-19 13:59:39 +00:00
$this -> timestamp = $row [ 'Timestamp' ];
$this -> hidden = $row [ 'Hidden' ];
2013-07-08 07:40:48 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* updates a ticket_reply entry based on the objects attributes .
*/
2013-07-08 07:40:48 +00:00
public function update (){
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2014-05-27 22:18:44 +00:00
$dbl -> update ( " ticket " , Array ( 'Ticket' => $this -> ticket , 'Content' => $this -> content , 'Author' => $this -> author , 'Timestamp' => $this -> timestamp , 'Hidden' => $this -> hidden ), " TReplyId= $this->tReplyId , " );
2013-07-08 07:40:48 +00:00
}
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-09-12 17:28:56 +00:00
/**
* get ticket attribute of the object .
*/
2013-07-08 07:40:48 +00:00
public function getTicket (){
return $this -> ticket ;
}
2013-09-12 17:28:56 +00:00
/**
* get content attribute of the object .
*/
2013-07-08 07:40:48 +00:00
public function getContent (){
return $this -> content ;
}
2013-09-12 17:28:56 +00:00
/**
* get author attribute of the object .
*/
2013-07-08 07:40:48 +00:00
public function getAuthor (){
return $this -> author ;
}
2013-09-12 17:28:56 +00:00
/**
* get timestamp attribute of the object .
* The output format is defined by the Helpers class function , outputTime () .
*/
2013-07-08 07:40:48 +00:00
public function getTimestamp (){
2013-07-19 14:30:58 +00:00
return Helpers :: outputTime ( $this -> timestamp );
2013-07-08 07:40:48 +00:00
}
2013-09-12 17:28:56 +00:00
/**
* get tReplyId attribute of the object .
*/
2013-07-08 07:40:48 +00:00
public function getTReplyId (){
return $this -> tReplyId ;
}
2013-07-19 13:59:39 +00:00
2013-09-12 17:28:56 +00:00
/**
* get hidden attribute of the object .
*/
2013-07-19 13:59:39 +00:00
public function getHidden (){
return $this -> hidden ;
}
2013-07-08 07:40:48 +00:00
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Setters////////////////////////////////////////////////////
2013-09-12 17:28:56 +00:00
/**
* set ticket attribute of the object .
* @ param $t integer id of the ticket
*/
2013-07-08 07:40:48 +00:00
public function setTicket ( $t ){
$this -> ticket = $t ;
}
2013-09-12 17:28:56 +00:00
/**
* set content attribute of the object .
* @ param $c integer id of the ticket_content entry
*/
2013-07-08 07:40:48 +00:00
public function setContent ( $c ){
$this -> content = $c ;
}
2013-09-12 17:28:56 +00:00
/**
* set author attribute of the object .
* @ param $a integer id of the user
*/
2013-07-08 07:40:48 +00:00
public function setAuthor ( $a ){
$this -> author = $a ;
}
2013-09-12 17:28:56 +00:00
/**
* set timestamp attribute of the object .
* @ param $t timestamp of the reply
*/
2013-07-08 07:40:48 +00:00
public function setTimestamp ( $t ){
$this -> timestamp = $t ;
}
2013-09-12 17:28:56 +00:00
/**
* set tReplyId attribute of the object .
* @ param $i integer id of the ticket_reply
*/
2013-07-08 07:40:48 +00:00
public function setTReplyId ( $i ){
$this -> tReplyId = $i ;
}
2013-07-19 13:59:39 +00:00
2013-09-12 17:28:56 +00:00
/**
* set hidden attribute of the object .
* @ param $h should be 0 or 1
*/
2013-07-19 13:59:39 +00:00
public function setHidden ( $h ){
$this -> hidden = $h ;
}
2014-05-27 22:18:44 +00:00
}