ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $lng;
23
24 return $lng->txt("mem_cron_min_members");
25 }
26
27 public function getDescription()
28 {
29 global $lng;
30
31 return $lng->txt("mem_cron_min_members_info");
32 }
33
34 public function getDefaultScheduleType()
35 {
37 }
38
39 public function getDefaultScheduleValue()
40 {
41 return;
42 }
43
44 public function hasAutoActivation()
45 {
46 return true;
47 }
48
49 public function hasFlexibleSchedule()
50 {
51 return false;
52 }
53
54 public function run()
55 {
57 $message = null;
58
59 $recipients_map = array();
60
61 $this->getCourses($recipients_map);
62 $this->getGroups($recipients_map);
63
64 if(sizeof($recipients_map))
65 {
66 foreach($recipients_map as $reci_id => $items)
67 {
68 $this->sendMessage($reci_id, $items);
69 }
70
72 $message = sizeof($recipients_map)." notifications sent";
73 }
74
76 $result->setStatus($status);
77 $result->setMessage($message);
78
79 return $result;
80 }
81
82 protected function getCourses(array &$a_recipients_map)
83 {
84 include_once "Modules/Course/classes/class.ilObjCourse.php";
85 foreach(ilObjCourse::findCoursesWithNotEnoughMembers() as $obj_id => $item)
86 {
87 $too_few = (bool)$item[0];
88
89 /*
90 $ilDB->manipulate("UPDATE crs_settings".
91 " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
92 " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
93 */
94
95 if($too_few)
96 {
97 // not enough members: notifiy course admins
98 foreach($item[1] as $reci_id)
99 {
100 $a_recipients_map[$reci_id][] = array("crs", $obj_id, $item[0]);
101 }
102 }
103 else
104 {
105 // enough members: notify members?
106
107 // :TODO: ?
108 }
109 }
110 }
111
112 protected function getGroups(array &$a_recipients_map)
113 {
114 include_once "Modules/Group/classes/class.ilObjGroup.php";
115 foreach(ilObjGroup::findGroupsWithNotEnoughMembers() as $obj_id => $item)
116 {
117 $too_few = (bool)$item[0];
118
119 /*
120 $ilDB->manipulate("UPDATE grp_settings".
121 " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
122 " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
123 */
124
125 if($too_few)
126 {
127 // not enough members: notifiy group admins
128 foreach($item[1] as $reci_id)
129 {
130 $a_recipients_map[$reci_id][] = array("grp", $obj_id, $item[0]);
131 }
132 }
133 else
134 {
135 // enough members: notify members?
136
137 // :TODO: ?
138 }
139 }
140 }
141
142 protected function sendMessage($a_reci_id, array $a_items)
143 {
144 global $ilUser;
145
146 include_once "Services/Link/classes/class.ilLink.php";
147 include_once "./Services/Notification/classes/class.ilSystemNotification.php";
148 $ntf = new ilSystemNotification();
149 $ntf->setLangModules(array("crs"));
150
151 // #17097
152 $ntf->setReasonLangId("mem_cron_min_members_reason");
153 $ntf->setTaskLangId("mem_cron_min_members_task");
154
155 // user specific language
156 $lng = $ntf->getUserLanguage($a_reci_id);
157
158 $list = array();
159 foreach($a_items as $item)
160 {
161 $obj_type = $item[0];
162 $obj_id = $item[1];
163 $ref_id = array_pop(ilObject::_getAllReferences($obj_id));
164
165 $title = ilObject::_lookupTitle($obj_id);
166 $url = ilLink::_getLink($ref_id, $obj_type);
167
168 $list[] = $title."\n".$url."\n";
169 }
170 $list = implode($ntf->getBlockBorder(), $list);
171
172 $ntf->addAdditionalInfo("mem_cron_min_members_intro", $list, true);
173
174 $mail = new ilMail(ANONYMOUS_USER_ID);
175 $mail->enableSOAP(false); // #10410
176 $mail->sendMail(ilObjUser::_lookupLogin($a_reci_id),
177 null,
178 null,
179 $lng->txt("mem_cron_min_members_subject"),
180 $ntf->composeAndGetMessage($a_reci_id, null, "read", true),
181 null,
182 array("system"));
183 }
184}
185
186?>
$result
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
Class Mail this class handles base functions for mail handling.
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.
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
$url
Definition: shib_logout.php:72
global $ilUser
Definition: imgupload.php:15