protected function modify(Comment $comment) { $q = $this->dao->prepare('UPDATE T_NEW_commentc SET NCC_fk_NMC = :auteur, NCC_content = :contenu WHERE NCC_id = :id'); $q->bindValue(':auteur', $comment->auteur()); $q->bindValue(':contenu', $comment->contenu()); $q->bindValue(':id', $comment->id(), \PDO::PARAM_INT); $q->execute(); }
protected function modify(Comment $comment) { $q = $this->dao->prepare('UPDATE comments SET auteur = :auteur, contenu = :contenu WHERE id = :id'); $q->bindValue(':auteur', $comment->auteur()); $q->bindValue(':contenu', $comment->contenu()); $q->bindValue(':id', $comment->id(), \PDO::PARAM_INT); $q->execute(); }
/** * Méthode permettant d'enregistrer un commentaire. * @param $comment Le commentaire à enregistrer * @return void */ public function save(Comment $comment) { if ($comment->isValid()) { $comment->isNew() ? $this->add($comment) : $this->modify($comment); } else { throw new \RuntimeException('Le commentaire doit être validé pour être enregistré'); } }
public function executeUpdateCommentUsingAjax(HTTPRequest $Request) { $ManagerComment = $this->managers->getManagerof('Comments'); $Comment = $ManagerComment->getUnique($Request->getData('comment_id')); $Membre = $this->app->user()->getAttribute('user'); $this->page->setTemplate('jsonLayout.php'); if (!$Comment) { $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => 'Le commentaire n\'existe pas !'))); return; } if ($Comment->Membre()->id() != $Membre->id() && $Membre->level() != MemberManager::ADMINISTRATOR) { $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => 'Droits insuffisants'))); return; } $CommentPosted = new Comment(); $CommentPosted->setId($Request->getData('comment_id')); $CommentPosted->setAuteurId($this->app->user()->getAttribute('user')->id()); $CommentPosted->setContenu($Request->postData('contenu')); $FormBuilder = new CommentFormBuilder($CommentPosted); $FormBuilder->build(); $Form = $FormBuilder->form(); // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer). $FormHandler = new \OCFram\FormHandler($Form, $ManagerComment, $Request); if (!$FormHandler->process()) { $errors_a = []; foreach ($Form->fields() as $Field) { $Field->isValid(); $errors_a[$Field->id()] = $Field->errorMessage(); } $this->page->setTemplate('jsonLayout.php'); $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => $errors_a))); return; } $CommentPosted = $ManagerComment->getUnique($CommentPosted->id()); $this->page->addVar('ajax', json_encode(array('success' => true, 'comment' => $CommentPosted))); }
protected function modify(Comment $comment) { $q = $this->dao->prepare('UPDATE t_for_commentc SET FCC_fk_FMC = :auteurId, FCC_content = :contenu, FCC_dateupdate = NOW() WHERE FCC_id = :id'); $q->bindValue(':auteurId', $comment->auteurId(), \PDO::PARAM_INT); $q->bindValue(':contenu', $comment->contenu(), \PDO::PARAM_STR); $q->bindValue(':id', $comment->id(), \PDO::PARAM_INT); $q->execute(); }
<?php require_once '../before.php'; use Entity\Comment; if (isset($_GET['id'])) { $post = $entityManager->getRepository('Entity\\Post')->find($_GET['id']); } if (isset($_POST['submit'])) { $comment = new Comment(); $comment->setMessage($_POST['message']); $comment->setAuthor($user); $comment->setPost($post); $entityManager->persist($comment); $entityManager->flush($comment); } $comments = $entityManager->getRepository('Entity\\Comment')->findBy(array('post' => $post), array('date' => 'ASC')); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Les commentaires</title> </head> <body> <h1><?php echo $post->getSubject(); ?> </h1> <p> <?php
$_SESSION['error'] = "Could not delete the comment."; header('Location: showthread.php?id=' . $_GET['tid']); } } else { $_SESSION['error'] = "You are not allowed to delete comments as anonymous."; header('Location: showthread.php?id=' . $_GET['tid']); } } else { $_SESSION['error'] = "Invalid action."; header('Location: threads.php'); } } else { if (!empty($_POST)) { if ($_POST['action'] == "addcomment") { $post = $em->find('Entity\\Post', intval($_POST['comment_tid'])); $comment = new Comment(); $comment->setMessage($_POST['comment_message']); $comment->setPost($post); $comment->setDate(new DateTime()); if ($userLoggedIn) { $comment->setAuthor($user); } else { $anon = $em->getRepository('Entity\\User')->find(1); $comment->setAuthor($anon); } $em->persist($comment); $em->flush(); $_SESSION['success'] = "Comment added."; header('Location: showthread.php?id=' . $_POST['comment_tid']); } else { $_SESSION['error'] = "Invalid action.";