-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/2124 notification bar #2167
Changes from all commits
e91b948
b2061c1
b63e46d
3d48cdd
db614bd
72aae06
81e12fe
ff83218
76dd173
b253402
22ca17f
84873dd
efec353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace ChurchCRM\Service; | ||
use ChurchCRM\dto\SystemConfig; | ||
|
||
class NotificationService | ||
{ | ||
public static function updateNotifications() | ||
{ | ||
/* Get the latest notifications from the source. Store in session variable | ||
* | ||
*/ | ||
try { | ||
$TempNotificaions = json_decode(file_get_contents(SystemConfig::getValue("sCloudURL")."notifications.json", false, $context)); | ||
if (isset($TempNotificaions->TTL) ) { | ||
$_SESSION['SystemNotifications'] = $TempNotificaions; | ||
$_SESSION['SystemNotifications']->expires = new \DateTime(); | ||
$_SESSION['SystemNotifications']->expires->add(new \DateInterval("PT".$_SESSION['SystemNotifications']->TTL."S")); | ||
} | ||
} catch (\Exception $ex) { | ||
//a failure here should never prevent the page from loading. | ||
//Possibly log an exception when a unified logger is implemented. | ||
//for now, do nothing. | ||
} | ||
} | ||
|
||
public static function getNotifications() | ||
{ | ||
/* retreive active notifications from the session variable for display | ||
* | ||
*/ | ||
if (isset($_SESSION['SystemNotifications'])) | ||
{ | ||
$notifications = array(); | ||
foreach ($_SESSION['SystemNotifications']->messages as $message) | ||
{ | ||
if($message->targetVersion == $_SESSION['sSoftwareInstalledVersion']) | ||
{ | ||
if (! $message->adminOnly || $_SESSION['user']->isAdmin()) | ||
{ | ||
array_push($notifications, $message); | ||
} | ||
} | ||
} | ||
return $notifications; | ||
} | ||
} | ||
|
||
public static function hasActiveNotifications() | ||
{ | ||
return count(NotificationService::getNotifications()) > 0; | ||
} | ||
|
||
public static function isUpdateRequired() | ||
{ | ||
/* | ||
* If session does not contain notifications, or if the notification TTL has expired, return true | ||
* otherwise return false. | ||
*/ | ||
if (!isset($_SESSION['SystemNotifications']) || $_SESSION['SystemNotifications']->expires < new \DateTime()) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,22 @@ | |
|
||
use ChurchCRM\Service\SystemService; | ||
use ChurchCRM\dto\SystemURLs; | ||
use ChurchCRM\Service\NotificationService; | ||
|
||
function Header_system_notifications() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this should be ajax There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section is only accessing the local session variable - there is no hit to the database or web services here - only session variable. It really shouldn't be that big of a performance hit. |
||
{ | ||
if (NotificationService::hasActiveNotifications()) { | ||
?> | ||
<div class="systemNotificationBar"> | ||
<?php | ||
foreach (NotificationService::getNotifications() as $notification) { | ||
echo "<a href=\"".$notification->link."\">".$notification->title."</a>"; | ||
} ?> | ||
</div> | ||
<?php | ||
|
||
} | ||
} | ||
|
||
function Header_head_metatag() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,9 @@ | |
</head> | ||
|
||
<body class="hold-transition <?= $_SESSION['sStyle'] ?> sidebar-mini"> | ||
<?php | ||
Header_system_notifications(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure i like this as it is only used once, no need for a funcation |
||
?> | ||
<!-- Site wrapper --> | ||
<div class="wrapper"> | ||
<?php | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.systemNotificationBar{ | ||
display:block; | ||
overflow:hidden; | ||
width:100%; | ||
margin: 0px; | ||
border: 0px; | ||
padding:0px; | ||
background-color:red; | ||
z-index: 2000; | ||
position: relative; | ||
text-align: center; | ||
} | ||
|
||
.systemNotificationBar a { | ||
color:white; | ||
display:inline; | ||
font-size:15px; | ||
font-weight:bold; | ||
padding-right: 15px; | ||
text-decoration: underline; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we really need private config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never be displayed to the user - I didn't add it to any of the sections.