Skip to content

Commit f638731

Browse files
committed
Show comments when viewing documents
1 parent d1ef389 commit f638731

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/controllers/Document/View.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BNETDocs\Controllers\Document;
44

55
use \BNETDocs\Controllers\Redirect as RedirectController;
6+
use \BNETDocs\Libraries\Comment;
67
use \BNETDocs\Libraries\Common;
78
use \BNETDocs\Libraries\Controller;
89
use \BNETDocs\Libraries\Document;
@@ -27,7 +28,7 @@ public function __construct($document_id) {
2728

2829
public function run(Router &$router) {
2930
$model = new DocumentViewModel();
30-
$model->document_id = $this->document_id;
31+
$model->document_id = (int) $this->document_id;
3132
try {
3233
$model->document = new Document($this->document_id);
3334
} catch (DocumentNotFoundException $e) {
@@ -56,6 +57,12 @@ public function run(Router &$router) {
5657
default:
5758
throw new UnspecifiedViewException();
5859
}
60+
if ($model->document) {
61+
$model->comments = Comment::getAll(
62+
Comment::PARENT_TYPE_DOCUMENT,
63+
$model->document_id
64+
);
65+
}
5966
$model->user_session = UserSession::load($router);
6067
ob_start();
6168
$view->render($model);

src/models/Document/View.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
class View extends Model {
88

9+
public $comments;
910
public $document;
11+
public $document_id;
1012
public $user_session;
1113

1214
public function __construct() {
1315
parent::__construct();
16+
$this->comments = null;
1417
$this->document = null;
18+
$this->document_id = null;
1519
$this->user_session = null;
1620
}
1721

src/templates/Document/View.phtml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
namespace BNETDocs\Templates;
33

44
use \BNETDocs\Libraries\Common;
5+
use \BNETDocs\Libraries\Gravatar;
56
use \BNETDocs\Libraries\Pair;
67

8+
$comments = $this->getContext()->comments;
79
$object_id = $this->getContext()->document_id;
810
$object = $this->getContext()->document;
911

@@ -26,6 +28,7 @@ if ($object) {
2628
}
2729

2830
#$this->additional_css[] = "/a/document.css";
31+
$this->additional_css[] = "/a/comments.css";
2932
require("./header.inc.phtml");
3033
?>
3134
<article>
@@ -41,8 +44,21 @@ require("./header.inc.phtml");
4144
<article>
4245
<header>Comments</header>
4346
<section>
44-
<?php require("./NYI.inc.phtml"); ?>
45-
<p class="center">If you'd like to leave a suggestion or concern, you can do so <a href="https://github.com/BNETDocs/bnetdocs-web/issues/new?labels[]=bnetdocs-phoenix&labels[]=question&body=<?php echo rawurlencode("Hi,\n\n<fill in your question here>\n\nThanks!\n\nReference: " . $url); ?>" rel="external">over on GitHub</a>. Sorry for the trouble!</p>
47+
<?php if (!$comments) { ?>
48+
<p class="center"><em>no one has commented yet.</em></p>
49+
<?php } else { ?>
50+
<table class="comments"><tbody>
51+
<?php foreach ($comments as $c) {
52+
$c_user = $c->getUser();
53+
$c_user_name = $c_user->getName();
54+
$c_user_id = $c->getUserId();
55+
$c_user_url = Common::relativeUrlToAbsolute("/user/" . $c_user_id . "/" . Common::sanitizeForUrl($c_user_name, true));
56+
$c_user_avatar = "https:" . (new Gravatar($c_user->getEmail()))->getUrl(22, "identicon");
57+
?>
58+
<tr><td><a href="<?php echo $c_user_url; ?>"><img class="avatar" src="<?php echo $c_user_avatar; ?>"/> <?php echo htmlspecialchars($c_user_name, ENT_HTML5, "UTF-8"); ?></a><br/><time class="comment_timestamp" datetime="<?php echo $c->getCreatedDateTime()->format("c"); ?>"><?php echo $c->getCreatedDateTime()->format("D M j, Y g:ia T"); ?></time></td><td><?php echo $c->getContent(true); ?></td></tr>
59+
<?php } ?>
60+
</tbody></table>
61+
<?php } ?>
4662
</section>
4763
<?php } else { ?>
4864
<header class="red"><?php echo htmlspecialchars($title, ENT_HTML5, "UTF-8"); ?></header>

src/templates/Packet/View.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ $object = $this->getContext()->packet;
1111

1212
$title = "Packet Not Found";
1313
$description = "The requested packet does not exist or could not be found.";
14-
$description = "The requested packet does not exist or could not be found.";
1514

1615
$this->opengraph->attach(new Pair("type", "article"));
1716

0 commit comments

Comments
 (0)