public function getMilestoneRepresentation(Planning_Milestone $milestone, PFUser $user) { $milestone_representation = new MilestoneRepresentation(); $milestone_representation->build($milestone, $this->milestone_factory->getMilestoneStatusCount($user, $milestone), $this->getBacklogTrackers($milestone), $this->milestone_factory->userCanChangePrioritiesInMilestone($milestone, $user)); $this->event_manager->processEvent(AGILEDASHBOARD_EVENT_REST_GET_MILESTONE, array('version' => 'v1', 'user' => $user, 'milestone' => $milestone, 'milestone_representation' => &$milestone_representation)); return $milestone_representation; }
/** * Get the top milestones of a given project */ public function get(PFUser $user, $project, $limit, $offset, $order) { if (!$this->limitValueIsAcceptable($limit)) { throw new RestException(406, 'Maximum value for limit exceeded'); } $all_milestones = $this->getTopMilestones($user, $project); if ($order === 'desc') { $all_milestones = array_reverse($all_milestones); } $milestones = array_slice($all_milestones, $offset, $limit); $milestone_representations = array(); foreach ($milestones as $milestone) { $milestone_representation = new MilestoneRepresentation(); $milestone_representation->build($milestone, $this->milestone_factory->getMilestoneStatusCount($user, $milestone), $this->getBacklogTrackers($milestone), $this->milestone_factory->userCanChangePrioritiesInMilestone($milestone, $user)); $milestone_representations[] = $milestone_representation; } $this->sendAllowHeaders(); $this->sendPaginationHeaders($limit, $offset, count($all_milestones)); return $milestone_representations; }
/** * Get sub-milestones * * Get the sub-milestones of a given milestone. * A sub-milestone is a decomposition of a milestone (for instance a Release has Sprints as submilestones) * * @url GET {id}/milestones * @access hybrid * * @param int $id Id of the milestone * @param string $order In which order milestones are fetched. Default is asc {@from path}{@choice asc,desc} * * @return Array {@type Tuleap\AgileDashboard\REST\v1\MilestoneRepresentation} * * @throws 403 * @throws 404 */ public function getMilestones($id, $order = 'asc') { $this->checkAccess(); $user = $this->getCurrentUser(); $milestone = $this->getMilestoneById($user, $id); $this->sendAllowHeaderForSubmilestones(); $event_manager = $this->event_manager; $milestone_factory = $this->milestone_factory; $strategy_factory = $this->backlog_strategy_factory; $milestones = array_map(function (Planning_Milestone $milestone) use($user, $event_manager, $milestone_factory, $strategy_factory) { $milestone_representation = new MilestoneRepresentation(); $milestone_representation->build($milestone, $milestone_factory->getMilestoneStatusCount($user, $milestone), $strategy_factory->getBacklogStrategy($milestone)->getDescendantTrackers(), $milestone_factory->userCanChangePrioritiesInMilestone($milestone, $user)); $event_manager->processEvent(AGILEDASHBOARD_EVENT_REST_GET_MILESTONE, array('user' => $user, 'milestone' => $milestone, 'milestone_representation' => &$milestone_representation, 'version' => 'v1')); return $milestone_representation; }, $this->milestone_factory->getSubMilestones($user, $milestone)); if ($order === 'desc') { return array_reverse($milestones); } return $milestones; }