/** * Gets projectSummaries in an array, loops trough that arrays to make the projects independent and pushed into another array. * @array $partialProjectArray * @param $data * @return type */ public static function buildPartialProjectsFromArray($data) { $partialProjectArray = array(); if (!$data == null) { foreach ($data as $projectData) { $partialProjectArray[] = ProjectFactory::buildPartialProjectFromArray($projectData); } } else { throw new Exception("The base url to Jira REST API, username and/or password in parameters.yml isn't set correctly", 500); } return $partialProjectArray; }
/** * Another HTTP request, this time another url which is given by the controller * @param $url * @return type $sendProjects * * @ApiDoc( * description="http request for the project details", * ) */ public function getProjectDetails($url) { //init curl $curl = curl_init(); //set curl options $curlOptions = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $this->getUsername() . ':' . $this->getPassword(), CURLOPT_URL => $url); //build request curl_setopt_array($curl, $curlOptions); //executerequest $output = curl_exec($curl); //convert result $rawData = json_decode($output, true); //send raw data to projectFactory $sendProjects = ProjectFactory::buildProjectDetailFromArray($rawData); return $sendProjects; }
/** * This method initializes the jiraClient to do two http requests, enrich the objects with eachother and make the project * visible as json * @Route("/projects", name="Projects") * @return encodedObject * * @ApiDoc( * description="projectAction method", * ) */ public function projectAction(Request $request) { $client = $this->initClient(); //Object array with partialProjects $projects = $client->getProjectSummaries(); foreach ($projects as $p) { $id = $p->getId(); $url = $p->getSelf(); //initialize a new http request to get project details $projectDetails = $client->getProjectDetails($url); //initialize a new http request to get project issues $projectIssues = $client->getIssues($id); //make project objects complete ProjectFactory::enrichProject($p, $projectDetails); //enrich issue with project IssueFactory::enrichProjectWithIssue($p, $projectIssues); } $encodedObject = $this->jsonEncoder($projects); return $encodedObject; }