ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSkillNotifications.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Services/Cron/classes/class.ilCronJob.php";
6
13{
17 protected $lng;
18
22 protected $user;
23
27 protected $client_ini;
28
32 protected $tree;
33
34
38 public function __construct()
39 {
40 global $DIC;
41
42 $this->lng = $DIC->language();
43 if (isset($DIC["ilUser"])) {
44 $this->user = $DIC->user();
45 }
46 if (isset($DIC["ilClientIniFile"])) {
47 $this->client_ini = $DIC["ilClientIniFile"];
48 }
49 if (isset($DIC["tree"])) {
50 $this->tree = $DIC->repositoryTree();
51 }
52 }
53
54 public function getId()
55 {
56 return "skll_notification";
57 }
58
59 public function getTitle()
60 {
62 $lng->loadLanguageModule("skll");
63 return $lng->txt("skll_skill_notification");
64 }
65
66 public function getDescription()
67 {
69 $lng->loadLanguageModule("skll");
70 return $lng->txt("skll_skill_notification_desc");
71 }
72
73 public function getDefaultScheduleType()
74 {
76 }
77
78 public function getDefaultScheduleValue()
79 {
80 return;
81 }
82
83 public function hasAutoActivation()
84 {
85 return false;
86 }
87
88 public function hasFlexibleSchedule()
89 {
90 return true;
91 }
92
93 public function run()
94 {
95 global $DIC;
96
97 $lng = $DIC->language();
98
100 $log->debug("===Skill Notifications=== start");
101
103 $status_details = null;
104
105 $setting = new ilSetting("cron");
106 $last_run = $setting->get(get_class($this));
107
108 // no last run?
109 if (!$last_run) {
110 $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
111
112 $status_details = "No previous run found - starting from yesterday.";
113 } // migration: used to be date-only value
114 elseif (strlen($last_run) == 10) {
115 $last_run .= " 00:00:00";
116
117 $status_details = "Switched from daily runs to open schedule.";
118 }
119
120 // init language/date
121 $old_lng = $lng;
124
125
126 // $last_run = "2017-07-20 12:00:00";
127
128 // get latest course/group skill changes per user
129 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
130 $achievements = ilBasicSkill::getNewAchievementsPerUser($last_run);
131
132 foreach ($achievements as $user_id => $a) {
133 $this->sendMail($user_id, $a, $last_run);
134 }
135
136 // mails were sent - set cron job status accordingly
138
139 // reset language/date
141 $lng = $old_lng;
142
143 $log->debug("save run");
144
145 // save last run
146 $setting->set(get_class($this), date("Y-m-d H:i:s"));
147
148 $result = new ilCronJobResult();
149 $result->setStatus($status);
150
151 if ($status_details) {
152 $result->setMessage($status_details);
153 }
154
155 $log->debug("===Skill Notifications=== done");
156
157 return $result;
158 }
159
160
168 protected function sendMail($a_user_id, array $a_achievements, $a_last_run)
169 {
172 $ilClientIniFile = $this->client_ini;
174
175 include_once "./Services/Notification/classes/class.ilSystemNotification.php";
176 $ntf = new ilSystemNotification();
177 $ntf->setLangModules(array("skll"));
178
179 // user specific language
180 $lng = $ntf->getUserLanguage($a_user_id);
181
182 include_once './Services/Locator/classes/class.ilLocatorGUI.php';
183 require_once "./Services/UICore/classes/class.ilTemplate.php";
184 require_once "./Services/Link/classes/class.ilLink.php";
185
186
187 $tmp = array();
188 $txt = "";
189 $last_obj_id = 0;
190
191 // order skill achievements per virtual skill tree
192 include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
193 $vtree = new ilVirtualSkillTree();
194 $a_achievements = $vtree->getOrderedNodeset($a_achievements, "skill_id", "tref_id");
195
196 foreach ($a_achievements as $skill_level) {
197 $parent = array();
198
199 // path
200 $path = array();
201 foreach ($tree->getPathId($skill_level["trigger_ref_id"]) as $node) {
202 $path[] = $node;
203 }
204 $path = implode("-", $path);
205
206 $ref_id = $skill_level["trigger_ref_id"];
207 $obj_id = $skill_level["trigger_obj_id"];
208 $type = $skill_level["trigger_obj_type"];
209 $title = $skill_level["trigger_title"];
210
211 if ($skill_level["trigger_obj_id"] != $last_obj_id) {
212 $last_obj_id = $skill_level["trigger_obj_id"];
213 $txt .= "\n\n" . $lng->txt("obj_" . $type) . ": " . $title;
214 if ($tree->isInTree($ref_id)) {
215 $txt .= "\n" . ilLink::_getStaticLink($ref_id);
216 }
217 }
218
219 $date = ilDatePresentation::formatDate(new ilDateTime($skill_level["status_date"], IL_CAL_DATETIME));
220 $txt .= "\n $date, " . ilBasicSkill::_lookupTitle($skill_level["skill_id"], $skill_level["tref_id"]) . ": " .
221 ilBasicSkill::lookupLevelTitle($skill_level["level_id"]);
222 }
223
224 $ntf->setIntroductionLangId("skll_intro_skill_notification_for");
225
226 // index
227 $period = sprintf(
228 $lng->txt("skll_new_skill_achievements"),
231 );
232
233 // text
234 $ntf->addAdditionalInfo(
235 "",
236 trim($txt),
237 true
238 );
239
240 // :TODO: does it make sense to add client to subject?
241 $client = $ilClientIniFile->readVariable('client', 'name');
242 $subject = sprintf($lng->txt("skll_competence_achievements"), $client);
243
244 //die($ntf->composeAndGetMessage($a_user_id, null, "read", true));
245
246 // #10044
247 $mail = new ilMail(ANONYMOUS_USER_ID);
248 $mail->enableSOAP(false); // #10410
249 $mail->sendMail(
250 ilObjUser::_lookupLogin($a_user_id),
251 null,
252 null,
253 $subject,
254 $ntf->composeAndGetMessage($a_user_id, null, "read", true),
255 null,
256 array("system")
257 );
258 }
259}
$result
user()
Definition: user.php:4
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
static lookupLevelTitle($a_id)
Lookup level title.
static getNewAchievementsPerUser($a_timestamp, $a_timestamp_to=null, $a_user_id=0, $a_self_eval=0)
Get new achievements.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
static getLogger($a_component_id)
Get component logger.
static _lookupLogin($a_user_id)
lookup login
ILIAS Setting Class.
Course/group skill notification.
hasFlexibleSchedule()
Can the schedule be configured?
sendMail($a_user_id, array $a_achievements, $a_last_run)
Send news mail for 1 user and n objects.
getDefaultScheduleValue()
Get schedule value.
getDefaultScheduleType()
Get schedule type.
hasAutoActivation()
Is to be activated on "installation".
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
Wrapper classes for system notifications.
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$txt
Definition: error.php:11
$type
$log
Definition: sabredav.php:21
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18