parent
f10e671c0e
commit
5b6d393693
@ -0,0 +1,92 @@ |
|||||||
|
<template> |
||||||
|
<q-form> |
||||||
|
<q-input |
||||||
|
id="item_title" |
||||||
|
v-model="item.title" |
||||||
|
:placeholder="$t('Title')" |
||||||
|
:error="v$.item.title.$error" |
||||||
|
@input="v$.item.title.$touch()" |
||||||
|
@blur="v$.item.title.$touch()" |
||||||
|
:error-message="titleErrors" |
||||||
|
/> |
||||||
|
<slot></slot> |
||||||
|
</q-form> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
import has from 'lodash/has'; |
||||||
|
import useVuelidate from '@vuelidate/core'; |
||||||
|
import { required } from '@vuelidate/validators'; |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'MessageForm', |
||||||
|
setup () { |
||||||
|
return { v$: useVuelidate() } |
||||||
|
}, |
||||||
|
props: { |
||||||
|
values: { |
||||||
|
type: Object, |
||||||
|
required: true |
||||||
|
}, |
||||||
|
errors: { |
||||||
|
type: Object, |
||||||
|
default: () => {} |
||||||
|
}, |
||||||
|
initialValues: { |
||||||
|
type: Object, |
||||||
|
default: () => {} |
||||||
|
}, |
||||||
|
}, |
||||||
|
data() { |
||||||
|
return { |
||||||
|
title: null, |
||||||
|
parentResourceNodeId: null, |
||||||
|
receivers: [] |
||||||
|
}; |
||||||
|
}, |
||||||
|
computed: { |
||||||
|
item() { |
||||||
|
return this.initialValues || this.values; |
||||||
|
}, |
||||||
|
receiversErrors() { |
||||||
|
const errors = []; |
||||||
|
if (!this.v$.item.receivers.$dirty) return errors; |
||||||
|
has(this.violations, 'receivers') && errors.push(this.violations.receivers); |
||||||
|
|
||||||
|
if (this.v$.item.receivers.required) { |
||||||
|
return this.$t('Field is required') |
||||||
|
} |
||||||
|
|
||||||
|
return errors; |
||||||
|
}, |
||||||
|
titleErrors() { |
||||||
|
const errors = []; |
||||||
|
if (!this.v$.item.title.$dirty) return errors; |
||||||
|
has(this.violations, 'title') && errors.push(this.violations.title); |
||||||
|
|
||||||
|
if (this.v$.item.title.required) { |
||||||
|
return this.$t('Field is required') |
||||||
|
} |
||||||
|
|
||||||
|
return errors; |
||||||
|
}, |
||||||
|
|
||||||
|
violations() { |
||||||
|
return this.errors || {}; |
||||||
|
} |
||||||
|
}, |
||||||
|
validations: { |
||||||
|
item: { |
||||||
|
title: { |
||||||
|
required, |
||||||
|
}, |
||||||
|
receivers: { |
||||||
|
required, |
||||||
|
}, |
||||||
|
content: { |
||||||
|
required, |
||||||
|
}, |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
</script> |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
framework: |
||||||
|
messenger: |
||||||
|
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling. |
||||||
|
# failure_transport: failed |
||||||
|
|
||||||
|
transports: |
||||||
|
# https://symfony.com/doc/current/messenger.html#transport-configuration |
||||||
|
# async: '%env(MESSENGER_TRANSPORT_DSN)%' |
||||||
|
sync_priority_high: 'sync://' |
||||||
|
# failed: 'doctrine://default?queue_name=failed' |
||||||
|
# sync: 'sync://' |
||||||
|
|
||||||
|
routing: |
||||||
|
# Route your messages to the transports |
||||||
|
'Chamilo\CoreBundle\Entity\Message': sync_priority_high |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
framework: |
||||||
|
messenger: |
||||||
|
transports: |
||||||
|
sync_priority_high: 'in-memory://' |
||||||
@ -0,0 +1,74 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CoreBundle\DataPersister; |
||||||
|
|
||||||
|
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; |
||||||
|
use ApiPlatform\Core\DataPersister\ResumableDataPersisterInterface; |
||||||
|
use Chamilo\CoreBundle\Entity\Message; |
||||||
|
use Doctrine\ORM\EntityManager; |
||||||
|
use Symfony\Component\Messenger\MessageBusInterface; |
||||||
|
|
||||||
|
class MessageDataPersister implements ContextAwareDataPersisterInterface, ResumableDataPersisterInterface |
||||||
|
{ |
||||||
|
private EntityManager $entityManager; |
||||||
|
private ContextAwareDataPersisterInterface $decorated; |
||||||
|
private MessageBusInterface $bus; |
||||||
|
|
||||||
|
public function __construct(ContextAwareDataPersisterInterface $decorated, EntityManager $entityManager, MessageBusInterface $bus) |
||||||
|
{ |
||||||
|
$this->decorated = $decorated; |
||||||
|
$this->entityManager = $entityManager; |
||||||
|
$this->bus = $bus; |
||||||
|
} |
||||||
|
|
||||||
|
public function supports($data, array $context = []): bool |
||||||
|
{ |
||||||
|
return $this->decorated->supports($data, $context); |
||||||
|
} |
||||||
|
|
||||||
|
public function persist($data, array $context = []) |
||||||
|
{ |
||||||
|
$result = $this->decorated->persist($data, $context); |
||||||
|
|
||||||
|
if ($data instanceof Message && ( |
||||||
|
($context['collection_operation_name'] ?? null) === 'post' || |
||||||
|
($context['graphql_operation_name'] ?? null) === 'create' |
||||||
|
//($context['item_operation_name'] ?? null) === 'put' // on update |
||||||
|
) |
||||||
|
) { |
||||||
|
/*if (Message::MESSAGE_TYPE_INBOX === $result->getMsgType()) { |
||||||
|
$messageSent = clone $result; |
||||||
|
$messageSent |
||||||
|
->setMsgType(Message::MESSAGE_TYPE_OUTBOX) |
||||||
|
//->setRead(true) |
||||||
|
; |
||||||
|
$this->entityManager->persist($messageSent); |
||||||
|
$this->entityManager->flush(); |
||||||
|
echo 'send11'; |
||||||
|
|
||||||
|
// Send message. |
||||||
|
$this->bus->dispatch($data); |
||||||
|
}*/ |
||||||
|
} |
||||||
|
|
||||||
|
/*$this->entityManager->persist($data); |
||||||
|
$this->entityManager->flush();*/ |
||||||
|
|
||||||
|
return $result; |
||||||
|
} |
||||||
|
|
||||||
|
public function remove($data, array $context = []): void |
||||||
|
{ |
||||||
|
$this->entityManager->remove($data); |
||||||
|
$this->entityManager->flush(); |
||||||
|
} |
||||||
|
|
||||||
|
public function resumable(array $context = []): bool |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
namespace Chamilo\CoreBundle\DataProvider\Extension; |
||||||
|
|
||||||
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; |
||||||
|
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface; |
||||||
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; |
||||||
|
use Chamilo\CoreBundle\Entity\Message; |
||||||
|
use Doctrine\ORM\QueryBuilder; |
||||||
|
use Symfony\Component\Security\Core\Security; |
||||||
|
|
||||||
|
final class UserRelUserExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface |
||||||
|
{ |
||||||
|
private Security $security; |
||||||
|
|
||||||
|
public function __construct(Security $security) |
||||||
|
{ |
||||||
|
$this->security = $security; |
||||||
|
} |
||||||
|
|
||||||
|
public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null): void |
||||||
|
{ |
||||||
|
$this->addWhere($queryBuilder, $resourceClass); |
||||||
|
} |
||||||
|
|
||||||
|
public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, string $operationName = null, array $context = []): void |
||||||
|
{ |
||||||
|
//error_log('applyToItem'); |
||||||
|
//$this->addWhere($queryBuilder, $resourceClass); |
||||||
|
} |
||||||
|
|
||||||
|
private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): void |
||||||
|
{ |
||||||
|
if (Message::class !== $resourceClass) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/*if ($this->security->isGranted('ROLE_ADMIN')) { |
||||||
|
return; |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*$user = $this->security->getUser(); |
||||||
|
$alias = $queryBuilder->getRootAliases()[0]; |
||||||
|
|
||||||
|
$queryBuilder->andWhere(" |
||||||
|
($alias.userSender = :current AND $alias.msgType = :outbox) OR |
||||||
|
($alias.userReceiver = :current AND $alias.msgType = :inbox) OR |
||||||
|
($alias.userReceiver = :current AND $alias.msgType = :invitation) OR |
||||||
|
($alias.userReceiver = :current AND $alias.msgType = :promoted) OR |
||||||
|
($alias.userReceiver = :current AND $alias.msgType = :wallPost) OR |
||||||
|
($alias.userReceiver = :current AND $alias.msgType = :conversation) |
||||||
|
"); |
||||||
|
$queryBuilder->setParameters([ |
||||||
|
'current' => $user, |
||||||
|
'inbox' => Message::MESSAGE_TYPE_INBOX, |
||||||
|
'outbox' => Message::MESSAGE_TYPE_OUTBOX, |
||||||
|
'invitation' => Message::MESSAGE_TYPE_INVITATION, |
||||||
|
'promoted' => Message::MESSAGE_TYPE_PROMOTED, |
||||||
|
'wallPost' => Message::MESSAGE_TYPE_WALL, |
||||||
|
'conversation' => Message::MESSAGE_STATUS_CONVERSATION, |
||||||
|
]);*/ |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CoreBundle\MessageHandler; |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Entity\Message; |
||||||
|
use Chamilo\CoreBundle\Repository\MessageRepository; |
||||||
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail; |
||||||
|
use Symfony\Component\Mailer\Mailer; |
||||||
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; |
||||||
|
use Symfony\Component\Mime\Address; |
||||||
|
|
||||||
|
class MessageHandler implements MessageHandlerInterface |
||||||
|
{ |
||||||
|
private Mailer $mailer; |
||||||
|
private MessageRepository $repo; |
||||||
|
|
||||||
|
public function __construct(Mailer $mailer, MessageRepository $repo) |
||||||
|
{ |
||||||
|
$this->mailer = $mailer; |
||||||
|
$this->repo = $repo; |
||||||
|
} |
||||||
|
|
||||||
|
public function __invoke(Message $message): void |
||||||
|
{ |
||||||
|
if (Message::MESSAGE_TYPE_INBOX !== $message->getMsgType()) { |
||||||
|
// Only send messages to the inbox. |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
$email = (new TemplatedEmail()) |
||||||
|
->subject($message->getTitle()) |
||||||
|
->from(new Address($message->getSender()->getEmail(), $message->getSender()->getFirstname())) |
||||||
|
->htmlTemplate('@ChamiloCore/Mailer/Default/default.html.twig') |
||||||
|
->textTemplate('@ChamiloCore/Mailer/Default/default.text.twig') |
||||||
|
; |
||||||
|
foreach ($message->getReceivers() as $receiver) { |
||||||
|
$address = new Address($receiver->getEmail(), $receiver->getFirstname()); |
||||||
|
$email->addBcc($address); |
||||||
|
} |
||||||
|
|
||||||
|
$params = [ |
||||||
|
'content' => $message->getContent(), |
||||||
|
'automatic_email_text' => '', |
||||||
|
'mail_header_style' => '', |
||||||
|
'mail_content_style' => '', |
||||||
|
'theme' => '', |
||||||
|
]; |
||||||
|
$email->context($params); |
||||||
|
$this->mailer->send($email); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue