本文整理汇总了PHP中Self::validate_user_can_view_this_country_for_client方法的典型用法代码示例。如果您正苦于以下问题:PHP Self::validate_user_can_view_this_country_for_client方法的具体用法?PHP Self::validate_user_can_view_this_country_for_client怎么用?PHP Self::validate_user_can_view_this_country_for_client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Self
的用法示例。
在下文中一共展示了Self::validate_user_can_view_this_country_for_client方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptionsCountriesAction
/**
* @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;
}