Open Journal Systems  3.3.0
StatisticsReport.inc.php
1 <?php
2 
16 import('lib.pkp.classes.scheduledTask.ScheduledTask');
17 
20  private $_roleIds = [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR];
21 
23  private $_sleepEvery = 100;
24 
26  private $_sleepBy = 2;
27 
28 
32  public function getName() : string
33  {
34  return __('admin.scheduledTask.statisticsReport');
35  }
36 
40  public function executeActions() : bool
41  {
42  @set_time_limit(0);
43  import('lib.pkp.classes.notification.managerDelegate.EditorialReportNotificationManager');
44 
45  $contextDao = Application::get()->getContextDAO();
46  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
47 
48  $sentMessages = 0;
49  for ($contexts = $contextDao->getAll(true); $context = $contexts->next(); ) {
51  [LOCALE_COMPONENT_PKP_USER, LOCALE_COMPONENT_PKP_MANAGER, LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_PKP_COMMON, LOCALE_COMPONENT_APP_COMMON],
52  $context->getPrimaryLocale()
53  );
54  $editorialReportNotificationManager = new EditorialReportNotificationManager(NOTIFICATION_TYPE_EDITORIAL_REPORT);
55  $editorialReportNotificationManager->initialize(
56  $context,
57  new DateTimeImmutable('first day of previous month midnight'),
58  new DateTimeImmutable('first day of this month midnight')
59  );
60  $notifiedUsersSet = [];
61  foreach ($this->_roleIds as $roleId) {
62  for ($userGroups = $userGroupDao->getByRoleId($context->getId(), $roleId); $userGroup = $userGroups->next(); ) {
63  for ($users = $userGroupDao->getUsersById($userGroup->getId(), $context->getId()); $user = $users->next(); ) {
64  if (isset($notifiedUsersSet[$user->getId()])) {
65  continue;
66  }
67  $editorialReportNotificationManager->notify($user);
68  $notifiedUsersSet[$user->getId()] = 0;
69  if (!(++$sentMessages % $this->_sleepEvery)) {
70  sleep($this->_sleepBy);
71  }
72  }
73  }
74  }
75  }
76  return true;
77  }
78 }
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
StatisticsReport
Class responsible to send the monthly statistics report.
Definition: StatisticsReport.inc.php:18
EditorialReportNotificationManager
Editorial report notification manager.
Definition: EditorialReportNotificationManager.inc.php:17
ScheduledTask
Base class for executing scheduled tasks. All scheduled task classes must extend this class and imple...
Definition: ScheduledTask.inc.php:20
StatisticsReport\getName
getName()
Definition: StatisticsReport.inc.php:41
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
StatisticsReport\executeActions
executeActions()
Definition: StatisticsReport.inc.php:49