diff options
| author | Malf Furious <m@lfurio.us> | 2017-06-01 23:35:44 -0400 | 
|---|---|---|
| committer | Malf Furious <m@lfurio.us> | 2017-06-01 23:35:44 -0400 | 
| commit | 37db482851a7724520e5db7aef89dcd8490cc081 (patch) | |
| tree | 1f8d8ad6152c17d51fd0d2c175a477e796166ada | |
| parent | 34d384c78f73bb059f38655fe62c17698183f6e6 (diff) | |
| download | scrott-37db482851a7724520e5db7aef89dcd8490cc081.tar.gz scrott-37db482851a7724520e5db7aef89dcd8490cc081.zip | |
Add issue class
Diffstat (limited to '')
| -rw-r--r-- | app/class/issue.class.php | 117 | 
1 files changed, 117 insertions, 0 deletions
| 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 @@ +<?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 (!($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); +    } +} + +?> | 
