ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 11 of file class.ilForumCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumCronNotification::__construct ( )

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

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

Member Function Documentation

◆ activationWasToggled()

ilForumCronNotification::activationWasToggled (   $a_currently_active)

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

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

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

◆ getDefaultScheduleType()

ilForumCronNotification::getDefaultScheduleType ( )

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

46  {
47  return self::SCHEDULE_TYPE_IN_HOURS;
48  }

◆ getDefaultScheduleValue()

ilForumCronNotification::getDefaultScheduleValue ( )

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

51  {
52  return 1;
53  }

◆ getDescription()

ilForumCronNotification::getDescription ( )

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

References $lng.

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

◆ getId()

ilForumCronNotification::getId ( )

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

27  {
28  return "frm_notification";
29  }

◆ getTitle()

ilForumCronNotification::getTitle ( )

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

References $lng.

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

◆ hasAutoActivation()

ilForumCronNotification::hasAutoActivation ( )

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

56  {
57  return false;
58  }

◆ hasCustomSettings()

ilForumCronNotification::hasCustomSettings ( )
Returns
bool

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

69  {
70  return true;
71  }

◆ hasFlexibleSchedule()

ilForumCronNotification::hasFlexibleSchedule ( )

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

61  {
62  return true;
63  }

◆ run()

ilForumCronNotification::run ( )

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

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

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

References ilPropertyFormGUI\getInput().

311  {
312  $this->settings->set('max_notification_age', $a_form->getInput('max_notification_age'));
313  return true;
314  }
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 157 of file class.ilForumCronNotification.php.

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

Referenced by run().

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


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