You are here

public function Ads::load in SimpleAds 8

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

File

src/Ads.php, line 121

Class

Ads
Ads utility class.

Namespace

Drupal\simpleads

Code

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