function signup_save_node in Signup 7
Same name and namespace in other branches
- 5.2 signup.module \signup_save_node()
- 6.2 includes/node_form.inc \signup_save_node()
- 6 includes/node_form.inc \signup_save_node()
TODO: this doc is not correct for D7 Save signup-related information when a node is created or edited.
This is a helper function invoked via signup_nodeapi(). If signups are disabled, the record from {signup} (if any) is cleared. If the signup administrator editing the node decided to remove all signup data, all the records from the {signup_log} table for this node are also removed. This function is also responsible for testing if the node has a start time and if the autoclose period has already begun, in which case signups are closed. If a new node is being saved, or an existing node is updated and is newly-enabled for signups, the site-wide default signup settings are copied into a record in the {signup} table for this node so that the node is properly signup-enabled (these settings can be changed by visiting the "Settings" subtab under the "Signups" tab at node/N/signups/settings).
Parameters
stdClass $node: The node object given to signup_nodeapi().
string $op: The hook_nodeapi() operation, either 'insert' or 'update'.
See also
signup_nodeapi()
2 calls to signup_save_node()
- signup_node_insert in ./
signup.module - Implements hook_node_insert().
- signup_node_update in ./
signup.module - Implements hook_node_update().
File
- includes/
node_form.inc, line 30 - Signup-related code needed while editing a node.
Code
function signup_save_node($node, $op) {
// See if a user is editing a node and disables signups for it.
if ($op == 'update' && isset($node->signup_enabled)) {
switch ($node->signup_enabled) {
case 2:
// Disabled, and delete {signup_log}, too
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("DELETE FROM {signup_log} WHERE nid = %d", $node->nid) */
db_delete('signup_log')
->condition('nid', $node->nid)
->execute();
// No break, fall through and remove from {signup} too.
case 0:
// Disabled, but leave {signup_log} alone
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("DELETE FROM {signup} WHERE nid = %d", $node->nid) */
db_delete('signup')
->condition('nid', $node->nid)
->execute();
// We're done.
return;
}
}
// If the form is configured to have signups enabled, or the form doesn't
// include that information at all but the node type defaults to have
// signups enabled (which would happen if a user without signup admin
// permission created a node that defaulted to have signups enabled based on
// the node type), see if we need to insert a new record into the {signup}
// table for this node using the site-wide defaults.
$needs_defaults = FALSE;
if (isset($node->signup_enabled) && $node->signup_enabled == 1 || !isset($node->signup_enabled) && variable_get('signup_node_default_state_' . $node->type, 'disabled') == 'enabled_on') {
if ($op == 'insert') {
$needs_defaults = TRUE;
}
else {
// Updating -- see if we already have a record for this node.
$has_record = db_query("SELECT nid FROM {signup} WHERE nid = :nid", array(
':nid' => $node->nid,
))
->fetchField();
$needs_defaults = empty($has_record);
}
}
if ($needs_defaults) {
//TODO: this is untested
$values = db_query("SELECT forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email FROM {signup} WHERE nid = 0")
->fetchAssoc();
$values['nid'] = $node->nid;
db_insert('signup')
->fields(array(
'forwarding_email',
'send_confirmation',
'confirmation_email',
'close_signup_limit',
'send_reminder',
'reminder_days_before',
'reminder_email',
'nid',
))
->values($values)
->execute();
}
if (isset($node->signup_user_reg)) {
db_update('signup')
->fields(array(
'user_reg_form' => $node->signup_user_reg,
))
->condition('nid', $node->nid)
->execute();
}
$node = node_load($node->nid);
// We clear CCK's cache for this node due to an edge case bug:
// http://drupal.org/node/605594.
// TODO: is this still needed for D7?
if (module_exists('content')) {
cache_clear_all('content:' . $node->nid . ':' . $node->vid, content_cache_tablename());
}
if (_signup_node_completed($node) && !empty($node->signup_status)) {
// If this is an time-based node, and it's already past the close in
// advance time (e.g. someone just changed the node start time), and
// signups are still open, close them now.
signup_close_signup($node->nid);
drupal_set_message(t('%node_type start time is already past the signup close-in-advance time, signups now closed.', array(
'%node_type' => node_type_get_name($node->type),
)));
}
}