Browse Source

Actually get ticket data from the database

develop
Sven Slootweg 9 years ago
parent
commit
724dec5a61
  1. 7
      public_html/classes/ticket.php
  2. 95
      public_html/classes/ticketmessage.php
  3. 4
      public_html/include/constants.php
  4. 17
      public_html/modules/error/404.php
  5. 62
      public_html/modules/project/tickets/view.php
  6. 3
      public_html/rewrite.php
  7. 57
      public_html/templates/project/tickets/view.tpl

7
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(

95
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";
}
}
}
}

4
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,

17
public_html/modules/error/404.php

@ -0,0 +1,17 @@
<?php
/*
* Cryto Team is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
http_status_code(404);
$sPageContents = NewTemplater::Render("error/404", $locale->strings, array());

62
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");
}

3
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 */

57
public_html/templates/project/tickets/view.tpl

@ -1,24 +1,24 @@
<div class="section ticket-original">
<h2>This is a sample ticket</h2>
<h2>{%?title}</h2>
<div class="metadata">
<div class="currentdata">
<div class="priority">
<span class="key">Priority</span>
<span class="value">High</span>
<span class="value">{%?priority}</span>
</div>
<div class="status">
<span class="key">Status</span>
<span class="value">Open</span>
<span class="value">{%?status}</span>
</div>
<div class="owner">
<span class="key">Owner</span>
<span class="value">joepie91</span>
<span class="value">{%?owner}</span>
</div>
</div>
<div class="originaldata">
<div class="creator">
<span class="key">Creator</span>
<span class="value">joepie91</span>
<span class="value">{%?creator}</span>
</div>
<div class="date">
<span class="key">Date</span>
@ -28,30 +28,31 @@
<div class="clear"></div>
</div>
<div class="body">
<p>This is a sample ticket body.</p>
{%?body}
</div>
</div>
<div class="section ticket-updates">
<div class="message">
<div class="metadata">
<span class="author">joepie91</span>
<span class="date">2013/01/17 11:10:16</span>
</div>
<p>This is a sample ticket response.</p>
</div>
<div class="event">
<span class="author">joepie91</span> changed the ticket status to <span class="value">Open</span>.
<div class="date">2013/01/17 11:16:23</div>
</div>
<div class="message">
<div class="metadata">
<span class="author">joepie91</span>
<span class="date">2013/01/17 11:19:06</span>
</div>
<p>This is another sample ticket response.</p>
</div>
{%foreach update in updates}
{%if update[event] == true}
<div class="event">
{%if update[component] == "owner"}
<span class="author">{%?update[user]}</span> changed the owner to <span class="value">{%?update[operation]}</span>.
{%elseif update[component] == "status"}
<span class="author">{%?update[user]}</span> changed the ticket status to <span class="value">{%?update[operation]}</span>.
{%elseif update[component] == "priority"}
<span class="author">{%?update[user]}</span> changed the priority to <span class="value">{%?update[operation]}</span>.
{%/if}
<div class="date">{%?update[date]}</div>
</div>
{%else}
<div class="message">
<div class="metadata">
<span class="author">{%?update[author]}</span>
<span class="date">{%?update[date]}</span>
</div>
<p>{%?update[body]}</p>
</div>
{%/if}
{%/foreach}
</div>
Loading…
Cancel
Save