You are here

public function Campaigns::save in SimpleAds 8

File

src/Campaigns.php, line 145

Class

Campaigns
Campaigns utility class.

Namespace

Drupal\simpleads

Code

public function save() {
  $fields = [
    'uid' => $this->user
      ->id(),
    'name' => $this
      ->getCampaignName(),
    'description' => $this
      ->getDescription(),
    'type' => $this
      ->getType(),
    'options' => $this
      ->getOptions(),
    'status' => $this
      ->getStatus(),
    'created_at' => $this
      ->getCreatedAt(),
    'changed_at' => $this
      ->getChangedAt(),
  ];
  if ($id = $this
    ->getId()) {
    $query = db_update('simpleads_campaigns')
      ->fields($fields)
      ->condition('id', $id);
    drupal_set_message($this
      ->t('Campaign successfully updated.'));
  }
  else {
    $query = db_insert('simpleads_campaigns')
      ->fields($fields);
    drupal_set_message($this
      ->t('New campaign successfully created.'));
  }
  $query
    ->execute();
}