summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-06-03 17:42:27 -0400
committerMalf Furious <m@lfurio.us>2017-06-03 17:42:27 -0400
commit6b69e5a8f85ebdf92b84e3330bea306d4a90a115 (patch)
tree69754416b1e236b2cfddbcecf93f3a53d06efbd8
parent34d384c78f73bb059f38655fe62c17698183f6e6 (diff)
parentda90fc87384b1daa8104cdea14fb1b52f0f747b7 (diff)
downloadscrott-6b69e5a8f85ebdf92b84e3330bea306d4a90a115.tar.gz
scrott-6b69e5a8f85ebdf92b84e3330bea306d4a90a115.zip
Merge branch 'feature/issues' into dev
-rw-r--r--app/class/issue.class.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/app/class/issue.class.php b/app/class/issue.class.php
new file mode 100644
index 0000000..3127a87
--- /dev/null
+++ b/app/class/issue.class.php
@@ -0,0 +1,122 @@
+<?php
+
+/*
+ * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * For more information, please refer to UNLICENSE
+ */
+
+require_once "class/object.class.php";
+require_once "class/stage.class.php";
+require_once "class/user.class.php";
+require_once "class/mesg.class.php";
+
+/*
+ * This class models Scrott issues. Issues represent units of work, can
+ * be assigned to users, and advance through a pipeline.
+ */
+class issue extends object
+{
+ /*
+ * Constructor
+ */
+ public function __construct(?string $guid = NULL)
+ {
+ $this->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 ($stage->objtype != "stage")
+ return;
+
+ if (!($next = $stage->getNext()))
+ $this->close();
+ else
+ $this->setParent($next);
+ }
+
+ /*
+ * Mark this issue as completed and closed.
+ */
+ public function close() : void
+ {
+ $pad = $this->getParent()->getParent();
+
+ if ($pad)
+ $this->setParent($pad);
+ }
+}
+
+?>