ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMembershipCronMinMembers.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Services/Cron/classes/class.ilCronJob.php";
6
14{
15 public function getId()
16 {
17 return "mem_min_members";
18 }
19
20 public function getTitle()
21 {
22 global $DIC;
23
24 $lng = $DIC['lng'];
25
26 return $lng->txt("mem_cron_min_members");
27 }
28
29 public function getDescription()
30 {
31 global $DIC;
32
33 $lng = $DIC['lng'];
34
35 return $lng->txt("mem_cron_min_members_info");
36 }
37
38 public function getDefaultScheduleType()
39 {
41 }
42
43 public function getDefaultScheduleValue()
44 {
45 return;
46 }
47
48 public function hasAutoActivation()
49 {
50 return true;
51 }
52
53 public function hasFlexibleSchedule()
54 {
55 return false;
56 }
57
58 public function run()
59 {
61 $message = null;
62
63 $recipients_map = array();
64
65 $this->getCourses($recipients_map);
66 $this->getGroups($recipients_map);
67
68 if (sizeof($recipients_map)) {
69 foreach ($recipients_map as $reci_id => $items) {
70 $this->sendMessage($reci_id, $items);
71 }
72
74 $message = sizeof($recipients_map) . " notifications sent";
75 }
76
78 $result->setStatus($status);
79 $result->setMessage($message);
80
81 return $result;
82 }
83
84 protected function getCourses(array &$a_recipients_map)
85 {
86 include_once "Modules/Course/classes/class.ilObjCourse.php";
87 foreach (ilObjCourse::findCoursesWithNotEnoughMembers() as $obj_id => $item) {
88 $too_few = (bool) $item[0];
89
90 /*
91 $ilDB->manipulate("UPDATE crs_settings".
92 " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
93 " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
94 */
95
96 if ($too_few) {
97 // not enough members: notifiy course admins
98 foreach ($item[1] as $reci_id) {
99 $a_recipients_map[$reci_id][] = array("crs", $obj_id, $item[0]);
100 }
101 } else {
102 // enough members: notify members?
103
104 // :TODO: ?
105 }
106 }
107 }
108
109 protected function getGroups(array &$a_recipients_map)
110 {
111 include_once "Modules/Group/classes/class.ilObjGroup.php";
112 foreach (ilObjGroup::findGroupsWithNotEnoughMembers() as $obj_id => $item) {
113 $too_few = (bool) $item[0];
114
115 /*
116 $ilDB->manipulate("UPDATE grp_settings".
117 " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
118 " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
119 */
120
121 if ($too_few) {
122 // not enough members: notifiy group admins
123 foreach ($item[1] as $reci_id) {
124 $a_recipients_map[$reci_id][] = array("grp", $obj_id, $item[0]);
125 }
126 } else {
127 // enough members: notify members?
128
129 // :TODO: ?
130 }
131 }
132 }
133
134 protected function sendMessage($a_reci_id, array $a_items)
135 {
136 global $DIC;
137
138 $ilUser = $DIC['ilUser'];
139
140 include_once "Services/Link/classes/class.ilLink.php";
141 include_once "./Services/Notification/classes/class.ilSystemNotification.php";
142 $ntf = new ilSystemNotification();
143 $ntf->setLangModules(array("crs"));
144
145 // #17097
146 $ntf->setReasonLangId("mem_cron_min_members_reason");
147
148 // user specific language
149 $lng = $ntf->getUserLanguage($a_reci_id);
150
151 $list = array();
152 foreach ($a_items as $item) {
153 $obj_type = $item[0];
154 $obj_id = $item[1];
155 $ref_id = array_pop(ilObject::_getAllReferences($obj_id));
156
157 $title = ilObject::_lookupTitle($obj_id);
158 $url = ilLink::_getLink($ref_id, $obj_type);
159
160 $list[] = $title . "\n" . $url . "\n";
161 }
162 $list = implode($ntf->getBlockBorder(), $list);
163
164
165 $ntf->addAdditionalInfo("mem_cron_min_members_intro", $list, true);
166 $ntf->addAdditionalInfo("mem_cron_min_members_task", "");
167
168 $mail = new ilMail(ANONYMOUS_USER_ID);
169 $mail->enqueue(
170 ilObjUser::_lookupLogin($a_reci_id),
171 null,
172 null,
173 $lng->txt("mem_cron_min_members_subject"),
174 $ntf->composeAndGetMessage($a_reci_id, null, "read", true),
175 []
176 );
177 }
178}
$result
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
Cron for course/group minimum members.
hasAutoActivation()
Is to be activated on "installation".
hasFlexibleSchedule()
Can the schedule be configured?
static findCoursesWithNotEnoughMembers()
Minimum members check @global type $ilDB.
static findGroupsWithNotEnoughMembers()
Minimum members check @global $ilDB $ilDB.
static _lookupLogin($a_user_id)
lookup login
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Wrapper classes for system notifications.
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$url
$lng
$message
Definition: xapiexit.php:14