SHARE
TWEET

Symfony 4 Code - Metr0me

a guest Mar 26th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected function execute(InputInterface $input, OutputInterface $output) {
  2.         for ($jour = 0; $jour <= 7; $jour++) {
  3.             $futureDay = date('Y-m-d', strtotime('+'.$jour.' days'));
  4.            
  5.             $curl = curl_init();
  6.  
  7.             curl_setopt_array($curl, array(
  8.                 CURLOPT_URL => "https://api.mapado.net/v2/activities?fields=@id,title,shortDate,nextDate,activityType,locale,description,address&itemsPerPage=1000&when=".$futureDay."&periodOfDay=evening",
  9.                 CURLOPT_RETURNTRANSFER => true,
  10.                 CURLOPT_ENCODING => "",
  11.                 CURLOPT_MAXREDIRS => 10,
  12.                 CURLOPT_TIMEOUT => 30,
  13.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  14.                 CURLOPT_CUSTOMREQUEST => "GET",
  15.                 CURLOPT_HTTPHEADER => array(
  16.                     "Authorization: Bearer MTMwZWJiODFiZjA4YTcyOGY2ZmMzMGYwOTQyYWM2NDZjODVlNDg1MzU0MzE3M2I4MTdiMDQyZjU5MDVkZjFjZA",
  17.                     "Cache-Control: no-cache",
  18.                     "Conent-Type: application/json",
  19.                     "Content-Type: application/x-www-form-urlencoded",
  20.                     "Postman-Token: 55672a19-0ffc-4fe6-a866-3e15c3df9dae"
  21.                 ),
  22.             ));
  23.  
  24.             $response = curl_exec($curl);
  25.             $err = curl_error($curl);
  26.  
  27.             $mapado_events = json_decode($response, JSON_PRETTY_PRINT);
  28.  
  29.             for ($i = 0; $i < count($mapado_events['hydra:member']); $i++) {
  30.  
  31.                 if ($mapado_events['hydra:member'][$i]['locale'] == 'fr') {
  32.  
  33.                     $mapado_id = $mapado_events['hydra:member'][$i]['@id'];
  34.                     $mapado_date = \date('Y-m-d', strtotime($mapado_events['hydra:member'][$i]['nextDate']));
  35.  
  36.                     $result = $this->getContainer()
  37.                         ->get('doctrine')
  38.                         ->getRepository(MapadoIDs::class)
  39.                         ->findOneBy(['mapado_id' => $mapado_id]);
  40.  
  41.                     if ($result == null) {
  42.                         echo 'event existe pas, ajout en bdd'.PHP_EOL;
  43.                         $MapadoIDs = new MapadoIDs();
  44.                         $MapadoIDs->setMapadoId($mapado_id);
  45.                         $this->em->persist($MapadoIDs);
  46.  
  47.                         $mapado = json_decode($response, JSON_PRETTY_PRINT);
  48.  
  49.                         $event = new Event();
  50.  
  51.                         $event->setLongitude($mapado['hydra:member'][$i]['address']['longitude']);
  52.                         $event->setLatitude($mapado['hydra:member'][$i]['address']['latitude']);
  53.                         $event->setTitle($mapado['hydra:member'][$i]['title']);
  54.                         $event->setDate($mapado_date);
  55.                         $event->setFormattedAddress($mapado['hydra:member'][$i]['address']['formattedAddress']);
  56.                         $event->setCity($mapado['hydra:member'][$i]['address']['city']);
  57.                         $event->setLocale($mapado['hydra:member'][$i]['locale']);
  58.                         $event->setActivityType($mapado['hydra:member'][$i]['activityType']);
  59.                         $event->setDescription($mapado['hydra:member'][$i]['description']);
  60.  
  61.                         $this->em->persist($event);                    
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.        
  67.         $this->em->flush();
  68.  
  69.         curl_close($curl);
  70.  
  71.         if ($err) {
  72.             echo "cURL Error #: " . $err;
  73.         } else {
  74.             echo $response;
  75.         }
  76.     }
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top