/** * 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!) */ public static function getRepliesOfTicket($ticket_id, $view_as_admin) { $dbl = new DBLayer("lib"); $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)); $row = $statement->fetchAll(); $result = array(); foreach ($row as $tReply) { //only add hidden replies if the user is a mod/admin if (!$tReply['Hidden'] || $view_as_admin) { //load author $instanceAuthor = Ticket_User::constr_TUserId($tReply['Author']); $instanceAuthor->setExternId($tReply['ExternId']); $instanceAuthor->setPermission($tReply['Permission']); //load content $instanceContent = new Ticket_Content(); $instanceContent->setTContentId($tReply['TContentId']); $instanceContent->setContent($tReply['Content']); //load reply and add the author and content object in it. $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; } } return $result; }