2013-07-08 07:40:48 +00:00
< ? php
class Ticket_Reply {
private $tReplyId ;
private $ticket ;
private $content ;
private $author ;
private $timestamp ;
2013-07-19 13:59:39 +00:00
private $hidden ;
2013-07-08 07:40:48 +00:00
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId
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-07-10 00:41:03 +00:00
//return constructed element based on TCategoryId
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-07-19 13:59:39 +00:00
if ( ! $tReply [ 'Hidden' ] || $view_as_admin ){
$instanceAuthor = Ticket_User :: constr_TUserId ( $tReply [ 'Author' ]);
$instanceAuthor -> setExternId ( $tReply [ 'ExternId' ]);
$instanceAuthor -> setPermission ( $tReply [ 'Permission' ]);
$instanceContent = new Ticket_Content ();
$instanceContent -> setTContentId ( $tReply [ 'TContentId' ]);
$instanceContent -> setContent ( $tReply [ 'Content' ]);
$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-07-19 13:59:39 +00:00
public static function createReply ( $content , $author , $ticket_id , $hidden ){
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 ();
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-07-08 07:40:48 +00:00
2013-07-10 10:36:14 +00:00
public function __construct () {
2013-07-08 07:40:48 +00:00
}
//Set ticket_reply object
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
}
//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-19 13:59:39 +00:00
$query = " INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp, Hidden) VALUES (:ticket, :content, :author, now(), :hidden) " ;
$values = Array ( 'ticket' => $this -> ticket , 'content' => $this -> content , 'author' => $this -> author , 'hidden' => $this -> hidden );
2013-07-12 17:43:33 +00:00
$this -> tReplyId = $dbl -> executeReturnId ( $query , $values );
2013-07-08 07:40:48 +00:00
}
//return constructed element based on TId
public function load_With_TReplyId ( $id ) {
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-08 07:40:48 +00:00
$statement = $dbl -> execute ( " SELECT * FROM ticket_reply WHERE TReplyId=:id " , array ( 'id' => $id ));
$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
}
//update private data to DB.
public function update (){
2013-07-10 10:36:14 +00:00
$dbl = new DBLayer ( " lib " );
2013-07-19 13:59:39 +00:00
$query = " UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp, Hidden = :hidden WHERE TReplyId=:id " ;
$values = Array ( 'id' => $this -> tReplyId , 'timestamp' => $this -> timestamp , 'ticket' => $this -> ticket , 'content' => $this -> content , 'author' => $this -> author , 'hidden' => $this -> hidden );
2013-07-08 07:40:48 +00:00
$statement = $dbl -> execute ( $query , $values );
}
2013-07-08 12:49:03 +00:00
////////////////////////////////////////////Getters////////////////////////////////////////////////////
2013-07-08 07:40:48 +00:00
public function getTicket (){
return $this -> ticket ;
}
public function getContent (){
return $this -> content ;
}
public function getAuthor (){
return $this -> author ;
}
public function getTimestamp (){
2013-07-19 14:30:58 +00:00
return Helpers :: outputTime ( $this -> timestamp );
2013-07-08 07:40:48 +00:00
}
public function getTReplyId (){
return $this -> tReplyId ;
}
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-07-08 07:40:48 +00:00
public function setTicket ( $t ){
$this -> ticket = $t ;
}
public function setContent ( $c ){
$this -> content = $c ;
}
public function setAuthor ( $a ){
$this -> author = $a ;
}
public function setTimestamp ( $t ){
$this -> timestamp = $t ;
}
public function setTReplyId ( $i ){
$this -> tReplyId = $i ;
}
2013-07-19 13:59:39 +00:00
public function setHidden ( $h ){
$this -> hidden = $h ;
}
2013-07-08 07:40:48 +00:00
}