class Notifications_Scheduler_New_Posts in Notifications 7
Send new content posted since last notification.
Hierarchy
- class \Notifications_Scheduler_Event extends \Notifications_Event
Expanded class hierarchy of Notifications_Scheduler_New_Posts
1 string reference to 'Notifications_Scheduler_New_Posts'
- notifications_scheduler_notifications in notifications_scheduler/
notifications_scheduler.module - Implements hook_notifications().
File
- notifications_scheduler/
notifications_scheduler.inc, line 249 - Drupal Notifications Framework - Default class file
View source
class Notifications_Scheduler_New_Posts extends Notifications_Scheduler_Latest_Posts {
/**
* Set action parameters, get field mapping from context
*
* We need to find out when this was last executed for which we build a unique key based on parameters
* and also we must log it somewhere
*/
protected function prepare_context() {
parent::prepare_context();
$this->action = 'new_posts';
foreach ($this
->get_objects() as $object) {
$this->action .= ':' . $object
->index();
}
// Our action could look like new_posts:type:story:term:25
}
/**
* Load nodes created and published since last time this was executed. It doesn't check node access
*/
protected function load_content() {
// Only nodes updated since last time
$query = db_select('node', 'n')
->fields('n', array(
'nid',
'created',
))
->orderBy('n.created', 'DESC')
->condition('n.status', 1)
->condition('n.changed', $this
->get_last_time(), '>=')
->extend('PagerDefault')
->limit($this
->get_action_context('node_number', 50));
if ($type = $this
->get_action_context('node_type')) {
$query
->condition('type', $type);
}
if ($tid = $this
->get_action_context('taxonomy_term')) {
$query
->join('taxonomy_index', 't', 'n.nid = t.nid');
$query
->condition('t.tid', $tid);
}
if ($nids = $query
->execute()
->fetchCol()) {
return node_load_multiple($nids);
}
}
/**
* Get last time (timestamp) when this event/action was executed
*
* @return int (timestamp)
*/
protected function get_last_time() {
$last = (int) db_query('SELECT MAX(created) FROM {notifications_event} WHERE type = :type AND action = :action', array(
':type' => $this->type,
':action' => $this->action,
))
->fetchField();
return $last ? $last : variable_get('notifications_scheduler_last', 0);
}
/**
* Check user access to event's objects.
*/
public function user_access($account, $op = 'view') {
return user_access('access content', $account);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Notifications_Scheduler_Event:: |
protected | property | ||
Notifications_Scheduler_Event:: |
protected | property | ||
Notifications_Scheduler_Event:: |
public | property | ||
Notifications_Scheduler_Event:: |
public | property | ||
Notifications_Scheduler_Event:: |
protected | property | ||
Notifications_Scheduler_Event:: |
protected | property | ||
Notifications_Scheduler_Event:: |
function | Create message template to build this event as text | ||
Notifications_Scheduler_Event:: |
public | function | When done these events cannot be just deleted, we need to keep track of last time it was executed | |
Notifications_Scheduler_Event:: |
public | function | Get property from action context | |
Notifications_Scheduler_Event:: |
function | Prepare this event to be triggered | ||
Notifications_Scheduler_Event:: |
protected | function | Groups subscriptions. This one will just create a group for all | |
Notifications_Scheduler_Event:: |
function | Process event, send pending notifications. Subscriptions start on $counter (min sid) | ||
Notifications_Scheduler_Event:: |
protected | function | Process group, add all to a message and send out | |
Notifications_Scheduler_Event:: |
function | Build query for subscriptions that match this event type | ||
Notifications_Scheduler_Event:: |
public | function | Set action parameters | |
Notifications_Scheduler_Latest_Posts:: |
function | Get subscription types triggered by this event | ||
Notifications_Scheduler_New_Posts:: |
protected | function | Get last time (timestamp) when this event/action was executed | |
Notifications_Scheduler_New_Posts:: |
protected | function |
Load nodes created and published since last time this was executed. It doesn't check node access Overrides Notifications_Scheduler_Latest_Posts:: |
|
Notifications_Scheduler_New_Posts:: |
protected | function |
Set action parameters, get field mapping from context Overrides Notifications_Scheduler_Latest_Posts:: |
|
Notifications_Scheduler_New_Posts:: |
public | function |
Check user access to event's objects. Overrides Notifications_Scheduler_Latest_Posts:: |