Browse files

Beginnings of Ticket class

  • Loading branch information...
1 parent 9bb8ed8 commit 3bc304332b9cfb767fe06c4760c0c7792b3f3490 @danielbeardsley danielbeardsley committed Oct 23, 2011
Showing with 42 additions and 0 deletions.
  1. +42 −0 ticket.php
View
42 ticket.php
@@ -0,0 +1,42 @@
+<?php
+
+class Ticket {
+ public static $github;
+
+ private $id;
+ private $attr;
+
+ public static function loadFromTrac($id) {
+ $q_select = "SELECT * FROM `ticket` WHERE `id` = $id";
+ $result = Trac::execute($q_select);
+ return $result ? new self($result) : null;
+ }
+
+ public __construct($dbAttributes) {
+ $this->attr = $dbAttributes;
+ $this->id = $this->attr['id'];
+ }
+
+ public function toIssueJson() {
+ $json = array(
+ 'title' => $this->attr['summary'],
+ 'body' => $this->translateDescription(),
+ 'assignee' => GitUsers::fromTrac($this->attr['owner']) ?: $this->attr['owner'],
+ 'milestone' => GitMilestones::fromTrac($this->attr['milestone'])
+ );
+
+ return $json;
+ }
+
+ public function saveToGithub() {
+ self::github->add_issue($this->toIssueJson());
+ if ($this->$attr['status'] == 'closed') {
+ self::github->update_issue($this->id, array('state' => 'closed'));
+ }
+ }
+
+ private function translateDescription() {
+ // more on this later
+ return $this->attr['description'];
+ }
+}

0 comments on commit 3bc3043

Please sign in to comment.