You are here

public function Campaigns::load in SimpleAds 8

1 call to Campaigns::load()
Campaigns::delete in src/Campaigns.php

File

src/Campaigns.php, line 103

Class

Campaigns
Campaigns utility class.

Namespace

Drupal\simpleads

Code

public function load() {
  if ($id = $this
    ->getId()) {
    $record = db_select('simpleads_campaigns', 's')
      ->fields('s')
      ->condition('s.id', $id)
      ->execute()
      ->fetchObject();
    $item = (new self())
      ->setId($id)
      ->setCampaignName($record->name)
      ->setDescription($record->description)
      ->setType($record->type)
      ->setOptions(!empty($record->options) ? json_decode($record->options, TRUE) : [])
      ->setStatus($record->status)
      ->setCreatedAt($record->created_at)
      ->setChangedAt($record->changed_at);
    return $item;
  }
  return $this;
}