Skip to content

Commit 7f4467f

Browse files
authored
Merge pull request #603 from topcoder-platform/issues-533
Issues-533: Added Posts Count/Comments Count, Issues-535
2 parents 62ef0d7 + 293e0d3 commit 7f4467f

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function dateUpdated($row, $wrap = null) {
305305

306306
if ($dateUpdated) {
307307
$updateUser = Gdn::userModel()->getID($updateUserID);
308-
$dateUpdatedFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($dateUpdated, false, DateTimeFormatter::FORCE_FULL_FORMAT);
308+
$dateUpdatedFormatted = formatDateCustom($dateUpdated, false);
309309
if ($updateUser && $insertUserID != $updateUserID) {
310310
$title = sprintf(t('Edited %s by %s.'), $dateUpdatedFormatted, val('Name', $updateUser));
311311
$link = userAnchor($updateUser);
@@ -987,4 +987,20 @@ function discussionUrl($discussion, $page = '', $withDomain = true) {
987987

988988
return url($result, $withDomain);
989989
}
990-
}
990+
}
991+
992+
if (!function_exists('formatDateCustom')) {
993+
function formatDateCustom($timestamp, $showDayOfWeek=true) {
994+
$dateFormat = $showDayOfWeek? '%a, %b %e, %Y': '%b %e, %Y';
995+
$dateFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($timestamp, false, $dateFormat);
996+
$timeFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($timestamp, false, '%I:%M %p');
997+
return sprintf('%1$s at %2$s', $dateFormatted, $timeFormatted);
998+
}
999+
}
1000+
if (!function_exists('authorProfileStats')) {
1001+
function authorProfileStats($user) {
1002+
$countDiscussions = plural( $user->CountDiscussions, '%s Post', '%s Posts');
1003+
$countComments = plural( $user->CountComments, '%s Comment', '%s Comments');
1004+
return '<span class="MItem AuthorProfileStats AuthorProfileStats_'.$user->UserID.'">'.sprintf('%1s %2s', $countDiscussions,$countComments).'</span>';
1005+
}
1006+
}

vanilla/applications/vanilla/controllers/class.discussioncontroller.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,11 @@ public function delete($discussionID, $target = '') {
794794
}
795795

796796
$this->jsonTarget(".Section-DiscussionList #Discussion_$discussionID", null, 'SlideUp');
797+
// FIX: https://github.com/topcoder-platform/forums/issues/533
798+
$insertUserID = val('InsertUserID',$discussion);
799+
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
800+
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');
801+
797802
}
798803
}
799804

@@ -820,10 +825,11 @@ public function deleteComment($commentID = '', $transientKey = '') {
820825
$defaultTarget = '/discussions/';
821826
$validCommentID = is_numeric($commentID) && $commentID > 0;
822827
$validUser = $session->UserID > 0 && $session->validateTransientKey($transientKey);
823-
828+
$insertUserID = false;
824829
if ($validCommentID && $validUser) {
825830
// Get comment and discussion data
826831
$comment = $this->CommentModel->getID($commentID);
832+
$insertUserID = $comment->InsertUserID;
827833
$discussionID = val('DiscussionID', $comment);
828834
$discussion = $this->DiscussionModel->getID($discussionID);
829835

@@ -868,6 +874,9 @@ public function deleteComment($commentID = '', $transientKey = '') {
868874
$this->setJson('ErrorMessage', $this->Form->errors());
869875
} else {
870876
$this->jsonTarget("#Comment_$commentID", '', 'SlideUp');
877+
// FIX: https://github.com/topcoder-platform/forums/issues/533
878+
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
879+
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');
871880
}
872881

873882
$this->render();

vanilla/applications/vanilla/controllers/class.postcontroller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,13 @@ public function comment($DiscussionID = '') {
917917
$this->ClassName = 'DiscussionController';
918918
$this->ControllerName = 'discussion';
919919
$this->View = 'comments';
920+
921+
// FIX: https://github.com/topcoder-platform/forums/issues/533
922+
$comment = $this->CommentModel->getID($CommentID);
923+
$insertUserID = val('InsertUserID',$comment);
924+
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
925+
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');
926+
920927
// }
921928

922929
// Make sure to set the user's discussion watch records

vanilla/applications/vanilla/js/post.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,41 @@ jQuery(document).ready(function($) {
101101

102102
// Handler before submitting
103103
$(frm).triggerHandler('BeforeDiscussionSubmit', [frm, btn]);
104+
var maxCommentLength = $(frm).find('input:hidden[name$=MaxCommentLength]');
105+
var defaultValues = [
106+
undefined,
107+
null,
108+
'',
109+
'[{\"insert\":\"\\n\"}]'
110+
];
111+
112+
var editorContainer = $(frm).find('.EasyMDEContainer');
113+
var messageContainer = $(frm).find('.editor-statusbar .message');
114+
var textbox = $(frm).find('textarea#Form_Body');
115+
var currentVal = $(textbox).val();
116+
currentVal = gdn.normalizeText(currentVal);
117+
if(defaultValues.includes(currentVal) || currentVal.trim().length == 0) {
118+
$(editorContainer).addClass('error');
119+
$(messageContainer).text('Cannot post an empty message');
120+
$(frm).find(':submit').attr('disabled', 'disabled');
121+
$(frm).find('.Buttons a.Button:not(.Cancel)').addClass('Disabled');
122+
return false;
123+
}
124+
125+
if(currentVal.length > maxCommentLength.val()) {
126+
$(editorContainer).addClass('error');
127+
var count = currentVal.length - maxCommentLength.val();
128+
$(messageContainer).text('Discussion is '+ count +' characters too long');
129+
$(frm).find(':submit').attr('disabled', 'disabled');
130+
$(frm).find('.Buttons a.Button:not(.Cancel)').addClass('Disabled');
131+
return false;
132+
}
133+
134+
$(editorContainer).removeClass('error');
135+
$(messageContainer).text('');
136+
$(frm).find(':submit').removeAttr("disabled");
137+
$(frm).find('.Buttons a.Button').removeClass('Disabled');
138+
104139

105140
var inpDiscussionID = $(frm).find(':hidden[name$=DiscussionID]');
106141
var inpDraftID = $(frm).find(':hidden[name$=DraftID]');

vanilla/applications/vanilla/models/class.commentmodel.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ public function save($formPostValues, $settings = false) {
12831283
$commentID = $this->SQL->insert($this->Name, $fields);
12841284
}
12851285
if ($commentID) {
1286+
// FIX: https://github.com/topcoder-platform/forums/issues/533
1287+
// if this comment is added by the discussion author.
1288+
$this->updateUser($fields['InsertUserID'], false);
1289+
12861290
$bodyValue = $fields["Body"] ?? null;
12871291
if ($bodyValue) {
12881292
$this->calculateMediaAttachments($commentID, !$insert);
@@ -1356,7 +1360,8 @@ public function save2($CommentID, $Insert, $CheckExisting = true, $IncUser = fal
13561360
// the number of discussions created by the user that s/he has
13571361
// unread messages in) if this comment was not added by the
13581362
// discussion author.
1359-
$this->updateUser($Fields['InsertUserID'], $IncUser && $Insert);
1363+
// Move it to save() due to https://github.com/topcoder-platform/forums/issues/533
1364+
// $this->updateUser($Fields['InsertUserID'], $IncUser && $Insert);
13601365

13611366
// Mark the user as participated.
13621367
$this->SQL->replace(

vanilla/applications/vanilla/views/discussion/discussion.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
</span>
5353
</div>
5454
<div class="Meta DiscussionMeta">
55-
<span class="MItem DateCreated">
56-
<?php echo Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($Discussion->DateInserted, true,
57-
DateTimeFormatter::FORCE_FULL_FORMAT); ?>
58-
</span>
55+
<?php echo authorProfileStats($Author);?>
56+
<span class="MItem DateCreated">
57+
<?php
58+
echo formatDateCustom($Discussion->DateInserted);
59+
?>
60+
</span>
5961
<?php
6062
echo dateUpdated($Discussion, ['<span class="MItem">', '</span>']);
6163
?>

vanilla/applications/vanilla/views/discussion/helper_functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ function writeComment($comment, $sender, $session, $currentOffset) {
176176
</span>
177177
</div>
178178
<div class="Meta CommentMeta CommentInfo">
179+
<?php echo authorProfileStats($author);?>
179180
<span class="MItem DateCreated">
180-
<?php echo Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($comment->DateInserted, true,
181-
DateTimeFormatter::FORCE_FULL_FORMAT); ?>
181+
<?php echo formatDateCustom($comment->DateInserted); ?>
182182
</span>
183183
<?php
184184
echo dateUpdated($comment, ['<span class="MItem">', '</span>']);

0 commit comments

Comments
 (0)