public function view($id)
 {
     // on recupere en bdd l objet en fonction du profil id
     $profileManager = new ProfileManager();
     $profile = $profileManager->findByUserId($id);
     // echo $profile['created_at'] . '</br>';
     // echo gettype($profile['created_at']) . '</br>';
     // $date = strtotime($profile['created_at']);
     // echo '$date : ' . $date . '</br>';
     // $date = new DateTime('now');
     // echo $date->format('F Y') . '</br>';
     // $date = $profile['created_at'];
     // echo '$date : ' . $date . '</br>';
     // $date = strtotime($date);
     // echo date('F Y', strtotime($profile['created_at']));
     //echo date_format($date, 'F Y') . '</br>';
     //print_r($profile);
     $language_fr = explode(',', $profile['language_fr']);
     $language_en = explode(',', $profile['language_en']);
     $language_es = explode(',', $profile['language_es']);
     $language_it = explode(',', $profile['language_it']);
     $language_de = explode(',', $profile['language_de']);
     $language_pt = explode(',', $profile['language_pt']);
     // $blablarun = 'pas du tout';
     // if ($profile['blablarun'] == 1) {
     // 	$blablarun = 'un peu';
     // }
     // if ($profile['blablarun'] == 2) {
     // 	$blablarun = 'beaucoup';
     // }
     $blablarun = '';
     if ($profile['blablarun'] == 0) {
         $blablarun = 'pas du tout';
     }
     if ($profile['blablarun'] == 1) {
         $blablarun = 'un peu';
     }
     if ($profile['blablarun'] == 2) {
         $blablarun = 'beaucoup';
     }
     switch ($profile['time_10km']) {
         case 0:
             $profile['time_10km'] = 'non renseigné';
             break;
         case 1:
             $profile['time_10km'] = '-35min';
             break;
         case 2:
             $profile['time_10km'] = 'entre 35 et 40min';
             break;
         case 3:
             $profile['time_10km'] = 'entre 40 et 50min';
             break;
         case 4:
             $profile['time_10km'] = 'entre 50min et 1h';
             break;
         case 5:
             $profile['time_10km'] = 'entre minuit et 1h';
             break;
         case 6:
             $profile['time_10km'] = 'entre 1h et 1h10 min';
             break;
         case 7:
             $profile['time_10km'] = 'entre 1h10 et 1h20 min';
             break;
         case 8:
             $profile['time_10km'] = '+1h20 min';
             break;
     }
     switch ($profile['time_20km']) {
         case 0:
             $profile['time_20km'] = 'non renseigné';
             break;
         case 1:
             $profile['time_20km'] = '-1h30';
             break;
         case 2:
             $profile['time_20km'] = 'entre 1h30 et 1h40';
             break;
         case 3:
             $profile['time_20km'] = 'entre 1h40 et 1h50';
             break;
         case 4:
             $profile['time_20km'] = 'entre 1h50 et 2h00';
             break;
         case 5:
             $profile['time_20km'] = 'entre 2h00 et 2h10';
             break;
         case 6:
             $profile['time_20km'] = 'entre 2h10 et 2h20';
             break;
         case 7:
             $profile['time_20km'] = 'entre 2h20 et 2h30';
             break;
         case 8:
             $profile['time_20km'] = '+2h30 min';
             break;
     }
     switch ($profile['time_half']) {
         case 0:
             $profile['time_half'] = 'non renseigné';
             break;
         case 1:
             $profile['time_half'] = '-1h30';
             break;
         case 2:
             $profile['time_half'] = 'entre 1h30 et 1h40';
             break;
         case 3:
             $profile['time_half'] = 'entre 1h40 et 1h50';
             break;
         case 4:
             $profile['time_half'] = 'entre 1h50 et 2h00';
             break;
         case 5:
             $profile['time_half'] = 'entre 2h00 et 2h10';
             break;
         case 6:
             $profile['time_half'] = 'entre 2h10 et 2h20';
             break;
         case 7:
             $profile['time_half'] = 'entre 2h20 et 2h30';
             break;
         case 8:
             $profile['time_half'] = '+2h30 min';
             break;
     }
     switch ($profile['time_marathon']) {
         case 0:
             $profile['time_marathon'] = 'non renseigné';
             break;
         case 1:
             $profile['time_marathon'] = '-3h00';
             break;
         case 2:
             $profile['time_marathon'] = 'entre 3h00 et 3h20';
             break;
         case 3:
             $profile['time_marathon'] = 'entre 3h20 et 3h40';
             break;
         case 4:
             $profile['time_marathon'] = 'entre 3h40 et 4h00';
             break;
         case 5:
             $profile['time_marathon'] = 'entre 4h20 et 4h40';
             break;
         case 6:
             $profile['time_marathon'] = 'entre 4h40 et 5h00';
             break;
         case 7:
             $profile['time_marathon'] = 'entre 5h00 et 5h20';
             break;
         case 8:
             $profile['time_marathon'] = '+5h20';
             break;
     }
     $this->show('profile/view', ['profile' => $profile, 'language_fr' => $language_fr, 'language_en' => $language_en, 'language_es' => $language_es, 'language_it' => $language_it, 'language_de' => $language_de, 'language_pt' => $language_pt, 'blablarun' => $blablarun]);
 }
 public function updateProfileSubmit()
 {
     // Affecter une variable à chaque valeur clé de $_POST (sauf profile_picture)
     $firstname = trim(htmlentities($_POST['firstname']));
     $lastname = trim(htmlentities($_POST['lastname']));
     $gender = trim(htmlentities($_POST['gender']));
     $home_town = trim(htmlentities($_POST['home_town']));
     $home_country = trim(htmlentities($_POST['home_country']));
     $description = trim(htmlentities($_POST['description']));
     $blablarun = $_POST['blablarun'];
     $language_fr = $_POST['language_fr'];
     $language_en = $_POST['language_en'];
     $language_es = $_POST['language_es'];
     $language_it = $_POST['language_it'];
     $language_de = $_POST['language_de'];
     $language_pt = $_POST['language_pt'];
     $time_10km = trim(htmlentities($_POST['time_10km']));
     $time_20km = trim(htmlentities($_POST['time_20km']));
     $time_half = trim(htmlentities($_POST['time_half']));
     $time_marathon = trim(htmlentities($_POST['time_marathon']));
     // Initialisation d'un tableau d'erreurs (associatif)
     $errors = [];
     // recuperation de l user en session
     $userId = $this->getUser();
     //debug($userId);
     // Instanciation d'un object de type UserManager
     $profileManager = new ProfileManager();
     $profile = $profileManager->findByUserId($userId['id']);
     //
     $profile_picture = $profile['profile_picture'];
     // debug($_FILES);
     // die;
     // verif si un objet va etre uploadé
     if (isset($_FILES)) {
         $uploadFileName = $_FILES['profile_picture']['name'];
         $uploadFileType = $_FILES['profile_picture']['type'];
         $uploadFileSize = $_FILES['profile_picture']['size'];
         if (!strstr($uploadFileType, 'jpg') && !strstr($uploadFileType, 'jpeg') && !strstr($uploadFileType, 'gif') && !strstr($uploadFileType, 'png')) {
             $errors['profile_picture'] = "ERREUR - Le fichier n'est pas une image au format web";
         } elseif ($uploadFileSize > 10000000) {
             $errors['profile_picture'] = "ERREUR - Le fichier dépasse le poids max";
         } elseif (move_uploaded_file($_FILES['profile_picture']['tmp_name'], __DIR__ . '/../../uploads/' . $_FILES['profile_picture']['name'])) {
             $errors['profile_picture'] = "Votre image a bien été chargé !";
             $profile_picture = $_FILES['profile_picture']['name'];
         } else {
             $errors['profile_picture'] = "ERREUR - Votre image n'a pas été uploadé correctement";
         }
     }
     // debug($_FILES);
     // debug($errors);
     // echo $profile_picture;
     // objet datetime
     $date = new DateTime();
     // si le profil existe, on le met a jour
     if ($profile) {
         $resultProfile = $profileManager->update(['profile_picture' => $profile_picture, 'firstname' => $firstname, 'lastname' => $lastname, 'gender' => $gender, 'home_town' => $home_town, 'home_country' => $home_country, 'description' => $description, 'blablarun' => $blablarun, 'language_fr' => $language_fr, 'language_en' => $language_en, 'language_es' => $language_es, 'language_it' => $language_it, 'language_de' => $language_de, 'language_pt' => $language_pt, 'time_10km' => $time_10km, 'time_20km' => $time_20km, 'time_half' => $time_half, 'time_marathon' => $time_marathon, 'updated_at' => $date->format('Y-m-d H:i:s'), 'user_id' => $userId['id']], $profile['id']);
     } else {
         $resultProfile = $profileManager->insert(['profile_picture' => $profile_picture, 'firstname' => $firstname, 'lastname' => $lastname, 'gender' => $gender, 'home_town' => $home_town, 'home_country' => $home_country, 'description' => $description, 'blablarun' => $blablarun, 'language_fr' => $language_fr, 'language_en' => $language_en, 'language_es' => $language_es, 'language_it' => $language_it, 'language_de' => $language_de, 'language_pt' => $language_pt, 'time_10km' => $time_10km, 'time_20km' => $time_20km, 'time_half' => $time_half, 'time_marathon' => $time_marathon, 'created_at' => $date->format('Y-m-d H:i:s'), 'updated_at' => $date->format('Y-m-d H:i:s'), 'user_id' => $userId['id']]);
     }
     // Check ma soumission du formulaire
     if (isset($_POST['action'])) {
         echo "<pre>";
         print_r($_POST);
         echo "</pre>";
         echo "<pre>";
         print_r($_FILES);
         echo "</pre>";
         // 1. Faire un echo de la taille du fichier envoyer
         echo "Le poids du fichier est :" . $_FILES['profile_picture']['size'];
         // 2. Afficher le type de l'image
         echo "Le type d'image est :" . $_FILES['profile_picture']['type'];
         // 4. Checker le type de fichier d'image
         // 5.
         $uploadFileName = $_FILES['profile_picture']['name'];
         $uploadFileType = $_FILES['profile_picture']['type'];
         $uploadFileSize = $_FILES['profile_picture']['size'];
         if (!strstr($uploadFileType, 'jpg') && !strstr($uploadFileType, 'jpeg') && !strstr($uploadFileType, 'gif')) {
             echo "ERREUR - Le fichier n'est pas une image au format web";
         } elseif ($uploadFileSize > 10000000) {
             echo "ERREUR - Le fichier dépasse le poids max";
         } elseif (move_uploaded_file($_FILES['profile_picture']['tmp_name'], './img/' . $_FILES['profile_picture']['name'])) {
             echo "Votre image a bien été chargé !";
         } else {
             echo "ERREUR - Votre image n'a pas été uploadé correctement";
         }
     }
     if ($resultProfile) {
         $_SESSION['message'] = "Vos modifications ont bien été enregistrées.";
         // $this->redirectToRoute('viewProfile', ['id' => $resultProfile['id']]);
         $this->redirectToRoute('viewProfile', ['id' => $userId['id']]);
     } else {
         $_SESSION['error'] = "Une erreur est intervenue. Vos mises à jour n'ont pas été enregistrées.";
     }
     $this->show('profile/updateProfile', ['errors' => $errors]);
     //$this->redirectToRoute('viewProfile', ['id' => $resultProfile['id'],'success' => $success, 'errors' => $errors]);
 }