Skip to content

Commit 75a3822

Browse files
committed
Show comments when editing documents
1 parent ad117d9 commit 75a3822

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

src/controllers/Document/Edit.php

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BNETDocs\Controllers\Document;
44

55
use \BNETDocs\Libraries\Authentication;
6+
use \BNETDocs\Libraries\Comment;
67
use \BNETDocs\Libraries\Document;
78
use \BNETDocs\Libraries\EventTypes;
89
use \BNETDocs\Libraries\Exceptions\DocumentNotFoundException;
@@ -46,6 +47,11 @@ public function &run(Router &$router, View &$view, array &$args) {
4647
} else {
4748
$flags = $model->document->getOptionsBitmask();
4849

50+
$model->comments = Comment::getAll(
51+
Comment::PARENT_TYPE_DOCUMENT,
52+
$model->document_id
53+
);
54+
4955
$model->content = $model->document->getContent(false);
5056
$model->markdown = ($flags & Document::OPTION_MARKDOWN);
5157
$model->published = ($flags & Document::OPTION_PUBLISHED);

src/templates/Comment/Section.inc.phtml

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
22
namespace BNETDocs\Templates\Comment;
3+
use \BNETDocs\Libraries\Authentication;
34
use \BNETDocs\Libraries\Comment;
45
use \BNETDocs\Libraries\User;
56
use \CarlBennett\MVC\Libraries\Common;
6-
$c_edit_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
7-
$c_delete_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
7+
$active_user = $this->getContext()->active_user ?? Authentication::$user;
8+
$active_user_id = ($active_user ? $active_user->getId() : null);
9+
$c_edit_visible_admin = ($active_user && ($active_user->getOptionsBitmask() & User::OPTION_ACL_COMMENT_MODIFY));
10+
$c_delete_visible_admin = ($active_user && ($active_user->getOptionsBitmask() & User::OPTION_ACL_COMMENT_DELETE));
811
?>
912
<div class="row mt-3">
1013
<div class="col">
@@ -25,8 +28,8 @@ $c_delete_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User
2528

2629
$c_user_string = ($c_user ? sprintf('<a href="%s"><img src="%s"/> %s</a>', $c_user_url, $c_user_avatar, $c_user_name) : $c_user_name);
2730

28-
$c_edit_visible = ($c_user_id == $logged_in_id || $c_edit_visible_admin);
29-
$c_delete_visible = ($c_user_id == $logged_in_id || $c_delete_visible_admin); ?>
31+
$c_edit_visible = ($c_user_id == $active_user_id || $c_edit_visible_admin);
32+
$c_delete_visible = ($c_user_id == $active_user_id || $c_delete_visible_admin); ?>
3033
<tr><td>
3134
<?=$c_user_string?><br/>
3235
<time datetime="<?=$c_created_dt->format('c')?>"><?=$c_created_dt->format('D M j, Y g:ia T')?></time>
@@ -43,13 +46,13 @@ $c_delete_visible_admin = ($logged_in && ($logged_in->getOptionsBitmask() & User
4346
<? } ?>
4447
</div>
4548
</div>
46-
<? if ($logged_in) { ?>
49+
<? if ($active_user) { ?>
4750
<div class="row mt-3">
4851
<div class="col-2"></div>
4952
<div class="col-8">
5053
<form method="POST" action="<?=Common::relativeUrlToAbsolute('/comment/create')?>">
5154
<input type="hidden" name="parent_type" value="<?=$comment_parent_type?>"/>
52-
<input type="hidden" name="parent_id" value="<?=$object_id?>"/>
55+
<input type="hidden" name="parent_id" value="<?=$comment_parent_id?>"/>
5356
<div class="form-group">
5457
<label for="comment-content" class="font-weight-bold">Make a Comment:</label>
5558
<textarea id="comment-content" class="border border-secondary form-control bg-dark text-light" name="content"></textarea>

src/templates/Document/Edit.phtml

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
22
namespace BNETDocs\Templates\Document;
3+
use \BNETDocs\Libraries\Comment;
34
use \CarlBennett\MVC\Libraries\Common;
45
use \CarlBennett\MVC\Libraries\Pair;
56
$title = 'Edit Document';
67
$description = 'This form allows an individual to edit a document.';
78
$this->opengraph->attach(new Pair('url', '/document/edit'));
89
$this->opengraph->attach(new Pair('type', 'article'));
10+
$comments = $this->getContext()->comments;
911
$document_id = $this->getContext()->document_id;
1012
$document_url = ($this->getContext()->document ? $this->getContext()->document->getURI() : Common::relativeUrlToAbsolute('/document/' . rawurlencode($document_id)));
1113
$error = $this->getContext()->error;
@@ -27,6 +29,7 @@ require('./header.inc.phtml'); ?>
2729
<p><?=$description?></p>
2830
<? if (is_null($error) || $error == 'NOT_FOUND') {
2931
require('./Document/Form.inc.phtml');
32+
$comment_parent_type = Comment::PARENT_TYPE_DOCUMENT; $comment_parent_id = $document_id; require('./Comment/Section.inc.phtml');
3033
} else if ($error !== false) { ?>
3134
<div class="alert alert-danger">
3235
<p class="mb-0"><?=$message?></p>

src/templates/Document/View.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ require('./header.inc.phtml'); ?>
6060
) : 'Anonymous'
6161
); ?>
6262
</div></div>
63-
<? $comment_parent_type = Comment::PARENT_TYPE_DOCUMENT; require('./Comment/Section.inc.phtml');
63+
<? $comment_parent_type = Comment::PARENT_TYPE_DOCUMENT; $comment_parent_id = $object_id; require('./Comment/Section.inc.phtml');
6464
} else { ?>
6565
<div class="alert alert-danger">
6666
<p><strong><?=filter_var($title, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?></strong></p>

src/templates/MarkdownBootstrapFix.inc.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
/**
55
* Adds CSS classes to Markdown output
66
*/
7-
function MarkdownBootstrapFix(string $v)
7+
function MarkdownBootstrapFix(string $v, bool $sm = false)
88
{
99
// Tables
10-
$v = str_replace('<table>', '<table class="table table-hover table-markdown table-striped">', $v);
10+
$v = str_replace('<table>', '<table class="table table-hover table-markdown ' . ($sm ? 'table-sm ' : '') . 'table-striped">', $v);
1111

1212
// Blockquotes
1313
$v = str_replace('<blockquote>', '<blockquote class="blockquote">', $v);

src/templates/News/View.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ require('./header.inc.phtml'); ?>
8181
<div class="container mb-3">
8282
<?
8383

84-
$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST;
84+
$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST; $comment_parent_id = $object_id;
8585
require("./Comment/Section.inc.phtml");
8686

8787
} else { ?>

src/templates/Packet/View.phtml

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
5454
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
5555
& User::OPTION_ACL_PACKET_DELETE));
5656

57+
require_once('./MarkdownBootstrapFix.inc.php');
5758
require('./header.inc.phtml'); ?>
5859
<div class="container mb-3">
5960
<? if ($object) { ?>
@@ -102,8 +103,8 @@ require('./header.inc.phtml'); ?>
102103
</td></tr>
103104
</tbody></table>
104105

105-
<h2>Remarks</h2>
106-
<div class="container"><? echo $object->getPacketRemarks(true); ?></div>
106+
<h1>Remarks</h1>
107+
<div class="container"><?=\BNETDocs\Templates\MarkdownBootstrapFix($object->getPacketRemarks(true), true)?></div>
107108

108109
<div class="card mt-3"><div class="card-body">
109110
<span class="float-right text-muted">
@@ -118,7 +119,7 @@ require('./header.inc.phtml'); ?>
118119
) : 'Anonymous'
119120
); ?>
120121
</div></div>
121-
<? $comment_parent_type = Comment::PARENT_TYPE_PACKET; require('./Comment/Section.inc.phtml');
122+
<? $comment_parent_type = Comment::PARENT_TYPE_PACKET; $comment_parent_id = $object_id; require('./Comment/Section.inc.phtml');
122123
} else { ?>
123124
<h1 class="text-danger"><?=filter_var($title, FILTER_SANITIZE_STRING)?></h1>
124125
<div class="row"><div class="col"><?=filter_var($description, FILTER_SANITIZE_STRING)?></div></div>

0 commit comments

Comments
 (0)