Social: Show likes and dislikes in comment

pull/4161/head
Angel Fernando Quiroz Campos 3 years ago
parent 51aa413e59
commit d3c6c1a8f9
  1. 32
      assets/vue/components/socialnetwork/PostComment.vue
  2. 27
      src/CoreBundle/Entity/Message.php
  3. 3
      src/CoreBundle/EventListener/TwigListener.php

@ -12,14 +12,28 @@
<q-item-label caption>{{ $filters.relativeDatetime(comment.sendDate) }}</q-item-label>
</q-item-section>
<q-item-section
v-if="isOwner"
side
top
>
<q-item-section side top>
<q-btn
:aria-label="$t('Delete comment')"
v-if="enableMessagesFeedbackConfig"
:label="comment.countLikes"
:title="$t('Like')"
dense
flat
icon="mdi-heart-plus"
/>
<q-btn
v-if="enableMessagesFeedbackConfig && !disableDislikeOption"
:label="comment.countDislikes"
:title="$t('Dislike')"
dense
flat
icon="mdi-heart-remove"
/>
<q-btn
v-if="isOwner"
:title="$t('Delete comment')"
dense
flat
icon="delete"
@click="deleteComment"
/>
@ -29,6 +43,7 @@
<script>
import {useStore} from "vuex";
import {ref} from "vue";
export default {
name: "SocialNetworkPostComment",
@ -50,9 +65,14 @@ export default {
.then(() => context.emit('deleted'));
}
const enableMessagesFeedbackConfig = ref(window.config['social.social_enable_messages_feedback'] === 'true');
const disableDislikeOption = ref(window.config['social.disable_dislike_option'] === 'true');
return {
deleteComment,
isOwner: currentUser['@id'] === props.comment.sender['@id'],
enableMessagesFeedbackConfig,
disableDislikeOption,
};
}
}

@ -240,12 +240,17 @@ class Message
protected Collection $attachments;
/**
* @var Collection|MessageFeedback[]
* @var Collection<int, MessageFeedback>
*
* @ORM\OneToMany(targetEntity="MessageFeedback", mappedBy="message", orphanRemoval=true)
*/
protected Collection $likes;
#[Groups(['message:read'])]
protected int $countLikes = 0;
#[Groups(['message:read'])]
protected int $countDislikes = 0;
public function __construct()
{
$this->sendDate = new DateTime('now');
@ -545,4 +550,24 @@ class Message
return $this;
}
public function getCountLikes(): int
{
$criteria = Criteria::create();
$criteria->where(
Criteria::expr()->eq('liked', true)
);
return $this->likes->matching($criteria)->count();
}
public function getCountDislikes(): int
{
$criteria = Criteria::create();
$criteria->where(
Criteria::expr()->eq('disliked', true)
);
return $this->likes->matching($criteria)->count();
}
}

@ -71,6 +71,9 @@ class TwigListener
'platform.load_term_conditions_section',
'registration.allow_terms_conditions',
'agenda.personal_calendar_show_sessions_occupation',
'social.social_enable_messages_feedback',
'social.disable_dislike_option',
];
// @todo get variables in 1 query.

Loading…
Cancel
Save