protected function RateDefaultWidget::init in Rate 7.2
Initialize the widget.
Load layout from database and generate default elements like vote count and description.
Overrides RateWidget::init
File
- classes/
default.inc, line 100
Class
Code
protected function init() {
$this->layout = array();
// Get numeric display mode as used in the elements table.
$modes = array(
'format_full' => 1,
'format_compact' => 2,
'format_full_disabled' => 4,
'format_compact_disabled' => 8,
'format_closed' => 16,
);
$mode = isset($modes[$this->mode]) ? $modes[$this->mode] : 0;
$elements = db_select('rate_widget_element', 'e')
->fields('e', array(
'type',
'prefix',
'suffix',
'mode',
))
->condition('e.wid', $this->wid)
->orderBy('e.weight', 'asc')
->execute()
->fetchAll();
foreach ($elements as $element) {
if ($element->mode & $mode) {
$this->layout[] = $element;
}
}
foreach ($this->elements as $element) {
if ($element instanceof RateButton) {
$highlight = FALSE;
if ($this->rating == $element
->getValue() && $this->highlight_voted & 1) {
$highlight = TRUE;
}
if ($this->rating > $element
->getValue() && $this->highlight_voted & 2) {
$highlight = TRUE;
}
if ($this->rating < $element
->getValue() && $this->highlight_voted & 4) {
$highlight = TRUE;
}
if ($highlight) {
$element
->addClass('highlighted');
}
}
}
$this->elements['description'] = $this
->getDescription();
}