protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addBoolean(self::CONFIRMED);
     parent::_addForeignKeyColumn(self::BUILD, Builds::getTable(), Builds::ID);
     parent::_addForeignKeyColumn(self::ISSUE, Issues::getTable(), Issues::ID);
     parent::_addForeignKeyColumn(self::STATUS, ListTypes::getTable(), ListTypes::ID);
 }
 public function getByIssueIDs($issue_ids)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::ISSUE, $issue_ids, Criteria::DB_IN);
     $crit->addJoin(Issues::getTable(), Issues::ID, self::ISSUE, array(), Criteria::DB_INNER_JOIN);
     $crit->addJoin(Builds::getTable(), Builds::ID, self::BUILD, array(), Criteria::DB_INNER_JOIN);
     $res = $this->doSelect($crit, false);
     return $res;
 }
示例#3
0
 /**
  * Assign a user story to a release
  *
  * @Route(url="/assign/issue/release/:release_id")
  *
  * @param framework\Request $request
  */
 public function runAssignRelease(framework\Request $request)
 {
     try {
         $issue = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById((int) $request['issue_id']);
         $release = \thebuggenie\core\entities\tables\Builds::getTable()->selectById((int) $request['release_id']);
         $issue->addAffectedBuild($release);
         return $this->renderJSON(array('issue_id' => $issue->getID(), 'release_id' => $release->getID(), 'closed_pct' => $release->getPercentComplete()));
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => framework\Context::getI18n()->__('An error occured when trying to assign the issue to the release')));
     }
 }
示例#4
0
 /**
  * Populates builds inside the project
  *
  * @return void
  */
 protected function _populateBuilds()
 {
     if ($this->_builds === null) {
         $this->_builds = array();
         foreach (tables\Builds::getTable()->getByProjectID($this->getID()) as $build) {
             if ($build->hasAccess()) {
                 $this->_builds[$build->getID()] = $build;
             }
         }
     }
 }
示例#5
0
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null, $sortfields = array(self::LAST_UPDATED => 'asc'))
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::DELETED, false);
     $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
     if (count($filters) > 0) {
         $crit->addJoin(IssueCustomFields::getTable(), IssueCustomFields::ISSUE_ID, Issues::ID);
         $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
         $filter_keys = array_keys($filters);
         foreach ($filters as $filter) {
             self::parseFilter($crit, $filter, $filter_keys);
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         $crit3 = $this->getCriteria();
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? Criteria::SORT_ASC : Criteria::SORT_DESC : Criteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit->addSelectionColumn(ListTypes::NAME);
                     $crit->addOrderBy(ListTypes::NAME, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit3->addOrderBy(ListTypes::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit3->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     $crit3->addOrderBy(self::MILESTONE, $grouporder);
                     $crit3->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNEE_TEAM);
                     $crit->addSelectionColumn(self::ASSIGNEE_USER);
                     $crit->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     $crit3->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit3->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     $crit3->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'severity':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     $crit3->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     $crit3->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'priority':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(IssueTypes::NAME);
                     $crit->addOrderBy(IssueTypes::NAME, $grouporder);
                     $crit3->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit3->addOrderBy(IssueTypes::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit->addSelectionColumn(Editions::NAME);
                     $crit->addOrderBy(Editions::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit3->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit3->addOrderBy(Editions::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit->addSelectionColumn(Builds::NAME);
                     $crit->addOrderBy(Builds::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit3->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit3->addOrderBy(Builds::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit->addSelectionColumn(Components::NAME);
                     $crit->addOrderBy(Components::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit3->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit3->addOrderBy(Components::NAME, $grouporder);
                     break;
             }
         }
         foreach ($sortfields as $field => $sortorder) {
             $crit->addSelectionColumn($field);
             $crit->addOrderBy($field, $sortorder);
         }
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $ids[] = $row->get(self::ID);
             }
             $ids = array_reverse($ids);
             $crit3->addWhere(self::ID, $ids, Criteria::DB_IN);
             foreach ($sortfields as $field => $sortorder) {
                 $crit3->addOrderBy($field, $sortorder);
             }
             $res = $this->doSelect($crit3);
             $rows = $res->getAllRows();
         } else {
             $rows = array();
         }
         unset($res);
         return array($rows, $count, $ids);
     } else {
         return array(null, 0, array());
     }
 }
     echo '<div id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;display: inline;">';
     echo $action->getTargetValue() ? include_component('main/userdropdown', array('user' => $action->getTargetValue())) : __('Value provided by user');
     echo '</div>';
     break;
 case \thebuggenie\core\entities\CustomDatatype::TEAM_CHOICE:
     echo __('Set issue field %key to ', array('%key' => $action->getCustomActionType()));
     echo '<div id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;display: inline;">';
     echo $action->getTargetValue() ? include_component('main/teamdropdown', array('team' => $action->getTargetValue())) : __('Value provided by user');
     echo '</div>';
     break;
 case \thebuggenie\core\entities\CustomDatatype::CLIENT_CHOICE:
     $target = $action->getTargetValue() ? \thebuggenie\core\entities\tables\Clients::getTable()->selectById((int) $action->getTargetValue()) : null;
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? $target->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::RELEASES_CHOICE:
     $target = $action->getTargetValue() ? \thebuggenie\core\entities\tables\Builds::getTable()->selectById((int) $action->getTargetValue()) : null;
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::COMPONENTS_CHOICE:
     $target = $action->getTargetValue() ? \thebuggenie\core\entities\tables\Components::getTable()->selectById((int) $action->getTargetValue()) : null;
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::EDITIONS_CHOICE:
     $target = $action->getTargetValue() ? \thebuggenie\core\entities\tables\Editions::getTable()->selectById((int) $action->getTargetValue()) : null;
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::MILESTONE_CHOICE:
     $target = $action->getTargetValue() ? \thebuggenie\core\entities\tables\Milestones::getTable()->selectById((int) $action->getTargetValue()) : null;
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::STATUS_CHOICE:
示例#7
0
 protected function _populateOptions()
 {
     if ($this->_options === null) {
         if ($this->hasCustomOptions()) {
             $this->_b2dbLazyload('_options');
         } else {
             switch ($this->getType()) {
                 case self::RELEASES_CHOICE:
                     $this->_options = framework\Context::isProjectContext() ? framework\Context::getCurrentProject()->getBuilds() : \thebuggenie\core\entities\tables\Builds::getTable()->selectAll();
                     break;
                 case self::COMPONENTS_CHOICE:
                     $this->_options = framework\Context::isProjectContext() ? framework\Context::getCurrentProject()->getComponents() : \thebuggenie\core\entities\tables\Components::getTable()->selectAll();
                     break;
                 case self::EDITIONS_CHOICE:
                     $this->_options = framework\Context::isProjectContext() ? framework\Context::getCurrentProject()->getEditions() : \thebuggenie\core\entities\tables\Editions::getTable()->selectAll();
                     break;
                 case self::MILESTONE_CHOICE:
                     $this->_options = framework\Context::isProjectContext() ? framework\Context::getCurrentProject()->getMilestonesForIssues() : \thebuggenie\core\entities\tables\Milestones::getTable()->selectAll();
                     break;
                 case self::STATUS_CHOICE:
                     $this->_options = \thebuggenie\core\entities\Status::getAll();
                     break;
             }
         }
     }
 }
 public function getRuleValueAsJoinedString()
 {
     $is_core = in_array($this->_name, array(self::RULE_STATUS_VALID, self::RULE_RESOLUTION_VALID, self::RULE_REPRODUCABILITY_VALID, self::RULE_PRIORITY_VALID, self::RULE_TEAM_MEMBERSHIP_VALID, self::RULE_ISSUE_IN_MILESTONE_VALID));
     $is_custom = $this->isCustom();
     $customtype = $this->getCustomType();
     if ($this->_name == self::RULE_STATUS_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Status';
     } elseif ($this->_name == self::RULE_RESOLUTION_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Resolution';
     } elseif ($this->_name == self::RULE_REPRODUCABILITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Reproducability';
     } elseif ($this->_name == self::RULE_PRIORITY_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Priority';
     } elseif ($this->_name == self::RULE_TEAM_MEMBERSHIP_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Team';
     } elseif ($this->_name == self::RULE_ISSUE_IN_MILESTONE_VALID) {
         $fieldname = '\\thebuggenie\\core\\entities\\Milestone';
     }
     if ($is_core || $is_custom) {
         $values = explode(',', $this->getRuleValue());
         if ($is_custom) {
             $custom_field_key = substr($this->_name, strlen(self::CUSTOMFIELD_VALIDATE_PREFIX) - 1);
             $custom_field = tables\CustomFields::getTable()->getByKey($custom_field_key);
         }
         $return_values = array();
         foreach ($values as $value) {
             try {
                 if ($is_core) {
                     $field = $fieldname::getB2DBTable()->selectByID((int) $value);
                 } elseif ($is_custom) {
                     switch ($customtype) {
                         case CustomDatatype::RADIO_CHOICE:
                         case CustomDatatype::DROPDOWN_CHOICE_TEXT:
                             $field = tables\CustomFieldOptions::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::TEAM_CHOICE:
                             $field = Teams::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::STATUS_CHOICE:
                             $field = ListTypes::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::MILESTONE_CHOICE:
                             $field = Milestones::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::CLIENT_CHOICE:
                             $field = Clients::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::COMPONENTS_CHOICE:
                             $field = Components::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::EDITIONS_CHOICE:
                             $field = Editions::getTable()->selectById((int) $value);
                             break;
                         case CustomDatatype::RELEASES_CHOICE:
                             $field = Builds::getTable()->selectById((int) $value);
                             break;
                     }
                 }
                 if ($field instanceof \thebuggenie\core\entities\common\Identifiable) {
                     if ($field instanceof Milestone || $field instanceof Component || $field instanceof Edition || $field instanceof Build) {
                         $return_values[] = $field->getProject()->getName() . ' - ' . $field->getName();
                     } elseif ($field instanceof Status) {
                         $return_values[] = '<span class="status_badge" style="background-color: ' . $field->getColor() . '; color: ' . $field->getTextColor() . ';">' . $field->getName() . '</span>';
                     } else {
                         $return_values[] = $field->getName();
                     }
                 }
             } catch (\Exception $e) {
             }
         }
         return join(' / ', $return_values);
     } else {
         $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionValidationRule::getRuleValueAsJoinedString', $this);
         $event->triggerUntilProcessed();
         return $event->getReturnValue();
     }
 }
示例#9
0
 public function runConfigureWorkflowTransition(framework\Request $request)
 {
     $this->workflow = null;
     $this->transition = null;
     try {
         $this->workflow = tables\Workflows::getTable()->selectById((int) $request['workflow_id']);
         if ($request->hasParameter('transition_id')) {
             $mode = $request['mode'];
             $this->transition = tables\WorkflowTransitions::getTable()->selectById((int) $request['transition_id']);
             if ($request->isPost()) {
                 if ($mode == 'edit') {
                     if (!$this->transition->isInitialTransition()) {
                         $this->transition->setName($request['transition_name']);
                         $this->transition->setDescription($request['transition_description']);
                         if ($request['template']) {
                             $this->transition->setTemplate($request['template']);
                         } else {
                             $this->transition->setTemplate(null);
                         }
                     }
                     try {
                         $step = tables\WorkflowSteps::getTable()->selectById((int) $request['outgoing_step_id']);
                         $this->transition->setOutgoingStep($step);
                     } catch (\Exception $e) {
                     }
                     $this->transition->save();
                     $transition = $this->transition;
                     $redirect_transition = true;
                 } elseif ($mode == 'delete') {
                     $this->transition->deleteTransition($request['direction'], $request['step_id']);
                     $this->forward(framework\Context::getRouting()->generate('configure_workflow_step', array('workflow_id' => $this->workflow->getID(), 'step_id' => $request['step_id'])));
                 } elseif ($mode == 'delete_action') {
                     $this->action = tables\WorkflowTransitionActions::getTable()->selectById((int) $request['action_id']);
                     $this->action->delete();
                     return $this->renderJSON(array('message' => $this->getI18n()->__('The action has been deleted')));
                 } elseif ($mode == 'new_action') {
                     $action = new entities\WorkflowTransitionAction();
                     $action->setActionType($request['action_type']);
                     $action->setTransition($this->transition);
                     $action->setWorkflow($this->workflow);
                     $action->setTargetValue('');
                     $action->save();
                     return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/workflowtransitionaction', array('action' => $action))));
                 } elseif ($mode == 'update_action') {
                     $this->action = tables\WorkflowTransitionActions::getTable()->selectById((int) $request['action_id']);
                     $this->action->setTargetValue($request['target_value']);
                     $this->action->save();
                     $text = $request['target_value'];
                     switch ($this->action->getActionType()) {
                         case entities\WorkflowTransitionAction::ACTION_ASSIGN_ISSUE:
                             if ($this->action->hasTargetValue()) {
                                 $target_details = explode('_', $this->action->getTargetValue());
                                 $text = $target_details[0] == 'user' ? entities\User::getB2DBTable()->selectById((int) $target_details[1])->getNameWithUsername() : entities\Team::getB2DBTable()->selectById((int) $target_details[1])->getName();
                             } else {
                                 $text = $this->getI18n()->__('User specified during transition');
                             }
                             break;
                         case entities\WorkflowTransitionAction::ACTION_SET_RESOLUTION:
                             $text = $this->action->getTargetValue() ? tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Resolution specified by user');
                             break;
                         case entities\WorkflowTransitionAction::ACTION_SET_REPRODUCABILITY:
                             $text = $this->action->getTargetValue() ? tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Reproducability specified by user');
                             break;
                         case entities\WorkflowTransitionAction::ACTION_SET_STATUS:
                             $target = $this->action->getTargetValue() ? tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                             $text = $this->action->getTargetValue() ? '<span class="status_badge" style="background-color: ' . $target->getColor() . '; color: ' . $target->getTextColor() . ';">' . $target->getName() . '</span>' : $this->getI18n()->__('Status provided by user');
                             break;
                         case entities\WorkflowTransitionAction::ACTION_SET_PRIORITY:
                             $text = $this->action->getTargetValue() ? tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Priority specified by user');
                             break;
                         case entities\WorkflowTransitionAction::ACTION_SET_MILESTONE:
                             $target = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                             $text = $this->action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : $this->getI18n()->__('Milestone specified by user');
                             break;
                         case entities\WorkflowTransitionAction::CUSTOMFIELD_SET_PREFIX . $this->action->getCustomActionType():
                             switch (\thebuggenie\core\entities\CustomDatatype::getByKey($this->action->getCustomActionType())->getType()) {
                                 case \thebuggenie\core\entities\CustomDatatype::INPUT_TEXTAREA_MAIN:
                                 case \thebuggenie\core\entities\CustomDatatype::INPUT_TEXTAREA_SMALL:
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::DATE_PICKER:
                                     return $this->renderJSON(array('content' => date('Y-m-d', (int) $text)));
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::USER_CHOICE:
                                     return $this->renderJSON(array('content' => $this->getComponentHTML('main/userdropdown', array('user' => $text))));
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::TEAM_CHOICE:
                                     return $this->renderJSON(array('content' => $this->getComponentHTML('main/teamdropdown', array('team' => $text))));
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::CLIENT_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $text = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\Clients::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::RELEASES_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $target = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\Builds::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                                         $text = $this->action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::COMPONENTS_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $target = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\Components::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                                         $text = $this->action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::EDITIONS_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $target = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\Editions::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                                         $text = $this->action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::MILESTONE_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $target = $this->action->getTargetValue() ? \thebuggenie\core\entities\tables\Milestones::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                                         $text = $this->action->getTargetValue() ? $target->getProject()->getName() . ' - ' . $target->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::STATUS_CHOICE:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $target = $this->action->getTargetValue() ? tables\ListTypes::getTable()->selectById((int) $this->action->getTargetValue()) : null;
                                         $text = $this->action->getTargetValue() ? '<span class="status_badge" style="background-color: ' . $target->getColor() . '; color: ' . $target->getTextColor() . ';">' . $target->getName() . '</span>' : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                                 case \thebuggenie\core\entities\CustomDatatype::DROPDOWN_CHOICE_TEXT:
                                 default:
                                     if (is_numeric($this->action->getTargetValue())) {
                                         $text = $this->action->getTargetValue() ? tables\CustomFieldOptions::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Value provided by user');
                                     }
                                     break;
                             }
                             break;
                     }
                     return $this->renderJSON(array('content' => $text));
                 } elseif ($mode == 'delete_validation_rule') {
                     $this->rule = tables\WorkflowTransitionValidationRules::getTable()->selectById((int) $request['rule_id']);
                     $this->rule->delete();
                     return $this->renderJSON(array('message' => $this->getI18n()->__('The validation rule has been deleted')));
                 } elseif ($mode == 'new_validation_rule') {
                     if (!in_array($request['postorpre'], array('post', 'pre'))) {
                         throw new \InvalidArgumentException($this->getI18n()->__('Invalid transition definition'));
                     }
                     $rule = new entities\WorkflowTransitionValidationRule();
                     if ($request['postorpre'] == 'post') {
                         $exists = (bool) $this->transition->hasPostValidationRule($request['rule']);
                         if (!$exists) {
                             $rule->setPost();
                         }
                     } elseif ($request['postorpre'] == 'pre') {
                         $exists = (bool) $this->transition->hasPreValidationRule($request['rule']);
                         if (!$exists) {
                             $rule->setPre();
                         }
                     }
                     if ($exists) {
                         $this->getResponse()->setHttpStatus(400);
                         return $this->renderJSON(array('message' => $this->getI18n()->__('This validation rule already exist')));
                     }
                     $rule->setRule($request['rule']);
                     $rule->setRuleValue('');
                     $rule->setTransition($this->transition);
                     $rule->setWorkflow($this->workflow);
                     $rule->save();
                     return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/workflowtransitionvalidationrule', array('rule' => $rule))));
                 } elseif ($mode == 'update_validation_rule') {
                     $rule = tables\WorkflowTransitionValidationRules::getTable()->selectById((int) $request['rule_id']);
                     $text = null;
                     if ($rule->isCustom()) {
                         switch ($rule->getCustomType()) {
                             case entities\CustomDatatype::RADIO_CHOICE:
                             case entities\CustomDatatype::DROPDOWN_CHOICE_TEXT:
                             case entities\CustomDatatype::TEAM_CHOICE:
                             case entities\CustomDatatype::STATUS_CHOICE:
                             case entities\CustomDatatype::MILESTONE_CHOICE:
                             case entities\CustomDatatype::CLIENT_CHOICE:
                             case entities\CustomDatatype::COMPONENTS_CHOICE:
                             case entities\CustomDatatype::EDITIONS_CHOICE:
                             case entities\CustomDatatype::RELEASES_CHOICE:
                                 $rule->setRuleValue(join(',', $request['rule_value'] ?: array()));
                                 $text = $rule->getRuleValue() ? $rule->getRuleValueAsJoinedString() : $this->getI18n()->__('Any valid value');
                                 break;
                         }
                     } else {
                         switch ($rule->getRule()) {
                             case entities\WorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES:
                                 $rule->setRuleValue($request['rule_value']);
                                 $text = $rule->getRuleValue() ? $rule->getRuleValue() : $this->getI18n()->__('Unlimited');
                                 break;
                             case entities\WorkflowTransitionValidationRule::RULE_PRIORITY_VALID:
                             case entities\WorkflowTransitionValidationRule::RULE_REPRODUCABILITY_VALID:
                             case entities\WorkflowTransitionValidationRule::RULE_RESOLUTION_VALID:
                             case entities\WorkflowTransitionValidationRule::RULE_STATUS_VALID:
                             case entities\WorkflowTransitionValidationRule::RULE_TEAM_MEMBERSHIP_VALID:
                             case entities\WorkflowTransitionValidationRule::RULE_ISSUE_IN_MILESTONE_VALID:
                                 $rule->setRuleValue(join(',', $request['rule_value'] ?: array()));
                                 $text = $rule->getRuleValue() ? $rule->getRuleValueAsJoinedString() : $this->getI18n()->__('Any valid value');
                                 break;
                         }
                     }
                     $rule->save();
                     $this->rule = $rule;
                     return $this->renderJSON(array('content' => $text));
                 }
             }
         } elseif ($request->isPost() && $request->hasParameter('step_id')) {
             $step = tables\WorkflowSteps::getTable()->selectById((int) $request['step_id']);
             if ($request['add_transition_type'] == 'existing' && $request->hasParameter('existing_transition_id')) {
                 $transition = tables\WorkflowTransitions::getTable()->selectById((int) $request['existing_transition_id']);
                 $redirect_transition = false;
             } else {
                 if ($request['transition_name'] && $request['outgoing_step_id'] && $request->hasParameter('template')) {
                     if (($outgoing_step = tables\WorkflowSteps::getTable()->selectById((int) $request['outgoing_step_id'])) && $step instanceof entities\WorkflowStep) {
                         if (!$request['template'] || array_key_exists($request['template'], entities\WorkflowTransition::getTemplates())) {
                             $transition = new entities\WorkflowTransition();
                             $transition->setWorkflow($this->workflow);
                             $transition->setName($request['transition_name']);
                             $transition->setDescription($request['transition_description']);
                             $transition->setOutgoingStep($outgoing_step);
                             $transition->setTemplate($request['template']);
                             $transition->save();
                             $step->addOutgoingTransition($transition);
                             $redirect_transition = true;
                         } else {
                             throw new \InvalidArgumentException($this->getI18n()->__('Please select a valid template'));
                         }
                     } else {
                         throw new \InvalidArgumentException($this->getI18n()->__('Please select a valid outgoing step'));
                     }
                 } else {
                     throw new \InvalidArgumentException($this->getI18n()->__('Please fill in all required fields'));
                 }
             }
             $step->addOutgoingTransition($transition);
         } else {
             throw new \InvalidArgumentException('Invalid action');
         }
     } catch (\InvalidArgumentException $e) {
         $this->error = $e->getMessage();
     } catch (\Exception $e) {
         $this->error = $this->getI18n()->__('This workflow / transition does not exist');
     }
     if (isset($redirect_transition) && $redirect_transition) {
         $this->forward(framework\Context::getRouting()->generate('configure_workflow_transition', array('workflow_id' => $this->workflow->getID(), 'transition_id' => $transition->getID())));
     } elseif (isset($redirect_transition)) {
         $this->forward(framework\Context::getRouting()->generate('configure_workflow_steps', array('workflow_id' => $this->workflow->getID())));
     }
 }
示例#10
0
 /**
  * Return the value of a custom field
  *
  * @param string $key
  *
  * @return mixed
  */
 public function getCustomField($key)
 {
     $var_name = "_customfield{$key}";
     if (property_exists($this, $var_name)) {
         $customtype = CustomDatatype::getByKey($key);
         if ($customtype->getType() == CustomDatatype::CALCULATED_FIELD) {
             $result = null;
             $options = $customtype->getOptions();
             if (!empty($options)) {
                 $formula = array_pop($options)->getValue();
                 preg_match_all('/{([[:alnum:]]+)}/', $formula, $matches);
                 $hasValues = false;
                 for ($i = 0; $i < count($matches[0]); $i++) {
                     $value = $this->getCustomField($matches[1][$i]);
                     if ($value instanceof \thebuggenie\core\entities\CustomDatatypeOption) {
                         $value = $value->getValue();
                     }
                     if (is_numeric($value)) {
                         $hasValues = true;
                     }
                     $value = floatval($value);
                     $formula = str_replace($matches[0][$i], $value, $formula);
                 }
                 // Check to verify formula only includes numbers and allowed operators
                 if ($hasValues && !preg_match('/[^0-9\\+-\\/*\\(\\)%]/', $formula)) {
                     try {
                         $m = new \Webit\Util\EvalMath\EvalMath();
                         $m->suppress_errors = true;
                         $result = $m->evaluate($formula);
                         if (!empty($m->last_error)) {
                             $result = $m->last_error;
                         } else {
                             $result = round($result, 2);
                         }
                     } catch (\Exception $e) {
                         $result = 'N/A';
                     }
                 }
             }
             return $result;
         } elseif ($this->{$var_name} && $customtype->hasCustomOptions() && !$this->{$var_name} instanceof \thebuggenie\core\entities\CustomDatatypeOption) {
             $this->{$var_name} = tables\CustomFieldOptions::getTable()->selectById($this->{$var_name});
         } elseif ($this->{$var_name} && $customtype->hasPredefinedOptions() && !$this->{$var_name} instanceof \thebuggenie\core\entities\common\Identifiable) {
             try {
                 switch ($customtype->getType()) {
                     case CustomDatatype::EDITIONS_CHOICE:
                         $this->{$var_name} = tables\Editions::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::COMPONENTS_CHOICE:
                         $this->{$var_name} = tables\Components::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::RELEASES_CHOICE:
                         $this->{$var_name} = tables\Builds::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::MILESTONE_CHOICE:
                         $this->{$var_name} = tables\Milestones::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::CLIENT_CHOICE:
                         $this->{$var_name} = tables\Clients::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::USER_CHOICE:
                         $this->{$var_name} = tables\Users::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::TEAM_CHOICE:
                         $this->{$var_name} = tables\Teams::getTable()->selectById($this->{$var_name});
                         break;
                     case CustomDatatype::STATUS_CHOICE:
                         $this->{$var_name} = Status::getB2DBTable()->selectById($this->{$var_name});
                         break;
                 }
             } catch (\Exception $e) {
             }
         }
         return $this->{$var_name};
     } else {
         return null;
     }
 }
示例#11
0
 /**
  * Sets an issue field to a specified value
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runIssueSetField(framework\Request $request)
 {
     if ($issue_id = $request['issue_id']) {
         try {
             $issue = entities\Issue::getB2DBTable()->selectById($issue_id);
         } catch (\Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderText('fail');
         }
     } else {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderText('no issue');
     }
     framework\Context::loadLibrary('common');
     if (!$issue instanceof entities\Issue) {
         return false;
     }
     switch ($request['field']) {
         case 'description':
             if (!$issue->canEditDescription()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             $issue->setDescription($request->getRawParameter('value'));
             $issue->setDescriptionSyntax($request->getParameter('value_syntax'));
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isDescriptionChanged(), 'field' => array('id' => (int) ($issue->getDescription() != ''), 'name' => $issue->getParsedDescription(array('issue' => $issue))), 'description' => $issue->getParsedDescription(array('issue' => $issue))));
         case 'shortname':
             if (!$issue->canEditShortname()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             $issue->setShortname($request->getRawParameter('shortname_value'));
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isShortnameChanged(), 'field' => array('id' => (int) ($issue->getShortname() != ''), 'name' => $issue->getShortname()), 'shortname' => $issue->getShortname()));
         case 'reproduction_steps':
             if (!$issue->canEditReproductionSteps()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             $issue->setReproductionSteps($request->getRawParameter('value'));
             $issue->setReproductionStepsSyntax($request->getParameter('value_syntax'));
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isReproductionStepsChanged(), 'field' => array('id' => (int) ($issue->getReproductionSteps() != ''), 'name' => $issue->getParsedReproductionSteps(array('issue' => $issue))), 'reproduction_steps' => $issue->getParsedReproductionSteps(array('issue' => $issue))));
         case 'title':
             if (!$issue->canEditTitle()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             if ($request['value'] == '') {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You have to provide a title')));
             }
             $issue->setTitle($request->getRawParameter('value'));
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isTitleChanged(), 'field' => array('id' => 1, 'name' => strip_tags($issue->getTitle()))));
         case 'percent_complete':
             if (!$issue->canEditPercentage()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             $issue->setPercentCompleted($request['percent']);
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'field' => 'percent_complete', 'changed' => $issue->isPercentCompletedChanged(), 'percent' => $issue->getPercentCompleted()));
         case 'estimated_time':
             if (!$issue->canEditEstimatedTime()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             if (!$issue->isUpdateable()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('This issue cannot be updated')));
             }
             if ($request['estimated_time']) {
                 $issue->setEstimatedTime($request['estimated_time']);
             } elseif ($request->hasParameter('value')) {
                 $issue->setEstimatedTime($request['value']);
             } else {
                 if ($request->hasParameter('months')) {
                     $issue->setEstimatedMonths($request['months']);
                 }
                 if ($request->hasParameter('weeks')) {
                     $issue->setEstimatedWeeks($request['weeks']);
                 }
                 if ($request->hasParameter('days')) {
                     $issue->setEstimatedDays($request['days']);
                 }
                 if ($request->hasParameter('hours')) {
                     $issue->setEstimatedHours($request['hours']);
                 }
                 if ($request->hasParameter('minutes')) {
                     $issue->setEstimatedMinutes($request['minutes']);
                 }
                 if ($request->hasParameter('points')) {
                     $issue->setEstimatedPoints($request['points']);
                 }
             }
             if ($request['do_save']) {
                 $issue->save();
             }
             return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isEstimatedTimeChanged(), 'field' => $issue->hasEstimatedTime() ? array('id' => 1, 'name' => entities\Issue::getFormattedTime($issue->getEstimatedTime(true, true))) : array('id' => 0), 'values' => $issue->getEstimatedTime(true, true), 'percentbar' => $this->getComponentHTML('main/percentbar', array('percent' => $issue->getEstimatedPercentCompleted(), 'height' => 3))));
         case 'posted_by':
         case 'owned_by':
         case 'assigned_to':
             if ($request['field'] == 'posted_by' && !$issue->canEditPostedBy()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             } elseif ($request['field'] == 'owned_by' && !$issue->canEditOwner()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             } elseif ($request['field'] == 'assigned_to' && !$issue->canEditAssignee()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             if ($request->hasParameter('value')) {
                 if ($request->hasParameter('identifiable_type')) {
                     if (in_array($request['identifiable_type'], array('team', 'user')) && $request['value'] != 0) {
                         switch ($request['identifiable_type']) {
                             case 'user':
                                 $identified = entities\User::getB2DBTable()->selectById($request['value']);
                                 break;
                             case 'team':
                                 $identified = entities\Team::getB2DBTable()->selectById($request['value']);
                                 break;
                         }
                         if ($identified instanceof entities\User || $identified instanceof entities\Team) {
                             if ($identified instanceof entities\User && (bool) $request->getParameter('teamup', false)) {
                                 $team = new entities\Team();
                                 $team->setName($identified->getBuddyname() . ' & ' . $this->getUser()->getBuddyname());
                                 $team->setOndemand(true);
                                 $team->save();
                                 $team->addMember($identified);
                                 $team->addMember($this->getUser());
                                 $identified = $team;
                             }
                             if ($request['field'] == 'owned_by') {
                                 $issue->setOwner($identified);
                             } elseif ($request['field'] == 'assigned_to') {
                                 $issue->setAssignee($identified);
                             }
                         }
                     } else {
                         if ($request['field'] == 'owned_by') {
                             $issue->clearOwner();
                         } elseif ($request['field'] == 'assigned_to') {
                             $issue->clearAssignee();
                         }
                     }
                 } elseif ($request['field'] == 'posted_by') {
                     $identified = entities\User::getB2DBTable()->selectById($request['value']);
                     if ($identified instanceof entities\User) {
                         $issue->setPostedBy($identified);
                     }
                 }
                 if ($request['field'] == 'posted_by') {
                     return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isPostedByChanged(), 'field' => array('id' => $issue->getPostedByID(), 'name' => $this->getComponentHTML('main/userdropdown', array('user' => $issue->getPostedBy())))));
                 }
                 if ($request['field'] == 'owned_by') {
                     return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isOwnerChanged(), 'field' => $issue->isOwned() ? array('id' => $issue->getOwner()->getID(), 'name' => $issue->getOwner() instanceof entities\User ? $this->getComponentHTML('main/userdropdown', array('user' => $issue->getOwner())) : $this->getComponentHTML('main/teamdropdown', array('team' => $issue->getOwner()))) : array('id' => 0)));
                 }
                 if ($request['field'] == 'assigned_to') {
                     return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isAssigneeChanged(), 'field' => $issue->isAssigned() ? array('id' => $issue->getAssignee()->getID(), 'name' => $issue->getAssignee() instanceof entities\User ? $this->getComponentHTML('main/userdropdown', array('user' => $issue->getAssignee())) : $this->getComponentHTML('main/teamdropdown', array('team' => $issue->getAssignee()))) : array('id' => 0)));
                 }
             }
             break;
         case 'category':
         case 'resolution':
         case 'severity':
         case 'reproducability':
         case 'priority':
         case 'milestone':
         case 'issuetype':
         case 'status':
         case 'pain_bug_type':
         case 'pain_likelihood':
         case 'pain_effect':
             if ($request['field'] == 'category' && !$issue->canEditCategory() || $request['field'] == 'resolution' && !$issue->canEditResolution() || $request['field'] == 'severity' && !$issue->canEditSeverity() || $request['field'] == 'reproducability' && !$issue->canEditReproducability() || $request['field'] == 'priority' && !$issue->canEditPriority() || $request['field'] == 'milestone' && !$issue->canEditMilestone() || $request['field'] == 'issuetype' && !$issue->canEditIssuetype() || $request['field'] == 'status' && !$issue->canEditStatus() || in_array($request['field'], array('pain_bug_type', 'pain_likelihood', 'pain_effect')) && !$issue->canEditUserPain()) {
                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => framework\Context::getI18n()->__('You do not have permission to perform this action')));
             }
             try {
                 $classname = null;
                 $parameter_name = mb_strtolower($request['field']);
                 $parameter_id_name = "{$parameter_name}_id";
                 $is_pain = in_array($parameter_name, array('pain_bug_type', 'pain_likelihood', 'pain_effect'));
                 if ($is_pain) {
                     switch ($parameter_name) {
                         case 'pain_bug_type':
                             $set_function_name = 'setPainBugType';
                             $is_changed_function_name = 'isPainBugTypeChanged';
                             $get_pain_type_label_function = 'getPainBugTypeLabel';
                             break;
                         case 'pain_likelihood':
                             $set_function_name = 'setPainLikelihood';
                             $is_changed_function_name = 'isPainLikelihoodChanged';
                             $get_pain_type_label_function = 'getPainLikelihoodLabel';
                             break;
                         case 'pain_effect':
                             $set_function_name = 'setPainEffect';
                             $is_changed_function_name = 'isPainEffectChanged';
                             $get_pain_type_label_function = 'getPainEffectLabel';
                             break;
                     }
                 } else {
                     $classname = "\\thebuggenie\\core\\entities\\" . ucfirst($parameter_name);
                     $lab_function_name = $classname;
                     $set_function_name = 'set' . ucfirst($parameter_name);
                     $is_changed_function_name = 'is' . ucfirst($parameter_name) . 'Changed';
                 }
                 if ($request->hasParameter($parameter_id_name)) {
                     $parameter_id = $request->getParameter($parameter_id_name);
                     if ($parameter_id !== 0) {
                         $is_valid = $is_pain ? in_array($parameter_id, array_keys(entities\Issue::getPainTypesOrLabel($parameter_name))) : $parameter_id == 0 || ($parameter = $lab_function_name::getB2DBTable()->selectByID($parameter_id)) instanceof $classname;
                     }
                     if ($parameter_id == 0 || $parameter_id !== 0 && $is_valid) {
                         if ($classname == '\\thebuggenie\\core\\entities\\Issuetype') {
                             $visible_fields = $issue->getIssuetype() instanceof entities\Issuetype ? $issue->getProject()->getVisibleFieldsArray($issue->getIssuetype()->getID()) : array();
                         } else {
                             $visible_fields = null;
                         }
                         $issue->{$set_function_name}($parameter_id);
                         if ($is_pain) {
                             if (!$issue->{$is_changed_function_name}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'field' => array('id' => 0), 'user_pain' => $issue->getUserPain(), 'user_pain_diff_text' => $issue->getUserPainDiffText()));
                             }
                             return $parameter_id == 0 ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0), 'user_pain' => $issue->getUserPain(), 'user_pain_diff_text' => $issue->getUserPainDiffText())) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => $parameter_id, 'name' => $issue->{$get_pain_type_label_function}()), 'user_pain' => $issue->getUserPain(), 'user_pain_diff_text' => $issue->getUserPainDiffText()));
                         } else {
                             if (isset($parameter)) {
                                 $name = $parameter->getName();
                             } else {
                                 $name = null;
                             }
                             $field = array('id' => $parameter_id, 'name' => $name);
                             if ($classname == '\\thebuggenie\\core\\entities\\Issuetype') {
                                 framework\Context::loadLibrary('ui');
                                 $field['src'] = htmlspecialchars(framework\Context::getWebroot() . 'images/' . $issue->getIssuetype()->getIcon() . '_small.png');
                             }
                             if (!$issue->{$is_changed_function_name}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'field' => $field));
                             }
                             if ($parameter_id == 0) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0)));
                             } else {
                                 $options = array('issue_id' => $issue->getID(), 'changed' => true, 'visible_fields' => $visible_fields, 'field' => $field);
                                 if ($request['field'] == 'milestone') {
                                     $options['field']['url'] = $this->getRouting()->generate('project_milestone_details', array('project_key' => $issue->getProject()->getKey(), 'milestone_id' => $issue->getMilestone()->getID()));
                                 }
                                 if ($request['field'] == 'status') {
                                     $options['field']['color'] = $issue->getStatus()->getItemdata();
                                 }
                                 return $this->renderJSON($options);
                             }
                         }
                     }
                 }
             } catch (\Exception $e) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => $e->getMessage()));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('No valid field value specified')));
         default:
             if ($customdatatype = entities\CustomDatatype::getByKey($request['field'])) {
                 $key = $customdatatype->getKey();
                 $customdatatypeoption_value = $request->getParameter("{$key}_value");
                 if (!$customdatatype->hasCustomOptions()) {
                     switch ($customdatatype->getType()) {
                         case entities\CustomDatatype::EDITIONS_CHOICE:
                         case entities\CustomDatatype::COMPONENTS_CHOICE:
                         case entities\CustomDatatype::RELEASES_CHOICE:
                         case entities\CustomDatatype::STATUS_CHOICE:
                         case entities\CustomDatatype::MILESTONE_CHOICE:
                         case entities\CustomDatatype::USER_CHOICE:
                         case entities\CustomDatatype::TEAM_CHOICE:
                         case entities\CustomDatatype::CLIENT_CHOICE:
                             if ($customdatatypeoption_value == '') {
                                 $issue->setCustomField($key, "");
                                 $finalvalue = "";
                             } else {
                                 switch ($customdatatype->getType()) {
                                     case entities\CustomDatatype::EDITIONS_CHOICE:
                                         $temp = tables\Editions::getTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::COMPONENTS_CHOICE:
                                         $temp = tables\Components::getTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::RELEASES_CHOICE:
                                         $temp = tables\Builds::getTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::MILESTONE_CHOICE:
                                         $temp = tables\Milestones::getTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::STATUS_CHOICE:
                                         $temp = entities\Status::getB2DBTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::USER_CHOICE:
                                         $temp = entities\User::getB2DBTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::TEAM_CHOICE:
                                         $temp = entities\Team::getB2DBTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                     case entities\CustomDatatype::CLIENT_CHOICE:
                                         $temp = tables\Clients::getTable()->selectById($request->getRawParameter("{$key}_value"));
                                         break;
                                 }
                                 $issue->setCustomField($key, $customdatatypeoption_value);
                                 if ($customdatatype->getType() == entities\CustomDatatype::STATUS_CHOICE && isset($temp) && is_object($temp)) {
                                     $finalvalue = '<div class="status_badge" style="background-color: ' . $temp->getColor() . ';"><span>' . $temp->getName() . '</span></div>';
                                 } elseif ($customdatatype->getType() == entities\CustomDatatype::USER_CHOICE && isset($temp) && is_object($temp)) {
                                     $finalvalue = $this->getComponentHTML('main/userdropdown', array('user' => $temp));
                                 } elseif ($customdatatype->getType() == entities\CustomDatatype::TEAM_CHOICE && isset($temp) && is_object($temp)) {
                                     $finalvalue = $this->getComponentHTML('main/teamdropdown', array('team' => $temp));
                                 } else {
                                     $finalvalue = is_object($temp) ? $temp->getName() : $this->getI18n()->__('Unknown');
                                 }
                             }
                             $changed_methodname = "isCustomfield{$key}Changed";
                             if (!$issue->{$changed_methodname}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false));
                             }
                             return $customdatatypeoption_value == '' ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('value' => $key, 'name' => $finalvalue)));
                         case entities\CustomDatatype::INPUT_TEXTAREA_MAIN:
                         case entities\CustomDatatype::INPUT_TEXTAREA_SMALL:
                             if ($customdatatypeoption_value == '') {
                                 $issue->setCustomField($key, "");
                             } else {
                                 $issue->setCustomField($key, $request->getRawParameter("{$key}_value"));
                             }
                             $changed_methodname = "isCustomfield{$key}Changed";
                             if (!$issue->{$changed_methodname}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false));
                             }
                             return $customdatatypeoption_value == '' ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('value' => $key, 'name' => tbg_parse_text($request->getRawParameter("{$key}_value")))));
                         case entities\CustomDatatype::DATE_PICKER:
                             if ($customdatatypeoption_value == '') {
                                 $issue->setCustomField($key, "");
                             } else {
                                 $issue->setCustomField($key, $request->getParameter("{$key}_value"));
                             }
                             $changed_methodname = "isCustomfield{$key}Changed";
                             if (!$issue->{$changed_methodname}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false));
                             }
                             return $customdatatypeoption_value == '' ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('value' => $key, 'name' => date('Y-m-d', (int) $request->getRawParameter("{$key}_value")))));
                         default:
                             if ($customdatatypeoption_value == '') {
                                 $issue->setCustomField($key, "");
                             } else {
                                 $issue->setCustomField($key, $request->getParameter("{$key}_value"));
                             }
                             $changed_methodname = "isCustomfield{$key}Changed";
                             if (!$issue->{$changed_methodname}()) {
                                 return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false));
                             }
                             return $customdatatypeoption_value == '' ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('value' => $key, 'name' => filter_var($customdatatypeoption_value, FILTER_VALIDATE_URL) !== false ? "<a href=\"{$customdatatypeoption_value}\">{$customdatatypeoption_value}</a>" : $customdatatypeoption_value)));
                     }
                 }
                 $customdatatypeoption = $customdatatypeoption_value ? entities\CustomDatatypeOption::getB2DBTable()->selectById($customdatatypeoption_value) : null;
                 if ($customdatatypeoption instanceof entities\CustomDatatypeOption) {
                     $issue->setCustomField($key, $customdatatypeoption->getID());
                 } else {
                     $issue->setCustomField($key, null);
                 }
                 $changed_methodname = "isCustomfield{$key}Changed";
                 if (!$issue->{$changed_methodname}()) {
                     return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false));
                 }
                 return !$customdatatypeoption instanceof entities\CustomDatatypeOption ? $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => true, 'field' => array('value' => $customdatatypeoption->getID(), 'name' => $customdatatypeoption->getName())));
             }
             break;
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('No valid field specified (%field)', array('%field' => $request['field']))));
 }
     echo __('Set issue field %key to ', array('%key' => $action->getCustomActionType()));
     echo '<div id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;display: inline;">';
     echo $action->getTargetValue() ? include_component('main/userdropdown', array('user' => $action->getTargetValue())) : __('Value provided by user');
     echo '</div>';
     break;
 case \thebuggenie\core\entities\CustomDatatype::TEAM_CHOICE:
     echo __('Set issue field %key to ', array('%key' => $action->getCustomActionType()));
     echo '<div id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;display: inline;">';
     echo $action->getTargetValue() ? include_component('main/teamdropdown', array('team' => $action->getTargetValue())) : __('Value provided by user');
     echo '</div>';
     break;
 case \thebuggenie\core\entities\CustomDatatype::CLIENT_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\Clients::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::RELEASES_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\Builds::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::COMPONENTS_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\Components::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::EDITIONS_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\Editions::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::MILESTONE_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\Milestones::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::STATUS_CHOICE:
     echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\tables\ListTypes::getTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
     break;
 case \thebuggenie\core\entities\CustomDatatype::DROPDOWN_CHOICE_TEXT:
 default:
示例#13
0
 public function runFilterGetDynamicChoices(framework\Request $request)
 {
     $subproject_ids = explode(',', $request['subprojects']);
     $existing_ids = $request['existing_ids'];
     $results = array();
     $projects = $request['project_id'] != '' ? entities\Project::getAllByIDs(explode(',', $request['project_id'])) : entities\Project::getAll();
     $items = array('build' => array(), 'edition' => array(), 'component' => array(), 'milestone' => array());
     foreach ($projects as $project) {
         foreach ($project->getBuilds() as $build) {
             $items['build'][$build->getID()] = $build;
         }
         foreach ($project->getEditions() as $edition) {
             $items['edition'][$edition->getID()] = $edition;
         }
         foreach ($project->getComponents() as $component) {
             $items['component'][$component->getID()] = $component;
         }
         foreach ($project->getMilestones() as $milestone) {
             $items['milestone'][$milestone->getID()] = $milestone;
         }
     }
     $filters = array();
     $filters['build'] = entities\SearchFilter::createFilter('build');
     $filters['edition'] = entities\SearchFilter::createFilter('edition');
     $filters['component'] = entities\SearchFilter::createFilter('component');
     $filters['milestone'] = entities\SearchFilter::createFilter('milestone');
     if (isset($existing_ids['build'])) {
         foreach (tables\Builds::getTable()->getByIDs($existing_ids['build']) as $build) {
             $items['build'][$build->getID()] = $build;
         }
         $filters['build']->setValue(join(',', $existing_ids['build']));
     }
     if (isset($existing_ids['edition'])) {
         foreach (tables\Editions::getTable()->getByIDs($existing_ids['edition']) as $edition) {
             $items['edition'][$edition->getID()] = $edition;
         }
         $filters['edition']->setValue(join(',', $existing_ids['edition']));
     }
     if (isset($existing_ids['component'])) {
         foreach (tables\Components::getTable()->getByIDs($existing_ids['component']) as $component) {
             $items['component'][$component->getID()] = $component;
         }
         $filters['component']->setValue(join(',', $existing_ids['component']));
     }
     if (isset($existing_ids['milestone'])) {
         foreach (tables\Milestones::getTable()->getByIDs($existing_ids['milestone']) as $milestone) {
             $items['milestone'][$milestone->getID()] = $milestone;
         }
         $filters['milestone']->setValue(join(',', $existing_ids['milestone']));
     }
     foreach (array('build', 'edition', 'component', 'milestone') as $k) {
         $results[$k] = $this->getComponentHTML('search/interactivefilterdynamicchoicelist', array('filter' => $filters[$k], 'items' => $items[$k]));
     }
     return $this->renderJSON(compact('results'));
 }