Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. <?php
  2.  
  3. class Navigation
  4. {
  5. function __toString()
  6. {
  7. $siteLogin = SiteLogin::singleton();
  8. /** @var \Rhubarb\Scaffolds\AuthenticationWithRoles\User $user */
  9. try{
  10. $user = User::getLoggedInUser();
  11. } catch (NotLoggedInException $notLoggedInException)
  12. {
  13. // The user is not loggedin
  14. $user = false;
  15. }
  16. $nav = <<<HTML
  17. <!-- Fixed navbar -->
  18. <nav class="navbar navbar-default navbar-fixed-top">
  19. <div class="container">
  20. <div class="navbar-header">
  21. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
  22. aria-expanded="false" aria-controls="navbar">
  23. <span class="sr-only">Toggle navigation</span>
  24. <span class="icon-bar"></span>
  25. <span class="icon-bar"></span>
  26. <span class="icon-bar"></span>
  27. </button>
  28. <a class="navbar-brand" href="/">Company Name</a>
  29. </div>
  30. HTML;
  31.  
  32. if ($user !== false) {
  33. $nav .= $this->getLoggedInUserHtml($user);
  34. } else {
  35. $nav .= '<a href="/login/" class="pull-right login-link">Login</a>';
  36. }
  37. $nav .= <<<HTML
  38. </div><!--/.nav-collapse -->
  39. </div>
  40. </nav>
  41. HTML;
  42.  
  43. return $nav;
  44. }
  45.  
  46. /**
  47. * @param $user
  48. * @return string
  49. */
  50. private function getLoggedInUserHtml(User $user): string
  51. {
  52. $settings = ApplicationSettings::singleton();
  53. $notificationHours = $settings->HoursBeforeReminder > 0 ? $settings->HoursBeforeReminder : 1;
  54. $searchAhead = new RhubarbDateTime("+" . $notificationHours . " hours");
  55. $taskNotifications = Task::find(
  56. new AndGroup(
  57. new Equals("UserID", $user->UserID),
  58. new Equals("Done", false),
  59. new LessThan("CompletedBy", $searchAhead, true
  60. )
  61. )
  62. )->count();
  63.  
  64. $notesNotifications = 0;
  65.  
  66. if ($user->hasRole("Admin")) {
  67. $notesNotifications = Note::find(new Equals("DealtWith", false))->count();
  68. }
  69. $taskNotificationCount = $taskNotifications > 0 ? "(" . $taskNotifications . ")" : "";
  70. $notesNotificationsCount = $notesNotifications > 0 ? "(" . $notesNotifications . ")" : "";
  71. $totalNotifications = $notesNotifications + $taskNotifications;
  72. $totalNotificationsCount = $totalNotifications > 0 ? "(" . $totalNotifications . ")" : "";
  73. $nav = <<<HTML
  74. <div id="navbar" class="navbar-collapse collapse">
  75. <ul class="nav navbar-nav">
  76. <li id="home"><a href="/">Home</a></li>
  77. <li id="clients"><a href="/clients/">Clients</a></li>
  78. <li id="bookings"><a href="/bookings/">Bookings</a></li>
  79. <li id="notes"><a href="/notes/add/">✚ Note</a></li>
  80. </ul>
  81. <ul class="nav navbar-nav navbar-right">
  82. <li class="dropdown">
  83. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  84. aria-haspopup="true" aria-expanded="false">Welcome Back
  85. {$user->Forename} {$totalNotificationsCount}
  86.  
  87. <span class="caret"></span></a>
  88. <ul class="dropdown-menu">
  89. HTML;
  90. if ($user->hasRole("Admin")) {
  91. $nav .= $this->getAdminHtml();
  92. }
  93. $nav .= <<<HTML
  94. <li><a href="/notes/">Notes {$notesNotificationsCount}</a></li>
  95. <li><a href="/tasks/">Tasks</a></li>
  96. <li>
  97. <a href="/my-tasks/">My Tasks
  98. {$taskNotificationCount}
  99. </a>
  100. </li>
  101. <li role="separator" class="divider"></li>
  102. <li><a href="/login/logout">Logout</a></li>
  103. </ul>
  104. </li>
  105. </ul>
  106. HTML;
  107. return $nav;
  108. }
  109.  
  110. /**
  111. * @return string
  112. */
  113. public function getAdminHtml(): string
  114. {
  115. return <<<HTML
  116. <li><a href="/hospitalities/">Hospitalities</a></li>
  117. <li><a href="/equipment/">Equipment</a></li>
  118. <li><a href="/settings/">Settings</a></li>
  119. <li role="separator" class="divider"></li>
  120. HTML;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement