/**
* Adds a row to the sidebar.
*
* If containers/sections are not added explicitly to the view
* through the "containers" property, these rows will be used
* instead.
*
* @param array $row A hash with the row information. Possible
* values:
* - label: (string) The row text.
* - selected: (boolean) Whether to mark the row as active.
* - style: (string) Additional CSS styles to apply to the row.
* - url (string) URL to link the row to.
* - type (string, optional) The row type, defaults to "tree". Further
* $row properties depending on the type:
* - tree:
* - cssClass: (string) CSS class for the icon.
* - id: (string) DOM ID for the row link.
* - checkbox:
* - radiobox:
* - color: (string, optional) Background color.
* - edit: (string, optional) URL for extra edit icon.
* @param string $container If using multiple sidebar sections, the ID of
* the section to add the row to. Sections will
* be rendered in the order of their first usage.
*/
public function addRow(array $row, $container = '')
{
if (!isset($this->containers[$container])) {
$this->containers[$container] = array('rows' => array());
if ($container) {
$this->containers[$container]['id'] = $container;
}
}
$boxrow = isset($row['type']) && ($row['type'] == 'checkbox' || $row['type'] == 'radiobox');
$label = htmlspecialchars($row['label']);
if (isset($row['url'])) {
$url = empty($row['url']) ? new Horde_Url() : $row['url'];
if ($boxrow) {
$attributes = array();
} else {
$ak = Horde::getAccessKey($label);
$attributes = $ak ? array('accesskey' => $ak) : array();
}
foreach (array('onclick', 'target', 'class') as $attribute) {
if (!empty($row[$attribute])) {
$attributes[$attribute] = $row[$attribute];
}
}
if ($boxrow) {
$class = 'horde-resource-' . (empty($row['selected']) ? 'off' : 'on');
if ($row['type'] == 'radiobox') {
$class .= ' horde-radiobox';
}
if (empty($attributes['class'])) {
$attributes['class'] = $class;
} else {
$attributes['class'] .= ' ' . $class;
}
$row['link'] = $url->link($attributes) . $label . '</a>';
} else {
$row['link'] = $url->link($attributes) . Horde::highlightAccessKey($label, $ak) . '</a>';
}
} else {
$row['link'] = '<span class="horde-resource-none">' . $label . '</span>';
}
if ($boxrow) {
$this->containers[$container]['type'] = $row['type'];
if (!isset($row['style'])) {
$row['style'] = '';
}
if (!isset($row['color'])) {
$row['color'] = '#dddddd';
}
$foreground = '000';
if (Horde_Image::brightness($row['color']) < 128) {
$foreground = 'fff';
}
if (strlen($row['style'])) {
$row['style'] .= ';';
}
$row['style'] .= 'background-color:' . $row['color'] . ';color:#' . $foreground;
if (isset($row['edit'])) {
$row['editLink'] = $row['edit']->link(array('title' => _("Edit"), 'class' => 'horde-resource-edit-' . $foreground)) . '►' . '</a>';
}
}
$this->containers[$container]['rows'][] = $row;
}