You are here

class Notifications_Scheduler_New_Posts in Notifications 7

Send new content posted since last notification.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
Notifications_Scheduler_Event::$accion_context protected property
Notifications_Scheduler_Event::$action_object protected property
Notifications_Scheduler_Event::$counter public property
Notifications_Scheduler_Event::$queue public property
Notifications_Scheduler_Event::$queue_item protected property
Notifications_Scheduler_Event::$subscriptions protected property
Notifications_Scheduler_Event::create_template function Create message template to build this event as text
Notifications_Scheduler_Event::done public function When done these events cannot be just deleted, we need to keep track of last time it was executed
Notifications_Scheduler_Event::get_action_context public function Get property from action context
Notifications_Scheduler_Event::prepare function Prepare this event to be triggered
Notifications_Scheduler_Event::prepare_subscriptions protected function Groups subscriptions. This one will just create a group for all
Notifications_Scheduler_Event::process function Process event, send pending notifications. Subscriptions start on $counter (min sid)
Notifications_Scheduler_Event::process_group protected function Process group, add all to a message and send out
Notifications_Scheduler_Event::query_subscriptions function Build query for subscriptions that match this event type
Notifications_Scheduler_Event::set_action public function Set action parameters
Notifications_Scheduler_Latest_Posts::subscription_types function Get subscription types triggered by this event
Notifications_Scheduler_New_Posts::get_last_time protected function Get last time (timestamp) when this event/action was executed
Notifications_Scheduler_New_Posts::load_content protected function Load nodes created and published since last time this was executed. It doesn't check node access Overrides Notifications_Scheduler_Latest_Posts::load_content
Notifications_Scheduler_New_Posts::prepare_context protected function Set action parameters, get field mapping from context Overrides Notifications_Scheduler_Latest_Posts::prepare_context
Notifications_Scheduler_New_Posts::user_access public function Check user access to event's objects. Overrides Notifications_Scheduler_Latest_Posts::user_access