From 37db482851a7724520e5db7aef89dcd8490cc081 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 1 Jun 2017 23:35:44 -0400 Subject: Add issue class --- app/class/issue.class.php | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 app/class/issue.class.php diff --git a/app/class/issue.class.php b/app/class/issue.class.php new file mode 100644 index 0000000..e439dff --- /dev/null +++ b/app/class/issue.class.php @@ -0,0 +1,117 @@ +fields['issues'] = array( + "guid", + "numb", + "assignee", + "seen", + "description", + "due", + "tags", + ); + + parent::__construct($guid); + $this->expectType("issue"); + } + + /* + * Initialize a new issue object with the given name, parent, and + * owner. + */ + public static function initNew(string $name, user $owner, stage $parent) : issue + { + $pad = $parent->getParent(); + $numb = $pad->issueNumb++; + $pad->saveObj(); + + $issue = new issue(); + $issue->setOwner($owner); + $issue->setParent($parent); + $issue->name = $name; + $issue->objtype = "issue"; + $issue->numb = $numb; + $issue->saveObj(); + return $issue; + } + + /* + * Get all activity for this issue. Messages are sorted by date + * created. + */ + public function getMesgs_ordByDatetime() : array + { + $query = "SELECT guid FROM objects WHERE objtype = 'mesg' AND " . + "parent = '" . database::esc($this->guid) . "' ORDER BY created"; + $res = database::query($query); + + $mesgs = array(); + + foreach ($res as $m) + $mesgs[] = new mesg($m['guid']); + + return $mesgs; + } + + /* + * Reset the seen flag and reassign this issue. + */ + public function assignTo(user $assignee) : void + { + $this->seen = 0; + $this->assignee = $assignee->guid; + $this->saveObj(); + } + + /* + * Advance this issue in the pipeline, closing it if already in the + * last stage. + */ + public function advance() : void + { + $stage = $this->getParent(); + + if (!($next = $stage->getNext())) + $this->close(); + + $this->setParent($next); + } + + /* + * Mark this issue as completed and closed. + */ + public function close() : void + { + $pad = $this->getParent()->getParent(); + $this->setParent($pad); + } +} + +?> -- cgit v1.2.3