You are here

class Notifications_Scheduler_Latest_Posts in Notifications 7

Test this schedule class, send latest created nodes

Hierarchy

Expanded class hierarchy of Notifications_Scheduler_Latest_Posts

1 string reference to 'Notifications_Scheduler_Latest_Posts'
notifications_scheduler_notifications in notifications_scheduler/notifications_scheduler.module
Implements hook_notifications().

File

notifications_scheduler/notifications_scheduler.inc, line 186
Drupal Notifications Framework - Default class file

View source
class Notifications_Scheduler_Latest_Posts extends Notifications_Scheduler_Event {

  /**
   * Set action parameters, get field mapping from context
   */
  protected function prepare_context() {
    if ($type = $this
      ->get_action_context('node_type')) {
      $this
        ->add_object('node_type', $type);
    }

    // Some hack, try a field with array value ??
    if ($tid = $this
      ->get_action_context('taxonomy_term')) {
      $this
        ->add_object('taxonomy_term', $tid);
    }
  }

  /**
   * Load nodes created and published or updated since latest time. It doesn't check node access
   */
  protected function load_content() {
    $query = db_select('node', 'n')
      ->fields('n', array(
      'nid',
      'created',
    ))
      ->orderBy('n.created', 'DESC')
      ->condition('n.status', 1)
      ->extend('PagerDefault')
      ->limit($this
      ->get_action_context('node_number', variable_get('default_nodes_main', 10)));
    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);
    }
  }

  /**
   * Check user access to event's objects.
   */
  public function user_access($account, $op = 'view') {
    return user_access('access content', $account);
  }

  /**
   * Get subscription types triggered by this event
   */
  function subscription_types() {
    $types = parent::subscription_types();
    $type = $this
      ->get_action_context('node_type');
    $term = $this
      ->get_action_context('taxonomy_term');
    if ($type) {
      $types[] = 'content_type';
    }
    if ($term) {
      $types[] = 'taxonomy_term';
    }
    if ($type && $term) {
      $types[] = 'content_type_term';
    }
    return $types;
  }

}

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::load_content protected function Load nodes created and published or updated since latest time. It doesn't check node access Overrides Notifications_Scheduler_Event::load_content 1
Notifications_Scheduler_Latest_Posts::prepare_context protected function Set action parameters, get field mapping from context Overrides Notifications_Scheduler_Event::prepare_context 1
Notifications_Scheduler_Latest_Posts::subscription_types function Get subscription types triggered by this event
Notifications_Scheduler_Latest_Posts::user_access public function Check user access to event's objects. Overrides Notifications_Scheduler_Event::user_access 1