/** * Méthode permettant de supprimer tous les commentaires liés à une news * @param $news L'identifiant de la news dont les commentaires doivent être supprimés * @return void */ public function save(Tag $tag) { if ($tag->isValid()) { $tag->isNew() ? $this->add($tag) : $this->modify($tag); } else { throw new \RuntimeException('Le commentaire doit être validé pour être enregistré'); } }
public function executeIndex(HTTPRequest $request) { $this->run(); $managers = $this->managers->getManagerOf('Tag'); if ($request->method() == 'POST' && $request->postData('name') != '') { $tag = new Tag(['name' => $request->postData('name')]); $table = TagController::separateTag($tag->name()); var_dump($table); var_dump(count($table)); TagController::saveTag($table, $managers); } else { $tag = new Tag(); } $formBuilder = new TagFormBuilder($tag); // même formbuilder ? $formBuilder->build($managers); $form = $formBuilder->form(); $this->page->addVar('form', $form->createView()); }
public function processForm(HTTPRequest $request) { $this->run(); //manager news $managersNews = $this->managers->getManagerOf('News'); // manager tag $managersTag = $this->managers->getManagerOf('Tag'); if ($request->method() == 'POST') { // Éléménet News $news = new News(['auteur' => $this->app->user()->getAttribute('user'), 'titre' => $request->postData('titre'), 'contenu' => $request->postData('contenu')]); // Élément Tag if ($request->postData('name') != '') { $tag = new Tag(['name' => $request->postData('name')]); $table = NewsController::separateTag($tag->name()); //vraiment ici ? //on sauvegarde tout les tags rentré si ils n'existes pas ! } else { $tag = new Tag(); } if ($request->getExists('id')) { $news->setId($request->getData('id')); $tag = new Tag(); } } else { // L'identifiant de la news est transmis si on veut la modifier if ($request->getExists('id')) { $news = $managersNews->getUnique($request->getData('id')); $text = ''; foreach ($managersTag->getUnique($request->getData('id')) as $value) { $text = $text . ' ' . $value['NTC_name']; } $tag = new Tag(['name' => $text]); if ($news == null) { $this->app->httpResponse()->redirect404(); } } else { $news = new News(); $tag = new Tag(); } } //construction formulaire news $formBuilderNews = new NewsMemberFormBuilder($news); $formBuilderNews->build(); $formNews = $formBuilderNews->form(); $formHandlerNews = new FormHandler($formNews, $managersNews, $request); //Construction formulaire Tag $formBuilderTag = new TagFormBuilder($tag); // même formbuilder ? $formBuilderTag->build($managersTag); $formTag = $formBuilderTag->form(); // manager tagd $managersTagd = $this->managers->getManagerOf('Tagd'); if ($formHandlerNews->process()) { //Refaire proprement le handler pour les tags $this->app->user()->setFlash($news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !'); // récupérer le dernier id de news if ($news->isNew()) { $news->setId($managersNews->getlastid()); } //var_dump($news->id()); NewsController::saveTag($table, $managersTag); foreach ($table as $key => $value) { $idtag = $managersTag->getId($value); $tagd = new Tagd(); $tagd->setIdnew($news->id()); $tagd->setIdtag($idtag); $managersTagd->add($tagd); } $this->app->httpResponse()->redirect($this->app->router()->getBuiltRoute('News', 'index', [])); } $this->page->addVar('formNews', $formNews->createView()); $this->page->addVar('formTag', $formTag->createView()); }
protected function modify(Tag $tag) { $q = $this->dao->prepare('UPDATE T_NEW_tagc SET name = :name WHERE NTC_id = :id'); $q->bindValue(':id', $tag->id()); $q->execute(); }