class Popup_announcement_block in Pop-up announcement 7
Class for work with block with announcements
Hierarchy
- class \Popup_announcement_block
Expanded class hierarchy of Popup_announcement_block
File
- ./
popup_announcement.module, line 274 - Primarily Drupal hooks and custom functions for creating block with pop-up announcement.
View source
class Popup_announcement_block {
/**
* Get blocks
*/
public function get_blocks() {
return variable_get('popup_announcement_blocks');
}
/**
* Get block
*/
public function get_block($bid) {
$bs = $this
->get_blocks();
return $bs[$bid];
}
/**
* Save block
*
* @param array
* Announcement, may be new (will be added to array)
* or old (will be edited).
*
* @return int
* This is key in array with all announcements.
*
*/
public function save_block($b) {
$bs = $this
->get_blocks();
$bid = $b['bid'];
// if old block
if ($bid) {
$bs[$bid] = $b;
}
else {
$bs[] = $b;
end($bs);
$bid = key($bs);
// add new key (bid)
$bs[$bid]['bid'] = $bid;
}
variable_set('popup_announcement_blocks', $bs);
block_flush_caches();
return $bid;
}
/**
* Create new block with fields
*
* @return array
* Standard settings and localized welcome text
*/
public function create_block() {
// welcome text on current language
// get locale and create first announcement from template if possible, or standard 'en'.
$default_language = language_default();
$welcomes = scandir(DRUPAL_ROOT . '/' . drupal_get_path('module', 'popup_announcement') . '/welcomes');
$f = in_array($default_language->language . '.html', $welcomes) ? $default_language->language . '.html' : 'en.html';
$text = file_get_contents(DRUPAL_ROOT . '/' . drupal_get_path('module', 'popup_announcement') . '/welcomes/' . $f);
return array(
'bid' => FALSE,
'name' => FALSE,
'text' => $text,
'number_visit' => '1,2,5',
'width' => 500,
'height' => 300,
'created' => time(),
'delay' => 2,
);
}
/**
* Delete block
*/
function delete_block($bid) {
$bs = $this
->get_blocks();
unset($bs[$bid]);
variable_set('popup_announcement_blocks', $bs);
// @todo: travel in debugger when uninstalling module -> find how to delete old blocks more pretty!
db_delete('block')
->condition('delta', 'popup_announcement_' . $bid)
->execute();
block_flush_caches();
// @todo: realy need it here?
}
/**
* Get list with visit numbers, when announcement must be visible.
*
* @return array
* Array or boolean - list with visit numbers or TRUE if announcement
* must be appears at every visit
*/
public function when_visible($bid) {
$b = $this
->get_block($bid);
return empty($b['number_visit']) ? TRUE : explode(',', $b['number_visit']);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Popup_announcement_block:: |
public | function | Create new block with fields | |
Popup_announcement_block:: |
function | Delete block | ||
Popup_announcement_block:: |
public | function | Get block | |
Popup_announcement_block:: |
public | function | Get blocks | |
Popup_announcement_block:: |
public | function | Save block | |
Popup_announcement_block:: |
public | function | Get list with visit numbers, when announcement must be visible. |