Skip to content

Commit

Permalink
Updated comments section of profile and comments page.
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismeonmounteverest committed Nov 4, 2023
1 parent 7d62981 commit 323ebfc
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 274 deletions.
2 changes: 1 addition & 1 deletion build/members/member.entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public function getVisitorsSubset(PagerWidget $pager)
return $this->createEntity('ProfileVisit')->getVisitingMembersSubset($this, $pager);
}

public function get_comments($count = 0) {
public function get_comments_received($count = 0) {
$sql = "
SELECT comments.*,
comments.Quality AS comQuality,
Expand Down
37 changes: 23 additions & 14 deletions build/members/templates/profile.subcolumn_right.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function wasGuestOrHost(string $relations) {

// build array with combined comments
$comments = [];
$commentsReceived = $this->member->get_comments();
$commentsReceived = $this->member->get_comments_received();
$commentsWritten = $this->member->get_comments_written();

$commentCount = $this->member->count_comments();
Expand Down Expand Up @@ -100,29 +100,34 @@ function wasGuestOrHost(string $relations) {
}

// First check if anything is visible at all
$commentFrom = $c['from'] ?? null;
$commentTo = $c['to'] ?? null;
$commentFrom = $c['from'] ?? null;

$visibleTo = false;
$visibleFrom = false;

$visible = false;
if (null !== $commentFrom) {
$visible |= ($commentFrom->DisplayInPublic != '0') || $showHiddenComments;
$visibleFrom = ($commentFrom->DisplayInPublic != '0') || $showHiddenComments;
}
if (null !== $commentTo) {
$visible |= ($commentTo->DisplayInPublic != '0') || $showHiddenComments;
$visibleTo = ($commentTo->DisplayInPublic != '0') || $showHiddenComments;
}
if (!$visible) {

if (!$visibleTo && !$visibleFrom) {
continue;
}

if ($commentLoopCount != 0) {
if ($commentLoopCount != 0 && $shownPairs != 0) {
echo '<hr class="my-3" style="border-top:1px solid gray;">';
}

// skip items that are hidden from public
if (null !== $commentFrom) {
if ($visibleFrom) {

$commentLoopCount++;
$comment = $commentFrom;
// skip items that are hidden for public
if ($comment->DisplayInPublic == 0 && !$showHiddenComments) {continue;}

$quality = "neutral";
if ($comment->comQuality == "Good") {
$quality = "good";
Expand Down Expand Up @@ -176,7 +181,7 @@ class="float-left gray align-self-center"><i class="fa fa-flag" alt="<?=$words->
</div>
</div>
<?php } else {
if ($loggedIn === $commentTo->UsernameToMember) {
if ($loggedIn === $commentTo->UsernameToMember && $commentFrom === null) {
$addCommentTranslation = str_replace('{username}', $commentTo->UsernameFromMember, $words->getSilent('profile.add.comment'));
?>
<div class="clearfix">
Expand All @@ -192,13 +197,16 @@ class="align-self-center float-left"><button class="o-button"><?= $addCommentTra
echo $noCommentYet;
?></div>
<?php }
}
}

// skip items that are hidden for public
if (null !== $commentTo) {
if ($visibleTo) {

$commentLoopCount++;
$comment = $commentTo;
// skip items that are hidden for public
if ($comment->DisplayInPublic == 0 && !$showHiddenComments) {continue;}

$quality = "neutral";
if ($comment->comQuality == "Good") {
$quality = "good";
Expand Down Expand Up @@ -250,8 +258,9 @@ class="align-self-center float-left"><button class="o-button"><?= $addCommentTra
</div>
</div>

<?php } else {
if ($loggedIn === $comment->UsernameToMember) {
<?php }
} else {
if ($loggedIn === $comment->UsernameToMember && $commentTo === null) {
$addCommentTranslation = str_replace('{username}', $comment->UsernameFromMember, $words->getSilent('profile.add.comment'));
?>
<div class="clearfix">
Expand Down
16 changes: 9 additions & 7 deletions src/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function addComment(
$comment->setFromMember($loggedInMember);
if (CommentQualityType::NEGATIVE === $comment->getQuality()) {
$comment->setAdminAction(CommentAdminActionType::ADMIN_CHECK);
$comment->setEditingAllowed(false);
}
$entityManager->persist($comment);

Expand Down Expand Up @@ -192,14 +193,16 @@ public function addComment(
/**
* @Route("/members/{username}/comment/edit", name="edit_comment",
* requirements={"username" = "(?i:[a-z](?!.*[-_.][-_.])[a-z0-9-._]{2,18}[a-z0-9])"}))
*
* @return Response|RedirectResponse
*/
public function editComment(
Request $request,
Member $member,
CommentModel $commentModel,
Mailer $mailer,
EntityManagerInterface $entityManager
): Response {
) {
/** @var Member $loggedInMember */
$loggedInMember = $this->getUser();

Expand Down Expand Up @@ -250,12 +253,15 @@ public function editComment(

if (CommentQualityType::NEGATIVE === $comment->getQuality()) {
$comment->setAdminAction(CommentAdminActionType::ADMIN_CHECK);
$comment->setEditingAllowed(false);
}

$entityManager->persist($comment);
$entityManager->flush();

$mailer->sendCommentUpdateNotification($comment);
if ($comment->getDisplayInPublic()) {
$mailer->sendCommentUpdateNotification($comment);
}

if ($newExperience || $changedToNegative || $changedToPositive) {
return $this->redirectToRoute('profile_comments', ['username' => $loggedInMember->getUsername()]);
Expand Down Expand Up @@ -319,11 +325,7 @@ public function showCommentsForMember(
$statusFormView = (null === $statusForm) ? null : $statusForm->createView();

$commentRepository = $entityManager->getRepository(Comment::class);
if (in_array(Member::ROLE_ADMIN_SAFETYTEAM, $loggedInMember->getRoles())) {
$comments = $commentRepository->getAllCommentsMember($member);
} else {
$comments = $commentRepository->getCommentsMember($member);
}
$comments = $commentRepository->getAllCommentsMember($member);

return $this->render('profile/comments.html.twig', [
'use_lightbox' => false,
Expand Down
Loading

0 comments on commit 323ebfc

Please sign in to comment.