15 import(
'lib.pkp.classes.notification.NotificationManagerDelegate');
25 private $_attachmentFilename;
27 private $_editorialTrends;
29 private $_editorialTrendsTotal;
31 private $_userRolesOverview;
36 public function __construct(
int $notificationType) {
37 parent::__construct($notificationType);
47 public function initialize(
Context $context, DateTimeInterface $dateStart, DateTimeInterface $dateEnd) :
void
49 $this->_context = $context;
51 $dateStart = $dateStart;
58 $this->_editorialTrends =
Services::get(
'editorialStats')->getOverview([
59 'contextIds' => [$this->_context->getId()],
60 'dateStart' => $dateStart->format(
'Y-m-d'),
61 'dateEnd' => $dateEnd->format(
'Y-m-d'),
63 $this->_editorialTrendsTotal =
Services::get(
'editorialStats')->getOverview([
64 'contextIds' => [$this->_context->getId()]
67 foreach ($this->_editorialTrends as $stat) {
68 switch ($stat[
'key']) {
69 case 'submissionsReceived':
70 $newSubmissions = $stat[
'value'];
72 case 'submissionsDeclined':
73 $declinedSubmissions = $stat[
'value'];
75 case 'submissionsAccepted':
76 $acceptedSubmissions = $stat[
'value'];
82 'newSubmissions' => $newSubmissions,
83 'declinedSubmissions' => $declinedSubmissions,
84 'acceptedSubmissions' => $acceptedSubmissions,
85 'totalSubmissions' =>
Services::get(
'editorialStats')->countSubmissionsReceived([
'contextIds' => [$this->_context->getId()]]),
87 'year' => $dateStart->format(
'Y'),
88 'editorialStatsLink' => $dispatcher->url($this->_request, ROUTE_PAGE, $this->_context->getPath(),
'stats',
'editorial'),
89 'publicationStatsLink' => $dispatcher->url($this->_request, ROUTE_PAGE, $this->_context->getPath(),
'stats',
'publications')
92 $this->_userRolesOverview =
Services::get(
'user')->getRolesOverview([
'contextId' => $this->_context->getId()]);
96 $file =
new SplFileObject(tempnam(sys_get_temp_dir(),
'tmp'),
'wb');
99 $file->fwrite(
"\xEF\xBB\xBF");
101 __(
'stats.submissionsActive', [], $locale),
102 __(
'stats.total', [], $locale)
107 Services::get(
'editorialStats')->countActiveByStages($stageId)
115 __(
'stats.trends', [], $locale),
116 $this->
_getLocalizedMonthName($dateStart, $locale) . __(
'common.commaListSeparator', [], $locale) . $dateStart->format(
'Y'),
117 __(
'stats.total', [], $locale)
119 foreach ($this->_editorialTrends as $i => $stat) {
121 __($stat[
'name'], [], $locale),
123 $this->_editorialTrendsTotal[$i][
'value']
131 __(
'manager.users', [], $locale),
132 __(
'stats.total', [], $locale)
134 foreach ($this->_userRolesOverview as $role) {
136 __($role[
'name'], [], $locale),
141 $this->_attachmentFilename = $file->getRealPath();
158 $formatter = $cache[$locale] ?? $cache[$locale] = \IntlDateFormatter::create($locale,
null,
null,
null,
null,
'MMMM');
159 return $formatter->format($date);
167 return __(
'notification.type.editorialReport', [], $this->_context->getPrimaryLocale());
175 return Services::get(
'emailTemplate')->getByKey($notification->getContextId(),
'STATISTICS_REPORT_NOTIFICATION');
183 $context =
$application->getContextDAO()->getById($notification->getContextId());
184 return $application->getDispatcher()->url($this->_request, ROUTE_PAGE, $context->
getPath(),
'stats',
'editorial');
192 return 'notifyIconInfo';
200 return NOTIFICATION_STYLE_CLASS_INFORMATION;
210 return parent::createNotification(
213 NOTIFICATION_TYPE_EDITORIAL_REPORT,
214 $this->_context->getId(),
217 NOTIFICATION_LEVEL_TASK,
218 [
'contents' => __(
'notification.type.editorialReport.contents', [], $this->_context->getPrimaryLocale())],
220 function ($mail) use ($user) {
221 return $this->_setupMessage($mail, $user);
231 import(
'lib.pkp.classes.mail.MailTemplate');
232 $mail =
new MailTemplate(
'STATISTICS_REPORT_NOTIFICATION', $this->_context->getPrimaryLocale(), $this->_context,
false);
242 private function _setupMessage(
Mail $mail,
User $user) :
Mail
244 $mail->assignParams($this->_getMessageParams($user));
245 if ($this->_getMessageAttachment()) {
246 $mail->
addAttachment($this->_getMessageAttachment(),
'editorial-report.csv');
256 private function _getMessageParams(
User $user) : array
258 return $this->_params + [
'name' => $user->getLocalizedGivenName($this->_context->getPrimaryLocale())];
265 private function _getMessageAttachment() : string
267 return $this->_attachmentFilename;