From 5340dce8ad70a8cfc62116144f668f22845a2f31 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 5 Apr 2017 22:31:50 -0400 Subject: Add stage class --- app/class/stage.class.php | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 app/class/stage.class.php diff --git a/app/class/stage.class.php b/app/class/stage.class.php new file mode 100644 index 0000000..31f6a94 --- /dev/null +++ b/app/class/stage.class.php @@ -0,0 +1,137 @@ +fields['stages'] = array( + "guid", + "stage", + ); + + parent::__construct($guid); + $this->expectType("stage"); + } + + /* + * Initialize a new stage object with the given name and parent + * pad. + */ + public static function initNew(string $name, pad $parent) : stage + { + $stage = new stage(); + $stage->setParent($parent); + $stage->name = $name; + $stage->objtype = "stage"; + return $stage; + } + + /* + * Get the stage following this one in the pipeline. NULL is + * returned if no stage is next. + */ + public function getNext() : ?stage + { + if (!isset($this->stage) || $this->stage == "") + return NULL; + + return new stage($this->stage); + } + + /* + * Get the stage preceding this one in the pipeline. NULL is + * returned if no stage is previous. + */ + public function getPrev() : ?stage + { + $pad = new pad($this->getParent()); + + if ($pad->stage == $this->guid) + return NULL; + + $query = "SELECT guid FROM stages WHERE stage = '" . database::esc($this->guid) . "'"; + $res = database::query($query); + + if (count($res) == 0) + return NULL; + + return new stage($res[0]['guid']); + } + + /* + * Get an array of all stages reachable from this one. The array + * is in proper order and includes the current stage. + */ + public function getArray() : array + { + $stages = array(); + $curr = $this; + + do $stages[] = $curr; + while (($curr = $curr->getNext())); + + return $stages; + } + + /* + * Reorder the stages of a pipeline by moving this one forward. + * This swaps the places of the current stage and the one following + * it. If this stage is the last in its pipeline, nothing is done + * and false is returned. + */ + public function moveForward() : bool + { + if (!($next = $this->getNext())) + return false; + + if (!($prev = $this->getPrev())) + $prev = new pad($this->getParent()); + + $tmp = $next->stage; + $prev->stage = $next->guid; + $next->stage = $this->guid; + $this->stage = $tmp; + + $next->saveObj(); + $prev->saveObj(); + return true; + } + + /* + * Reorder the stages of a pipeline by moving this one backward. + * This swaps the places of the current stage and the one preceding + * it. If this stage is the first in its pipeline, nothing is done + * and false is returned. + */ + public function moveBackward() : bool + { + if (!($prev = $this->getPrev())) + return false; + + return $prev->moveForward(); + } +} + +?> -- cgit v1.2.3 From 291b5a784e34099ece1839bf0bb3e8091c411576 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Fri, 7 Apr 2017 23:51:17 -0400 Subject: Update use of object getParent() function This function has been updated to construct and return the proper object type. This commit addresses the uses of this function so far to account for this. --- app/class/stage.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 31f6a94..150ac5d 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -66,7 +66,7 @@ class stage extends object */ public function getPrev() : ?stage { - $pad = new pad($this->getParent()); + $pad = $this->getParent(); if ($pad->stage == $this->guid) return NULL; @@ -107,7 +107,7 @@ class stage extends object return false; if (!($prev = $this->getPrev())) - $prev = new pad($this->getParent()); + $prev = $this->getParent(); $tmp = $next->stage; $prev->stage = $next->guid; -- cgit v1.2.3 From db7ad4f8943625e5c79fc09dae94a865f655493d Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 8 Apr 2017 02:36:07 -0400 Subject: Fix bug in stage moveForward() function Since this function is used by moveBackward(), failing to call $this->saveObj() would result in changes made to $this being lost. $this is now written back to the db every time and calling saveObj() manually when using moveBackward() can result in bad data being written to the db. --- app/class/stage.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 150ac5d..2616bee 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -116,6 +116,7 @@ class stage extends object $next->saveObj(); $prev->saveObj(); + $this->saveObj(); return true; } -- cgit v1.2.3 From dd3aeb526b497ccde45e7ba018e963f2e249387a Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 8 Apr 2017 23:00:56 -0400 Subject: Add stage function insertStage() --- app/class/stage.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 2616bee..1d21dcb 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -133,6 +133,17 @@ class stage extends object return $prev->moveForward(); } + + /* + * Insert a stage object in this pipeline, following $this object + */ + public function insertStage(stage $stage) : void + { + $stage->stage = $this->stage; + $this->stage = $stage->guid; + $stage->saveObj(); + $this->saveObj(); + } } ?> -- cgit v1.2.3 From 06e36d6b4009df47b0912c0f5b438171d153558f Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 04:31:43 -0400 Subject: Add stage function getIssues_ordByDueByNumb() --- app/class/stage.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 1d21dcb..08a3708 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -95,6 +95,25 @@ class stage extends object return $stages; } + /* + * Get all issues in this stage, sorted by due date, then by + * issue number. + */ + public function getIssues_ordByDueByNumb() : array + { + $query = "SELECT o.guid FROM objects o JOIN issues i ON o.guid = i.guid " . + "WHERE o.objtype = 'issue' AND o.parent = '" . database::esc($this->guid) . + "' ORDER BY i.due, i.numb"; + $res = database::query($query); + + $issues = array(); + + foreach ($res as $i) + $issues[] = new issue($i['guid']); + + return $issues; + } + /* * Reorder the stages of a pipeline by moving this one forward. * This swaps the places of the current stage and the one following -- cgit v1.2.3 From 4cd8b4e9cac6ff104141cfb9154d11353cf9aab5 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 04:44:09 -0400 Subject: Add stage function removeStage() --- app/class/stage.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 08a3708..1142bdd 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -163,6 +163,25 @@ class stage extends object $stage->saveObj(); $this->saveObj(); } + + /* + * Remove this stage object and move all of its issues. Issues are + * moved to the given stage object. Additionally, the pad may be + * given, in which case, those issues will be closed. + */ + public function removeStage(object $mvt) : void + { + if (!($prev = $this->getPrev())) + $prev = $this->getParent(); + + foreach ($this->getIssues_ordByDueByNumb() as $i) + $i->setParent($mvt); + + $prev->stage = $this->stage; + $prev->saveObj(); + + $this->delObj(); + } } ?> -- cgit v1.2.3 From d23eeb18e1604210dd55570c595fd184d8038f58 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 14:41:39 -0400 Subject: Add missing require --- app/class/stage.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 1142bdd..1825546 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -14,6 +14,7 @@ require_once "class/object.class.php"; require_once "class/pad.class.php"; +require_once "class/issue.class.php"; /* * This class models Scrott pad stages. Stages form a pipeline through -- cgit v1.2.3 From 478504986a348bb53765e137a6ea8293929954aa Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 15:01:54 -0400 Subject: Add pad function insertStage() --- app/class/pad.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/class/pad.class.php b/app/class/pad.class.php index 7c53f30..d062b0c 100644 --- a/app/class/pad.class.php +++ b/app/class/pad.class.php @@ -14,6 +14,7 @@ require_once "class/object.class.php"; require_once "class/agent.class.php"; +require_once "class/stage.class.php"; /* * This class models Scrott pads. Pads are the space for projects to track @@ -82,6 +83,17 @@ class pad extends object $pad->issueNumb = 0; return $pad; } + + /* + * Insert a stage object at the front of this pad's pipeline + */ + public function insertStage(stage $stage) : void + { + $stage->stage = $this->stage; + $this->stage = $stage->guid; + $stage->saveObj(); + $this->saveObj(); + } } ?> -- cgit v1.2.3 From 8a1a277c3cf747cbb82c9dcb660a925963f635a5 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 17:48:27 -0400 Subject: Add pad function getStages() --- app/class/pad.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/class/pad.class.php b/app/class/pad.class.php index d062b0c..a5c771b 100644 --- a/app/class/pad.class.php +++ b/app/class/pad.class.php @@ -84,6 +84,16 @@ class pad extends object return $pad; } + /* + * Get an array of all stages under this pad. The array is in + * proper sequential order. + */ + public function getStages() : array + { + $stage = new stage($this->stage); + return $stage->getArray(); + } + /* * Insert a stage object at the front of this pad's pipeline */ -- cgit v1.2.3