Skip to content

Commit

Permalink
Beginnings of Ticket class
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbeardsley committed Oct 23, 2011
1 parent 9bb8ed8 commit 3bc3043
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ticket.php
Original file line number Original file line Diff line number Diff line change
@@ -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.