[eluser]neen[/eluser]
Model:
Code:
<?php
/*
| ********************************************************************** |
| This code is Copyright (c) 2008 neen and c0mpub0mb |
| |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
| ********************************************************************** |
*/
class Menu_model extends Model {
private $items = null;
private $item_id = null;
private $sidemenu;
private $breadcrumbs;
public function __construct()
{
parent::Model();
}
public function item($classname,$title)
{
if(is_null($this->item_id))
$this->item_id = 0;
else
$this->item_id++;
$this->items[$this->item_id]['classname'] = $classname;
$this->items[$this->item_id]['title'] = $title;
return $this;
}
public function create($title)
{
$this->items[$this->item_id]['items']['create'] = $title;
return $this;
}
public function edit($title)
{
$this->items[$this->item_id]['items']['edit'] = $title;
return $this;
}
public function listitems($title)
{
$this->items[$this->item_id]['items']['list'] = $title;
return $this;
}
public function delete($title)
{
$this->items[$this->item_id]['items']['delete'] = $title;
return $this;
}
public function menuList()
{
return $this->items;
}
public function registerBreadcrumb($uri, $title)
{
$this->items[$this->item_id]['breadcrumbs'][$uri] = $title;
return $this;
}
public function generateSidemenu($id = 0)
{
// set the indent
$indent = '';
// $i = 2, because we only want this to activate when there are more than 2 segments in the url
for($i = 2; $i < $this->uri->total_segments(); $i++)
{
$indent .= '../';
}
// get the menu list
$this->sidemenu = $this->menuList();
$this->sidemenu = $this->sidemenu[$id];
$this->sidemenu['indent'] = $indent;
return $this->sidemenu;
}
public function generateBreadcrumbs()
{
$this->breadcrumbs = '';
// iterate through the levels to build the anchor
// get the uris
$uri = explode('/', $this->uri->uri_string());
// dump($this->items);
for($i = $this->uri->total_segments(); $i > 0; $i--)
{
// repeat the string
$anchor = str_repeat('../', $i - 1);
switch($i)
{
// first iteration through loop
case $this->uri->total_segments():
$this->breadcrumbs = '<a href="' . $anchor . '">Administration Home</a><span> / </span>';
break;
// 2nd iteration through the loop
case 2:
$this->title = $this->items[0]['breadcrumbs']['manage'];
$this->breadcrumbs .= '<a href="' . $anchor . '">' . $this->title . '</a><span> / </span>';
break;
// last iteration through loop
case 1:
$this->title = $this->items[0]['breadcrumbs'][$this->uri->segment(2)];
$this->breadcrumbs .= '<strong>'. $this->title . '</strong>';
break;
}
}
return $this->breadcrumbs;
}
public function generateGlobalMenu()
{
}
}
?>