id = $id;
$this->title = $title;
$this->itemSpace = $itemSpace;
$this->pinned = [];
$this->items = [];
}
public function addItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false)
{
if ($show) {
$item = $this->itemDef($title, $url, $img, $active, $id, $class);
if ($pinned) {
$this->pinned[] = $item;
} else {
$this->items[$title] = $item;
}
}
}
public function prependItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false)
{
if ($show) {
$item = $this->itemDef($title, $url, $img, $active, $id, $class);
if ($pinned) {
array_unshift($this->pinned, $item);
} else {
$this->items[$title] = $item;
}
}
}
public function draw()
{
if (count($this->items) + count($this->pinned) == 0) {
return '';
}
$res =
'
' .
($this->title ? '
' . $this->title . '
' : '') .
'
' . "\n";
// 1. Display pinned items (unsorted)
for ($i = 0; $i < count($this->pinned); $i++) {
if ($i + 1 < count($this->pinned) && $this->itemSpace != '') {
$res .= preg_replace('|$|', $this->itemSpace . '', $this->pinned[$i]);
$res .= "\n";
} else {
$res .= $this->pinned[$i] . "\n";
}
}
// 2. Display unpinned itmes (sorted)
$i = 0;
dcUtils::lexicalKeySort($this->items);
foreach ($this->items as $title => $item) {
if ($i + 1 < count($this->items) && $this->itemSpace != '') {
$res .= preg_replace('|$|', $this->itemSpace . '', $item);
$res .= "\n";
} else {
$res .= $item . "\n";
}
$i++;
}
$res .= '
' . "\n";
return $res;
}
protected function itemDef($title, $url, $img, $active, $id = null, $class = null)
{
if (is_array($url)) {
$link = $url[0];
$ahtml = (!empty($url[1])) ? ' ' . $url[1] : '';
} else {
$link = $url;
$ahtml = '';
}
$img = dc_admin_icon_url($img);
return
'' .
'' . $title . '' . "\n";
}
}