+
+ /**
+ * Returns a list of lowercase admin email addresses from the comma-separated list in the config
+ *
+ * @return array
+ */
+ public static function getAdminEmailList(): array
+ {
+ $adminEmails = strtolower(str_replace(' ', '', DI::config()->get('config', 'admin_email')));
+ if (!$adminEmails) {
+ return [];
+ }
+
+ return explode(',', $adminEmails);
+ }
+
+ /**
+ * Returns the complete list of admin user accounts
+ *
+ * @param array $fields
+ * @return array
+ * @throws Exception
+ */
+ public static function getAdminList(array $fields = []): array
+ {
+ $condition = [
+ 'email' => self::getAdminEmailList(),
+ 'parent-uid' => 0,
+ 'blocked' => 0,
+ 'verified' => true,
+ 'account_removed' => false,
+ 'account_expired' => false,
+ ];
+
+ return DBA::selectToArray('user', $fields, $condition, ['order' => ['uid']]);
+ }
+
+ /**
+ * Return a list of admin user accounts where each unique email address appears only once.
+ *
+ * This method is meant for admin notifications that do not need to be sent multiple times to the same email address.
+ *
+ * @param array $fields
+ * @return array
+ * @throws Exception
+ */
+ public static function getAdminListForEmailing(array $fields = []): array
+ {
+ return array_filter(self::getAdminList($fields), function ($user) {
+ static $emails = [];
+
+ if (in_array($user['email'], $emails)) {
+ return false;
+ }
+
+ $emails[] = $user['email'];
+
+ return true;
+ });
+ }
+
+ public static function setRegisterMethodByUserCount()
+ {
+ $max_registered_users = DI::config()->get('config', 'max_registered_users');
+ if ($max_registered_users <= 0) {
+ return;
+ }
+
+ $register_policy = DI::config()->get('config', 'register_policy');
+ if (!in_array($register_policy, [Register::OPEN, Register::CLOSED])) {
+ Logger::debug('Unsupported register policy.', ['policy' => $register_policy]);
+ return;
+ }
+
+ $users = DBA::count('user', ['blocked' => false, 'account_removed' => false, 'account_expired' => false]);
+ if (($users >= $max_registered_users) && ($register_policy == Register::OPEN)) {
+ DI::config()->set('config', 'register_policy', Register::CLOSED);
+ Logger::notice('Max users reached, registration is closed.', ['users' => $users, 'max' => $max_registered_users]);
+ } elseif (($users < $max_registered_users) && ($register_policy == Register::CLOSED)) {
+ DI::config()->set('config', 'register_policy', Register::OPEN);
+ Logger::notice('Below maximum users, registration is opened.', ['users' => $users, 'max' => $max_registered_users]);
+ } else {
+ Logger::debug('Unchanged register policy', ['policy' => $register_policy, 'users' => $users, 'max' => $max_registered_users]);
+ }
+ }