public function editAction() { //on charge le model de formation $maFormationSession = App::getModel('FormationSession'); //crée la liste des matières via une collection $collection = App::getCollection('Formation'); $collection->select(); $coll_for = $collection->getItems(); if (isset($_GET['id'])) { $maFormationSession->load($_GET['id']); } if (isset($_POST['submit'])) { //Si id existe et n'est pas vide, on modifie if (isset($_POST['id']) && !empty($_POST['id'])) { $maFormationSession->store(array('id' => $_POST['id'])); } else { //sinon c'est une création $maFormationSession->store(array('id' => 0)); } $maFormationSession->store(array('begin_date' => $_POST['begin_date'], 'ending_date' => $_POST['ending_date'], 'formations_id' => $_POST['formations'])); //on appelle la méthode qui stock les infos dans l'objet crée $maFormationSession->save(); //Formation et les réf pedago lié sont crée, on retoure au listing header("Location: index.php?c=FormationSession"); } //On transmet via setDatas() la collection de formation dans un tableau associatif Template::getInstance()->setFileName("FormationSession/edit_formationsession")->setDatas(array('maFormationSession' => $maFormationSession, 'coll_for' => $coll_for))->render(); }
public function editAction() { //on charge le model de formation $maFormation = App::getModel('Formation'); //crée la liste des matières via une collection $collection = App::getCollection('Matter'); $collection->select(); $coll_matter = $collection->getItems(); if (isset($_GET['id'])) { $maFormation->load($_GET['id']); } if (isset($_POST['submit'])) { //Si id existe et n'est pas vide, on modifie if (isset($_POST['id']) && !empty($_POST['id'])) { $maFormation->store(array('id' => $_POST['id'])); } else { //sinon c'est une création $maFormation->store(array('id' => 0)); } $maFormation->store(array('title' => $_POST['title'], 'average_effective' => $_POST['average_effective'], 'convention_hour_center' => $_POST['convention_hour_center'], 'convention_hour_company' => $_POST['convention_hour_company'], 'deal_code' => $_POST['deal_code'], 'order_giver' => $_POST['order_giver'], 'deal_begin_date' => $_POST['deal_begin_date'], 'deal_ending_date' => $_POST['deal_ending_date'])); //on appelle la méthode qui stock les infos dans l'objet crée $maFormation->save(); //On prépare la sauvegardes des references pedagogique lié a la formation for ($i = 0; $i < count($_POST['matters']); $i++) { //on crée un model de refpedago $ref = App::getModel('RefPedago'); //on store l'ID de la formation qui vien d'être crée et l'ID de la matière courante $ref->store(array('formations_id' => $maFormation->getData('id'), 'matters_id' => $_POST['matters'][$i])); //On sauvegarde dans la bdd la réf pedago une fois initialisé $ref->save(); } //Formation et les réf pedago lié sont crée, on retoure au listing header("Location: index.php?c=Formation"); } //On transmet via setDatas() la collection de formation dans un tableau associatif Template::getInstance()->setFileName("Formation/edit_formations")->setDatas(array('maFormation' => $maFormation, 'coll_matter' => $coll_matter))->render(); }