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; }