Commit 303d99061fb628b4338edd49094aaa6aa1b29748
1 parent
323faae3
fix for KTS-437
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4990 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
54 additions
and
2 deletions
lib/dashboard/Notification.inc.php
| ... | ... | @@ -89,7 +89,12 @@ class KTNotification extends KTEntity { |
| 89 | 89 | |
| 90 | 90 | // Static function |
| 91 | 91 | function &get($iId) { return KTEntityUtil::get('KTNotification', $iId); } |
| 92 | - function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTNotification', $sWhereClause); } | |
| 92 | + function &getList($sWhereClause = null, $aOptions = null ) { | |
| 93 | + if(!is_array($aOptions)) $aOptions = array($aOptions); | |
| 94 | + $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'creation_date DESC'); | |
| 95 | + return KTEntityUtil::getList2('KTNotification', $sWhereClause, $aOptions); | |
| 96 | + } | |
| 97 | + | |
| 93 | 98 | function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTNotification', $aOptions); } |
| 94 | 99 | |
| 95 | 100 | } | ... | ... |
notify.php
| ... | ... | @@ -21,11 +21,16 @@ class KTNotificationDispatcher extends KTStandardDispatcher { |
| 21 | 21 | var $notification; |
| 22 | 22 | |
| 23 | 23 | function check() { |
| 24 | + $clear_all = KTUtil::arrayGet($_REQUEST, 'clearAll'); | |
| 25 | + if ($clear_all) { | |
| 26 | + return true; | |
| 27 | + } | |
| 28 | + | |
| 24 | 29 | $notification_id = KTUtil::arrayGet($_REQUEST, 'id', null); |
| 25 | 30 | $oKTNotification =& KTNotification::get($notification_id); |
| 26 | 31 | |
| 27 | 32 | if (PEAR::isError($oKTNotification)) { |
| 28 | - $_SESSION['KTErrorMessage'][] = 'Invalid notification.'; | |
| 33 | + $this->addErrorMessage(_('Invalid notification.')); | |
| 29 | 34 | exit(redirect(generateControllerLink('dashboard'))); |
| 30 | 35 | } |
| 31 | 36 | |
| ... | ... | @@ -34,9 +39,32 @@ class KTNotificationDispatcher extends KTStandardDispatcher { |
| 34 | 39 | return true; |
| 35 | 40 | } |
| 36 | 41 | function do_main() { |
| 42 | + $clear_all = KTUtil::arrayGet($_REQUEST, 'clearAll'); | |
| 43 | + if ($clear_all) { | |
| 44 | + return $this->clearAll(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + | |
| 37 | 48 | // get the notification-handler, instantiate it, call resolveNotification. |
| 38 | 49 | return $this->notification->resolve(); |
| 39 | 50 | } |
| 51 | + | |
| 52 | + function clearAll() { | |
| 53 | + $this->startTransaction(); | |
| 54 | + $aNotifications = KTNotification::getList('user_id = ' . $this->oUser->getId()); | |
| 55 | + | |
| 56 | + foreach ($aNotifications as $oNotification) { | |
| 57 | + $res = $oNotification->delete(); | |
| 58 | + if (PEAR::isError($res)) { | |
| 59 | + $this->rollbackTransaction(); | |
| 60 | + $this->addErrorMessage(_('Failed to clear notifications.')); | |
| 61 | + exit(redirect(generateControllerLink('dashboard'))); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + $this->commitTransaction(); | |
| 65 | + $this->addInfoMessage(_('Notifications cleared.')); | |
| 66 | + exit(redirect(generateControllerLink('dashboard'))); | |
| 67 | + } | |
| 40 | 68 | } |
| 41 | 69 | |
| 42 | 70 | $dispatcher =& new KTNotificationDispatcher(); | ... | ... |
plugins/ktcore/KTDashlets.php
| ... | ... | @@ -34,11 +34,21 @@ class KTNotificationDashlet extends KTBaseDashlet { |
| 34 | 34 | function render() { |
| 35 | 35 | |
| 36 | 36 | $notifications = KTNotification::getList(array("user_id = ?", $this->oUser->getId())); |
| 37 | + $num_notifications = count($notifications); | |
| 38 | + | |
| 39 | + $_MAX_NOTIFICATIONS = 5; | |
| 40 | + | |
| 41 | + // FIXME in lieu of pagination, we slice. | |
| 42 | + if ($num_notifications > $_MAX_NOTIFICATIONS) { | |
| 43 | + $notifications = array_slice($notifications, 0, $_MAX_NOTIFICATIONS); | |
| 44 | + } | |
| 37 | 45 | |
| 38 | 46 | $oTemplating = new KTTemplating; |
| 39 | 47 | $oTemplate = $oTemplating->loadTemplate("ktcore/dashlets/notifications"); |
| 40 | 48 | $aTemplateData = array( |
| 41 | 49 | "notifications" => $notifications, |
| 50 | + "notification_count" => $num_notifications, | |
| 51 | + "visible_count" => count($notifications), | |
| 42 | 52 | ); |
| 43 | 53 | return $oTemplate->render($aTemplateData); |
| 44 | 54 | } | ... | ... |
templates/ktcore/dashlets/notifications.smarty
| ... | ... | @@ -5,6 +5,15 @@ |
| 5 | 5 | {$oNotification->render()} |
| 6 | 6 | {/foreach} |
| 7 | 7 | </dl> |
| 8 | +{if ($notification_count > $visible_count)} | |
| 9 | +{* pagination standin *} | |
| 10 | +<p class="descriptiveText">{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}</p> | |
| 11 | +{/if} | |
| 12 | +{* clear all link *} | |
| 13 | +<a href="{ktLink base="notify.php" query="clearAll=1"}" | |
| 14 | + class="ktAction ktInline ktDelete">{i18n}Clear all notifications{/i18n}</a> | |
| 15 | +<a href="{ktLink base="notify.php" query="clearAll=1"}" | |
| 16 | + class="ktDelete">{i18n}Clear all notifications{/i18n}</a> | |
| 8 | 17 | {else} |
| 9 | 18 | <div class="ktInfo"><p>{i18n}No items require your attention.{/i18n}</p></div> |
| 10 | 19 | {/if} | ... | ... |