diff --git a/lib/dashboard/Notification.inc.php b/lib/dashboard/Notification.inc.php index 2fe0ebe..35ea581 100644 --- a/lib/dashboard/Notification.inc.php +++ b/lib/dashboard/Notification.inc.php @@ -89,7 +89,12 @@ class KTNotification extends KTEntity { // Static function function &get($iId) { return KTEntityUtil::get('KTNotification', $iId); } - function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTNotification', $sWhereClause); } + function &getList($sWhereClause = null, $aOptions = null ) { + if(!is_array($aOptions)) $aOptions = array($aOptions); + $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'creation_date DESC'); + return KTEntityUtil::getList2('KTNotification', $sWhereClause, $aOptions); + } + function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTNotification', $aOptions); } } diff --git a/notify.php b/notify.php index 5c32728..b36ae0b 100644 --- a/notify.php +++ b/notify.php @@ -21,11 +21,16 @@ class KTNotificationDispatcher extends KTStandardDispatcher { var $notification; function check() { + $clear_all = KTUtil::arrayGet($_REQUEST, 'clearAll'); + if ($clear_all) { + return true; + } + $notification_id = KTUtil::arrayGet($_REQUEST, 'id', null); $oKTNotification =& KTNotification::get($notification_id); if (PEAR::isError($oKTNotification)) { - $_SESSION['KTErrorMessage'][] = 'Invalid notification.'; + $this->addErrorMessage(_('Invalid notification.')); exit(redirect(generateControllerLink('dashboard'))); } @@ -34,9 +39,32 @@ class KTNotificationDispatcher extends KTStandardDispatcher { return true; } function do_main() { + $clear_all = KTUtil::arrayGet($_REQUEST, 'clearAll'); + if ($clear_all) { + return $this->clearAll(); + } + + // get the notification-handler, instantiate it, call resolveNotification. return $this->notification->resolve(); } + + function clearAll() { + $this->startTransaction(); + $aNotifications = KTNotification::getList('user_id = ' . $this->oUser->getId()); + + foreach ($aNotifications as $oNotification) { + $res = $oNotification->delete(); + if (PEAR::isError($res)) { + $this->rollbackTransaction(); + $this->addErrorMessage(_('Failed to clear notifications.')); + exit(redirect(generateControllerLink('dashboard'))); + } + } + $this->commitTransaction(); + $this->addInfoMessage(_('Notifications cleared.')); + exit(redirect(generateControllerLink('dashboard'))); + } } $dispatcher =& new KTNotificationDispatcher(); diff --git a/plugins/ktcore/KTDashlets.php b/plugins/ktcore/KTDashlets.php index 12b4087..dd0e460 100644 --- a/plugins/ktcore/KTDashlets.php +++ b/plugins/ktcore/KTDashlets.php @@ -34,11 +34,21 @@ class KTNotificationDashlet extends KTBaseDashlet { function render() { $notifications = KTNotification::getList(array("user_id = ?", $this->oUser->getId())); + $num_notifications = count($notifications); + + $_MAX_NOTIFICATIONS = 5; + + // FIXME in lieu of pagination, we slice. + if ($num_notifications > $_MAX_NOTIFICATIONS) { + $notifications = array_slice($notifications, 0, $_MAX_NOTIFICATIONS); + } $oTemplating = new KTTemplating; $oTemplate = $oTemplating->loadTemplate("ktcore/dashlets/notifications"); $aTemplateData = array( "notifications" => $notifications, + "notification_count" => $num_notifications, + "visible_count" => count($notifications), ); return $oTemplate->render($aTemplateData); } diff --git a/templates/ktcore/dashlets/notifications.smarty b/templates/ktcore/dashlets/notifications.smarty index 7beb749..dc66de6 100644 --- a/templates/ktcore/dashlets/notifications.smarty +++ b/templates/ktcore/dashlets/notifications.smarty @@ -5,6 +5,15 @@ {$oNotification->render()} {/foreach} +{if ($notification_count > $visible_count)} +{* pagination standin *} +

{i18n arg_count=$notification_count arg_visible=$visible_count}These are the most recent #visible# notifications. You have a total of #count# notifications waiting.{/i18n}

+{/if} +{* clear all link *} +{i18n}Clear all notifications{/i18n} +{i18n}Clear all notifications{/i18n} {else}

{i18n}No items require your attention.{/i18n}

{/if}