Created
September 12, 2017 14:49
-
-
Save MartelliEnrico/656bddb2e66e2d21f0871e4fce25a89e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function runGenReportActivity(Request $request) | |
{ | |
$activities = []; | |
$date_from = trim($request['date_from']); | |
$date_to = trim($request['date_to']); | |
$time_spent_table = entities\IssueSpentTime::getB2DBTable(); | |
$crit = $time_spent_table->getCriteria(); | |
$crit->addWhere(tables\IssueSpentTimes::EDITED_AT, $date_from, $crit::DB_GREATER_THAN_EQUAL); | |
$crit->addWhere(tables\IssueSpentTimes::EDITED_AT, $date_to, $crit::DB_LESS_THAN_EQUAL); | |
$crit->addOrderBy(tables\IssueSpentTimes::EDITED_AT, $crit::SORT_DESC_NUMERIC); | |
$activity_type_ids = []; | |
$issue_ids = []; | |
foreach ($time_spent_table->select($crit) as $activity) | |
{ | |
$activity_type_ids[] = $activity->getActivityTypeID(); | |
$issue_ids[] = $activity->getIssueID(); | |
$minutesProvided = ($activity->getSpentWeeks() * 2400) + ($activity->getSpentDays() * 480 ) + (($activity->getSpentHours()/100)*60) + $activity->getSpentMinutes(); | |
$activities[] = ["issue_id" => $activity->getIssueID(),"minutes_provided" => $minutesProvided,"comment" => $activity->getComment(), "date_of_entry" => $activity->getEditedAt(),"activity_type_id" => $activity->getActivityTypeID(),"activity_type_desc" => "","assigned_to" => "","issue_description" => "","owned_by" => "","issue_type" => "","issue_status" => "","ticket_type" => "","ref_order" => "","ref_depart" => "","ref_customer" => ""]; | |
} | |
$activity_types_desc = $this->getActivityTypesDescForIDs($activity_type_ids); // TODO, format [activity_type_id => activity_type_desc, ...] | |
$issues = $this->getIssuesForIDs($issue_ids); // TODO, format [issue_id => {issue}, ...] | |
$projects_ids = []; | |
foreach ($issues as $issue) | |
{ | |
$projects_ids[] = $issue->getProjectID(); | |
} | |
$projects_prefix = $this->getProjectsPrefixForIDs($projects_ids); // TODO, format [project_id => project_prefix, ...] | |
$custom_values = $this->getCustomValuesForIssueIDs(array_keys($issues)); // TODO, format [issue_id => {custom values}, ...] | |
foreach ($activities as &$activity) | |
{ | |
$issue = $issues[$activity["issue_id"]]; | |
if(isset($activity_types_desc[$activity["activity_type_id"]])) { | |
$activity["activity_type_desc"] = $activity_types_desc[$activity["activity_type_id"]]; | |
} | |
$activity["project_prefix"] = $projects_prefix[$activity["project_id"]]; | |
if($issue->hasAssignee()){ | |
$assignee = $issue->getAssignee(); | |
if($assignee != null){ | |
$activity["assigned_to"] = $assignee->getUsername(); | |
} | |
} | |
if($issue->getDescription() != null){ | |
$activity["issue_description"] = $issue->getDescription(); | |
} | |
$owner = $issue->getOwner(); | |
if($owner != null){ | |
if($owner instanceof Team ){ | |
$owner = $owner->getName(); | |
}else if($owner instanceof User){ | |
$owner = $owner->getRealname(); | |
}else{ | |
$owner = $owner->getUsername(); | |
} | |
$activity["owned_by"] = $owner; | |
} | |
$type = $issues[$activity["issue_id"]]->getIssueType(); | |
if($type != null) { | |
$activity["issue_type"] = $type; | |
} | |
$status = $issues[$activity["issue_id"]]->getStatus(); | |
if($status != null) { | |
$activity["issue_status"] = $status; | |
} | |
if(isset($custom_values[$activity["issue_id"]][2])){ | |
$activity["ticket_type"] = $customValues[2]; | |
} | |
if(isset($custom_values[$activity["issue_id"]][1])){ | |
$activity["ref_order"] = $customValues[1]; | |
} | |
if(isset($custom_values[$activity["issue_id"]][5])){ | |
$activity["ref_depart"] = $customValues[5]; | |
} | |
if(isset($custom_values[$activity["issue_id"]][4])){ | |
$activity["ref_customer"] = $customValues[4]; | |
} | |
$activity["estimated_minutes"] = ($issue->getEstimatedWeeks() * 2400) + ($issue->getEstimatedDays() * 480) + (($issue->getEstimatedHours())*60) + $issue->getEstimatedMinutes(); | |
} | |
return $this->json($activities); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment