Пример #1
0
 public function editComment($id)
 {
     $errorModel = new CommentInformation();
     $comment = CommentsRepository::create()->filterById($id)->findOne();
     $commentViewModel = new CommentViewModel($comment->getId(), $comment->getComment(), $comment->getDateTime(), $comment->getAuthorName(), $comment->getUserId());
     $allModels = [];
     $allModels[] = $commentViewModel;
     $allModels[] = $errorModel;
     if (isset($_POST['edit-comment'])) {
         if ($_POST['comment'] == '') {
             $errorModel->error = true;
             return new View($allModels);
         }
         $dateTime = new \DateTime(null, new \DateTimeZone('Europe/Sofia'));
         $stringTime = $dateTime->format('Y-m-d H:i:s');
         $comment->setComment($_POST['comment'])->setDateTime($stringTime);
         $result = CommentsRepository::save();
         if ($result) {
             $commentViewModel->setComment($_POST['comment']);
             $errorModel->success = true;
             return new View($allModels);
         }
         $errorModel->success = true;
         return new View($errorModel);
     }
     return new View($allModels);
 }
Пример #2
0
 /**
  * @param CommentViewModel $model
  * @throws \Exception
  */
 private static function update(CommentViewModel $model)
 {
     $db = Database::getInstance('app');
     $query = "UPDATE comments SET comment_text = ?, date_time = ? WHERE id = ?";
     $result = $db->prepare($query);
     $result->execute([$model->getComment(), $model->getDateTime(), $model->getId()]);
 }