ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMembershipCronMinMembers.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5
6
26
33{
34 protected ilLanguage $lng;
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 }
42
43 public function getId(): string
44 {
45 return "mem_min_members";
46 }
47
48 public function getTitle(): string
49 {
50 return $this->lng->txt("mem_cron_min_members");
51 }
52
53 public function getDescription(): string
54 {
55 return $this->lng->txt("mem_cron_min_members_info");
56 }
57
59 {
60 return JobScheduleType::DAILY;
61 }
62
63 public function getDefaultScheduleValue(): ?int
64 {
65 return null;
66 }
67
68 public function hasAutoActivation(): bool
69 {
70 return true;
71 }
72
73 public function hasFlexibleSchedule(): bool
74 {
75 return false;
76 }
77
78 public function run(): JobResult
79 {
80 $status = JobResult::STATUS_NO_ACTION;
81 $message = '';
82
83 $recipients_map = array();
84
85 $this->getCourses($recipients_map);
86 $this->getGroups($recipients_map);
87
88 if (count($recipients_map)) {
89 foreach ($recipients_map as $reci_id => $items) {
90 $this->sendMessage($reci_id, $items);
91 }
92 $status = JobResult::STATUS_OK;
93 $message = count($recipients_map) . " notifications sent";
94 }
95
96 $result = new JobResult();
97 $result->setStatus($status);
98 $result->setMessage($message);
99
100 return $result;
101 }
102
103 protected function getCourses(array &$a_recipients_map): void
104 {
105 foreach (ilObjCourse::findCoursesWithNotEnoughMembers() as $obj_id => $item) {
106 $too_few = (bool) $item[0];
107
108
109 if ($too_few) {
110 // not enough members: notifiy course admins
111 foreach ($item[1] as $reci_id) {
112 $a_recipients_map[$reci_id][] = array("crs", $obj_id, $item[0]);
113 }
114 }
115 }
116 }
117
118 protected function getGroups(array &$a_recipients_map): void
119 {
120 foreach (ilObjGroup::findGroupsWithNotEnoughMembers() as $obj_id => $item) {
121 $too_few = (bool) $item[0];
122
123
124 if ($too_few) {
125 // not enough members: notifiy group admins
126 foreach ($item[1] as $reci_id) {
127 $a_recipients_map[$reci_id][] = array("grp", $obj_id, $item[0]);
128 }
129 }
130 }
131 }
132
133 protected function sendMessage(int $a_reci_id, array $a_items): void
134 {
135 $ntf = new ilSystemNotification();
136 $ntf->setLangModules(array("crs"));
137
138 // #17097
139 $ntf->setReasonLangId("mem_cron_min_members_reason");
140
141 // user specific language
142 $lng = $ntf->getUserLanguage($a_reci_id);
143
144 $list = array();
145 foreach ($a_items as $item) {
146 $obj_type = (string) $item[0];
147 $obj_id = (int) $item[1];
148 $ref_ids = ilObject::_getAllReferences($obj_id);
149 $ref_id = array_pop($ref_ids);
150 $title = ilObject::_lookupTitle($obj_id);
151 $url = ilLink::_getLink($ref_id, $obj_type);
152
153 $list[] = $title . "\n" . $url . "\n";
154 }
155 $list = implode($ntf->getBlockBorder(), $list);
156
157 $ntf->addAdditionalInfo("mem_cron_min_members_intro", $list, true);
158 $ntf->addAdditionalInfo("mem_cron_min_members_task", "");
159
160 $mail = new ilMail(ANONYMOUS_USER_ID);
161 $mail->enqueue(
162 ilObjUser::_lookupLogin($a_reci_id),
163 '',
164 '',
165 $lng->txt("mem_cron_min_members_subject"),
166 $ntf->composeAndGetMessage($a_reci_id, null, "read", true),
167 []
168 );
169 }
170}
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getUserLanguage()
Return language of user.
Cron for course/group minimum members.
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
sendMessage(int $a_reci_id, array $a_items)
static findCoursesWithNotEnoughMembers()
static findGroupsWithNotEnoughMembers()
static _lookupLogin(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$message
Definition: xapiexit.php:31