-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Message: Send mail when saving inbox message - refs BT#21613
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\State; | ||
|
||
use ApiPlatform\Metadata\DeleteOperationInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\State\ProcessorInterface; | ||
use Chamilo\CoreBundle\Entity\Message; | ||
use MessageManager; | ||
|
||
final class MessageProcessor implements ProcessorInterface | ||
{ | ||
public function __construct( | ||
private readonly ProcessorInterface $persistProcessor, | ||
private readonly ProcessorInterface $removeProcessor, | ||
) {} | ||
|
||
public function process($data, Operation $operation, array $uriVariables = [], array $context = []) | ||
{ | ||
if ($operation instanceof DeleteOperationInterface) { | ||
return $this->removeProcessor->process($data, $operation, $uriVariables, $context); | ||
} | ||
|
||
$message = $this->persistProcessor->process($data, $operation, $uriVariables, $context); | ||
|
||
assert($message instanceof Message); | ||
|
||
if ($operation instanceof Post) { | ||
if (Message::MESSAGE_TYPE_INBOX === $message->getMsgType()) { | ||
$this->sendMailForInboxMessage($message); | ||
} | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
private function sendMailForInboxMessage(Message $message): void | ||
{ | ||
foreach ($message->getReceivers() as $receiver) { | ||
$user = $receiver->getReceiver(); | ||
|
||
MessageManager::send_message( | ||
$user->getId(), | ||
$message->getTitle(), | ||
$message->getContent(), | ||
[], | ||
[], | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
false, | ||
0, | ||
true, | ||
false, | ||
Message::MESSAGE_TYPE_INBOX | ||
); | ||
} | ||
} | ||
} |