public function getItems() { $collection = new MenuCollection(); $collection->filterByParent($this->id); $collection->orderBy('sort'); $currentParentUrl = false; if ($current = Ajde_Cms::getInstance()->getRoutedNode()) { $currentParentUrl = $current->getParent() && $current->getParent()->hasLoaded() ? $current->getParent()->getUrl() : false; } $items = []; foreach ($collection as $item) { /* @var $item MenuModel */ $name = $item->name; $target = ''; $submenus = []; $current = ''; $node = new NodeModel(); if ($item->type == 'URL') { $url = $item->url; if (substr($url, 0, 7) === 'http://' || substr($url, 0, 8) === 'https://') { $target = '_blank'; } } else { if ($item->type == 'Node link') { $node->loadByPK($item->node); $url = $node->getUrl(); } else { if ($item->type == 'Submenu') { $node->loadByPK($item->node); $url = $node->getUrl(); $submenus = $item->getItems(); foreach ($submenus as $submenu) { if ($submenu['current']) { $current = 'active sub-active'; } } } } } if ($url == Ajde::app()->getRoute()->getOriginalRoute()) { $current = 'active'; } if (Ajde::app()->getRoute()->getOriginalRoute() == '' && $url == config('routes.homepage')) { $current = 'active'; } if ($url == $currentParentUrl) { $current = 'active sub-active'; } if ($item->type == 'Node link' && !$node->hasLoaded()) { } else { $items[] = ['node' => $node, 'name' => $name, 'url' => $url, 'target' => $target, 'current' => $current, 'submenus' => $submenus]; } } return $items; }
<?php require_once __DIR__ . '/../common/autoload_cms.php'; require_once 'include/header.php'; if (isset($_GET['id']) && isset($_GET['confirm'])) { $menuCollection = new MenuCollection(); $menuCollection->remove(array('id' => $_GET['id'])); header('Location: menu_list.php'); } ?> <div class="container"> <h1>Are you sure you want to delete this menu?</h1> <a href="menu_delete.php?id=<?php echo $_GET['id']; ?> &confirm=1" class="btn btn-danger">Yes</a> <a href="menu_list.php" class="btn btn-default">No</a> </div> <?php require_once 'include/footer.php';
<?php require_once __DIR__ . '/../common/autoload_cms.php'; require_once 'include/header.php'; $menuCollection = new MenuCollection(); $menus = $menuCollection->all(); ?> <div class="container"> <a href="menu_add.php" class="btn btn-default">Add Menu</a> <br><br> <table class="table table-striped"> <tr> <th>Title</th> <th>URL</th> <th>Action?</th> </tr> <?php foreach ($menus as $menu) { ?> <tr> <td><?php echo $menu->getTitle(); ?> </td> <td><?php echo $menu->getUrl(); ?> </td> <td>
<?php require_once __DIR__ . '/../common/autoload_cms.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $entity = new Menu(); $entity->setTitle($_POST['title'])->setUrl($_POST['url']); $menuCollection = new MenuCollection(); $menuCollection->save($entity); header('Location: menu_list.php'); exit; } require_once 'include/header.php'; ?> <div class="container"> <form method="post" action="" enctype="multipart/form-data"> <div class="form-group"> <label for="title">Title:</label> <input type="text" name="title" id="title" class="form-control"> </div> <div class="form-group"> <label for="url">URL:</label> <input type="text" name="url" id="url" class="form-control"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> </div>
<?php require_once __DIR__ . '/../common/autoload_cms.php'; $menuCollection = new MenuCollection(); $menu = $menuCollection->one(array('id' => $_GET['id'])); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $menu->setTitle($_POST['title'])->setUrl($_POST['url']); $menuCollection->save($menu); header('Location: menu_list.php'); exit; } require_once 'include/header.php'; ?> <div class="container"> <form method="post" action="" enctype="multipart/form-data"> <div class="form-group"> <label for="title">Title:</label> <input type="text" name="title" id="title" value="<?php echo $menu->getTitle(); ?> " class="form-control"> </div> <div class="form-group"> <label for="url">URL:</label> <input type="text" name="url" id="url" value="<?php echo $menu->getUrl(); ?>