From 724dec5a61ea41bd9d1a965bae7225f83cd5ef8e Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 17 Jan 2013 14:43:51 +0100 Subject: [PATCH] Actually get ticket data from the database --- public_html/classes/ticket.php | 7 +- public_html/classes/ticketmessage.php | 95 ++++++++++++++++++- public_html/include/constants.php | 4 + public_html/modules/error/404.php | 17 ++++ public_html/modules/project/tickets/view.php | 62 +++++++++++- public_html/rewrite.php | 3 +- .../templates/project/tickets/view.tpl | 57 +++++------ 7 files changed, 211 insertions(+), 34 deletions(-) create mode 100644 public_html/modules/error/404.php diff --git a/public_html/classes/ticket.php b/public_html/classes/ticket.php index 400c7dd..8746bb6 100644 --- a/public_html/classes/ticket.php +++ b/public_html/classes/ticket.php @@ -25,13 +25,16 @@ class Ticket extends CPHPDatabaseRecordClass ), 'numeric' => array( 'Status' => "Status", - 'CreatorId' => "UserId", + 'CreatorId' => "CreatorId", 'OwnerId' => "OwnerId", 'Priority' => "Priority", 'ProjectId' => "ProjectId" ), + "timestamp" => array( + 'CreationDate' => "CreationDate" + ), 'user' => array( - 'Creator' => "UserId", + 'Creator' => "CreatorId", 'Owner' => "OwnerId" ), 'project' => array( diff --git a/public_html/classes/ticketmessage.php b/public_html/classes/ticketmessage.php index e6fd0a1..b3bb55c 100644 --- a/public_html/classes/ticketmessage.php +++ b/public_html/classes/ticketmessage.php @@ -20,7 +20,7 @@ class TicketMessage extends CPHPDatabaseRecordClass public $verify_query = "SELECT * FROM ticket_messages WHERE `Id` = :Id"; public $prototype = array( - 'string' => array( + 'simplehtml' => array( 'Body' => "Body" ), 'boolean' => array( @@ -34,6 +34,9 @@ class TicketMessage extends CPHPDatabaseRecordClass 'timestamp' => array( 'Date' => "Date" ), + 'boolean' => array( + 'IsEvent' => "Event" + ), 'user' => array( 'Author' => "UserId" ), @@ -44,4 +47,94 @@ class TicketMessage extends CPHPDatabaseRecordClass 'Project' => "ProjectId" ) ); + + public function __get($name) + { + switch($name) + { + case "sComponent": + return $this->GetComponentName(); + break; + case "sOperation": + return $this->GetOperationName(); + break; + default: + return parent::__get($name); + break; + } + } + + private function UnpackEvent() + { + if(empty($this->uEventData)) + { + $this->uEventData = json_decode($this->uBody); + } + } + + public function GetComponentName() + { + $this->UnpackEvent(); + + switch($this->uEventData->component) + { + case STATUS: + return "status"; + case PRIORITY: + return "priority"; + case OWNER: + return "owner"; + default: + return "unknown"; + } + } + + public function GetOperationName() + { + $this->UnpackEvent(); + + if($this->uEventData->component == OWNER) + { + $sEventUser = new User($this->uEventData->operation); + return $sEventUser->sDisplayName; + } + elseif($this->uEventData->component == PRIORITY) + { + switch($this->uEventData->operation) + { + case PRIORITY_LOWEST: + return "Lowest"; + case PRIORITY_LOW: + return "Low"; + case PRIORITY_NORMAL: + return "Normal"; + case PRIORITY_HIGH: + return "High"; + case PRIORITY_CRITICAL: + return "Critical"; + default: + return "Unknown"; + } + } + elseif($this->uEventData->component == STATUS) + { + switch($this->uEventData->operation) + { + case NEWTICKET: + return "New"; + case OPEN: + return "Open"; + case CLOSED: + return "Closed"; + case INVALID: + return "Invalid"; + case NEEDS_REVIEW: + return "Needs Review"; + case IN_PROGRESS: + return "In Progress"; + default: + return "Unknown"; + } + } + } } diff --git a/public_html/include/constants.php b/public_html/include/constants.php index bebc7f7..1b6a2c3 100644 --- a/public_html/include/constants.php +++ b/public_html/include/constants.php @@ -27,6 +27,10 @@ $constants = array( "NEEDS_REVIEW" => 5, "IN_PROGRESS" => 6, + "STATUS" => 1, + "PRIORITY" => 2, + "OWNER" => 3, + "ATTACHMENT_FILE" => 1, "ATTACHMENT_COMMIT" => 2, "ATTACHMENT_TICKET" => 3, diff --git a/public_html/modules/error/404.php b/public_html/modules/error/404.php new file mode 100644 index 0000000..6e71823 --- /dev/null +++ b/public_html/modules/error/404.php @@ -0,0 +1,17 @@ +strings, array()); diff --git a/public_html/modules/project/tickets/view.php b/public_html/modules/project/tickets/view.php index 3cee471..7827e45 100644 --- a/public_html/modules/project/tickets/view.php +++ b/public_html/modules/project/tickets/view.php @@ -14,4 +14,64 @@ if(!isset($_APP)) { die("Unauthorized."); } $sCurrentPage = "tickets"; -$sPageContents = NewTemplater::Render("project/tickets/view", $locale->strings, array()); + +try +{ + $sTicket = new Ticket($router->uParameters[2]); + + $sInitialMessage = TicketMessage::CreateFromQuery("SELECT * FROM ticket_messages WHERE `TicketId` = :TicketId AND `FirstMessage` = 1", + array(":TicketId" => $sTicket->sId), 0, true); + + $sUpdates = array(); + + try + { + $result = TicketMessage::CreateFromQuery("SELECT * FROM ticket_messages WHERE `TicketId` = :TicketId AND `FirstMessage` = 0 ORDER BY `Date` ASC", + array(":TicketId" => $sTicket->sId), 0); + } + catch (NotFoundException $e) + { + $result = array(); + } + + foreach($result as $sMessage) + { + if($sMessage->sIsEvent) + { + $uEventData = json_decode($sMessage->uBody); + + $sUpdates[] = array( + "event" => true, + "user" => $sMessage->sAuthor->sDisplayName, + "component" => $sMessage->sComponent, + "operation" => $sMessage->sOperation, + "date" => local_from_unix($sMessage->sDate, $locale->datetime_short) + ); + } + else + { + $sUpdates[] = array( + "event" => false, + "author" => $sMessage->sAuthor->sDisplayName, + "body" => $sMessage->sBody, + "date" => local_from_unix($sMessage->sDate, $locale->datetime_short) + ); + } + } + + $sPageContents = NewTemplater::Render("project/tickets/view", $locale->strings, array( + "title" => $sTicket->sSubject, + "priority" => $sTicket->sPriorityName, + "status" => $sTicket->sStatusName, + "owner" => $sTicket->sOwner->sDisplayName, + "creator" => $sTicket->sCreator->sDisplayName, + "date" => local_from_unix($sTicket->sCreationDate, $locale->datetime_short), + "body" => $sInitialMessage->sBody, + "updates" => $sUpdates + )); +} +catch (NotFoundException $e) +{ + pretty_dump($e); + require("modules/error/404.php"); +} diff --git a/public_html/rewrite.php b/public_html/rewrite.php index c50517c..9c12a1c 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -67,8 +67,7 @@ try } catch (RouterException $e) { - http_status_code(404); - $sPageContents = NewTemplater::Render("error/404", $locale->strings, array()); + require("modules/error/404.php"); } /* Render the resulting page */ diff --git a/public_html/templates/project/tickets/view.tpl b/public_html/templates/project/tickets/view.tpl index b867fa1..7024fce 100644 --- a/public_html/templates/project/tickets/view.tpl +++ b/public_html/templates/project/tickets/view.tpl @@ -1,24 +1,24 @@
-

This is a sample ticket

+

{%?title}