Nav.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. if(!defined('APP_KEY')) { exit('Access Denied'); }
  3. class Helper_Nav implements Suco_Helper_Interface
  4. {
  5. protected $src;
  6. public static function callback($args)
  7. {
  8. return new self($args[0], $args[1]);
  9. }
  10. public function output()
  11. {
  12. $admin = M('Admin')->getCurUser();
  13. $paths = M('Admin_Menu')->getCurNote()->getPath();
  14. $nav = M('Admin_Menu')->select()
  15. ->order('rank ASC')
  16. ->fetchRows()
  17. ->toTree();
  18. return '<ul class="nav">'.$this->showMenu($nav, $paths->toArray(), $admin).'</ul>';
  19. }
  20. public function showMenu($arr, $paths, $user) {
  21. $html = '';
  22. foreach ($arr as $row) {
  23. $allow = explode(',', $row['allow_group']);
  24. if (!$row['is_enabled']) continue;
  25. if ($row['allow_group'] && @!in_array($user['group_id'], $allow)) continue;
  26. $url = H('Url', 'controller=admin_menu&action=redirect&id='.$row['id']);
  27. $opened = isset($paths[$row['id']]) ? 'active open' : '';
  28. if ($row['childs_num']) {
  29. $html .= '<li class="'.$opened.' has-childs"><a href="'.$url.'">';
  30. if ($row['icon']) { $html .= '<i class="fa fa-'.$row['icon'].' fa-fw"></i> '; }
  31. $html .= '<span class="menu-text">'.$row['name'].'</span>';
  32. } else {
  33. $html .= '<li class="'.$opened.'"><a href="'.$url.'">';
  34. if ($row['icon']) { $html .= '<i class="fa fa-'.$row['icon'].' fa-fw"></i> '; }
  35. $html .= '<span class="menu-text">'.$row['name'].'</span>';
  36. }
  37. $html .= '</a>';
  38. if (isset($row['childnotes'])) {
  39. $html .= '<ul id="snv-'.$row['id'].'" class="nav" role="collapse">'.$this->showMenu($row['childnotes'], $paths, $user).'</ul>';
  40. }
  41. }
  42. return $html;
  43. }
  44. public function __toString()
  45. {
  46. return $this->output();
  47. }
  48. }