ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilForumCronNotification Class Reference

Forum notifications. More...

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

Public Member Functions

 __construct ()
 getId ()
 Get id.
 getTitle ()
 Get title.
 getDescription ()
 Get description.
 getDefaultScheduleType ()
 Get schedule type.
 getDefaultScheduleValue ()
 Get schedule value.
 hasAutoActivation ()
 Is to be activated on "installation".
 hasFlexibleSchedule ()
 Can the schedule be configured?
 hasCustomSettings ()
 run ()
 Run job.
 activationWasToggled ($a_currently_active)
 Cron job status was changed.
 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?
 getScheduleType ()
 Get current schedule type (if flexible)
 getScheduleValue ()
 Get current schedule value (if flexible)
 setSchedule ($a_type, $a_value)
 Update current schedule (if flexible)
 getValidScheduleTypes ()
 Get all available schedule types.
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually.
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form.
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form.

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

ilForumCronNotification::__construct ( )

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

{
$this->settings = new ilSetting('frma');
}

Member Function Documentation

ilForumCronNotification::activationWasToggled (   $a_currently_active)

Cron job status was changed.

Parameters
bool$a_currently_active

Reimplemented from ilCronJob.

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

References $ilSetting.

{
global $ilSetting;
// propagate cron-job setting to object setting
if((bool)$a_currently_active)
{
$ilSetting->set('forum_notification', 2);
}
else
{
$ilSetting->set('forum_notification', 1);
}
}
ilForumCronNotification::getDefaultScheduleType ( )

Get schedule type.

Returns
int

Reimplemented from ilCronJob.

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

References ilCronJob\SCHEDULE_TYPE_IN_HOURS.

ilForumCronNotification::getDefaultScheduleValue ( )

Get schedule value.

Returns
int|array

Reimplemented from ilCronJob.

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

{
return 1;
}
ilForumCronNotification::getDescription ( )

Get description.

Returns
string

Reimplemented from ilCronJob.

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

References $lng.

{
global $lng;
return $lng->txt("cron_forum_notification_crob_desc");
}
ilForumCronNotification::getId ( )

Get id.

Returns
string

Reimplemented from ilCronJob.

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

{
return "frm_notification";
}
ilForumCronNotification::getTitle ( )

Get title.

Returns
string

Reimplemented from ilCronJob.

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

References $lng.

{
global $lng;
return $lng->txt("cron_forum_notification");
}
ilForumCronNotification::hasAutoActivation ( )

Is to be activated on "installation".

Returns
boolean

Reimplemented from ilCronJob.

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

{
return false;
}
ilForumCronNotification::hasCustomSettings ( )
Returns
bool

Reimplemented from ilCronJob.

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

{
return true;
}
ilForumCronNotification::hasFlexibleSchedule ( )

Can the schedule be configured?

Returns
boolean

Reimplemented from ilCronJob.

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

{
return true;
}
ilForumCronNotification::run ( )

Run job.

Returns
ilCronJobResult

Reimplemented from ilCronJob.

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

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

{
global $ilDB, $ilLog, $ilSetting, $lng;
$lng->loadLanguageModule('forum');
if(!($last_run_datetime = $ilSetting->get('cron_forum_notification_last_date')))
{
$last_run_datetime = null;
}
$numRows = 0;
$types = array();
$values = array();
if($last_run_datetime != null &&
checkDate(date('m', strtotime($last_run_datetime)), date('d', strtotime($last_run_datetime)), date('Y', strtotime($last_run_datetime))))
{
$threshold = max(strtotime($last_run_datetime), strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time()));
}
else
{
$threshold = strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time());
}
$date_condition = ' frm_posts.pos_date >= %s AND ';
$types[] = 'timestamp';
$values[] = date('Y-m-d H:i:s', $threshold);
$cj_start_date = date('Y-m-d H:i:s');
/*** FORUMS ***/
$res = $ilDB->queryf('
SELECT frm_threads.thr_subject thr_subject,
frm_data.top_name top_name,
frm_data.top_frm_fk obj_id,
frm_notification.user_id user_id,
frm_posts.*
FROM frm_notification, frm_posts, frm_threads, frm_data
WHERE '.$date_condition.' frm_posts.pos_thr_fk = frm_threads.thr_pk
AND frm_threads.thr_top_fk = frm_data.top_pk
AND frm_data.top_frm_fk = frm_notification.frm_id
ORDER BY frm_posts.pos_date ASC',
$types,
$values
);
$numRows += $this->sendMails($res);
/*** THREADS ***/
$res = $ilDB->queryf('
SELECT frm_threads.thr_subject thr_subject,
frm_data.top_name top_name,
frm_data.top_frm_fk obj_id,
frm_notification.user_id user_id,
frm_posts.*
FROM frm_notification, frm_posts, frm_threads, frm_data
WHERE '.$date_condition.' frm_posts.pos_thr_fk = frm_threads.thr_pk
AND frm_threads.thr_pk = frm_notification.thread_id
AND frm_data.top_pk = frm_threads.thr_top_fk
ORDER BY frm_posts.pos_date ASC',
$types,
$values
);
$numRows += $this->sendMails($res);
$ilSetting->set('cron_forum_notification_last_date', $cj_start_date);
$mess = 'Send '.$numRows.' messages.';
$ilLog->write(__METHOD__.': '.$mess);
if($numRows)
{
$result->setMessage($mess);
};
$result->setStatus($status);
return $result;
}

+ Here is the call graph for this function:

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

Reimplemented from ilCronJob.

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

References ilPropertyFormGUI\getInput().

{
$this->settings->set('max_notification_age', $a_form->getInput('max_notification_age'));
return true;
}

+ Here is the call graph for this function:

ilForumCronNotification::sendMails (   $res)
protected

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

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

Referenced by run().

{
global $ilAccess, $ilDB, $lng;
static $cache = array();
static $attachments_cache = array();
include_once 'Modules/Forum/classes/class.ilObjForum.php';
include_once 'Services/Mail/classes/class.ilMail.php';
include_once 'Services/User/classes/class.ilObjUser.php';
include_once 'Services/Language/classes/class.ilLanguage.php';
$forumObj = new ilObjForum();
$frm = $forumObj->Forum;
$numRows = 0;
$mail_obj = new ilMail(ANONYMOUS_USER_ID);
$mail_obj->enableSOAP(false);
while($row = $ilDB->fetchAssoc($res))
{
// don not send a notification to the post author
if($row['pos_usr_id'] != $row['user_id'])
{
// GET AUTHOR OF NEW POST
if($row['pos_usr_id'])
{
$row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_usr_id']);
}
else if(strlen($row['pos_usr_alias']))
{
$row['pos_usr_name'] = $row['pos_usr_alias'].' ('.$lng->txt('frm_pseudonym').')';
}
if($row['pos_usr_name'] == '')
{
$row['pos_usr_name'] = $lng->txt('forums_anonymous');
}
// get all references of obj_id
if(!isset($cache[$row['obj_id']]))
$cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']);
// check for attachments
$has_attachments = false;
if(!isset($attachments_cache[$row['obj_id']][$row['pos_pk']]))
{
$fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']);
$filesOfPost = $fileDataForum->getFilesOfPost();
foreach($filesOfPost as $attachment)
{
$attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name'];
$has_attachments = true;
}
}
else
{
$has_attachments = true;
}
// do rbac check before sending notification
$send_mail = false;
foreach((array)$cache[$row['obj_id']] as $ref_id)
{
if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
{
$row['ref_id'] = $ref_id;
$send_mail = true;
break;
}
}
$attached_files = array();
if($has_attachments == true)
{
$attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']];
}
if($send_mail)
{
$frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id']));
$mail_obj->sendMail(
ilObjUser::_lookupLogin($row['user_id']), '', '',
$frm->formatNotificationSubject($row),
$frm->formatNotification($row, 1, $attached_files, $row['user_id']),
array(), array(
'normal'
));
$numRows++;
}
}
}
return $numRows;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilForumCronNotification::$settings
protected

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


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