/**
  * Creates a new Participant model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Participant();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Crée les entrées de la table Participants correspondant aux équipes
  */
 public function run()
 {
     //TODO: à refaire car ca plante si on seed 2 fois car les id de région et de sports sont hardcodés
     $entrees = [["Arthur", "Archambault", 1, 1, 1, 0], ["Beowulf", "Beaulieu", 2, 1, 2, 0], ["Circé", "Charron", 3, 1, 3, 1], ["Donatello", "DeGrandPré", 4, 2, 1, 0], ["Elsa", "Eiffel", 5, 2, 2, 1], ["Francesco", "Funiculaire", 6, 2, 3, 0], ["Ginette", "Gargantua", 7, 3, 1, 1], ["Henri", "Hippocampe", 8, 3, 2, 0], ["Ivan", "Impitoyable", 9, 3, 3, 0], ["Josephte", "Jamboni", 10, 4, 1, 1], ["Kitty", "KitKat", 11, 4, 2, 1], ["Lola", "Lilalou", 12, 4, 3, 1], ["Manon", "Moriarty", 13, 5, 1, 1], ["Norbert", "Nucléaire", 14, 5, 2, 0], ["Osiris", "Orangeraie", 15, 5, 3, 0], ["Patricia", "Pédoncule", 16, 6, 1, 1], ["Quetzal", "Quelconque", 17, 6, 2, 0], ["Rosa", "Rubéole", 18, 6, 3, 1], ["Stephen", "Satan", 19, 1, 1, 0], ["Tarantula", "Tantrique", 20, 2, 2, 1], ["Ursulin", "Ultime Ninja", 21, 3, 3, 0], ["Vanessa", "Velociraptor", 22, 4, 1, 1], ["Waldorf", "Wolfenstein", 23, 5, 2, 0], ["Xanetia", "Xylophage", 24, 6, 3, 1], ["Yannick", "Ytterbium", 25, 1, 4, 0], ["Zaza", "Zébulon", 26, 2, 4, 1]];
     $sports = Sport::all();
     $regions = Region::all();
     Participant::where('equipe', '=', 0)->delete();
     foreach ($entrees as $entree) {
         $participant = new Participant();
         $participant->prenom = $entree[0];
         $participant->nom = $entree[1];
         $participant->numero = $entree[2];
         $participant->region_id = $regions[$entree[3]]->id;
         $participant->sexe = $entree[5];
         $participant->naissance = new DateTime();
         $participant->equipe = false;
         $participant->save();
         $participant->sports()->attach([$sports[$entree[4]]->id]);
     }
 }
 public function save()
 {
     if ($this->validate()) {
         $user = new User();
         $participant = new Participant();
         $user->email = $this->email;
         $user->group = $user::GROUP_PARTICIPANT;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->setUserInactive();
         $user->save(false);
         $participant->user_id = $user->id;
         #TODO: query active konkurs
         $participant->konkurs_id = 1;
         $participant->type = $this->getUserType();
         $participant->name = $this->makeNameForParticipant();
         $participant->smi_name = $this->smi_name;
         $participant->smi_type = $this->smi_type;
         $participant->smi_url = $this->smi_url;
         $participant->smi_editor = $this->smi_editor;
         $participant->smi_periodity = $this->smi_periodity;
         $participant->smi_field = $this->smi_field;
         $participant->smi_area = $this->smi_area;
         $participant->smi_status = $this->smi_status;
         $participant->smi_head = $this->smi_head;
         $participant->smi_jur_address = $this->smi_jur_address;
         $participant->occupation = $this->occupation;
         $participant->post_address = $this->post_address;
         $participant->city_phone = $this->clearPhone($this->city_phone);
         $participant->mobile_phone = $this->clearPhone($this->mobile_phone);
         $participant->save(false);
         $this->id = $participant->id;
         return $participant;
     }
     return false;
 }
 /**
  * Enregistre dans la bd le participant qui vient d'être créé.
  *
  * @return Response
  */
 public function store()
 {
     try {
         $input = Input::all();
         $participant = new Participant();
         $participant->equipe = false;
         $participant->nom = $input['nom'];
         $participant->prenom = $input['prenom'];
         $participant->telephone = $input['telephone'];
         $participant->nom_parent = $input['nom_parent'];
         $participant->numero = $input['numero'];
         $participant->sexe = $input['sexe'];
         $participant->adresse = $input['adresse'];
         $participant->region_id = $input['region_id'];
         //      Création de la date de naissance à partir des valeurs des trois comboboxes
         $anneeNaissance = $input['annee_naissance'] - 1;
         $moisNaissance = $input['mois_naissance'] - 1;
         $jourNaissance = $input['jour_naissance'] - 1;
         if (checkdate($moisNaissance, $jourNaissance, $anneeNaissance)) {
             $dateTest = new DateTime();
             $dateTest->setDate($anneeNaissance, $moisNaissance, $jourNaissance);
             $participant->naissance = $dateTest;
         } else {
             $participant->naissance = "invalide";
         }
         if ($participant->save()) {
             if (is_array(Input::get('sport'))) {
                 //FIXME: si le get plante, le save est déjà fait.
                 $participant->sports()->sync(array_keys(Input::get('sport')));
             } else {
                 $participant->sports()->detach();
             }
             //          Message de confirmation si la sauvegarde a réussi
             return Redirect::action('ParticipantsController@create')->with('status', 'Le partipant a été créé!');
         } else {
             return Redirect::back()->withInput()->withErrors($participant->validationMessages());
         }
     } catch (Exception $e) {
         App:
         abort(404);
     }
 }