ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronCourseGroupNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Mail/classes/class.ilMailNotification.php';
5 include_once 'Services/Mail/classes/class.ilMail.php';
6 
14 {
15  public function sendNotifications()
16  {
17  global $ilDB, $lng;
18 
19  $setting = new ilSetting("cron");
20  $last_run = $setting->get(get_class($this));
21 
22  // #10284 - we already did send today, do nothing
23  if($last_run == date("Y-m-d"))
24  {
25  return;
26  }
27 
28  // gather objects and participants with notification setting
29  $objects = array();
30  $set = $ilDB->query("SELECT usr_id,keyword FROM usr_pref".
31  " WHERE ".$ilDB->like("keyword", "text", "grpcrs_ntf_%").
32  " AND value = ".$ilDB->quote("1", "text"));
33  while($row = $ilDB->fetchAssoc($set))
34  {
35  $ref_id = substr($row["keyword"], 11);
37  if($type)
38  {
39  $objects[$type][$ref_id][] = $row["usr_id"];
40  }
41  }
42 
43  if(sizeof($objects))
44  {
45  $old_lng = $lng;
46 
47  include_once "Services/News/classes/class.ilNewsItem.php";
48  foreach($objects as $type => $ref_ids)
49  {
50  // type is not needed for now
51  foreach($ref_ids as $ref_id => $user_ids)
52  {
53  // gather news per object
54  $news_item = new ilNewsItem();
55  if($news_item->checkNewsExistsForGroupCourse($ref_id))
56  {
57  foreach($user_ids as $user_id)
58  {
59  // gather news for user
60  $user_news = $news_item->getNewsForRefId($ref_id,
61  false, false, 1, false, false, false, false,
62  $user_id);
63  if($user_news)
64  {
65  $this->sendMail($user_id, $ref_id, $user_news);
66  }
67  }
68  }
69  }
70  }
71 
72  $lng = $old_lng;
73  }
74 
75  // save last run
76  $setting->set(get_class($this), date("Y-m-d"));
77 
78  return true;
79  }
80 
88  public function sendMail($a_user_id, $a_ref_id, array $news)
89  {
90  global $lng, $ilUser;
91 
92  $obj_id = ilObject::_lookupObjId($a_ref_id);
94 
95  $this->initLanguage($a_user_id);
96  $this->getLanguage()->loadLanguageModule("crs");
97  $this->getLanguage()->loadLanguageModule("news");
98 
99  // needed for ilNewsItem
100  $lng = $this->getLanguage();
101 
102  $this->initMail();
103 
104  $obj_title = $this->getLanguageText($obj_type)." \"".ilObject::_lookupTitle($obj_id)."\"";
105 
106  $this->setRecipients($a_user_id);
107  $this->setSubject(sprintf($this->getLanguageText("crs_subject_course_group_notification"), $obj_title));
108 
109  $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
110  $this->appendBody("\n\n");
111 
112  $this->appendBody(sprintf($this->getLanguageText("crs_intro_course_group_notification_for"), $obj_title));
113  $this->appendBody("\n\n");
114 
115  // ilDatePresentation::setUseRelativeDates(false);
116 
117  // news summary
118  $counter = 1;
119  foreach($news as $item)
120  {
121  $title = ilNewsItem::determineNewsTitle($item["context_obj_type"],
122  $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"],
123  $item["aggregation"]);
124  $content = ilNewsItem::determineNewsContent($item["context_obj_type"],
125  $item["content"], $item["content_text_is_lang_var"]);
126 
127  /* process sub-item info
128  if($item["aggregation"])
129  {
130  $sub = array();
131  foreach($item["aggregation"] as $subitem)
132  {
133  $sub_id = ilObject::_lookupObjId($subitem["ref_id"]);
134  $sub_title = ilObject::_lookupTitle($sub_id);
135 
136  // to include posting title
137  if($subitem["context_obj_type"] == "frm")
138  {
139  $sub_title = ilNewsItem::determineNewsTitle($subitem["context_obj_type"],
140  $subitem["title"], $subitem["content_is_lang_var"]);
141  }
142 
143  $sub[] = $sub_title;
144 
145  $sub_content = ilNewsItem::determineNewsContent($subitem["context_obj_type"],
146  $subitem["content"], $subitem["content_text_is_lang_var"]);
147  if($sub_content)
148  {
149  $sub[] = strip_tags($sub_content);
150  }
151  }
152  $content .= "\n".implode("\n\n", $sub);
153  }
154  */
155 
156  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
157  $obj_title = ilObject::_lookupTitle($obj_id);
158 
159  // path
160  include_once './Services/Locator/classes/class.ilLocatorGUI.php';
161  $cont_loc = new ilLocatorGUI();
162  $cont_loc->addContextItems($item["ref_id"], true);
163  $cont_loc->setTextOnly(true);
164 
165  // #9954/#10044
166  // see ilInitialisation::requireCommonIncludes()
167  @include_once "HTML/Template/ITX.php"; // new implementation
168  if (class_exists("HTML_Template_ITX"))
169  {
170  include_once "./Services/UICore/classes/class.ilTemplateHTMLITX.php";
171  }
172  else
173  {
174  include_once "HTML/ITX.php"; // old implementation
175  include_once "./Services/UICore/classes/class.ilTemplateITX.php";
176  }
177  require_once "./Services/UICore/classes/class.ilTemplate.php";
178 
179  $loc = "[".$cont_loc->getHTML()."]";
180 
181  $this->appendBody("----------------------------------------------------------------------------------------------");
182  $this->appendBody("\n\n");
183  $this->appendBody('#'.$counter." - ".$loc." ".$obj_title."\n\n");
184  $this->appendBody($title);
185  if($content)
186  {
187  $this->appendBody("\n");
188  $this->appendBody($content);
189  }
190  $this->appendBody("\n\n");
191 
192  ++$counter;
193  }
194  $this->appendBody("----------------------------------------------------------------------------------------------");
195  $this->appendBody("\n\n");
196 
197  // link to object
198  $this->appendBody($this->getLanguageText("crs_course_group_notification_link"));
199  $this->appendBody("\n");
200  $object_link = ilUtil::_getHttpPath();
201  $object_link .= "/goto.php?target=".$obj_type."_".$a_ref_id.
202  "&client_id=".CLIENT_ID;
203  $this->appendBody($object_link);
204 
205  $this->appendBody("\n\n");
208 
209  // #10044
210  $mail = new ilMail($ilUser->getId());
211  $mail->enableSOAP(false); // #10410
212  $mail->sendMail(ilObjUser::_lookupLogin($a_user_id),null,null,
213  $this->getSubject(),$this->getBody(),null,array("system"));
214  }
215 }
216 
217 ?>