You are here

class RotatingBannerSlide in Rotating Banner 7.2

Same name and namespace in other branches
  1. 7 rotating_banner.classes.inc \RotatingBannerSlide

Hierarchy

Expanded class hierarchy of RotatingBannerSlide

2 string references to 'RotatingBannerSlide'
RotatingBannerSlide::get in ./rotating_banner.classes.inc
RotatingBannerSlide::getByRotatingBanner in ./rotating_banner.classes.inc

File

./rotating_banner.classes.inc, line 3

View source
class RotatingBannerSlide extends SimpleActiveRecord {
  public $sid;
  public $rbid;
  public $weight;
  public $fid;
  public $link;
  public $layout;
  public $textboxes;
  function initialize() {
    if (is_string($this->textboxes)) {
      $this->textboxes = drupal_json_decode($this->textboxes);
    }
  }
  protected function dbFields() {
    return array(
      'rbid',
      'weight',
      'fid',
      'link',
      'layout',
      'textboxes',
    );
  }
  public static function getDefaultSettings($key = NULL) {

    //@todo: add variables here.
    $defaults = array(
      'textboxes' => array(
        array(
          'position' => array(
            'top' => "20",
            'left' => '20',
          ),
          'content' => t('Banner Headline'),
          'type' => 'rb-textbox-type-header',
        ),
        array(
          'position' => array(
            'top' => "80",
            'left' => '20',
          ),
          'content' => t('Banner text goes here.<br/> <strong> Double click</strong> to edit.'),
          'type' => 'rb-textbox-type-text',
        ),
      ),
      'layout' => variable_get('rotating_banner_default_slide_layout', 'top-left'),
      'link' => '<front>',
      'weight' => 0,
      'fid' => NULL,
    );
    $fid = variable_get('rotating_banner_default_slide_fid', NULL);
    if ($fid) {
      $defaults['fid'] = $fid;
    }
    if ($key) {
      return $defaults[$key];
    }
    return $defaults;
  }
  public static function create($rbid, $weight = NULL, $fid = NULL, $link = NULL, $layout = NULL, $textboxes = NULL) {
    $defaults = RotatingBannerSlide::getDefaultSettings();
    $rbs = new RotatingBannerSlide();
    $rbs->rbid = $rbid;
    $rbs->weight = $weight ? $weight : $defaults['weight'];
    $rbs->fid = $fid ? $fid : $defaults['fid'];
    $rbs->link = $link ? $link : $defaults['link'];
    $rbs->layout = $layout ? $layout : $defaults['layout'];
    $rbs->textboxes = $textboxes ? $textboxes : $defaults['textboxes'];
    $rbs
      ->save();
    return $rbs;
  }
  public function delete() {
    return db_delete('rotating_banner_slides')
      ->condition('sid', $this->sid)
      ->execute();
  }
  function save() {
    if (!$this->rbid) {
      throw new Exception('Unable to save slide, rotating banner ID is required.');
    }
    foreach ($this
      ->dbFields() as $field_name) {
      $fields[$field_name] = $this->{$field_name};
    }
    if (!is_string($fields['textboxes'])) {
      $fields['textboxes'] = drupal_json_encode($fields['textboxes']);
    }
    if (!$this->sid) {
      $sid = db_insert('rotating_banner_slides')
        ->fields($fields)
        ->execute();
      $this->sid = $sid;
      if ($this->sid) {
        return TRUE;
      }
    }
    else {
      return (bool) db_update('rotating_banner_slides')
        ->condition('sid', $this->sid)
        ->fields($fields)
        ->execute();
    }
  }
  public static function get($sid) {
    $result = db_select('rotating_banner_slides', 's')
      ->fields('s')
      ->condition('sid', $sid)
      ->range(0, 1)
      ->execute()
      ->fetchAll(PDO::FETCH_CLASS, 'RotatingBannerSlide');
    if (!count($result)) {
      return FALSE;
    }
    SimpleActiveRecord::runInitialize($result);
    return array_shift($result);
  }
  public static function getByRotatingBanner($rbid) {
    $result = db_select('rotating_banner_slides', 's')
      ->fields('s')
      ->condition('rbid', $rbid)
      ->orderBy('weight')
      ->execute()
      ->fetchAll(PDO::FETCH_CLASS, 'RotatingBannerSlide');
    SimpleActiveRecord::runInitialize($result);
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RotatingBannerSlide::$fid public property
RotatingBannerSlide::$layout public property
RotatingBannerSlide::$link public property
RotatingBannerSlide::$rbid public property
RotatingBannerSlide::$sid public property
RotatingBannerSlide::$textboxes public property
RotatingBannerSlide::$weight public property
RotatingBannerSlide::create public static function
RotatingBannerSlide::dbFields protected function
RotatingBannerSlide::delete public function
RotatingBannerSlide::get public static function
RotatingBannerSlide::getByRotatingBanner public static function
RotatingBannerSlide::getDefaultSettings public static function
RotatingBannerSlide::initialize function
RotatingBannerSlide::save function
SimpleActiveRecord::runInitialize public static function Disclaimer: This is a hack. The PDO::FETCH_CLASS does not behave as documented. It is supposed to run the constructor *after* the properties have been assigned and in some versions of PHP, it does that.
SimpleActiveRecord::setValuesFromArray public function