first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
@@ -0,0 +1,114 @@
<?php
/**
* @file jobs/notifications/IssuePublishedMailUsers.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class IssuePublishedNotifyUsers
*
* @ingroup jobs
*
* @brief Class to send emails when a new issue is published
*/
namespace APP\jobs\notifications;
use APP\core\Application;
use APP\facades\Repo;
use APP\issue\Issue;
use APP\mail\mailables\IssuePublishedNotify;
use APP\notification\Notification;
use APP\notification\NotificationManager;
use Illuminate\Bus\Batchable;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
use PKP\context\Context;
use PKP\emailTemplate\EmailTemplate;
use PKP\jobs\BaseJob;
use PKP\user\User;
class IssuePublishedNotifyUsers extends BaseJob
{
use Batchable;
protected Collection $recipientIds;
protected int $contextId;
protected Issue $issue;
protected string $locale;
// The sender of the email
protected ?User $sender;
public function __construct(
Collection $recipientIds,
int $contextId,
Issue $issue,
string $locale,
?User $sender = null // Leave null to not send an email
) {
parent::__construct();
$this->recipientIds = $recipientIds;
$this->contextId = $contextId;
$this->issue = $issue;
$this->locale = $locale;
$this->sender = $sender;
}
public function handle()
{
$context = Application::getContextDAO()->getById($this->contextId);
$template = Repo::emailTemplate()->getByKey($this->contextId, IssuePublishedNotify::getEmailTemplateKey());
foreach ($this->recipientIds as $recipientId) {
/** @var int $recipientId */
$recipient = Repo::user()->get($recipientId);
if (!$recipient) {
continue;
}
$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
null,
$recipientId,
Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE,
$this->contextId,
Application::ASSOC_TYPE_ISSUE,
$this->issue->getId()
);
if (!$this->sender) {
continue;
}
$mailable = $this->createMailable($context, $this->issue, $recipient, $template, $notification);
$mailable->setData($this->locale);
Mail::send($mailable);
}
}
/**
* Creates new issue published notification email
*/
protected function createMailable(
Context $context,
Issue $issue,
User $recipient,
EmailTemplate $template,
Notification $notification
): IssuePublishedNotify {
$mailable = new IssuePublishedNotify($context, $issue);
$mailable
->recipients([$recipient])
->sender($this->sender)
->body($template->getLocalizedData('body', $this->locale))
->subject($template->getLocalizedData('subject', $this->locale))
->allowUnsubscribe($notification);
return $mailable;
}
}
@@ -0,0 +1,85 @@
<?php
/**
* @file jobs/notifications/OpenAccessMailUsers.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class OpenAccessMailUsers
*
* @ingroup jobs
*
* @brief Class to send issue open access notification to userIds
*/
namespace APP\jobs\notifications;
use APP\core\Application;
use APP\facades\Repo;
use APP\journal\Journal;
use APP\mail\mailables\OpenAccessNotify;
use APP\notification\Notification;
use APP\notification\NotificationManager;
use Illuminate\Bus\Batchable;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
use PKP\jobs\BaseJob;
class OpenAccessMailUsers extends BaseJob
{
use Batchable;
protected Collection $userIds;
protected int $contextId;
protected int $issueId;
public function __construct(Collection $userIds, int $contextId, int $issueId)
{
parent::__construct();
$this->userIds = $userIds;
$this->contextId = $contextId;
$this->issueId = $issueId;
}
public function handle()
{
$contextDao = Application::getContextDAO();
$context = $contextDao->getById($this->contextId); /** @var Journal $context */
$issue = Repo::issue()->get($this->issueId, $this->contextId);
if (!$context || !$issue) {
return;
}
$locale = $context->getPrimaryLocale();
$template = Repo::emailTemplate()->getByKey($this->contextId, OpenAccessNotify::getEmailTemplateKey());
foreach ($this->userIds as $userId) {
$user = Repo::user()->get($userId);
if (!$user) {
continue;
}
$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
null,
$userId,
Notification::NOTIFICATION_TYPE_OPEN_ACCESS,
$this->contextId
);
$mailable = new OpenAccessNotify($context, $issue);
$mailable
->subject($template->getLocalizedData('subject', $locale))
->body($template->getLocalizedData('body', $locale))
->from($context->getData('contactEmail'), $context->getData('contactName'))
->recipients([$user])
->allowUnsubscribe($notification);
Mail::send($mailable);
}
}
}