You are here

function _datereminder_load_reminders in Date Reminder 7

Same name and namespace in other branches
  1. 6.2 includes/db6.inc \_datereminder_load_reminders()
  2. 6 datereminder.module \_datereminder_load_reminders()

Load reminders filtering one one or more keys.

@example: $reminders = _datereminder_load_reminders(array('uid' => $uid));

Parameters

array $selectors: a key:value array specifying what to load from the reminders table. Anything in the reminder table is fair game, but generally the keys are 'nid', 'rid', or 'uid'.

node $node: Optional parameter. If set, $r->node is set for any loaded reminder with the right nid.

string $sortkey: Optional parameter. If set, returned nodes are sorted in this order.

Return value

array an array of reminder objects as selected from the database, keyed by rid. Each object also includes the node title and user name. Orer is as specified by sortkey.

4 calls to _datereminder_load_reminders()
datereminder_rules_action_set_reminder in ./datereminder.rules.inc
Called as a rule action to set a reminder on the given node.
_datereminder_form_summary in includes/datereminder_form.inc
Build a form with a list of reminders.
_datereminder_get_node_user_reminders in ./datereminder.module
Get existing reminder info for a node and current user.
_datereminder_update_node_reminders in includes/node.inc
Update all reminders for a node if the node is updated.

File

includes/db7.inc, line 155

Code

function _datereminder_load_reminders($selectors, $node = NULL, $sortkey = NULL) {
  $ret = array();
  $q = db_select('datereminder', 'r');
  $q
    ->join('node', 'n', 'r.nid = n.nid');
  $q
    ->join('users', 'u', 'r.uid = u.uid');
  $q
    ->fields('r');
  $q
    ->fields('u', array(
    'name',
  ));
  $q
    ->fields('n', array(
    'title',
  ));
  foreach ($selectors as $k => $v) {
    $q
      ->condition("r.{$k}", $v);
  }
  if ($sortkey != NULL) {
    $q
      ->orderBy("r.{$sortkey}");
  }
  $rems = $q
    ->execute()
    ->fetchAll();

  // Return is array keyed by rid.
  $ret = array();
  $user = $GLOBALS['user'];
  foreach ($rems as $r) {
    if ($node && $node->nid == $r->nid) {
      $r->node = $node;
    }
    if ($user && $user->uid == $r->uid) {
      $r->user = $user;
    }
    $ret[$r->rid] = $r;
  }
  return $ret;
}