/** * Commend a comment * * @param Request $request * @return Response (JSON) */ public function up(Request $request, Comment $comment) { $address = request()->ip(); foreach ($this->commentVotes->forComment($comment) as $vote) { if ($vote->address === $address) { return response()->json(['votes' => $comment->voteCount, 'error' => 'This IP Address has already commended this comment']); } } $vote = new CommentVote(); $vote->address = $address; $vote->comment_id = $comment->id; $vote->save(); $comment->voteCount = $comment->voteCount + 1; $comment->save(); return response()->json(['votes' => $comment->voteCount]); }
protected function createComponentTable() { $adminControl = new RouteItemsControl($this->commentRepository, $this->getExtendedPage()); $admin = $adminControl->getTable(); $table = $admin->getTable(); $table->setModel(new Doctrine($this->commentRepository->createQueryBuilder('a')->andWhere('a.extendedPage = :page')->setParameter('page', $this->extendedPage->id))); $repository = $this->commentRepository; $entity = $this->extendedPage; $form = $admin->createForm($this->commentFormFactory, 'Comment', function () use($repository, $entity) { return $repository->createNew(array($entity)); }, \CmsModule\Components\Table\Form::TYPE_FULL); $admin->connectFormWithAction($form, $table->getAction('edit'), $admin::MODE_PLACE); // Toolbar $toolbar = $admin->getNavbar(); $toolbar->addSection('new', 'Create', 'file'); $admin->connectFormWithNavbar($form, $toolbar->getSection('new'), $admin::MODE_PLACE); $table->addAction('delete', 'Delete')->getElementPrototype()->class[] = 'ajax'; $admin->connectActionAsDelete($table->getAction('delete')); return $adminControl; }
<?php namespace Fire\Model\Comment; add_action('fire/services/core', function ($fire) { $fire->singleton('comment.repository', function ($fire) { $repo = new CommentRepository(); $repo->registerEntityMapper(function () use($fire) { return new CommentEntityMapper($fire['post.repository'], $fire['comment.repository'], $fire['user.repository'], $fire['comment.repository']); }); return $repo; }); });
<?php namespace sql_nd_3\DDD; require_once "Comment.php"; require_once "CommentRepository.php"; require_once "TopicRepository.php"; $commentRepository = new CommentRepository(); $topicRepository = new TopicRepository(); $bla = "blablablabla"; $comment = new Comment(); $comment->setAuthor('Author' . rand(0, 1000)); $comment->setTopicID($topicRepository->getRandomId()); $comment->setComment(substr($bla, 0, rand(12, strlen($bla)))); $commentRepository->saveComment($comment); echo "<div>" . $comment->getTopicID() . "</div>"; echo "<div>" . $comment->getAuthor() . "</div>"; echo "<div>" . $comment->getComment() . "</div>";
<?php namespace sql_nd_3\DDD; include_once 'CommentRepository.php'; include_once 'TopicRepository.php'; $topicRepository = new TopicRepository(); $commentRepository = new CommentRepository(); $topics = $topicRepository->getAll(); echo "<h1> Topics </h1>"; echo "<ul>"; foreach ($topics as $topic) { echo "<li>"; echo "<b>ID:</b>" . $topic->getId() . " "; echo "<b>Name:</b>" . $topic->getName() . " "; echo "<b>Post Date:</b>" . $topic->getPostDate() . " "; echo "<b>Comment Count:</b>" . $topic->getCommentCount() . " "; echo "<h4> Comments: </h4>"; echo "<ul>"; $comments = $commentRepository->getAllByTopicId($topic->getId()); foreach ($comments as $comment) { echo "<li>"; echo "<b>ID:</b>" . $comment->getId() . " "; echo "<b>Author:</b>" . $comment->getAuthor() . " "; echo "<b>Date commented:</b>" . $comment->getDate() . " "; echo "<div>" . $comment->getComment() . "</div>"; echo "</li>"; echo "<br>"; } echo "</ul>"; echo "</li>";
/** * List comments. * * @return Response */ public function index() { $comments = $this->commentRepository->getUserComments(); return view('Front::comment.comments', ['comments' => $comments]); }
<?php include_once "../databaseWrapper.php"; include_once "CommentRepository.php"; include_once "TemaRepository.php"; include_once "display.php"; $dbWrapper = new DatabaseWrapper(); $connection = $dbWrapper->getConnection(); $temaRepository = new TemaRepository($connection); $commenRtepository = new CommentRepository($connection); $items = []; foreach ($temaRepository->getAll() as $tema) { $comments = $commenRtepository->getAllBySubjectId($tema->getId()); foreach ($comments as $comment) { $tema->setComments($comment); } $items[] = $tema; } display($items);
<?php /** * Created by PhpStorm. * User: Andriuss * Date: 11/22/2015 * Time: 2:54 PM */ namespace SQL3; include_once 'CommentRepository.php'; include_once 'ForumRepository.php'; $forumrep = new ForumRepository(); $commentrep = new CommentRepository(); $forums = $forumrep->getAll(); echo "<h1> Forums </h1>"; echo "<ul>"; foreach ($forums as $forum) { echo "<li>"; echo "<b>ID:</b>" . $forum->getId() . " "; echo "<b>Name:</b>" . $forum->getTheme() . " "; echo "<b>Post Date:</b>" . $forum->getDate() . " "; echo "<b>Comment Count:</b>" . $forum->getCommentCount() . " "; echo "<h4> Comments: </h4>"; echo "<ul>"; $comments = $commentrep->getAllByForumId($forum->getId()); foreach ($comments as $comment) { echo "<li>"; echo "<b>ID:</b>" . $comment->getId() . " "; echo "<b>Author:</b>" . $comment->getAuthor() . " "; echo "<b>Date commented:</b>" . $comment->getDate() . " ";
<?php namespace Akademija\DDD; include_once 'Theme.php'; include_once 'ThemeRepository.php'; include_once 'Comment.php'; include_once 'CommentRepository.php'; include_once 'dbConnection.php'; $db = new dbConnection('localhost', 'root', '', 'akademija-nd'); $db = $db->connect(); $themesRepository = new ThemeRepository($db); $commentsRepository = new CommentRepository($db); $themes = $themesRepository->loadAll(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Domain Driven Design</title> </head> <body> <?php foreach ($themes as $theme) { echo '<b>Tema:</b> ' . $theme->getTitle() . '<br> <b>Data:</b> ' . $theme->getDate() . '<br> <b>Komentaru skaicius:</b> ' . $theme->getCommentCount() . '<br><br>'; echo ' <form action="Add.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="themeId" value="' . $theme->getId() . '"> <b>Vardas:</b><br>
/** * @param Comment $comment */ public function remove(Comment $comment) { $this->repository->remove($comment); }