class RotatingBanner in Rotating Banner 7
Same name and namespace in other branches
- 7.2 rotating_banner.classes.inc \RotatingBanner
Hierarchy
- class \SimpleActiveRecord
- class \RotatingBanner
Expanded class hierarchy of RotatingBanner
2 string references to 'RotatingBanner'
File
- ./
rotating_banner.classes.inc, line 134
View source
class RotatingBanner extends SimpleActiveRecord {
public $rbid;
public $title;
public $machine_name;
public $settings;
protected function dbFields() {
return array(
'title',
'machine_name',
'settings',
);
}
public function initialize() {
if (is_string($this->settings)) {
$this->settings = unserialize($this->settings);
}
}
public static function create($title, $machine_name = NULL, $settings = NULL) {
$defaults = RotatingBanner::getDefaultSettings();
if ($settings) {
$settings = array_merge($defaults, $settings);
}
else {
$settings = $defaults;
}
$rb = new RotatingBanner();
$rb->title = $title;
$rb->machine_name = $machine_name ? $machine_name : uniqid('rb_');
$rb->settings = $settings;
$rb
->save();
return $rb;
}
public static function getDefaultSettings($key = NULL) {
//@todo: add variables here.
static $defaults = array(
'controls' => 'buttons',
'prev_next' => 0,
'width' => '',
'height' => '',
'fluid' => TRUE,
'cycle' => array(
'fx' => 'scrollDown',
'timeout' => 8000,
'fit' => 0,
),
);
if ($key) {
return $defaults[$key];
}
return $defaults;
}
/**
* Get by Id
* @param int $rbid
* @return RotatingBanner
*/
public static function get($rbid) {
$result = db_select('rotating_banners', 'rb')
->fields('rb')
->condition('rbid', $rbid)
->range(0, 1)
->execute()
->fetchAll(PDO::FETCH_CLASS, 'RotatingBanner');
if (!count($result)) {
return FALSE;
}
SimpleActiveRecord::runInitialize($result);
return array_shift($result);
}
public static function getAll() {
$result = db_select('rotating_banners', 'rb')
->fields('rb')
->execute()
->fetchAll(PDO::FETCH_CLASS, 'RotatingBanner');
if (!count($result)) {
return FALSE;
}
SimpleActiveRecord::runInitialize($result);
return $result;
}
public function getSlides() {
return RotatingBannerSlide::getByRotatingBanner($this->rbid);
}
function save() {
if (!$this->title) {
throw new Exception('Unable to save rotating banner, title is required');
}
foreach ($this
->dbFields() as $field_name) {
$fields[$field_name] = $this->{$field_name};
}
if (!is_string($fields['settings'])) {
$fields['settings'] = serialize($fields['settings']);
}
if (!$this->rbid) {
$rbid = db_insert('rotating_banners')
->fields($fields)
->execute();
$this->rbid = $rbid;
if ($this->rbid) {
return TRUE;
}
}
else {
db_update('rotating_banners')
->condition('rbid', $this->rbid)
->fields($fields)
->execute();
return TRUE;
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RotatingBanner:: |
public | property | ||
RotatingBanner:: |
public | property | ||
RotatingBanner:: |
public | property | ||
RotatingBanner:: |
public | property | ||
RotatingBanner:: |
public static | function | ||
RotatingBanner:: |
protected | function | ||
RotatingBanner:: |
public static | function | Get by Id | |
RotatingBanner:: |
public static | function | ||
RotatingBanner:: |
public static | function | ||
RotatingBanner:: |
public | function | ||
RotatingBanner:: |
public | function | ||
RotatingBanner:: |
function | |||
SimpleActiveRecord:: |
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:: |
public | function |