protected function add(Comment $comment)
 {
     $q = $this->dao->prepare('INSERT INTO comments SET news = :news, auteur = :auteur, contenu = :contenu, date = NOW()');
     $q->bindValue(':news', htmlspecialchars($comment->news()), \PDO::PARAM_INT);
     $q->bindValue(':auteur', htmlspecialchars($comment->auteur()));
     $q->bindValue(':contenu', htmlspecialchars($comment->contenu()));
     $q->execute();
     $comment->setId($this->dao->lastInsertId());
 }
 protected function add(Comment $comment)
 {
     if ($comment->email() != null) {
         $q = $this->dao->prepare('INSERT INTO T_NEW_commentc SET NCC_fk_NNC = :news, NCC_auteur = :auteur, NCC_email = :email, NCC_content = :contenu, NCC_date = NOW()');
         $q->bindValue(':email', $comment->email());
     } else {
         $q = $this->dao->prepare('INSERT INTO T_NEW_commentc SET NCC_fk_NNC = :news, NCC_fk_NMC = :auteur, NCC_content = :contenu, NCC_date = NOW()');
     }
     $q->bindValue(':news', $comment->news(), \PDO::PARAM_INT);
     $q->bindValue(':auteur', $comment->auteur());
     $q->bindValue(':contenu', $comment->contenu());
     $q->execute();
     $comment->setId($this->dao->lastInsertId());
 }
Exemple #3
0
 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)));
 }
 public function getUnique($comment_id)
 {
     $sql = 'SELECT *
         FROM t_for_commentc
         INNER JOIN t_for_memberc ON FCC_fk_FMC = FMC_id
         WHERE FCC_id = :comment_id';
     $requete = $this->dao->prepare($sql);
     $requete->bindValue('comment_id', $comment_id, \PDO::PARAM_INT);
     $requete->execute();
     $Comment = new Comment();
     while ($data = $requete->fetch()) {
         $Comment->setAuteurId($data['FCC_fk_FMC']);
         $Comment->setId($data['FCC_id']);
         $Comment->setContenu($data['FCC_content']);
         $Comment->setNewsId($data['FCC_fk_FNC']);
         $Comment->setDateAjout(new \DateTime($data['FCC_dateadd']));
         $Comment->setDateModif(new \DateTime($data['FCC_dateupdate']));
         $Comment->setMembre(new Member(array('login' => $data['FMC_login'], 'id' => $data['FMC_id'])));
     }
     if ($Comment->id()) {
         return $Comment;
     }
     return false;
 }