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