You are here

function royalslider_optionset_save in RoyalSlider Integration 7

Saves the given optionset to the database. Set the $new flag if this optionset has not been written before.

Parameters

object: The optionset to save.

boolean: Whether it's a new optionset or not.

Return value

object|boolean Returns the newly saved object, FALSE otherwise.

1 call to royalslider_optionset_save()
royalslider_form_optionset_add_submit in ./royalslider.admin.inc
Submit handler for adding a new option set.

File

./royalslider.module, line 233
RoyalSlider module.

Code

function royalslider_optionset_save($optionset, $new = FALSE) {

  // If the machine name is missing or already in use, return an error.
  if (empty($optionset->name) or FALSE != royalslider_optionset_exists($optionset->name) and $new) {
    return FALSE;
  }

  // Check for an invalid list of options
  if (isset($optionset->options) and !is_array($optionset->options)) {
    return FALSE;
  }

  // If the title is missing, default to the name
  if (empty($optionset->title)) {
    $optionset->title = $optionset->name;
  }

  // Merge default settings with any given settings
  $optionset_defaults = _royalslider_optionset_defaults();
  $optionset->options = $optionset_defaults += $optionset->options;

  // Prepare the database values.
  $db_values = array(
    'name' => $optionset->name,
    'title' => $optionset->title,
    'options' => _royalslider_typecast_optionset($optionset->options),
  );
  if ($new) {
    $result = drupal_write_record('royalslider_optionset', $db_values);
  }
  else {
    $result = drupal_write_record('royalslider_optionset', $db_values, 'name');
  }

  // Return the object if the values were saved successfully.
  if ($new and SAVED_NEW == $result or !$new and SAVED_UPDATED == $result) {
    return $optionset;
  }

  // Otherwise, an error occured
  return FALSE;
}