protected function setNavigation($parentId, $label, $url = '', array $selectedFor = null, $sequence = null)
{
$parentId = (int) $parentId;
$label = (string) $label;
$url = (string) $url;
$selectedFor = $selectedFor !== null && is_array($selectedFor) ? serialize($selectedFor) : null;
// no custom sequence
if ($sequence === null) {
// get maximum sequence for this parent
$maxSequence = (int) $this->getDB()->getVar('SELECT MAX(sequence)
FROM backend_navigation
WHERE parent_id = ?', array($parentId));
// add at the end
$sequence = $maxSequence + 1;
} else {
$sequence = (int) $sequence;
}
// get the id for this url
$id = (int) $this->getDB()->getVar('SELECT id
FROM backend_navigation
WHERE parent_id = ? AND label = ? AND url = ?', array($parentId, $label, $url));
// doesn't exist yet, add it
if ($id === 0) {
return $this->getDB()->insert('backend_navigation', array('parent_id' => $parentId, 'label' => $label, 'url' => $url, 'selected_for' => $selectedFor, 'sequence' => $sequence));
}
// already exists so return current id
return $id;
}