diff options
| -rw-r--r-- | app/class/issue.class.php | 179 | 
1 files changed, 125 insertions, 54 deletions
| diff --git a/app/class/issue.class.php b/app/class/issue.class.php index 0fc12e4..47adfa1 100644 --- a/app/class/issue.class.php +++ b/app/class/issue.class.php @@ -18,8 +18,8 @@ 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. + * This class models Scrott issues.  Issues represent units of work, track + * messages, can be assigned to users, and advance through a pipeline.   */  class issue extends obj  { @@ -31,14 +31,8 @@ class issue extends obj          $this->fields['issues'] = array(              "guid",              "numb", -            "assignee", -            "author", +            "mesg",              "closer", -            "seen", -            "description", -            "opened", -            "assigned", -            "authored",              "closed",              "due",              "tags", @@ -49,10 +43,11 @@ class issue extends obj      }      /* -     * Initialize a new issue object with the given name, parent, and -     * owner. +     * Initialize a new issue object with the given message, parent, +     * and owner.  The issue's name is taken from the message's name. +     * The given message object is updated to parent the new issue.       */ -    public static function initNew(string $name, user $owner, stage $parent) : issue +    public static function initNew(mesg $mesg, user $owner, stage $parent) : issue      {          $pad = $parent->getParent();          $numb = $pad->issueNumb++; @@ -61,61 +56,146 @@ class issue extends obj          $issue = new issue();          $issue->setOwner($owner);          $issue->setParent($parent); -        $issue->name = $name; +        $issue->name = $mesg->name;          $issue->objtype = "issue";          $issue->numb = $numb; -        $issue->setAuthor($owner); -        $issue->saveObj(); // get timestamp -        $issue->opened = $issue->created; -        $issue->authored = $issue->created; +        $issue->mesg = $mesg->guid;          $issue->saveObj(); + +        $mesg->setParent($issue); +          return $issue;      }      /* -     * Get the assignee for this issue +     * Get all assignees.  Assignees are returned as an array of +     * stdClass instances.  Objects contain data from the 'assignees' +     * database table with no defined operations.  Pointers to users +     * will be followed and an instanciated user object will be +     * in their place.  Limit of zero returns all assignees.       */ -    public function getAssignee() : ?user +    public function getAssignees(int $limit = 0) : array      { -        if (!isset($this->assignee) || $this->assignee == "") -            return NULL; +        $assign = array(); +        $query = "SELECT * FROM assignees WHERE guid = '" . +            database::esc($this->guid) . "'"; + +        if ($limit != 0) +            $query .= " LIMIT " . database::esc($limit); + +        $res = database::query($query); + +        foreach ($res as $a) +        { +            $obj = new stdClass(); + +            foreach ($a as $k => $v) +                $obj->{$k} = $v; + +            $obj->assignee = new user($obj->assignee); +            $obj->assigner = new user($obj->assigner); + +            if (isset($obj->dismisser) && $obj->dismisser != "") +                $obj->dismisser = new user($obj->dismisser); -        return new user($this->assignee); +            $assign[] = $obj; +        } + +        return $assign;      }      /* -     * Reset the seen flag and reassign this issue. +     * Add an assignee to this issue.  Returns false if user is +     * already assigned, or if another error occurs; true +     * otherwise.       */ -    public function assignTo(user $assignee) : void +    public function addAssignee(user $assignee, user $assigner) : bool      { -        $this->seen = 0; -        $this->assignee = $assignee->guid; -        $this->assigned = self::getCurrentTimestamp(); -        $this->saveObj(); +        if ($assignee->isAssignedTo($this) || !isset($assignee->guid) +            || !isset($assigner->guid)) +            return false; + +        $query = "INSERT INTO assignees (guid, assignee, assigner, assigned)" . +            " VALUES ('" . database::esc($this->guid) . "', '" . +            database::esc($assignee->guid) . "', '" . database::esc($assigner->guid) . +            "', '" . database::esc(self::getCurrentTimestamp()) . "')"; + +        database::query($query); +        return true;      }      /* -     * Get the author of this issue.  This is usually the user -     * that opened the issue, but may differ if this issue was -     * elevated from a previous discussion thread. +     * Dismiss an assignee, effectively unassigning them.  Returns +     * false if user is not already an active assignee, or if another +     * error occurs; true otherwise.       */ -    public function getAuthor() : user +    public function dismissAssignee(user $assignee, user $dismisser) : bool      { -        if (!isset($this->author) || $this->author == "") -            return NULL; +        if (!$assignee->isAssignedTo($this) || !isset($assignee->guid) +            || !isset($dismisser->guid)) +            return false; + +        $query = "UPDATE assignees SET dismisser = '" . database::esc($dismisser->guid) . +            "', dismissed = '" . database::esc(self::getCurrentTimestamp()) . +            "' WHERE guid = '" . database::esc($this->guid) . "' AND assignee = '" . +            database::esc($assignee->guid) . "'"; + +        database::query($query); +        return true; +    } + +    /* +     * Signoff an assignee's portion of this issue.  Returns false +     * if user is not already an active assignee, or if another +     * error occurs; true otherwise. +     */ +    public function signoffAssignee(user $assignee) : bool +    { +        if (!$assignee->isAssignedTo($this) || !isset($assignee->guid)) +            return false; + +        $query = "UPDATE assignees SET signedoff = '" . +            database::esc(self::getCurrentTimestamp()) . "' WHERE guid = '" . +            database::esc($this->guid) . "' AND assignee = '" . +            database::esc($assignee->guid) . "'"; + +        database::query($query); +        return true; +    } -        return new user($this->author); +    /* +     * Get the OP message for this issue. +     */ +    public function getOPMesg() : mesg +    { +        return new mesg($this->mesg);      }      /* -     * Set the author of this issue.  This should usually only -     * be done while constructing a new message or to clear out -     * references to a user that got removed. +     * Get all messages on this issue.  The OP message is filtered +     * from results.  Messages are sorted by date created.       */ -    public function setAuthor(user $author) : void +    public function getMesgs_ordByDatetime() : array      { -        $this->author = $author->guid; -        $this->saveObj(); +        $mesgs = parent::getMesgs_ordByDatetime(); +        $i = -1; + +        foreach ($mesgs as $k => $m) +        { +            if ($m->guid == $this->mesg) +            { +                $i = $k; +                break; +            } +        } + +        if ($i != -1) +        { +            unset($mesgs[$i]); +            $mesgs = array_values($mesgs); +        } + +        return $mesgs;      }      /* @@ -131,15 +211,6 @@ class issue extends obj      }      /* -     * Mark the user that closed this issue. -     */ -    public function setCloser(user $closer) : void -    { -        $this->closer = $closer->guid; -        $this->saveObj(); -    } - -    /*       * Get the pad this issue exists under       */      public function getPad() : pad @@ -154,9 +225,9 @@ class issue extends obj      /*       * Advance this issue in the pipeline, closing it if already in the -     * last stage. +     * last stage.  A closer is needed incase a close takes place.       */ -    public function advance() : void +    public function advance(user $closer) : void      {          $stage = $this->getParent(); @@ -164,7 +235,7 @@ class issue extends obj              return;          if (!($next = $stage->getNext())) -            $this->close(); +            $this->close($closer);          else              $this->setParent($next);      } @@ -178,8 +249,8 @@ class issue extends obj          if ($pad)          { +            $this->closer = $closer->guid;              $this->closed = self::getCurrentTimestamp(); -            $this->setCloser($closer);              $this->setParent($pad);          }      } | 
