You are here

public function Ads::save in SimpleAds 8

File

src/Ads.php, line 165

Class

Ads
Ads utility class.

Namespace

Drupal\simpleads

Code

public function save() {
  $fields = [
    'uid' => $this->user
      ->id(),
    'name' => $this
      ->getAdName(),
    'description' => $this
      ->getDescription(),
    'type' => $this
      ->getType(),
    'group_id' => !empty($this->group
      ->getId()) ? $this->group
      ->getId() : NULL,
    'campaign_id' => !empty($this->campaign
      ->getId()) ? $this->campaign
      ->getId() : NULL,
    'options' => $this
      ->getOptions(),
    'status' => $this
      ->getStatus(),
    'created_at' => $this
      ->getCreatedAt(),
    'changed_at' => $this
      ->getChangedAt(),
  ];
  if ($id = $this
    ->getId()) {
    $query = db_update('simpleads')
      ->fields($fields)
      ->condition('id', $id);
    drupal_set_message($this
      ->t('Advertisement successfully updated.'));
  }
  else {
    $query = db_insert('simpleads')
      ->fields($fields);
    drupal_set_message($this
      ->t('New advertisement successfully created.'));
  }
  $query
    ->execute();
}