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:
                        $target = $action->getTargetValue() ? \thebuggenie\core\entities\ListTypes::getTable()->selectById((int) $action->getTargetValue()) : null;
                        echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" class="status_badge" style="background-color: ' . $target->getColor() . '; color: ' . $target->getTextColor() . ';">' . ($action->getTargetValue() ? $target->getName() : __('Value provided by user')) . '</span>'));
                        break;
                    case \thebuggenie\core\entities\CustomDatatype::DROPDOWN_CHOICE_TEXT:
                    default:
                        $target = $action->getTargetValue() ? \thebuggenie\core\entities\CustomDatatypeOption::getB2DBTable()->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;
                }
                ?>
                        <?php 
            }
            ?>
                    <?php 
        } elseif ($action->getTargetValue()) {
            ?>
                        <span class="generic_error_message"><?php 
            echo __('Invalid transition configuration');
            ?>
</span>
                    <?php 
示例#2
0
 public function createNewOption($name, $value, $itemdata = null)
 {
     if ($this->getType() == self::CALCULATED_FIELD) {
         // Only allow one option/formula for the calculated field
         $opts = $this->getOptions();
         foreach ($opts as $option) {
             $option->delete();
         }
     }
     $option = new CustomDatatypeOption();
     $option->setName($name);
     $option->setKey($this->getKey());
     $option->setValue($value);
     $option->setItemdata($itemdata);
     $option->setCustomdatatype($this->_id);
     $option->save();
     // In order to set permissions correctly the item type has to be the same
     // as the option id not the item field. set the opton id with the newly generated
     // option ID and save again
     $option->setItemtype($option->getID());
     $option->save();
     $this->_options = null;
     return $option;
 }
示例#3
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']))));
 }
示例#4
0
 /**
  * Add or delete an issue field option
  *
  * @param framework\Request $request
  */
 public function runConfigureIssuefieldsAction(framework\Request $request)
 {
     $i18n = framework\Context::getI18n();
     $this->forward403unless($this->access_level == framework\Settings::ACCESS_FULL);
     $types = entities\Datatype::getTypes();
     switch ($request['mode']) {
         case 'saveorder':
             $itemtype = $request['type'];
             if (array_key_exists($itemtype, $types)) {
                 tables\ListTypes::getTable()->saveOptionOrder($request[$itemtype . '_list'], $itemtype);
             } else {
                 $customtype = entities\CustomDatatype::getByKey($request['type']);
                 tables\CustomFieldOptions::getTable()->saveOptionOrder($request[$itemtype . '_list'], $customtype->getID());
             }
             return $this->renderJSON('ok');
             break;
         case 'add':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $type_name = $types[$request['type']];
                     $item = new $type_name();
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     $item->save();
                 } else {
                     $customtype = entities\CustomDatatype::getByKey($request['type']);
                     $item = $customtype->createNewOption($request['name'], $request['value'], $request['itemdata']);
                 }
                 return $this->renderJSON(array('title' => framework\Context::getI18n()->__('The option was added'), 'content' => $this->getComponentHTML('issuefield', array('item' => $item, 'access_level' => $this->access_level, 'type' => $request['type']))));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid name')));
         case 'edit':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $classname = $types[$request['type']];
                     $item = $classname::getB2DBTable()->selectByID($request['id']);
                 } else {
                     $customtype = entities\CustomDatatype::getByKey($request['type']);
                     $item = entities\CustomDatatypeOption::getB2DBTable()->selectById($request['id']);
                 }
                 if ($item instanceof entities\DatatypeBase) {
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     if ($item instanceof entities\CustomDatatypeOption) {
                         $item->setValue($request['value']);
                     }
                     $item->save();
                     return $this->renderJSON(array('title' => framework\Context::getI18n()->__('The option was updated')));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid id')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid name')));
         case 'delete':
             if ($request->hasParameter('id')) {
                 if (array_key_exists($request['type'], $types)) {
                     $classname = $types[$request['type']];
                     $item = $classname::getB2DBTable()->doDeleteById($request['id']);
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 } else {
                     tables\CustomFieldOptions::getTable()->doDeleteById($request['id']);
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $i18n->__('Invalid id or type')));
             break;
     }
 }
                        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:
                        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\CustomDatatypeOption::getB2DBTable()->selectById((int) $action->getTargetValue())->getName() : __('Value provided by user')) . '</span>'));
                        break;
                }
                ?>
                        <?php 
            }
            ?>
                    <?php 
        } elseif ($action->getTargetValue()) {
            ?>
                        <span class="generic_error_message"><?php 
            echo __('Invalid transition configuration');
            ?>
</span>
                    <?php 
        }