Skip to content
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

Merged
merged 13 commits into from
Mar 26, 2017
67 changes: 67 additions & 0 deletions src/ChurchCRM/Service/NotificationService.php
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;
}

}
5 changes: 5 additions & 0 deletions src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ChurchCRM\Service;

use ChurchCRM\Service\AppIntegrityService;
use ChurchCRM\Service\NotificationService;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\FileSystemUtils;
Expand Down Expand Up @@ -364,6 +365,10 @@ public function reportIssue($data)

public function runTimerJobs()
{
if (NotificationService::isUpdateRequired())
{
NotificationService::updateNotifications();
}
//start the external backup timer job
if (SystemConfig::getValue('sEnableExternalBackupTarget') && SystemConfig::getValue('sExternalBackupAutoInterval') > 0) { //if remote backups are enabled, and the interval is greater than zero
try {
Expand Down
3 changes: 2 additions & 1 deletion src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ private static function buildConfigs()
"sConfirmSincerely" => new ConfigItem(1048, "sConfirmSincerely", "text", "Sincerely", gettext("Used to end a letter before Signer")),
"googleTrackingID" => new ConfigItem(1050, "googleTrackingID", "text", "", gettext("Google Analytics Tracking Code")),
"mailChimpApiKey" => new ConfigItem(2000, "mailChimpApiKey", "text", "", gettext("see http://kb.mailchimp.com/accounts/management/about-api-keys")),
"sDepositSlipType" => new ConfigItem(2001, "sDepositSlipType", "choice", "QBDT", gettext("Deposit ticket type. QBDT - Quickbooks"), '{"Choices":["QBDT"]}')
"sDepositSlipType" => new ConfigItem(2001, "sDepositSlipType", "choice", "QBDT", gettext("Deposit ticket type. QBDT - Quickbooks"), '{"Choices":["QBDT"]}'),
"sCloudURL" => new ConfigItem(2002, "sCloudURL", "text", "http://demo.churchcrm.io/", gettext("ChurchCRM Cloud Access URL"))
Copy link
Contributor

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

Copy link
Contributor Author

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.

);
}

Expand Down
16 changes: 16 additions & 0 deletions src/Include/Header-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@

use ChurchCRM\Service\SystemService;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\Service\NotificationService;

function Header_system_notifications()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should be ajax

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Include/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
</head>

<body class="hold-transition <?= $_SESSION['sStyle'] ?> sidebar-mini">
<?php
Header_system_notifications();
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
2 changes: 2 additions & 0 deletions src/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\Service\SystemService;
use ChurchCRM\UserQuery;
use ChurchCRM\Service\NotificationService;

$systemService = new SystemService();

Expand Down Expand Up @@ -214,6 +215,7 @@
$_SESSION['bSearchFamily'] = $currentUser->getSearchfamily();

$_SESSION['latestVersion'] = $systemService->getLatestRelese();
NotificationService::updateNotifications();
Redirect('CheckVersion.php');
exit;
}
Expand Down
1 change: 1 addition & 0 deletions src/skin/churchcrm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
@import 'scss/shortConfig';
@import 'scss/leftNav';
@import 'scss/imageOverlay';
@import 'scss/SystemNotifications';
21 changes: 21 additions & 0 deletions src/skin/scss/_SystemNotifications.scss
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;
}