You are here

function RotatingBanner::save in Rotating Banner 7.2

Same name and namespace in other branches
  1. 7 rotating_banner.classes.inc \RotatingBanner::save()

File

./rotating_banner.classes.inc, line 225

Class

RotatingBanner

Code

function save() {
  if (!$this->title) {
    throw new Exception('Unable to save rotating banner, title is required');
  }
  foreach ($this
    ->dbFields() as $field_name) {
    $fields[$field_name] = $this->{$field_name};
  }
  if (!is_string($fields['settings'])) {
    $fields['settings'] = serialize($fields['settings']);
  }
  if (!$this->rbid) {
    $rbid = db_insert('rotating_banners')
      ->fields($fields)
      ->execute();
    $this->rbid = $rbid;
    if ($this->rbid) {
      return TRUE;
    }
  }
  else {
    db_update('rotating_banners')
      ->condition('rbid', $this->rbid)
      ->fields($fields)
      ->execute();
    return TRUE;
  }
}