/** * @ApiDoc( * description = "Return a list of the countries which a user is allowed to see due to his permissions.", * section="Z_DISABLED", * statusCodes = { * 200 = "Returned when the request is without errors", * 403 = "Invalid API KEY", * 404 = "The database has no countries momentarely.", * 500 = "Header x-wsse does not exist" * }, * requirements = { * { * "name" = "_format", * "requirement" = "json|xml" * } * }, * parameters = { * {"name"="client_id", "dataType"="integer", "required"=true, "description"="The client id"}, * } * ) * @return array * @View() */ public function getOptionsCountriesAction(Request $request) { $user = $this->getUser(); $response = new Response(); if (empty($request->get('client_id'))) { $response->setStatusCode(400); $response->setContent(json_encode(array('success' => false, 'message' => 'Client id must be provided in the call.'))); return $response; } $client_id = $request->get('client_id'); $client = $this->getDoctrine()->getRepository('CampaignBundle:Client')->find($client_id); if (!$client) { $response->setStatusCode(400); $response->setContent(json_encode(array('success' => false, 'message' => 'There is no client for that id.'))); return $response; } // $countries = $this->getDoctrine()->getRepository('CampaignBundle:Country')->findAllWithout_temp_country(); $countries = $this->getDoctrine()->getRepository('CampaignBundle:Country')->findAll(); if (!$countries) { $response->setStatusCode(404); $response->setContent(json_encode(array('success' => false, 'message' => 'The database has no countries momentarely.'))); } $total = 0; $countries_array = array(); foreach ($countries as $country) { $can_view = Self::validate_user_can_view_this_country_for_client($user, $client, $country); if ($can_view) { $countries_array[$country->getId()] = $country->getName(); $total++; } if ($total > 0 && $country->getName() == 'temp_country') { $countries_array[$country->getId()] = ucfirst($country->getName()); } } asort($countries_array); $response->setStatusCode(200); $response->setContent(json_encode(array('countries' => $countries_array))); return $response; }