public function perform(\thebuggenie\core\entities\Issue $issue, $request = null)
 {
     switch ($this->_action_type) {
         case self::ACTION_ASSIGN_ISSUE_SELF:
             $issue->setAssignee(framework\Context::getUser());
             break;
         case self::ACTION_SET_STATUS:
             if ($this->getTargetValue()) {
                 $issue->setStatus(Status::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setStatus($request['status_id']);
             }
             break;
         case self::ACTION_CLEAR_MILESTONE:
             $issue->setMilestone(null);
             break;
         case self::ACTION_SET_MILESTONE:
             if ($this->getTargetValue()) {
                 $issue->setMilestone(Milestone::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setMilestone($request['milestone_id']);
             }
             break;
         case self::ACTION_CLEAR_PRIORITY:
             $issue->setPriority(null);
             break;
         case self::ACTION_SET_PRIORITY:
             if ($this->getTargetValue()) {
                 $issue->setPriority(Priority::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setPriority($request['priority_id']);
             }
             break;
         case self::ACTION_CLEAR_PERCENT:
             $issue->setPercentCompleted(0);
             break;
         case self::ACTION_SET_PERCENT:
             if ($this->getTargetValue()) {
                 $issue->setPercentCompleted((int) $this->getTargetValue());
             } else {
                 $issue->setPercentCompleted((int) $request['percent_complete_id']);
             }
             break;
         case self::ACTION_CLEAR_DUPLICATE:
             $issue->setDuplicateOf(null);
             break;
         case self::ACTION_SET_DUPLICATE:
             $issue->setDuplicateOf($request['duplicate_issue_id']);
             break;
         case self::ACTION_CLEAR_RESOLUTION:
             $issue->setResolution(null);
             break;
         case self::ACTION_SET_RESOLUTION:
             if ($this->getTargetValue()) {
                 $issue->setResolution(Resolution::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setResolution($request['resolution_id']);
             }
             break;
         case self::ACTION_CLEAR_REPRODUCABILITY:
             $issue->setReproducability(null);
             break;
         case self::ACTION_SET_REPRODUCABILITY:
             if ($this->getTargetValue()) {
                 $issue->setReproducability(Reproducability::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setReproducability($request['reproducability_id']);
             }
             break;
         case self::ACTION_CLEAR_ASSIGNEE:
             $issue->clearAssignee();
             break;
         case self::ACTION_ASSIGN_ISSUE:
             if ($this->getTargetValue()) {
                 $target_details = explode('_', $this->_target_value);
                 if ($target_details[0] == 'user') {
                     $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $target_details[1]);
                 } else {
                     $assignee = Team::getB2DBTable()->selectById((int) $target_details[1]);
                 }
                 $issue->setAssignee($assignee);
             } else {
                 $assignee = null;
                 switch ($request['assignee_type']) {
                     case 'user':
                         $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $request['assignee_id']);
                         break;
                     case 'team':
                         $assignee = Team::getB2DBTable()->selectById((int) $request['assignee_id']);
                         break;
                 }
                 if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof \thebuggenie\core\entities\User && $assignee->getID() != framework\Context::getUser()->getID()) {
                     $team = new \thebuggenie\core\entities\Team();
                     $team->setName($assignee->getBuddyname() . ' & ' . framework\Context::getUser()->getBuddyname());
                     $team->setOndemand(true);
                     $team->save();
                     $team->addMember($assignee);
                     $team->addMember(framework\Context::getUser());
                     $assignee = $team;
                 }
                 $issue->setAssignee($assignee);
             }
             break;
         case self::ACTION_USER_START_WORKING:
             $issue->clearUserWorkingOnIssue();
             if ($issue->getAssignee() instanceof \thebuggenie\core\entities\Team && $issue->getAssignee()->isOndemand()) {
                 $members = $issue->getAssignee()->getMembers();
                 $issue->startWorkingOnIssue(array_shift($members));
             } elseif ($issue->getAssignee() instanceof \thebuggenie\core\entities\User) {
                 $issue->startWorkingOnIssue($issue->getAssignee());
             }
             break;
         case self::ACTION_USER_STOP_WORKING:
             if ($request->getParameter('did', 'nothing') == 'nothing') {
                 $issue->clearUserWorkingOnIssue();
             } elseif ($request->getParameter('did', 'nothing') == 'this') {
                 $times = array();
                 if ($request['timespent_manual']) {
                     $times = Issue::convertFancyStringToTime($request['timespent_manual']);
                 } elseif ($request['timespent_specified_type']) {
                     $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0);
                     $times[$request['timespent_specified_type']] = $request['timespent_specified_value'];
                 }
                 if (array_sum($times) > 0) {
                     $times['hours'] *= 100;
                     $spenttime = new \thebuggenie\core\entities\IssueSpentTime();
                     $spenttime->setIssue($issue);
                     $spenttime->setUser(framework\Context::getUser());
                     $spenttime->setSpentPoints($times['points']);
                     $spenttime->setSpentHours($times['hours']);
                     $spenttime->setSpentDays($times['days']);
                     $spenttime->setSpentWeeks($times['weeks']);
                     $spenttime->setSpentMonths($times['months']);
                     $spenttime->setActivityType($request['timespent_activitytype']);
                     $spenttime->setComment($request['timespent_comment']);
                     $spenttime->save();
                 }
                 $issue->clearUserWorkingOnIssue();
             } else {
                 $issue->stopWorkingOnIssue();
             }
             break;
         default:
             if (strpos($this->_action_type, self::CUSTOMFIELD_CLEAR_PREFIX) === 0) {
                 $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_CLEAR_PREFIX));
                 $issue->setCustomField($customkey, null);
             } elseif (strpos($this->_action_type, self::CUSTOMFIELD_SET_PREFIX) === 0) {
                 $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_SET_PREFIX));
                 if ($this->getTargetValue()) {
                     $issue->setCustomField($customkey, $this->getTargetValue());
                 } else {
                     $issue->setCustomField($customkey, $request[$customkey . '_id']);
                 }
             } else {
                 $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionAction::perform', $issue, array('request' => $request));
                 $event->triggerUntilProcessed();
             }
     }
 }
Exemple #2
0
 static function resultGrouping(entities\Issue $issue, $groupby, $cc, $prevgroup_id)
 {
     $i18n = framework\Context::getI18n();
     $showtablestart = false;
     $showheader = false;
     $groupby_id = 0;
     $groupby_description = '';
     if ($cc == 1) {
         $showtablestart = true;
     }
     if ($groupby != '') {
         switch ($groupby) {
             case 'category':
                 if ($issue->getCategory() instanceof entities\Category) {
                     $groupby_id = $issue->getCategory()->getID();
                     $groupby_description = $issue->getCategory()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'status':
                 if ($issue->getStatus() instanceof entities\Status) {
                     $groupby_id = $issue->getStatus()->getID();
                     $groupby_description = $issue->getStatus()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'severity':
                 if ($issue->getSeverity() instanceof entities\Severity) {
                     $groupby_id = $issue->getSeverity()->getID();
                     $groupby_description = $issue->getSeverity()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'resolution':
                 if ($issue->getResolution() instanceof entities\Resolution) {
                     $groupby_id = $issue->getResolution()->getID();
                     $groupby_description = $issue->getResolution()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'edition':
                 if ($issue->getEditions()) {
                     $groupby_id = $issue->getFirstAffectedEdition()->getID();
                     $groupby_description = $issue->getFirstAffectedEdition()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('None');
                 }
                 break;
             case 'build':
                 if ($issue->getBuilds()) {
                     $groupby_id = $issue->getFirstAffectedBuild()->getID();
                     $groupby_description = $issue->getFirstAffectedBuild()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('None');
                 }
                 break;
             case 'component':
                 if ($issue->getComponents()) {
                     $groupby_id = $issue->getFirstAffectedComponent()->getID();
                     $groupby_description = $issue->getFirstAffectedComponent()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('None');
                 }
                 break;
             case 'priority':
                 if ($issue->getPriority() instanceof entities\Priority) {
                     $groupby_id = $issue->getPriority()->getID();
                     $groupby_description = $issue->getPriority()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'issuetype':
                 if ($issue->getIssueType() instanceof entities\Issuetype) {
                     $groupby_id = $issue->getIssueType()->getID();
                     $groupby_description = $issue->getIssueType()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Unknown');
                 }
                 break;
             case 'milestone':
                 if ($issue->getMilestone() instanceof entities\Milestone) {
                     $groupby_id = $issue->getMilestone()->getID();
                     $groupby_description = $issue->getMilestone()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Not targetted');
                 }
                 break;
             case 'assignee':
                 if ($issue->getAssignee() instanceof entities\common\Identifiable) {
                     $groupby_id = $issue->getAssignee()->getID();
                     $groupby_description = $issue->getAssignee()->getName();
                 } else {
                     $groupby_id = 0;
                     $groupby_description = $i18n->__('Not assigned');
                 }
                 break;
             case 'state':
                 if ($issue->isClosed()) {
                     $groupby_id = entities\Issue::STATE_CLOSED;
                     $groupby_description = $i18n->__('Closed');
                 } else {
                     $groupby_id = entities\Issue::STATE_OPEN;
                     $groupby_description = $i18n->__('Open');
                 }
                 break;
         }
         if ($groupby_id !== $prevgroup_id) {
             $showtablestart = true;
             $showheader = true;
         }
         $prevgroup_id = $groupby_id;
     }
     return array($showtablestart, $showheader, $prevgroup_id, $groupby_description);
 }