Skip to content

Commit d1ef389

Browse files
committed
Show comments when viewing packets
1 parent fda0667 commit d1ef389

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/controllers/Packet/View.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BNETDocs\Controllers\Packet;
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\Exceptions\PacketNotFoundException;
@@ -28,7 +29,7 @@ public function __construct($packet_id) {
2829

2930
public function run(Router &$router) {
3031
$model = new PacketViewModel();
31-
$model->packet_id = $this->packet_id;
32+
$model->packet_id = (int) $this->packet_id;
3233
try {
3334
$model->packet = new Packet($this->packet_id);
3435
} catch (PacketNotFoundException $e) {
@@ -58,6 +59,10 @@ public function run(Router &$router) {
5859
throw new UnspecifiedViewException();
5960
}
6061
if ($model->packet) {
62+
$model->comments = Comment::getAll(
63+
Comment::PARENT_TYPE_PACKET,
64+
$model->packet_id
65+
);
6166
$model->used_by = $this->getUsedBy($model->packet);
6267
} else {
6368
$model->used_by = null;

src/models/Packet/View.php

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

77
class View extends Model {
88

9+
public $comments;
910
public $packet;
11+
public $packet_id;
1012
public $used_by;
1113
public $user_session;
1214

1315
public function __construct() {
1416
parent::__construct();
17+
$this->comments = null;
1518
$this->packet = null;
19+
$this->packet_id = null;
1620
$this->used_by = null;
1721
$this->user_session = null;
1822
}

src/templates/Packet/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()->packet_id;
810
$object = $this->getContext()->packet;
911

@@ -31,6 +33,7 @@ if ($object) {
3133
}
3234

3335
$this->additional_css[] = "/a/packet.css";
36+
$this->additional_css[] = "/a/comments.css";
3437
require("./header.inc.phtml");
3538
?>
3639
<article>
@@ -67,8 +70,21 @@ require("./header.inc.phtml");
6770
<article>
6871
<header>Comments</header>
6972
<section>
70-
<?php require("./NYI.inc.phtml"); ?>
71-
<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>
73+
<?php if (!$comments) { ?>
74+
<p class="center"><em>no one has commented yet.</em></p>
75+
<?php } else { ?>
76+
<table class="comments"><tbody>
77+
<?php foreach ($comments as $c) {
78+
$c_user = $c->getUser();
79+
$c_user_name = $c_user->getName();
80+
$c_user_id = $c->getUserId();
81+
$c_user_url = Common::relativeUrlToAbsolute("/user/" . $c_user_id . "/" . Common::sanitizeForUrl($c_user_name, true));
82+
$c_user_avatar = "https:" . (new Gravatar($c_user->getEmail()))->getUrl(22, "identicon");
83+
?>
84+
<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>
85+
<?php } ?>
86+
</tbody></table>
87+
<?php } ?>
7288
</section>
7389
<?php } else { ?>
7490
<header class="red"><?php echo htmlspecialchars($title, ENT_HTML5, "UTF-8"); ?></header>

0 commit comments

Comments
 (0)