You are here

function _datereminder_set_node_enabled in Date Reminder 6.2

Same name and namespace in other branches
  1. 6 datereminder.module \_datereminder_set_node_enabled()
  2. 7 includes/db7.inc \_datereminder_set_node_enabled()

Enable/disable reminders for a node.

Note that this should only be used for node types with reminders enabled. (Or at least in RETAIN state.) If a type is set to DISASBLED, all node-specific information should be cleaned out by calling _datereminder_clean_type_reminders().

@todo This ought to use the database apis instead of the explicit insert...duplicate key. Probably best to try an update first, then an insert if that fails. It will only fail once per node.

Probably most of this except the actual database part should be moved to node.inc.

Parameters

node $node: The node

int $enabled: Value to set enable flag to for this node. If NULL, remove all record of this node in the datereminder tables.

3 calls to _datereminder_set_node_enabled()
datereminder_node_delete in includes/node.inc
Implements hook_node_delete().
datereminder_node_insert in includes/node.inc
Implements hook_node_insert().
_datereminder_form_submit_node in ./datereminder.module
Handle form submit when admin enables or disables reminder for a node.

File

includes/db6.inc, line 84

Code

function _datereminder_set_node_enabled($node, $enabled = NULL) {
  $nid = $node->nid;
  switch ($enabled) {
    case NULL:
    case DATEREMINDER_TYPE_DISABLED:
      _datereminder_clean_node_reminders($nid, $enabled);
      break;
    default:

      // Setting to one of the enabled states. We should probably read,
      // then update or insert. Maybe do update, then insert on failure?
      $q = 'INSERT INTO {datereminder_enable} (nid, enabled)';
      $q .= ' VALUE (%d,%d) ON DUPLICATE KEY UPDATE enabled = %d';
      db_query($q, $nid, $enabled, $enabled);
  }
}