class RotatingBannerSlide in Rotating Banner 7.2
Same name and namespace in other branches
- 7 rotating_banner.classes.inc \RotatingBannerSlide
Hierarchy
- class \SimpleActiveRecord
- class \RotatingBannerSlide
Expanded class hierarchy of RotatingBannerSlide
2 string references to 'RotatingBannerSlide'
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;
}
}