Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Navigation
- {
- function __toString()
- {
- $siteLogin = SiteLogin::singleton();
- /** @var \Rhubarb\Scaffolds\AuthenticationWithRoles\User $user */
- try{
- $user = User::getLoggedInUser();
- } catch (NotLoggedInException $notLoggedInException)
- {
- // The user is not loggedin
- $user = false;
- }
- $nav = <<<HTML
- <!-- Fixed navbar -->
- <nav class="navbar navbar-default navbar-fixed-top">
- <div class="container">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
- aria-expanded="false" aria-controls="navbar">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="/">Company Name</a>
- </div>
- HTML;
- if ($user !== false) {
- $nav .= $this->getLoggedInUserHtml($user);
- } else {
- $nav .= '<a href="/login/" class="pull-right login-link">Login</a>';
- }
- $nav .= <<<HTML
- </div><!--/.nav-collapse -->
- </div>
- </nav>
- HTML;
- return $nav;
- }
- /**
- * @param $user
- * @return string
- */
- private function getLoggedInUserHtml(User $user): string
- {
- $settings = ApplicationSettings::singleton();
- $notificationHours = $settings->HoursBeforeReminder > 0 ? $settings->HoursBeforeReminder : 1;
- $searchAhead = new RhubarbDateTime("+" . $notificationHours . " hours");
- $taskNotifications = Task::find(
- new AndGroup(
- new Equals("UserID", $user->UserID),
- new Equals("Done", false),
- new LessThan("CompletedBy", $searchAhead, true
- )
- )
- )->count();
- $notesNotifications = 0;
- if ($user->hasRole("Admin")) {
- $notesNotifications = Note::find(new Equals("DealtWith", false))->count();
- }
- $taskNotificationCount = $taskNotifications > 0 ? "(" . $taskNotifications . ")" : "";
- $notesNotificationsCount = $notesNotifications > 0 ? "(" . $notesNotifications . ")" : "";
- $totalNotifications = $notesNotifications + $taskNotifications;
- $totalNotificationsCount = $totalNotifications > 0 ? "(" . $totalNotifications . ")" : "";
- $nav = <<<HTML
- <div id="navbar" class="navbar-collapse collapse">
- <ul class="nav navbar-nav">
- <li id="home"><a href="/">Home</a></li>
- <li id="clients"><a href="/clients/">Clients</a></li>
- <li id="bookings"><a href="/bookings/">Bookings</a></li>
- <li id="notes"><a href="/notes/add/">✚ Note</a></li>
- </ul>
- <ul class="nav navbar-nav navbar-right">
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
- aria-haspopup="true" aria-expanded="false">Welcome Back
- {$user->Forename} {$totalNotificationsCount}
- <span class="caret"></span></a>
- <ul class="dropdown-menu">
- HTML;
- if ($user->hasRole("Admin")) {
- $nav .= $this->getAdminHtml();
- }
- $nav .= <<<HTML
- <li><a href="/notes/">Notes {$notesNotificationsCount}</a></li>
- <li><a href="/tasks/">Tasks</a></li>
- <li>
- <a href="/my-tasks/">My Tasks
- {$taskNotificationCount}
- </a>
- </li>
- <li role="separator" class="divider"></li>
- <li><a href="/login/logout">Logout</a></li>
- </ul>
- </li>
- </ul>
- HTML;
- return $nav;
- }
- /**
- * @return string
- */
- public function getAdminHtml(): string
- {
- return <<<HTML
- <li><a href="/hospitalities/">Hospitalities</a></li>
- <li><a href="/equipment/">Equipment</a></li>
- <li><a href="/settings/">Settings</a></li>
- <li role="separator" class="divider"></li>
- HTML;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement