ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
class.ilMembershipCronMinMembers.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
31{
32 protected ilLanguage $lng;
33
34 public function __construct()
35 {
36 global $DIC;
37
38 $this->lng = $DIC->language();
39 }
40
41 public function getId(): string
42 {
43 return "mem_min_members";
44 }
45
46 public function getTitle(): string
47 {
48 return $this->lng->txt("mem_cron_min_members");
49 }
50
51 public function getDescription(): string
52 {
53 return $this->lng->txt("mem_cron_min_members_info");
54 }
55
57 {
58 return JobScheduleType::DAILY;
59 }
60
61 public function getDefaultScheduleValue(): ?int
62 {
63 return null;
64 }
65
66 public function hasAutoActivation(): bool
67 {
68 return true;
69 }
70
71 public function hasFlexibleSchedule(): bool
72 {
73 return false;
74 }
75
76 public function run(): JobResult
77 {
78 $status = JobResult::STATUS_NO_ACTION;
79 $message = '';
80
81 $recipients_map = array();
82
83 $this->getCourses($recipients_map);
84 $this->getGroups($recipients_map);
85
86 if (count($recipients_map)) {
87 foreach ($recipients_map as $reci_id => $items) {
88 $this->sendMessage($reci_id, $items);
89 }
90 $status = JobResult::STATUS_OK;
91 $message = count($recipients_map) . " notifications sent";
92 }
93
94 $result = new JobResult();
95 $result->setStatus($status);
96 $result->setMessage($message);
97
98 return $result;
99 }
100
101 protected function getCourses(array &$a_recipients_map): void
102 {
103 foreach (ilObjCourse::findCoursesWithNotEnoughMembers() as $obj_id => $item) {
104 $too_few = (bool) $item[0];
105
106
107 if ($too_few) {
108 // not enough members: notifiy course admins
109 foreach ($item[1] as $reci_id) {
110 $a_recipients_map[$reci_id][] = array("crs", $obj_id, $item[0]);
111 }
112 }
113 }
114 }
115
116 protected function getGroups(array &$a_recipients_map): void
117 {
118 foreach (ilObjGroup::findGroupsWithNotEnoughMembers() as $obj_id => $item) {
119 $too_few = (bool) $item[0];
120
121
122 if ($too_few) {
123 // not enough members: notifiy group admins
124 foreach ($item[1] as $reci_id) {
125 $a_recipients_map[$reci_id][] = array("grp", $obj_id, $item[0]);
126 }
127 }
128 }
129 }
130
131 protected function sendMessage(int $a_reci_id, array $a_items): void
132 {
133 $ntf = new ilSystemNotification();
134 $ntf->setLangModules(array("crs"));
135
136 // #17097
137 $ntf->setReasonLangId("mem_cron_min_members_reason");
138
139 // user specific language
140 $lng = $ntf->getUserLanguage($a_reci_id);
141
142 $list = array();
143 foreach ($a_items as $item) {
144 $obj_type = (string) $item[0];
145 $obj_id = (int) $item[1];
146 $ref_ids = ilObject::_getAllReferences($obj_id);
147 $ref_id = array_pop($ref_ids);
148 $title = ilObject::_lookupTitle($obj_id);
149 $url = ilLink::_getLink($ref_id, $obj_type);
150
151 $list[] = $title . "\n" . $url . "\n";
152 }
153 $list = implode($ntf->getBlockBorder() . "\n", $list);
154
155 $ntf->addAdditionalInfo("mem_cron_min_members_intro", $list, true);
156 $ntf->addAdditionalInfo("mem_cron_min_members_task", "");
157
158 $mail = new ilMail(ANONYMOUS_USER_ID);
159 $mail->enqueue(
160 ilObjUser::_lookupLogin($a_reci_id),
161 '',
162 '',
163 $lng->txt("mem_cron_min_members_subject"),
164 $ntf->composeAndGetMessage($a_reci_id, null, "read", true),
165 []
166 );
167 }
168}
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:70