<?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>";