ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSkillNotifications Class Reference

Course/group skill notification. More...

+ Inheritance diagram for ilSkillNotifications:
+ Collaboration diagram for ilSkillNotifications:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?CronJobScheduleType $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Member Functions

 sendMail (int $a_user_id, array $a_achievements, string $a_last_run)
 Send news mail for 1 user and n objects. More...
 

Protected Attributes

ilLanguage $lng
 
ilObjUser $user
 
ilIniFile $client_ini
 
ilTree $tree
 
SkillTreeService $tree_service
 
- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Course/group skill notification.

Author
Alex Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..com

Definition at line 30 of file class.ilSkillNotifications.php.

Constructor & Destructor Documentation

◆ __construct()

ilSkillNotifications::__construct ( )

Definition at line 38 of file class.ilSkillNotifications.php.

References $DIC, ILIAS\Repository\lng(), and ILIAS\Repository\user().

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  $this->tree_service = $DIC->skills()->tree();
53  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultScheduleType()

ilSkillNotifications::getDefaultScheduleType ( )

Definition at line 74 of file class.ilSkillNotifications.php.

75  {
76  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
77  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilSkillNotifications::getDefaultScheduleValue ( )

Definition at line 79 of file class.ilSkillNotifications.php.

79  : ?int
80  {
81  return null;
82  }

◆ getDescription()

ilSkillNotifications::getDescription ( )

Definition at line 67 of file class.ilSkillNotifications.php.

References $lng, ilLanguage\loadLanguageModule(), and ilLanguage\txt().

67  : string
68  {
69  $lng = $this->lng;
70  $lng->loadLanguageModule("skll");
71  return $lng->txt("skll_skill_notification_desc");
72  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
+ Here is the call graph for this function:

◆ getId()

ilSkillNotifications::getId ( )

Definition at line 55 of file class.ilSkillNotifications.php.

55  : string
56  {
57  return "skll_notification";
58  }

◆ getTitle()

ilSkillNotifications::getTitle ( )

Definition at line 60 of file class.ilSkillNotifications.php.

References $lng, ilLanguage\loadLanguageModule(), and ilLanguage\txt().

60  : string
61  {
62  $lng = $this->lng;
63  $lng->loadLanguageModule("skll");
64  return $lng->txt("skll_skill_notification");
65  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilSkillNotifications::hasAutoActivation ( )

Definition at line 84 of file class.ilSkillNotifications.php.

84  : bool
85  {
86  return false;
87  }

◆ hasFlexibleSchedule()

ilSkillNotifications::hasFlexibleSchedule ( )

Definition at line 89 of file class.ilSkillNotifications.php.

89  : bool
90  {
91  return true;
92  }

◆ run()

ilSkillNotifications::run ( )

Definition at line 94 of file class.ilSkillNotifications.php.

References Vendor\Package\$a, $DIC, $lng, $log, ilLoggerFactory\getLogger(), ilBasicSkill\getNewAchievementsPerUser(), sendMail(), ilDatePresentation\setUseRelativeDates(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilDatePresentation\useRelativeDates().

95  {
96  global $DIC;
97 
98  $lng = $DIC->language();
99 
101  $log->debug("===Skill Notifications=== start");
102 
104  $status_details = null;
105 
106  $setting = new ilSetting("cron");
107  $last_run = $setting->get(get_class($this));
108 
109  // no last run?
110  if (!$last_run) {
111  $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
112 
113  $status_details = "No previous run found - starting from yesterday.";
114  } // migration: used to be date-only value
115  elseif (strlen($last_run) == 10) {
116  $last_run .= " 00:00:00";
117 
118  $status_details = "Switched from daily runs to open schedule.";
119  }
120 
121  // init language/date
122  $old_lng = $lng;
125 
126 
127  // get latest course/group skill changes per user
128  $achievements = ilBasicSkill::getNewAchievementsPerUser($last_run);
129 
130  foreach ($achievements as $user_id => $a) {
131  $this->sendMail($user_id, $a, $last_run);
132  }
133 
134  // mails were sent - set cron job status accordingly
135  $status = ilCronJobResult::STATUS_OK;
136 
137  // reset language/date
139  $lng = $old_lng;
140 
141  $log->debug("save run");
142 
143  // save last run
144  $setting->set(get_class($this), date("Y-m-d H:i:s"));
145 
146  $result = new ilCronJobResult();
147  $result->setStatus($status);
148 
149  if ($status_details) {
150  $result->setMessage($status_details);
151  }
152 
153  $log->debug("===Skill Notifications=== done");
154 
155  return $result;
156  }
sendMail(int $a_user_id, array $a_achievements, string $a_last_run)
Send news mail for 1 user and n objects.
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28
$log
Definition: result.php:33
static getNewAchievementsPerUser(string $a_timestamp, string $a_timestamp_to=null, int $a_user_id=0, int $a_self_eval=0)
final const STATUS_NO_ACTION
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static setUseRelativeDates(bool $a_status)
set use relative dates
+ Here is the call graph for this function:

◆ sendMail()

ilSkillNotifications::sendMail ( int  $a_user_id,
array  $a_achievements,
string  $a_last_run 
)
protected

Send news mail for 1 user and n objects.

Definition at line 161 of file class.ilSkillNotifications.php.

References $client, $client_ini, $path, $ref_id, $tree, $txt, ilLink\_getStaticLink(), ilObjUser\_lookupLogin(), ilSkillTreeNode\_lookupTitle(), ANONYMOUS_USER_ID, ilDatePresentation\formatDate(), ilTree\getPathId(), ilLanguage\getUserLanguage(), IL_CAL_DATETIME, IL_CAL_UNIX, ilTree\isInTree(), ilBasicSkill\lookupLevelTitle(), and ilLanguage\txt().

Referenced by run().

161  : void
162  {
163  $ilClientIniFile = $this->client_ini;
164  $tree = $this->tree;
165 
166  $ntf = new ilSystemNotification();
167  $ntf->setLangModules(array("skll"));
168 
169  // user specific language
170  $lng = $ntf->getUserLanguage($a_user_id);
171 
172  $txt = "";
173  $last_obj_id = 0;
174 
175  // order skill achievements per virtual skill tree
176  $vtree = $this->tree_service->getGlobalVirtualSkillTree();
177  $a_achievements = $vtree->getOrderedNodeset($a_achievements, "skill_id", "tref_id");
178 
179  foreach ($a_achievements as $skill_level) {
180  // path
181  $path = [];
182  foreach ($tree->getPathId($skill_level["trigger_ref_id"]) as $node) {
183  $path[] = $node;
184  }
185  $path = implode("-", $path);
186 
187  $ref_id = $skill_level["trigger_ref_id"];
188  $obj_id = $skill_level["trigger_obj_id"];
189  $type = $skill_level["trigger_obj_type"];
190  $title = $skill_level["trigger_title"];
191 
192  if ($skill_level["trigger_obj_id"] != $last_obj_id) {
193  $last_obj_id = $skill_level["trigger_obj_id"];
194  $txt .= "\n\n" . $lng->txt("obj_" . $type) . ": " . $title;
195  if ($tree->isInTree($ref_id)) {
197  }
198  }
199 
200  $date = ilDatePresentation::formatDate(new ilDateTime($skill_level["status_date"], IL_CAL_DATETIME));
201  $txt .= "\n $date, " . ilBasicSkill::_lookupTitle($skill_level["skill_id"], $skill_level["tref_id"]) . ": " .
202  ilBasicSkill::lookupLevelTitle($skill_level["level_id"]);
203  }
204 
205  $ntf->setIntroductionLangId("skll_intro_skill_notification_for");
206 
207  // index
208  $period = sprintf(
209  $lng->txt("skll_new_skill_achievements"),
212  );
213 
214  // text
215  $ntf->addAdditionalInfo(
216  "",
217  trim($txt),
218  true
219  );
220 
221  // :TODO: does it make sense to add client to subject?
222  $client = $ilClientIniFile->readVariable('client', 'name');
223  $subject = sprintf($lng->txt("skll_competence_achievements"), $client);
224 
225  //die($ntf->composeAndGetMessage($a_user_id, null, "read", true));
226 
227  // #10044
228  $mail = new ilMail(ANONYMOUS_USER_ID);
229  $mail->enqueue(
230  ilObjUser::_lookupLogin($a_user_id),
231  "",
232  "",
233  $subject,
234  $ntf->composeAndGetMessage($a_user_id, null, "read", true),
235  []
236  );
237  }
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:27
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getUserLanguage()
Return language of user.
isInTree(?int $a_node_id)
get all information of a node.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static lookupLevelTitle(int $a_id)
const IL_CAL_UNIX
$path
Definition: ltiservices.php:32
$client
$ref_id
Definition: ltiauth.php:67
$txt
Definition: error.php:14
getPathId(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupLogin(int $a_user_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $client_ini

ilIniFile ilSkillNotifications::$client_ini
protected

Definition at line 34 of file class.ilSkillNotifications.php.

Referenced by sendMail().

◆ $lng

ilLanguage ilSkillNotifications::$lng
protected

Definition at line 32 of file class.ilSkillNotifications.php.

Referenced by getDescription(), getTitle(), and run().

◆ $tree

ilTree ilSkillNotifications::$tree
protected

Definition at line 35 of file class.ilSkillNotifications.php.

Referenced by sendMail().

◆ $tree_service

SkillTreeService ilSkillNotifications::$tree_service
protected

Definition at line 36 of file class.ilSkillNotifications.php.

◆ $user

ilObjUser ilSkillNotifications::$user
protected

Definition at line 33 of file class.ilSkillNotifications.php.


The documentation for this class was generated from the following file: