public static function loadFixtures(TBGScope $scope) { $staff_members = new TBGTeam(); $staff_members->setName('Staff members'); $staff_members->save(); $developers = new TBGTeam(); $developers->setName('Developers'); $developers->save(); $team_leaders = new TBGTeam(); $team_leaders->setName('Team leaders'); $team_leaders->save(); $testers = new TBGTeam(); $testers->setName('Testers'); $testers->save(); $translators = new TBGTeam(); $translators->setName('Translators'); $translators->save(); }
public function runAddTeam(TBGRequest $request) { try { $mode = $request->getParameter('mode'); if ($team_name = $request->getParameter('team_name')) { if ($mode == 'clone') { try { $old_team = TBGContext::factory()->TBGTeam($request->getParameter('team_id')); } catch (Exception $e) { } if (!$old_team instanceof TBGTeam) { throw new Exception(TBGContext::getI18n()->__("You cannot clone this team")); } } if (TBGTeam::doesTeamNameExist(trim($team_name))) { throw new Exception(TBGContext::getI18n()->__("Please enter a team name that doesn't already exist")); } $team = new TBGTeam(); $team->setName($team_name); $team->save(); if ($mode == 'clone') { if ($request->getParameter('clone_permissions')) { TBGPermissionsTable::getTable()->cloneTeamPermissions($old_team->getID(), $team->getID()); } if ($request->getParameter('clone_memberships')) { TBGTeamMembersTable::getTable()->cloneTeamMemberships($old_team->getID(), $team->getID()); } $message = TBGContext::getI18n()->__('The team was cloned'); } else { $message = TBGContext::getI18n()->__('The team was added'); } return $this->renderJSON(array('failed' => false, 'message' => $message, 'content' => $this->getTemplateHTML('configuration/teambox', array('team' => $team)), 'total_count' => TBGTeam::getTeamsCount(), 'more_available' => TBGContext::getScope()->hasTeamsAvailable())); } else { throw new Exception(TBGContext::getI18n()->__('Please enter a team name')); } } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } }
public function perform(TBGIssue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(TBGContext::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(TBGContext::factory()->TBGStatus((int) $this->getTargetValue())); } else { $issue->setStatus($request['status_id']); } break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(TBGContext::factory()->TBGMilestone((int) $this->getTargetValue())); } else { $issue->setMilestone($request['milestone_id']); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(TBGContext::factory()->TBGPriority((int) $this->getTargetValue())); } else { $issue->setPriority($request['priority_id']); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request['percent_complete_id']); } break; case self::ACTION_CLEAR_DUPLICATE: $issue->setDuplicateOf(null); break; case self::ACTION_SET_DUPLICATE: $issue->setDuplicateOf($request['duplicate_issue_id']); break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(TBGContext::factory()->TBGResolution((int) $this->getTargetValue())); } else { $issue->setResolution($request['resolution_id']); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(TBGContext::factory()->TBGReproducability((int) $this->getTargetValue())); } else { $issue->setReproducability($request['reproducability_id']); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->clearAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $target_details = explode('_', $this->_target_value); if ($target_details[0] == 'user') { $assignee = TBGUser::getB2DBTable()->selectById((int) $target_details[1]); } else { $assignee = TBGTeam::getB2DBTable()->selectById((int) $target_details[1]); } $issue->setAssignee($assignee); } else { $assignee = null; switch ($request['assignee_type']) { case 'user': $assignee = TBGUser::getB2DBTable()->selectById((int) $request['assignee_id']); break; case 'team': $assignee = TBGTeam::getB2DBTable()->selectById((int) $request['assignee_id']); break; } if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof TBGUser && $assignee->getID() != TBGContext::getUser()->getID()) { $team = new TBGTeam(); $team->setName($assignee->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(TBGContext::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof TBGTeam && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } elseif ($issue->getAssignee() instanceof TBGUser) { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } elseif ($request->getParameter('did', 'nothing') == 'this') { $times = array(); if ($request['timespent_manual']) { $times = TBGIssue::convertFancyStringToTime($request['timespent_manual']); } elseif ($request['timespent_specified_type']) { $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0); $times[$request['timespent_specified_type']] = $request['timespent_specified_value']; } if (array_sum($times) > 0) { $times['hours'] *= 100; $spenttime = new TBGIssueSpentTime(); $spenttime->setIssue($issue); $spenttime->setUser(TBGContext::getUser()); $spenttime->setSpentPoints($times['points']); $spenttime->setSpentHours($times['hours']); $spenttime->setSpentDays($times['days']); $spenttime->setSpentWeeks($times['weeks']); $spenttime->setSpentMonths($times['months']); $spenttime->setActivityType($request['timespent_activitytype']); $spenttime->setComment($request['timespent_comment']); $spenttime->save(); } $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; } }
public function perform(TBGIssue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(TBGContext::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(TBGContext::factory()->TBGStatus((int) $this->getTargetValue())); } else { $issue->setStatus($request->getParameter('status_id')); } break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(TBGContext::factory()->TBGMilestone((int) $this->getTargetValue())); } else { $issue->setMilestone($request->getParameter('milestone_id')); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(TBGContext::factory()->TBGPriority((int) $this->getTargetValue())); } else { $issue->setPriority($request->getParameter('priority_id')); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request->getParameter('percent_complete_id')); } break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(TBGContext::factory()->TBGResolution((int) $this->getTargetValue())); } else { $issue->setResolution($request->getParameter('resolution_id')); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(TBGContext::factory()->TBGReproducability((int) $this->getTargetValue())); } else { $issue->setReproducability($request->getParameter('reproducability_id')); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->unsetAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $issue->setAssignee(TBGContext::factory()->TBGUser((int) $this->getTargetValue())); } else { $assignee = null; switch ($request->getParameter('assignee_type')) { case TBGIdentifiableClass::TYPE_USER: $assignee = TBGContext::factory()->TBGUser($request->getParameter('assignee_id')); break; case TBGIdentifiableClass::TYPE_TEAM: $assignee = TBGContext::factory()->TBGTeam($request->getParameter('assignee_id')); break; } if ((bool) $request->getParameter('assignee_teamup', false)) { $team = new TBGTeam(); $team->setName($assignee->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(TBGContext::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof TBGTeam && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } else { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; } }
/** * Sets an issue field to a specified value * * @param TBGRequest $request */ public function runIssueSetField(TBGRequest $request) { if ($issue_id = $request['issue_id']) { try { $issue = TBGIssuesTable::getTable()->selectById($issue_id); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderText('fail'); } } else { $this->getResponse()->setHttpStatus(400); return $this->renderText('no issue'); } TBGContext::loadLibrary('common'); if (!$issue instanceof TBGIssue) { return false; } switch ($request['field']) { case 'description': if (!$issue->canEditDescription()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::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)))); break; case 'reproduction_steps': if (!$issue->canEditReproductionSteps()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::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)))); break; case 'title': if (!$issue->canEditTitle()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::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' => TBGContext::getI18n()->__('You have to provide a title'))); } else { $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())))); } break; case 'percent_complete': if (!$issue->canEditPercentage()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::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())); break; case 'estimated_time': if (!$issue->canEditEstimatedTime()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if (!$issue->isUpdateable()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('This issue cannot be updated'))); } if ($request['estimated_time']) { $issue->setEstimatedTime($request['estimated_time']); } elseif ($request->hasParameter('value')) { $issue->setEstimatedTime($request['value']); } else { $issue->setEstimatedMonths($request['months']); $issue->setEstimatedWeeks($request['weeks']); $issue->setEstimatedDays($request['days']); $issue->setEstimatedHours($request['hours']); $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' => TBGIssue::getFormattedTime($issue->getEstimatedTime())) : array('id' => 0), 'values' => $issue->getEstimatedTime())); break; 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' => TBGContext::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' => TBGContext::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' => TBGContext::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 = TBGContext::factory()->TBGUser($request['value']); break; case 'team': $identified = TBGContext::factory()->TBGTeam($request['value']); break; } if ($identified instanceof TBGUser || $identified instanceof TBGTeam) { if ((bool) $request->getParameter('teamup', false)) { $team = new TBGTeam(); $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 = TBGContext::factory()->TBGUser($request['value']); if ($identified instanceof TBGUser) { $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 TBGUser ? $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 TBGUser ? $this->getComponentHTML('main/userdropdown', array('user' => $issue->getAssignee())) : $this->getComponentHTML('main/teamdropdown', array('team' => $issue->getAssignee()))) : array('id' => 0))); } } break; case 'spent_time': if (!$issue->canEditSpentTime()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if ($request['spent_time'] != TBGContext::getI18n()->__('Enter time spent here') && $request['spent_time']) { $issue->addSpentTime($request['spent_time']); } elseif ($request->hasParameter('value')) { $issue->addSpentTime($request['value']); } else { $issue->addSpentMonths($request['months']); $issue->addSpentWeeks($request['weeks']); $issue->addSpentDays($request['days']); $issue->addSpentHours($request['hours']); $issue->addSpentPoints($request['points']); } return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => $issue->isSpentTimeChanged(), 'field' => $issue->hasSpentTime() ? array('id' => 1, 'name' => TBGIssue::getFormattedTime($issue->getSpentTime())) : array('id' => 0), 'values' => $issue->getSpentTime())); 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()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'resolution' && !$issue->canEditResolution()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'severity' && !$issue->canEditSeverity()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'reproducability' && !$issue->canEditReproducability()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'priority' && !$issue->canEditPriority()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'milestone' && !$issue->canEditMilestone()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'issuetype' && !$issue->canEditIssuetype()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request['field'] == 'status' && !$issue->canEditStatus()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif (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' => TBGContext::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 = 'TBG' . 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(TBGIssue::getPainTypesOrLabel($parameter_name))) : $parameter_id == 0 || ($parameter = TBGContext::factory()->{$lab_function_name}($parameter_id)) instanceof $classname; } if ($parameter_id == 0 || $parameter_id !== 0 && $is_valid) { if ($classname == 'TBGIssuetype') { $visible_fields = $issue->getIssuetype() instanceof TBGIssuetype ? $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 (!$issue->{$is_changed_function_name}()) { return $this->renderJSON(array('issue_id' => $issue->getID(), 'changed' => false)); } if (isset($parameter)) { $name = $parameter->getName(); } else { $name = null; } $field = array('id' => $parameter_id, 'name' => $name); if ($classname == 'TBGIssuetype') { TBGContext::loadLibrary('ui'); $field['src'] = htmlspecialchars(TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getThemeName() . '/' . $issue->getIssuetype()->getIcon() . '_small.png'); } 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' => TBGContext::getI18n()->__('No valid field value specified'))); break; default: if ($customdatatype = TBGCustomDatatype::getByKey($request['field'])) { $key = $customdatatype->getKey(); $customdatatypeoption_value = $request->getParameter("{$key}_value"); if (!$customdatatype->hasCustomOptions()) { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: case TBGCustomDatatype::COMPONENTS_CHOICE: case TBGCustomDatatype::RELEASES_CHOICE: case TBGCustomDatatype::STATUS_CHOICE: case TBGCustomDatatype::MILESTONE_CHOICE: case TBGCustomDatatype::USER_CHOICE: case TBGCustomDatatype::TEAM_CHOICE: if ($customdatatypeoption_value == '') { $issue->setCustomField($key, ""); } else { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: $temp = TBGEditionsTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::COMPONENTS_CHOICE: $temp = TBGComponentsTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::RELEASES_CHOICE: $temp = TBGBuildsTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::MILESTONE_CHOICE: $temp = TBGMilestonesTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::STATUS_CHOICE: $temp = TBGStatus::getB2DBTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::USER_CHOICE: $temp = TBGUsersTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; case TBGCustomDatatype::TEAM_CHOICE: $temp = TBGTeamsTable::getTable()->selectById($request->getRawParameter("{$key}_value")); break; } $finalvalue = $temp->getName(); $issue->setCustomField($key, $request->getRawParameter("{$key}_value")); } if ($customdatatype->getType() == TBGCustomDatatype::STATUS_CHOICE && isset($temp) && is_object($temp)) { $finalvalue = '<div class="status_badge" style="background-color: ' . $temp->getColor() . ';"><span>' . $finalvalue . '</span></div>'; } elseif ($customdatatype->getType() == TBGCustomDatatype::USER_CHOICE && isset($temp) && is_object($temp)) { $finalvalue = $this->getComponentHTML('main/userdropdown', array('user' => $temp)); } elseif ($customdatatype->getType() == TBGCustomDatatype::TEAM_CHOICE && isset($temp) && is_object($temp)) { $finalvalue = $this->getComponentHTML('main/teamdropdown', array('team' => $temp)); } $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))); break; case TBGCustomDatatype::INPUT_TEXTAREA_MAIN: case TBGCustomDatatype::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"))))); break; case TBGCustomDatatype::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"))))); break; 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))); break; } } $customdatatypeoption = $customdatatypeoption_value ? TBGCustomDatatypeOption::getB2DBTable()->selectById($customdatatypeoption_value) : null; if ($customdatatypeoption instanceof TBGCustomDatatypeOption) { $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 TBGCustomDatatypeOption ? $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' => TBGContext::getI18n()->__('No valid field specified (%field)', array('%field' => $request['field'])))); }
/** * Sets an issue field to a specified value * * @param TBGRequest $request */ public function runIssueSetField(TBGRequest $request) { if ($issue_id = $request->getParameter('issue_id')) { try { $issue = TBGContext::factory()->TBGIssue($issue_id); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderText('fail'); } } else { $this->getResponse()->setHttpStatus(400); return $this->renderText('no issue'); } TBGContext::loadLibrary('common'); if (!$issue instanceof TBGIssue) { return false; } switch ($request->getParameter('field')) { case 'description': if (!$issue->canEditDescription()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } $issue->setDescription($request->getRawParameter('value')); return $this->renderJSON(array('changed' => $issue->isDescriptionChanged(), 'field' => array('id' => (int) ($issue->getDescription() != ''), 'name' => tbg_parse_text($issue->getDescription(), false, null, array('issue' => $issue))), 'description' => tbg_parse_text($issue->getDescription(), false, null, array('issue' => $issue)))); break; case 'reproduction_steps': if (!$issue->canEditReproductionSteps()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } $issue->setReproductionSteps($request->getRawParameter('value')); return $this->renderJSON(array('changed' => $issue->isReproductionStepsChanged(), 'field' => array('id' => (int) ($issue->getReproductionSteps() != ''), 'name' => tbg_parse_text($issue->getReproductionSteps(), false, null, array('issue' => $issue))), 'reproduction_steps' => tbg_parse_text($issue->getReproductionSteps(), false, null, array('issue' => $issue)))); break; case 'title': if (!$issue->canEditTitle()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if ($request->getParameter('value') == '') { return $this->renderJSON(array('changed' => false, 'failed' => true, 'error' => TBGContext::getI18n()->__('You have to provide a title'))); } else { $issue->setTitle($request->getRawParameter('value')); return $this->renderJSON(array('changed' => $issue->isTitleChanged(), 'field' => array('id' => 1, 'name' => strip_tags($issue->getTitle())), 'title' => strip_tags($issue->getTitle()))); } break; case 'percent': if (!$issue->canEditPercentage()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } $issue->setPercentCompleted($request->getParameter('percent')); return $this->renderJSON(array('changed' => $issue->isPercentCompletedChanged(), 'percent' => $issue->getPercentCompleted())); break; case 'estimated_time': if (!$issue->canEditEstimatedTime()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if ($request->getParameter('estimated_time') != TBGContext::getI18n()->__('Enter your estimate here') && $request->getParameter('estimated_time')) { $issue->setEstimatedTime($request->getParameter('estimated_time')); } elseif ($request->hasParameter('value')) { $issue->setEstimatedTime($request->getParameter('value')); } else { $issue->setEstimatedMonths($request->getParameter('estimated_time_months')); $issue->setEstimatedWeeks($request->getParameter('estimated_time_weeks')); $issue->setEstimatedDays($request->getParameter('estimated_time_days')); $issue->setEstimatedHours($request->getParameter('estimated_time_hours')); $issue->setEstimatedPoints($request->getParameter('estimated_time_points')); } return $this->renderJSON(array('changed' => $issue->isEstimatedTimeChanged(), 'field' => $issue->hasEstimatedTime() ? array('id' => 1, 'name' => $issue->getFormattedTime($issue->getEstimatedTime())) : array('id' => 0), 'values' => $issue->getEstimatedTime())); break; case 'owned_by': case 'posted_by': case 'assigned_to': if ($request->getParameter('field') == 'owned_by' && !$issue->canEditOwnedBy()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'posted_by' && !$issue->canEditPostedBy()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'assigned_to' && !$issue->canEditAssignedTo()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if ($request->hasParameter('value')) { if ($request->hasParameter('identifiable_type')) { if (in_array($request->getParameter('identifiable_type'), array(TBGIdentifiableClass::TYPE_USER, TBGIdentifiableClass::TYPE_TEAM))) { switch ($request->getParameter('identifiable_type')) { case TBGIdentifiableClass::TYPE_USER: $identified = TBGContext::factory()->TBGUser($request->getParameter('value')); break; case TBGIdentifiableClass::TYPE_TEAM: $identified = TBGContext::factory()->TBGTeam($request->getParameter('value')); break; } if ($identified instanceof TBGIdentifiableClass) { if ((bool) $request->getParameter('teamup', false)) { $team = new TBGTeam(); $team->setName($identified->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($identified); $team->addMember(TBGContext::getUser()); $identified = $team; } if ($request->getParameter('field') == 'owned_by') { $issue->setOwner($identified); } elseif ($request->getParameter('field') == 'assigned_to') { $issue->setAssignee($identified); } } } else { if ($request->getParameter('field') == 'owned_by') { $issue->unsetOwner(); } elseif ($request->getParameter('field') == 'assigned_to') { $issue->unsetAssignee(); } } } elseif ($request->getParameter('field') == 'posted_by') { $identified = TBGContext::factory()->TBGUser($request->getParameter('value')); if ($identified instanceof TBGIdentifiableClass) { $issue->setPostedBy($identified); } } if ($request->getParameter('field') == 'owned_by') { return $this->renderJSON(array('changed' => $issue->isOwnedByChanged(), 'field' => $issue->isOwned() ? array('id' => $issue->getOwnerID(), 'name' => $issue->getOwnerType() == TBGIdentifiableClass::TYPE_USER ? $this->getComponentHTML('main/userdropdown', array('user' => $issue->getOwner())) : $this->getComponentHTML('main/teamdropdown', array('team' => $issue->getOwner()))) : array('id' => 0))); } if ($request->getParameter('field') == 'posted_by') { return $this->renderJSON(array('changed' => $issue->isPostedByChanged(), 'field' => array('id' => $issue->getPostedByID(), 'name' => $this->getComponentHTML('main/userdropdown', array('user' => $issue->getPostedBy()))))); } if ($request->getParameter('field') == 'assigned_to') { return $this->renderJSON(array('changed' => $issue->isAssignedToChanged(), 'field' => $issue->isAssigned() ? array('id' => $issue->getAssigneeID(), 'name' => $issue->getAssigneeType() == TBGIdentifiableClass::TYPE_USER ? $this->getComponentHTML('main/userdropdown', array('user' => $issue->getAssignee())) : $this->getComponentHTML('main/teamdropdown', array('team' => $issue->getAssignee()))) : array('id' => 0))); } } break; case 'spent_time': if (!$issue->canEditSpentTime()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } if ($request->getParameter('spent_time') != TBGContext::getI18n()->__('Enter time spent here') && $request->getParameter('spent_time')) { $function = $request->hasParameter('spent_time_added_text') ? 'addSpentTime' : 'setSpentTime'; $issue->{$function}($request->getParameter('spent_time')); } elseif ($request->hasParameter('value')) { $issue->setSpentTime($request->getParameter('value')); } else { if ($request->hasParameter('spent_time_added_input')) { $issue->addSpentMonths($request->getParameter('spent_time_months')); $issue->addSpentWeeks($request->getParameter('spent_time_weeks')); $issue->addSpentDays($request->getParameter('spent_time_days')); $issue->addSpentHours($request->getParameter('spent_time_hours')); $issue->addSpentPoints($request->getParameter('spent_time_points')); } else { $issue->setSpentMonths($request->getParameter('spent_time_months')); $issue->setSpentWeeks($request->getParameter('spent_time_weeks')); $issue->setSpentDays($request->getParameter('spent_time_days')); $issue->setSpentHours($request->getParameter('spent_time_hours')); $issue->setSpentPoints($request->getParameter('spent_time_points')); } } return $this->renderJSON(array('changed' => $issue->isSpentTimeChanged(), 'field' => $issue->hasSpentTime() ? array('id' => 1, 'name' => $issue->getFormattedTime($issue->getSpentTime())) : array('id' => 0), 'values' => $issue->getSpentTime())); 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->getParameter('field') == 'category' && !$issue->canEditCategory()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'resolution' && !$issue->canEditResolution()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'severity' && !$issue->canEditSeverity()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'reproducability' && !$issue->canEditReproducability()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'priority' && !$issue->canEditPriority()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'milestone' && !$issue->canEditMilestone()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'issuetype' && !$issue->canEditIssuetype()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif ($request->getParameter('field') == 'status' && !$issue->canEditStatus()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } elseif (in_array($request->getParameter('field'), array('pain_bug_type', 'pain_likelihood', 'pain_effect')) && !$issue->canEditUserPain()) { return $this->renderJSON(array('changed' => false, 'error' => TBGContext::getI18n()->__('You do not have permission to perform this action'))); } try { $classname = null; $parameter_name = strtolower($request->getParameter('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 = 'TBG' . 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(TBGIssue::getPainTypesOrLabel($parameter_name))) : $parameter_id == 0 || ($parameter = TBGContext::factory()->{$lab_function_name}($parameter_id)) instanceof TBGIdentifiableClass; } if ($parameter_id == 0 || $parameter_id !== 0 && $is_valid) { if ($classname == 'TBGIssuetype') { $visible_fields = $issue->getIssuetype() instanceof TBGIssuetype ? $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('changed' => false, 'field' => array('id' => 0), 'user_pain' => $issue->getUserPain(), 'user_pain_diff_text' => $issue->getUserPainDiffText())); } return $parameter_id == 0 ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0), 'user_pain' => $issue->getUserPain(), 'user_pain_diff_text' => $issue->getUserPainDiffText())) : $this->renderJSON(array('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 (!$issue->{$is_changed_function_name}()) { return $this->renderJSON(array('changed' => false)); } if (isset($parameter)) { $name = $parameter->getName(); } else { $name = null; } $field = array('id' => $parameter_id, 'name' => $name); if ($classname == 'TBGIssuetype') { TBGContext::loadLibrary('ui'); $field['src'] = htmlspecialchars(TBGContext::getTBGPath() . 'themes/' . TBGSettings::getThemeName() . '/' . $issue->getIssuetype()->getIcon() . '_small.png'); } return $parameter_id == 0 ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('changed' => true, 'visible_fields' => $visible_fields, 'field' => $field)); } } } } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('No valid field value specified'))); break; default: if ($customdatatype = TBGCustomDatatype::getByKey($request->getParameter('field'))) { $key = $customdatatype->getKey(); $customdatatypeoption_value = $request->getParameter("{$key}_value"); if (!$customdatatype->hasCustomOptions()) { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: case TBGCustomDatatype::COMPONENTS_CHOICE: case TBGCustomDatatype::RELEASES_CHOICE: case TBGCustomDatatype::STATUS_CHOICE: if ($customdatatypeoption_value == '') { $issue->setCustomField($key, ""); } else { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: $temp = new TBGEdition($request->getRawParameter("{$key}_value")); $finalvalue = $temp->getName(); break; case TBGCustomDatatype::COMPONENTS_CHOICE: $temp = new TBGComponent($request->getRawParameter("{$key}_value")); $finalvalue = $temp->getName(); break; case TBGCustomDatatype::RELEASES_CHOICE: $temp = new TBGBuild($request->getRawParameter("{$key}_value")); $finalvalue = $temp->getName(); break; case TBGCustomDatatype::STATUS_CHOICE: $temp = new TBGStatus($request->getRawParameter("{$key}_value")); $finalvalue = $temp->getName(); break; } $issue->setCustomField($key, $request->getRawParameter("{$key}_value")); } if (isset($temp) && $customdatatype->getType() == TBGCustomDatatype::STATUS_CHOICE && is_object($temp)) { $finalvalue = '<div style="border: 1px solid #AAA; background-color: ' . $temp->getColor() . '; font-size: 1px; width: 20px; height: 15px; margin-right: 5px; float: left;" id="status_color"> </div>' . $finalvalue; } $changed_methodname = "isCustomfield{$key}Changed"; if (!$issue->{$changed_methodname}()) { return $this->renderJSON(array('changed' => false)); } return $customdatatypeoption_value == '' ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('changed' => true, 'field' => array('value' => $key, 'name' => $finalvalue))); break; case TBGCustomDatatype::INPUT_TEXTAREA_MAIN: case TBGCustomDatatype::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('changed' => false)); } return $customdatatypeoption_value == '' ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('changed' => true, 'field' => array('value' => $key, 'name' => tbg_parse_text($request->getRawParameter("{$key}_value"), false, null, array('issue' => $issue))))); break; 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('changed' => false)); } return $customdatatypeoption_value == '' ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('changed' => true, 'field' => array('value' => $key, 'name' => $customdatatypeoption_value))); break; } } if ($customdatatypeoption_value == '' || $customdatatypeoption_value && ($customdatatypeoption = TBGCustomDatatypeOption::getByValueAndKey($customdatatypeoption_value, $key)) instanceof TBGCustomDatatypeOption) { if ($customdatatypeoption_value == '') { $issue->setCustomField($key, ""); } else { $issue->setCustomField($key, $customdatatypeoption->getValue()); } $changed_methodname = "isCustomfield{$key}Changed"; if (!$issue->{$changed_methodname}()) { return $this->renderJSON(array('changed' => false)); } return $customdatatypeoption_value == '' ? $this->renderJSON(array('changed' => true, 'field' => array('id' => 0))) : $this->renderJSON(array('changed' => true, 'field' => array('value' => $customdatatypeoption_value, 'name' => $customdatatypeoption->getName()))); } } break; } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('No valid field specified (%field%)', array('%field%' => $request->getParameter('field'))))); }