You are here

function _signup_node_settings_panes_save in Signup 6.2

Helper function to save pane settings.

Called from the form submit handlers for node settings and sitewide defaults.

Parameters

$form_state_values: The $form_state['values']['signup_form_panes'] array from the calling form submit handler.

$nid: The nid of the node this signup is attached to. May also be 0 for the case that the defaults are being saved. This value should be used regardless.

2 calls to _signup_node_settings_panes_save()
signup_node_settings_form_submit in includes/node_settings.inc
Submit handler for the per-node signup settings form.
signup_settings_form_submit in includes/admin.settings.inc
Submits the signup settings form

File

includes/node_settings.inc, line 369
Code related to the per-node signup settings form.

Code

function _signup_node_settings_panes_save($form_state_values, $nid) {

  // WTF new nodes come here with ALL WEIGHTS set at 10???
  // @todo: new nodes probably need arbitrary weights setting?
  if (isset($form_state_values)) {
    foreach ($form_state_values as $pane_id => $form_state_values_panes) {
      if ($form_state_values_panes['enabled']) {
        $signup_panes[$pane_id] = $form_state_values_panes['weight'];
      }
    }
  }

  // Clear all the panes for the node.
  db_query("DELETE FROM {signup_panes} WHERE nid = %d", $nid);

  // If there are enabled panes, save them.
  if (count($signup_panes)) {

    // Give a singleton pane a weight value, arbitrarily set to 0.
    if (count($signup_panes) == 1) {

      // Convoluted way of getting the first (and only!) key to set the value to 0
      // @todo Suggestions for improvement welcome!
      reset($signup_panes);
      $pane_id = key($signup_panes);
      $signup_panes[$pane_id] = 0;
    }

    // Sort by weight, preserve keys.
    // obsolete asort($signup_panes);
    foreach ($signup_panes as $pane_id => $weight) {

      // Store the signup pane information. Note the callback is retrieve from
      // form values where we stashed it earlier.
      db_query("INSERT INTO {signup_panes} (nid, pane_id, callback, weight) VALUES (%d, '%s', '%s', %d)", $nid, $pane_id, $form_state_values[$pane_id]['callback'], $weight);
    }
  }
}