protected function _populateBurndownData() { if ($this->_burndowndata === null) { $this->_burndowndata = array(); $issues = array(); foreach ($this->getIssues() as $issue) { $issues[] = (int) $issue->getID(); foreach ($issue->getChildIssues() as $child_issue) { $issues[] = (int) $child_issue->getID(); } } $estimations = TBGIssueEstimates::getTable()->getEstimatesByDateAndIssueIDs($this->getStartingDate(), $this->getScheduledDate(), $issues); $spent_times = TBGIssueSpentTimesTable::getTable()->getSpentTimesByDateAndIssueIDs($this->getStartingDate(), $this->getScheduledDate(), $issues); $burndown = array(); foreach ($estimations['hours'] as $key => $val) { $burndown['hours'][$key] = array_key_exists($key, $spent_times['hours']) ? $val - $spent_times['hours'][$key] : $val; } foreach ($estimations['points'] as $key => $val) { $burndown['points'][$key] = array_key_exists($key, $spent_times['points']) ? $val - $spent_times['points'][$key] : $val; } foreach ($spent_times['hours'] as $key => $val) { $spent_times['hours'][$key] = round($spent_times['hours'][$key] / 100, 2); } $this->_burndowndata = array('estimations' => $estimations, 'spent_times' => $spent_times, 'burndown' => $burndown); } }
protected function _processChanges() { $related_issues_to_save = array(); $changed_properties = $this->_getChangedProperties(); if (count($changed_properties)) { $is_saved_estimated = false; $is_saved_spent = false; $is_saved_assignee = false; $is_saved_owner = false; foreach ($changed_properties as $property => $value) { $compare_value = is_object($this->{$property}) ? $this->{$property}->getID() : $this->{$property}; $original_value = $value['original_value']; if ($original_value != $compare_value) { switch ($property) { case '_title': $this->addLogEntry(TBGLogTable::LOG_ISSUE_UPDATE_TITLE, TBGContext::getI18n()->__("Title updated"), $original_value, $compare_value); break; case '_description': $this->addLogEntry(TBGLogTable::LOG_ISSUE_UPDATE_DESCRIPTION, TBGContext::getI18n()->__("Description updated"), $original_value, $compare_value); break; case '_reproduction_steps': $this->addLogEntry(TBGLogTable::LOG_ISSUE_UPDATE_REPRODUCTIONSTEPS, TBGContext::getI18n()->__("Reproduction steps updated"), $original_value, $compare_value); break; case '_category': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGCategory($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Not determined'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getCategory() instanceof TBGDatatype ? $this->getCategory()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_CATEGORY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_bug_type': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_bug_type', $original_value)) ? $old_item : TBGContext::getI18n()->__('Not determined'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_bug_type', $value['current_value'])) ? $new_item : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_PAIN_BUG_TYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_effect': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_effect', $original_value)) ? $old_item : TBGContext::getI18n()->__('Not determined'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_effect', $value['current_value'])) ? $new_item : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_PAIN_EFFECT, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_likelihood': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_likelihood', $original_value)) ? $old_item : TBGContext::getI18n()->__('Not determined'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_likelihood', $value['current_value'])) ? $new_item : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_PAIN_LIKELIHOOD, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_user_pain': $this->addLogEntry(TBGLogTable::LOG_ISSUE_PAIN_CALCULATED, $original_value . ' ⇒ ' . $value['current_value']); break; case '_status': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGStatus($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getStatus() instanceof TBGDatatype ? $this->getStatus()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_STATUS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_reproducability': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGReproducability($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getReproducability() instanceof TBGDatatype ? $this->getReproducability()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_REPRODUCABILITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_priority': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGPriority($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getPriority() instanceof TBGDatatype ? $this->getPriority()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_PRIORITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_assignee_team': case '_assignee_user': if (!$is_saved_assignee) { $new_name = $this->getAssignee() instanceof TBGIdentifiable ? $this->getAssignee()->getName() : TBGContext::getI18n()->__('Not assigned'); if ($this->getAssignee() instanceof TBGUser) { $this->startWorkingOnIssue($this->getAssignee()); } $this->addLogEntry(TBGLogTable::LOG_ISSUE_ASSIGNED, $new_name); $is_saved_assignee = true; } break; case '_posted_by': $old_identifiable = $original_value ? TBGContext::factory()->TBGUser($original_value) : TBGContext::getI18n()->__('Unknown'); $old_name = $old_identifiable instanceof TBGUser ? $old_identifiable->getName() : TBGContext::getI18n()->__('Unknown'); $new_name = $this->getPostedBy()->getName(); $this->addLogEntry(TBGLogTable::LOG_ISSUE_POSTED, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_being_worked_on_by_user': if ($original_value != 0) { $old_identifiable = TBGContext::factory()->TBGUser($original_value); $old_name = $old_identifiable instanceof TBGUser ? $old_identifiable->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not being worked on'); } $new_name = $this->getUserWorkingOnIssue() instanceof TBGUser ? $this->getUserWorkingOnIssue()->getName() : TBGContext::getI18n()->__('Not being worked on'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_USERS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_owner_team': case '_owner_user': if (!$is_saved_owner) { $new_name = $this->getOwner() instanceof TBGIdentifiable ? $this->getOwner()->getName() : TBGContext::getI18n()->__('Not owned by anyone'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_OWNED, $new_name); $is_saved_owner = true; } break; case '_percent_complete': $this->addLogEntry(TBGLogTable::LOG_ISSUE_PERCENT, $original_value . '% ⇒ ' . $this->getPercentCompleted() . '', $original_value, $compare_value); break; case '_resolution': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGResolution($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getResolution() instanceof TBGDatatype ? $this->getResolution()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_RESOLUTION, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_severity': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGSeverity($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getSeverity() instanceof TBGDatatype ? $this->getSeverity()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_SEVERITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_milestone': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGMilestone($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Not determined'); } else { $old_name = TBGContext::getI18n()->__('Not determined'); } $new_name = $this->getMilestone() instanceof TBGMilestone ? $this->getMilestone()->getName() : TBGContext::getI18n()->__('Not determined'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_MILESTONE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); $this->_milestone_order = 0; break; case '_issuetype': if ($original_value != 0) { $old_name = ($old_item = TBGContext::factory()->TBGIssuetype($original_value)) ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); } else { $old_name = TBGContext::getI18n()->__('Unknown'); } $new_name = $this->getIssuetype() instanceof TBGIssuetype ? $this->getIssuetype()->getName() : TBGContext::getI18n()->__('Unknown'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_ISSUETYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_estimated_months': case '_estimated_weeks': case '_estimated_days': case '_estimated_hours': case '_estimated_points': if (!$is_saved_estimated) { $old_time = array('months' => $this->getChangedPropertyOriginal('_estimated_months'), 'weeks' => $this->getChangedPropertyOriginal('_estimated_weeks'), 'days' => $this->getChangedPropertyOriginal('_estimated_days'), 'hours' => $this->getChangedPropertyOriginal('_estimated_hours'), 'points' => $this->getChangedPropertyOriginal('_estimated_points')); $old_formatted_time = array_sum($old_time) > 0 ? TBGIssue::getFormattedTime($old_time) : TBGContext::getI18n()->__('Not estimated'); $new_formatted_time = $this->hasEstimatedTime() ? TBGIssue::getFormattedTime($this->getEstimatedTime()) : TBGContext::getI18n()->__('Not estimated'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_TIME_ESTIMATED, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getEstimatedTime())); $is_saved_estimated = true; } break; case '_spent_months': case '_spent_weeks': case '_spent_days': case '_spent_hours': case '_spent_points': if (!$is_saved_spent) { $old_time = array('months' => $this->getChangedPropertyOriginal('_spent_months'), 'weeks' => $this->getChangedPropertyOriginal('_spent_weeks'), 'days' => $this->getChangedPropertyOriginal('_spent_days'), 'hours' => $this->getChangedPropertyOriginal('_spent_hours'), 'points' => $this->getChangedPropertyOriginal('_spent_points')); $old_formatted_time = array_sum($old_time) > 0 ? TBGIssue::getFormattedTime($old_time) : TBGContext::getI18n()->__('No time spent'); $new_formatted_time = $this->hasSpentTime() ? TBGIssue::getFormattedTime($this->getSpentTime()) : TBGContext::getI18n()->__('No time spent'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_TIME_SPENT, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getSpentTime())); $is_saved_spent = true; } break; case '_state': if ($this->isClosed()) { $this->addLogEntry(TBGLogTable::LOG_ISSUE_CLOSE); if ($this->getMilestone() instanceof TBGMilestone) { if ($this->getMilestone()->isSprint()) { if (!$this->getIssueType()->isTask()) { $this->setSpentPoints($this->getEstimatedPoints()); } else { if ($this->getSpentHours() < $this->getEstimatedHours()) { $this->setSpentHours($this->getEstimatedHours()); } foreach ($this->getParentIssues() as $parent_issue) { if ($parent_issue->checkTaskStates()) { $related_issues_to_save[$parent_issue->getID()] = true; } } } } $this->getMilestone()->updateStatus(); } } else { $this->addLogEntry(TBGLogTable::LOG_ISSUE_REOPEN); } break; case '_blocking': if ($this->isBlocking()) { $this->addLogEntry(TBGLogTable::LOG_ISSUE_BLOCKED); } else { $this->addLogEntry(TBGLogTable::LOG_ISSUE_UNBLOCKED); } break; default: if (mb_substr($property, 0, 12) == '_customfield') { $key = mb_substr($property, 12); $customdatatype = TBGCustomDatatype::getByKey($key); switch ($customdatatype->getType()) { case TBGCustomDatatype::INPUT_TEXT: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : TBGContext::getI18n()->__('Unknown'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case TBGCustomDatatype::INPUT_TEXTAREA_SMALL: case TBGCustomDatatype::INPUT_TEXTAREA_MAIN: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : TBGContext::getI18n()->__('Unknown'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case TBGCustomDatatype::EDITIONS_CHOICE: case TBGCustomDatatype::COMPONENTS_CHOICE: case TBGCustomDatatype::RELEASES_CHOICE: case TBGCustomDatatype::STATUS_CHOICE: $old_object = null; $new_object = null; try { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: $old_object = TBGContext::factory()->TBGEdition($original_value); break; case TBGCustomDatatype::COMPONENTS_CHOICE: $old_object = TBGContext::factory()->TBGComponent($original_value); break; case TBGCustomDatatype::RELEASES_CHOICE: $old_object = TBGContext::factory()->TBGBuild($original_value); break; case TBGCustomDatatype::STATUS_CHOICE: $old_object = TBGContext::factory()->TBGStatus($original_value); break; } } catch (Exception $e) { } try { switch ($customdatatype->getType()) { case TBGCustomDatatype::EDITIONS_CHOICE: $new_object = TBGContext::factory()->TBGEdition($this->getCustomField($key)); break; case TBGCustomDatatype::COMPONENTS_CHOICE: $new_object = TBGContext::factory()->TBGComponent($this->getCustomField($key)); break; case TBGCustomDatatype::RELEASES_CHOICE: $new_object = TBGContext::factory()->TBGBuild($this->getCustomField($key)); break; case TBGCustomDatatype::STATUS_CHOICE: $new_object = TBGContext::factory()->TBGStatus($this->getCustomField($key)); break; } } catch (Exception $e) { } $old_value = is_object($old_object) ? $old_object->getName() : TBGContext::getI18n()->__('Unknown'); $new_value = is_object($new_object) ? $new_object->getName() : TBGContext::getI18n()->__('Unknown'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; default: $old_item = null; try { $old_item = $original_value ? new TBGCustomDatatypeOption($original_value) : null; } catch (Exception $e) { } $old_value = $old_item instanceof TBGCustomDatatypeOption ? $old_item->getName() : TBGContext::getI18n()->__('Unknown'); $new_value = $this->getCustomField($key) instanceof TBGCustomDatatypeOption ? $this->getCustomField($key)->getName() : TBGContext::getI18n()->__('Unknown'); $this->addLogEntry(TBGLogTable::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; } } break; } } } if ($is_saved_estimated) { TBGIssueEstimates::getTable()->saveEstimate($this->getID(), $this->_estimated_months, $this->_estimated_weeks, $this->_estimated_days, $this->_estimated_hours, $this->_estimated_points); } } return $related_issues_to_save; }