ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSkillNotifications Class Reference

Course/group skill notification. More...

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

Public Member Functions

 __construct ()
 Constructor. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 isActive ($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
 Is job currently active? More...
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule ($a_type, $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...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually. More...
 
 hasCustomSettings ()
 Has cron job any custom setting which can be edited? More...
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form. More...
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 Save custom settings. More...
 
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form. More...
 
 activationWasToggled ($a_currently_active)
 Cron job status was changed. More...
 
 getId ()
 Get id. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 run ()
 Run job. More...
 

Protected Member Functions

 sendMail ($a_user_id, array $a_achievements, $a_last_run)
 Send news mail for 1 user and n objects. More...
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $lng
 
 $user
 
 $client_ini
 
 $tree
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 
const SCHEDULE_TYPE_IN_HOURS = 3
 
const SCHEDULE_TYPE_IN_DAYS = 4
 
const SCHEDULE_TYPE_WEEKLY = 5
 
const SCHEDULE_TYPE_MONTHLY = 6
 
const SCHEDULE_TYPE_QUARTERLY = 7
 
const SCHEDULE_TYPE_YEARLY = 8
 

Detailed Description

Course/group skill notification.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilSkillNotifications::__construct ( )

Constructor.

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

References $DIC, and user().

37  {
38  global $DIC;
39 
40  $this->lng = $DIC->language();
41  if (isset($DIC["ilUser"])) {
42  $this->user = $DIC->user();
43  }
44  if (isset($DIC["ilClientIniFile"])) {
45  $this->client_ini = $DIC["ilClientIniFile"];
46  }
47  if (isset($DIC["tree"])) {
48  $this->tree = $DIC->repositoryTree();
49  }
50  }
user()
Definition: user.php:4
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultScheduleType()

ilSkillNotifications::getDefaultScheduleType ( )

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

72  {
73  return self::SCHEDULE_TYPE_DAILY;
74  }

◆ getDefaultScheduleValue()

ilSkillNotifications::getDefaultScheduleValue ( )

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

77  {
78  return;
79  }

◆ getDescription()

ilSkillNotifications::getDescription ( )

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

References $lng.

65  {
66  $lng = $this->lng;
67  $lng->loadLanguageModule("skll");
68  return $lng->txt("skll_skill_notification_desc");
69  }

◆ getId()

ilSkillNotifications::getId ( )

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

53  {
54  return "skll_notification";
55  }

◆ getTitle()

ilSkillNotifications::getTitle ( )

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

References $lng.

58  {
59  $lng = $this->lng;
60  $lng->loadLanguageModule("skll");
61  return $lng->txt("skll_skill_notification");
62  }

◆ hasAutoActivation()

ilSkillNotifications::hasAutoActivation ( )

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

82  {
83  return false;
84  }

◆ hasFlexibleSchedule()

ilSkillNotifications::hasFlexibleSchedule ( )

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

87  {
88  return true;
89  }

◆ run()

ilSkillNotifications::run ( )

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

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

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

◆ sendMail()

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

Send news mail for 1 user and n objects.

Parameters
int$a_user_id
array$a_objects
string$a_last_run

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

References $client, $client_ini, $lng, $tree, $txt, $type, ilLink\_getStaticLink(), ilObjUser\_lookupLogin(), ilSkillTreeNode\_lookupTitle(), ANONYMOUS_USER_ID, ilDatePresentation\formatDate(), IL_CAL_DATETIME, IL_CAL_UNIX, and ilBasicSkill\lookupLevelTitle().

Referenced by run().

166  {
167  $ilClientIniFile = $this->client_ini;
168  $tree = $this->tree;
169 
170  $ntf = new ilSystemNotification();
171  $ntf->setLangModules(array("skll"));
172 
173  // user specific language
174  $lng = $ntf->getUserLanguage($a_user_id);
175 
176  $tmp = array();
177  $txt = "";
178  $last_obj_id = 0;
179 
180  // order skill achievements per virtual skill tree
181  $vtree = new ilVirtualSkillTree();
182  $a_achievements = $vtree->getOrderedNodeset($a_achievements, "skill_id", "tref_id");
183 
184  foreach ($a_achievements as $skill_level) {
185  $parent = array();
186 
187  // path
188  $path = array();
189  foreach ($tree->getPathId($skill_level["trigger_ref_id"]) as $node) {
190  $path[] = $node;
191  }
192  $path = implode("-", $path);
193 
194  $ref_id = $skill_level["trigger_ref_id"];
195  $obj_id = $skill_level["trigger_obj_id"];
196  $type = $skill_level["trigger_obj_type"];
197  $title = $skill_level["trigger_title"];
198 
199  if ($skill_level["trigger_obj_id"] != $last_obj_id) {
200  $last_obj_id = $skill_level["trigger_obj_id"];
201  $txt .= "\n\n" . $lng->txt("obj_" . $type) . ": " . $title;
202  if ($tree->isInTree($ref_id)) {
204  }
205  }
206 
207  $date = ilDatePresentation::formatDate(new ilDateTime($skill_level["status_date"], IL_CAL_DATETIME));
208  $txt .= "\n $date, " . ilBasicSkill::_lookupTitle($skill_level["skill_id"], $skill_level["tref_id"]) . ": " .
209  ilBasicSkill::lookupLevelTitle($skill_level["level_id"]);
210  }
211 
212  $ntf->setIntroductionLangId("skll_intro_skill_notification_for");
213 
214  // index
215  $period = sprintf(
216  $lng->txt("skll_new_skill_achievements"),
219  );
220 
221  // text
222  $ntf->addAdditionalInfo(
223  "",
224  trim($txt),
225  true
226  );
227 
228  // :TODO: does it make sense to add client to subject?
229  $client = $ilClientIniFile->readVariable('client', 'name');
230  $subject = sprintf($lng->txt("skll_competence_achievements"), $client);
231 
232  //die($ntf->composeAndGetMessage($a_user_id, null, "read", true));
233 
234  // #10044
235  $mail = new ilMail(ANONYMOUS_USER_ID);
236  $mail->enqueue(
237  ilObjUser::_lookupLogin($a_user_id),
238  null,
239  null,
240  $subject,
241  $ntf->composeAndGetMessage($a_user_id, null, "read", true),
242  []
243  );
244  }
static _lookupLogin($a_user_id)
lookup login
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:25
$type
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
static lookupLevelTitle(int $a_id)
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
$txt
Definition: error.php:13
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
Wrapper classes for system notifications.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $client_ini

ilSkillNotifications::$client_ini
protected

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

Referenced by sendMail().

◆ $lng

ilSkillNotifications::$lng
protected

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

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

◆ $tree

ilSkillNotifications::$tree
protected

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

Referenced by sendMail().

◆ $user

ilSkillNotifications::$user
protected

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


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