ILIAS  release_4-4 Revision
ilForumCronNotification Class Reference

Forum notifications. More...

+ Inheritance diagram for ilForumCronNotification:
+ Collaboration diagram for ilForumCronNotification:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 run ()
 
 activationWasToggled ($a_currently_active)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
- 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...
 
 getValidScheduleTypes ()
 Get all available schedule types. 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

 sendMails ($res)
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $settings
 

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

Forum notifications.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 12 of file class.ilForumCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumCronNotification::__construct ( )

Definition at line 22 of file class.ilForumCronNotification.php.

23  {
24  $this->settings = new ilSetting('frma');
25  }
ILIAS Setting Class.

Member Function Documentation

◆ activationWasToggled()

ilForumCronNotification::activationWasToggled (   $a_currently_active)

Definition at line 269 of file class.ilForumCronNotification.php.

References $ilSetting, $lng, ilCronJob\addCustomSettingsToForm(), ilPropertyFormGUI\addItem(), and ilNumberInputGUI\setSize().

270  {
271  global $ilSetting;
272 
273  // propagate cron-job setting to object setting
274  if((bool)$a_currently_active)
275  {
276  $ilSetting->set('forum_notification', 2);
277  }
278  else
279  {
280  $ilSetting->set('forum_notification', 1);
281  }
282  }
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilForumCronNotification::getDefaultScheduleType ( )

Definition at line 46 of file class.ilForumCronNotification.php.

47  {
48  return self::SCHEDULE_TYPE_IN_HOURS;
49  }

◆ getDefaultScheduleValue()

ilForumCronNotification::getDefaultScheduleValue ( )

Definition at line 51 of file class.ilForumCronNotification.php.

52  {
53  return 1;
54  }

◆ getDescription()

ilForumCronNotification::getDescription ( )

Definition at line 39 of file class.ilForumCronNotification.php.

References $lng.

40  {
41  global $lng;
42 
43  return $lng->txt("cron_forum_notification_crob_desc");
44  }
global $lng
Definition: privfeed.php:40

◆ getId()

ilForumCronNotification::getId ( )

Definition at line 27 of file class.ilForumCronNotification.php.

28  {
29  return "frm_notification";
30  }

◆ getTitle()

ilForumCronNotification::getTitle ( )

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

References $lng.

33  {
34  global $lng;
35 
36  return $lng->txt("cron_forum_notification");
37  }
global $lng
Definition: privfeed.php:40

◆ hasAutoActivation()

ilForumCronNotification::hasAutoActivation ( )

Definition at line 56 of file class.ilForumCronNotification.php.

57  {
58  return false;
59  }

◆ hasCustomSettings()

ilForumCronNotification::hasCustomSettings ( )
Returns
bool

Definition at line 69 of file class.ilForumCronNotification.php.

70  {
71  return true;
72  }

◆ hasFlexibleSchedule()

ilForumCronNotification::hasFlexibleSchedule ( )

Definition at line 61 of file class.ilForumCronNotification.php.

62  {
63  return true;
64  }

◆ run()

ilForumCronNotification::run ( )

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

References $ilLog, $ilSetting, $lng, $res, $result, sendMails(), ilCronJobResult\STATUS_NO_ACTION, and ilCronJobResult\STATUS_OK.

75  {
76  global $ilDB, $ilLog, $ilSetting, $lng;
77 
79 
80  $lng->loadLanguageModule('forum');
81 
82  if(!($last_run_datetime = $ilSetting->get('cron_forum_notification_last_date')))
83  {
84  $last_run_datetime = null;
85  }
86 
87  $numRows = 0;
88  $types = array();
89  $values = array();
90 
91  if($last_run_datetime != null &&
92  checkDate(date('m', strtotime($last_run_datetime)), date('d', strtotime($last_run_datetime)), date('Y', strtotime($last_run_datetime))))
93  {
94  $threshold = max(strtotime($last_run_datetime), strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time()));
95  }
96  else
97  {
98  $threshold = strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time());
99  }
100 
101  $date_condition = ' frm_posts.pos_date >= %s AND ';
102  $types[] = 'timestamp';
103  $values[] = date('Y-m-d H:i:s', $threshold);
104 
105  $cj_start_date = date('Y-m-d H:i:s');
106 
107  /*** FORUMS ***/
108  $res = $ilDB->queryf('
109  SELECT frm_threads.thr_subject thr_subject,
110  frm_data.top_name top_name,
111  frm_data.top_frm_fk obj_id,
112  frm_notification.user_id user_id,
113  frm_posts.*
114  FROM frm_notification, frm_posts, frm_threads, frm_data
115  WHERE '.$date_condition.' frm_posts.pos_thr_fk = frm_threads.thr_pk
116  AND frm_threads.thr_top_fk = frm_data.top_pk
117  AND frm_data.top_frm_fk = frm_notification.frm_id
118  ORDER BY frm_posts.pos_date ASC',
119  $types,
120  $values
121  );
122 
123  $numRows += $this->sendMails($res);
124 
125  /*** THREADS ***/
126  $res = $ilDB->queryf('
127  SELECT frm_threads.thr_subject thr_subject,
128  frm_data.top_name top_name,
129  frm_data.top_frm_fk obj_id,
130  frm_notification.user_id user_id,
131  frm_posts.*
132  FROM frm_notification, frm_posts, frm_threads, frm_data
133  WHERE '.$date_condition.' frm_posts.pos_thr_fk = frm_threads.thr_pk
134  AND frm_threads.thr_pk = frm_notification.thread_id
135  AND frm_data.top_pk = frm_threads.thr_top_fk
136  ORDER BY frm_posts.pos_date ASC',
137  $types,
138  $values
139  );
140 
141  $numRows += $this->sendMails($res);
142 
143  $ilSetting->set('cron_forum_notification_last_date', $cj_start_date);
144 
145  $mess = 'Send '.$numRows.' messages.';
146  $ilLog->write(__METHOD__.': '.$mess);
147 
148  $result = new ilCronJobResult();
149  if($numRows)
150  {
151  $status = ilCronJobResult::STATUS_OK;
152  $result->setMessage($mess);
153  };
154  $result->setStatus($status);
155  return $result;
156  }
$result
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
Cron job result data container.
+ Here is the call graph for this function:

◆ saveCustomSettings()

ilForumCronNotification::saveCustomSettings ( ilPropertyFormGUI  $a_form)
Parameters
ilPropertyFormGUI$a_form

Definition at line 311 of file class.ilForumCronNotification.php.

References ilPropertyFormGUI\getInput().

312  {
313  $this->settings->set('max_notification_age', $a_form->getInput('max_notification_age'));
314  return true;
315  }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
+ Here is the call graph for this function:

◆ sendMails()

ilForumCronNotification::sendMails (   $res)
protected

Definition at line 158 of file class.ilForumCronNotification.php.

References $lng, $ref_id, $res, $row, ilObject\_getAllReferences(), ilForum\_getLanguageInstanceByUsrId(), ilObjUser\_lookupLogin(), ilCronJob\addToExternalSettingsForm(), and ilAdministrationSettingsFormHandler\FORM_FORUM.

Referenced by run().

159  {
160  global $ilAccess, $ilDB, $lng;
161 
162  static $cache = array();
163  static $attachments_cache = array();
164 
165  include_once 'Modules/Forum/classes/class.ilObjForum.php';
166  include_once 'Services/Mail/classes/class.ilMail.php';
167  include_once 'Services/User/classes/class.ilObjUser.php';
168  include_once 'Services/Language/classes/class.ilLanguage.php';
169 
170  $forumObj = new ilObjForum();
171  $frm = $forumObj->Forum;
172 
173  $numRows = 0;
174  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
175  $mail_obj->enableSOAP(false);
176  while($row = $ilDB->fetchAssoc($res))
177  {
178  // don not send a notification to the post author
179  if($row['pos_usr_id'] != $row['user_id'])
180  {
181  // GET AUTHOR OF NEW POST
182  if($row['pos_usr_id'])
183  {
184  $row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_usr_id']);
185  }
186  else if(strlen($row['pos_usr_alias']))
187  {
188  $row['pos_usr_name'] = $row['pos_usr_alias'].' ('.$lng->txt('frm_pseudonym').')';
189  }
190 
191  if($row['pos_usr_name'] == '')
192  {
193  $row['pos_usr_name'] = $lng->txt('forums_anonymous');
194  }
195 
196  // get all references of obj_id
197  if(!isset($cache[$row['obj_id']]))
198  $cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']);
199 
200  // check for attachments
201  $has_attachments = false;
202  if(!isset($attachments_cache[$row['obj_id']][$row['pos_pk']]))
203  {
204  $fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']);
205  $filesOfPost = $fileDataForum->getFilesOfPost();
206  foreach($filesOfPost as $attachment)
207  {
208  $attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name'];
209  $has_attachments = true;
210  }
211  }
212  else
213  {
214  $has_attachments = true;
215  }
216 
217  // do rbac check before sending notification
218  $send_mail = false;
219  foreach((array)$cache[$row['obj_id']] as $ref_id)
220  {
221  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
222  {
223  $row['ref_id'] = $ref_id;
224  $send_mail = true;
225  break;
226  }
227  }
228  $attached_files = array();
229  if($has_attachments == true)
230  {
231  $attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']];
232  }
233 
234  if($send_mail)
235  {
236  $frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id']));
237  $mail_obj->sendMail(
238  ilObjUser::_lookupLogin($row['user_id']), '', '',
239  $frm->formatNotificationSubject($row),
240  $frm->formatNotification($row, 1, $attached_files, $row['user_id']),
241  array(), array(
242  'normal'
243  ));
244  $numRows++;
245  }
246  }
247  }
248 
249  return $numRows;
250  }
static _getAllReferences($a_id)
get all reference ids of object
Class Mail this class handles base functions for mail handling.
_lookupLogin($a_user_id)
lookup login
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:40
This class handles all operations on files for the forum object.
static _getLanguageInstanceByUsrId($usr_id)
Get the ilLanguage instance for the passed user id.
Class ilObjForum.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $settings

ilForumCronNotification::$settings
protected

Definition at line 17 of file class.ilForumCronNotification.php.


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