ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_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  {
36  return self::SCHEDULE_TYPE_DAILY;
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  foreach ($recipients_map as $reci_id => $items) {
66  $this->sendMessage($reci_id, $items);
67  }
68 
70  $message = sizeof($recipients_map) . " notifications sent";
71  }
72 
73  $result = new ilCronJobResult();
74  $result->setStatus($status);
75  $result->setMessage($message);
76 
77  return $result;
78  }
79 
80  protected function getCourses(array &$a_recipients_map)
81  {
82  include_once "Modules/Course/classes/class.ilObjCourse.php";
83  foreach (ilObjCourse::findCoursesWithNotEnoughMembers() as $obj_id => $item) {
84  $too_few = (bool) $item[0];
85 
86  /*
87  $ilDB->manipulate("UPDATE crs_settings".
88  " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
89  " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
90  */
91 
92  if ($too_few) {
93  // not enough members: notifiy course admins
94  foreach ($item[1] as $reci_id) {
95  $a_recipients_map[$reci_id][] = array("crs", $obj_id, $item[0]);
96  }
97  } else {
98  // enough members: notify members?
99 
100  // :TODO: ?
101  }
102  }
103  }
104 
105  protected function getGroups(array &$a_recipients_map)
106  {
107  include_once "Modules/Group/classes/class.ilObjGroup.php";
108  foreach (ilObjGroup::findGroupsWithNotEnoughMembers() as $obj_id => $item) {
109  $too_few = (bool) $item[0];
110 
111  /*
112  $ilDB->manipulate("UPDATE grp_settings".
113  " SET cancel_end_noti = ".$ilDB->quote($now, "integer").
114  " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
115  */
116 
117  if ($too_few) {
118  // not enough members: notifiy group admins
119  foreach ($item[1] as $reci_id) {
120  $a_recipients_map[$reci_id][] = array("grp", $obj_id, $item[0]);
121  }
122  } else {
123  // enough members: notify members?
124 
125  // :TODO: ?
126  }
127  }
128  }
129 
130  protected function sendMessage($a_reci_id, array $a_items)
131  {
132  global $ilUser;
133 
134  include_once "Services/Link/classes/class.ilLink.php";
135  include_once "./Services/Notification/classes/class.ilSystemNotification.php";
136  $ntf = new ilSystemNotification();
137  $ntf->setLangModules(array("crs"));
138 
139  // #17097
140  $ntf->setReasonLangId("mem_cron_min_members_reason");
141  $ntf->setTaskLangId("mem_cron_min_members_task");
142 
143  // user specific language
144  $lng = $ntf->getUserLanguage($a_reci_id);
145 
146  $list = array();
147  foreach ($a_items as $item) {
148  $obj_type = $item[0];
149  $obj_id = $item[1];
150  $ref_id = array_pop(ilObject::_getAllReferences($obj_id));
151 
152  $title = ilObject::_lookupTitle($obj_id);
153  $url = ilLink::_getLink($ref_id, $obj_type);
154 
155  $list[] = $title . "\n" . $url . "\n";
156  }
157  $list = implode($ntf->getBlockBorder(), $list);
158 
159  $ntf->addAdditionalInfo("mem_cron_min_members_intro", $list, true);
160 
161  $mail = new ilMail(ANONYMOUS_USER_ID);
162  $mail->enableSOAP(false); // #10410
163  $mail->sendMail(
164  ilObjUser::_lookupLogin($a_reci_id),
165  null,
166  null,
167  $lng->txt("mem_cron_min_members_subject"),
168  $ntf->composeAndGetMessage($a_reci_id, null, "read", true),
169  null,
170  array("system")
171  );
172  }
173 }
static _lookupLogin($a_user_id)
lookup login
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$result
Cron job application base class.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Cron for course/group minimum members.
static findGroupsWithNotEnoughMembers()
Minimum members check $ilDB $ilDB.
catch(Exception $e) $message
This class handles base functions for mail handling.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static findCoursesWithNotEnoughMembers()
Minimum members check type $ilDB.
global $lng
Definition: privfeed.php:17
$url
Cron job result data container.
Wrapper classes for system notifications.