コード例 #1
0
ファイル: IssueCreate.php プロジェクト: burbuja/indefero
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     // Add a tag for each label
     $tags = array();
     if ($this->show_full) {
         for ($i = 1; $i < 7; $i++) {
             if (strlen($this->cleaned_data['label' . $i]) > 0) {
                 if (strpos($this->cleaned_data['label' . $i], ':') !== false) {
                     list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2);
                     list($class, $name) = array(trim($class), trim($name));
                 } else {
                     $class = 'Other';
                     $name = trim($this->cleaned_data['label' . $i]);
                 }
                 $tags[] = IDF_Tag::add($name, $this->project, $class);
             }
         }
     } else {
         $tags[] = IDF_Tag::add('Medium', $this->project, 'Priority');
         $tags[] = IDF_Tag::add('Defect', $this->project, 'Type');
     }
     // Create the issue
     $issue = new IDF_Issue();
     $issue->project = $this->project;
     $issue->submitter = $this->user;
     if ($this->show_full) {
         $issue->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
         $issue->owner = self::findUser($this->cleaned_data['owner']);
     } else {
         $_t = $this->project->getTagIdsByStatus('open');
         $issue->status = new IDF_Tag($_t[0]);
         // first one is the default
         $issue->owner = null;
     }
     $issue->summary = trim($this->cleaned_data['summary']);
     $issue->create();
     foreach ($tags as $tag) {
         $issue->setAssoc($tag);
     }
     // add the first comment
     $comment = new IDF_IssueComment();
     $comment->issue = $issue;
     $comment->content = $this->cleaned_data['content'];
     $comment->submitter = $this->user;
     $comment->create();
     // If we have a file, create the IDF_IssueFile and attach
     // it to the comment.
     $created_files = array();
     for ($i = 1; $i < 4; $i++) {
         if ($this->cleaned_data['attachment' . $i]) {
             $file = new IDF_IssueFile();
             $file->attachment = $this->cleaned_data['attachment' . $i];
             $file->submitter = $this->user;
             $file->comment = $comment;
             $file->create();
             $created_files[] = $file;
         }
     }
     /**
      * [signal]
      *
      * IDF_Issue::create
      *
      * [sender]
      *
      * IDF_Form_IssueCreate
      *
      * [description]
      *
      * This signal allows an application to perform a set of tasks
      * just after the creation of an issue. The comment contains
      * the description of the issue.
      *
      * [parameters]
      *
      * array('issue' => $issue,
      *       'comment' => $comment,
      *       'files' => $attached_files);
      *
      */
     $params = array('issue' => $issue, 'comment' => $comment, 'files' => $created_files);
     Pluf_Signal::send('IDF_Issue::create', 'IDF_Form_IssueCreate', $params);
     return $issue;
 }
コード例 #2
0
ファイル: IssueUpdate.php プロジェクト: burbuja/indefero
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     if ($this->show_full) {
         // Add a tag for each label
         $tags = array();
         $tagids = array();
         for ($i = 1; $i < 7; $i++) {
             if (strlen($this->cleaned_data['label' . $i]) > 0) {
                 if (strpos($this->cleaned_data['label' . $i], ':') !== false) {
                     list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2);
                     list($class, $name) = array(trim($class), trim($name));
                 } else {
                     $class = 'Other';
                     $name = trim($this->cleaned_data['label' . $i]);
                 }
                 $tag = IDF_Tag::add($name, $this->project, $class);
                 $tags[] = $tag;
                 $tagids[] = $tag->id;
             }
         }
         // Compare between the old and the new data
         $changes = array();
         $oldtags = $this->issue->get_tags_list();
         foreach ($tags as $tag) {
             if (!Pluf_Model_InArray($tag, $oldtags)) {
                 if (!isset($changes['lb'])) {
                     $changes['lb'] = array();
                 }
                 if ($tag->class != 'Other') {
                     $changes['lb'][] = (string) $tag;
                     //new tag
                 } else {
                     $changes['lb'][] = (string) $tag->name;
                 }
             }
         }
         foreach ($oldtags as $tag) {
             if (!Pluf_Model_InArray($tag, $tags)) {
                 if (!isset($changes['lb'])) {
                     $changes['lb'] = array();
                 }
                 if ($tag->class != 'Other') {
                     $changes['lb'][] = '-' . (string) $tag;
                     //new tag
                 } else {
                     $changes['lb'][] = '-' . (string) $tag->name;
                 }
             }
         }
         // Status, summary and owner
         $status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status');
         if ($status->id != $this->issue->status) {
             $changes['st'] = $status->name;
         }
         if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) {
             $changes['su'] = trim($this->cleaned_data['summary']);
         }
         $owner = self::findUser($this->cleaned_data['owner']);
         if (is_null($owner) and !is_null($this->issue->get_owner()) or !is_null($owner) and is_null($this->issue->get_owner()) or !is_null($owner) and !is_null($this->issue->get_owner()) and $owner->id != $this->issue->get_owner()->id) {
             $changes['ow'] = is_null($owner) ? '---' : $owner->login;
         }
         // Update the issue
         $this->issue->batchAssoc('IDF_Tag', $tagids);
         $this->issue->summary = trim($this->cleaned_data['summary']);
         $this->issue->status = $status;
         $this->issue->owner = $owner;
     }
     // Create the comment
     $comment = new IDF_IssueComment();
     $comment->issue = $this->issue;
     $comment->content = $this->cleaned_data['content'];
     $comment->submitter = $this->user;
     if (!$this->show_full) {
         $changes = array();
     }
     $comment->changes = $changes;
     $comment->create();
     $this->issue->update();
     if ($this->issue->owner != $this->user->id and $this->issue->submitter != $this->user->id) {
         $this->issue->setAssoc($this->user);
         // interested user.
     }
     $attached_files = array();
     for ($i = 1; $i < 4; $i++) {
         if ($this->cleaned_data['attachment' . $i]) {
             $file = new IDF_IssueFile();
             $file->attachment = $this->cleaned_data['attachment' . $i];
             $file->submitter = $this->user;
             $file->comment = $comment;
             $file->create();
             $attached_files[] = $file;
         }
     }
     /**
      * [signal]
      *
      * IDF_Issue::update
      *
      * [sender]
      *
      * IDF_Form_IssueUpdate
      *
      * [description]
      *
      * This signal allows an application to perform a set of tasks
      * just after the update of an issue.
      *
      * [parameters]
      *
      * array('issue' => $issue,
      *       'comment' => $comment,
      *       'files' => $attached_files);
      *
      */
     $params = array('issue' => $this->issue, 'comment' => $comment, 'files' => $attached_files);
     Pluf_Signal::send('IDF_Issue::update', 'IDF_Form_IssueUpdate', $params);
     return $this->issue;
 }
コード例 #3
0
ファイル: TestIssue.php プロジェクト: burbuja/indefero
 public function testAddIssueComment()
 {
     $issue = new IDF_Issue();
     $issue->project = $this->projects[0];
     $issue->summary = 'This is a test issue';
     $issue->submitter = $this->users[0];
     $issue->create();
     $ic = new IDF_IssueComment();
     $ic->issue = $issue;
     $ic->submitter = $this->users[0];
     $ic->content = 'toto';
     $changes = array('s' => 'New summary', 'st' => 'Active', 't' => '-OS:Linux OS:Windows');
     $ic->changes = $changes;
     $ic->create();
     $comments = $issue->get_comments_list();
     $this->assertEqual($changes, $comments[0]->changes);
 }