ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
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 
75  $result = new ilCronJobResult();
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 ?>
static _lookupLogin($a_user_id)
lookup login
$result
Cron job application base class.
static _lookupTitle($a_id)
lookup object title
$url
Definition: shib_logout.php:72
static _getAllReferences($a_id)
get all reference ids of object
Cron for course/group minimum members.
static findGroupsWithNotEnoughMembers()
Minimum members check $ilDB $ilDB.
This class handles base functions for mail handling.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
$ref_id
Definition: sahs_server.php:39
static findCoursesWithNotEnoughMembers()
Minimum members check type $ilDB.
global $lng
Definition: privfeed.php:17
Cron job result data container.
Wrapper classes for system notifications.