예제 #1
0
 /**
  * @Method({"POST"})
  * @Route(
  *      "/expats_information_load",
  *      name="expats_information_load",
  *      host="{_locale}.{domain}",
  *      defaults={"_locale" = "%locale%", "domain" = "%domain%"},
  *      requirements={"_locale" = "%locale%|en", "domain" = "%domain%"},
  *      condition="request.isXmlHttpRequest()"
  * )
  * @Route(
  *      "/expats_information_load",
  *      name="expats_information_load_default",
  *      host="{domain}",
  *      defaults={"_locale" = "%locale%", "domain" = "%domain%"},
  *      requirements={"domain" = "%domain%"},
  *      condition="request.isXmlHttpRequest()"
  * )
  */
 public function expatsInformationLoadAction(Request $request)
 {
     // I really wanted to see that badass loader! XD
     usleep(250000);
     // ---
     $_translator = $this->get('translator');
     if (!$request->request->has('location') || !is_array($request->request->get('location')) || empty($request->request->get('location'))) {
         return new Response(json_encode(['message' => $_translator->trans('state.expats_information.empty.information')]), 302);
     }
     $categories = [];
     foreach (array_keys($request->request->get('location')) as $category) {
         if (in_array($category, InformationCategory::getInformationCategories(), TRUE)) {
             $categories[] = $category;
         }
     }
     if (!$categories) {
         return new Response(json_encode(['message' => $_translator->trans('state.expats_information.empty.information')]), 302);
     }
     $_manager = $this->getDoctrine()->getManager();
     $information = $_manager->getRepository('AppBundle:Information')->findByCategories($categories);
     if (!$information) {
         $response = ['data' => ['message' => $_translator->trans('state.expats_information.empty.information')], 'code' => 500];
     } else {
         $response = ['data' => ['categories' => Information::getTransformedCategories($information, $_translator), 'locations' => Information::getTransformedLocations($information)], 'code' => 200];
     }
     return new Response(json_encode($response['data']), $response['code']);
 }
예제 #2
0
 /**
  * Add information
  *
  * @param \AppBundle\Entity\Information $information
  * @return InformationCategory
  */
 public function addInformation(\AppBundle\Entity\Information $information)
 {
     $information->setInformationCategory($this);
     $this->information[] = $information;
     return $this;
 }