Commit 3192045499ba1156cf6b66c8cdf00d18a68d6a3d
1 parent
a6360f27
fix for KTS-348: discussion subscription notifications.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5954 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
130 additions
and
5 deletions
lib/dashboard/Notification.inc.php
| @@ -189,7 +189,9 @@ class KTSubscriptionNotification extends KTNotificationHandler { | @@ -189,7 +189,9 @@ class KTSubscriptionNotification extends KTNotificationHandler { | ||
| 189 | "CheckOutDocument" => 'document', | 189 | "CheckOutDocument" => 'document', |
| 190 | "MovedDocument" => 'document', | 190 | "MovedDocument" => 'document', |
| 191 | "ArchivedDocument" => 'document', // can go through and request un-archival (?) | 191 | "ArchivedDocument" => 'document', // can go through and request un-archival (?) |
| 192 | - "RestoredArchivedDocument" => 'document'); | 192 | + "RestoredArchivedDocument" => 'document', |
| 193 | + "DiscussDocument" => 'document', | ||
| 194 | + ); | ||
| 193 | 195 | ||
| 194 | function KTSubscriptionNotification() { | 196 | function KTSubscriptionNotification() { |
| 195 | $this->_eventTypeNames = array( | 197 | $this->_eventTypeNames = array( |
| @@ -204,7 +206,8 @@ class KTSubscriptionNotification extends KTNotificationHandler { | @@ -204,7 +206,8 @@ class KTSubscriptionNotification extends KTNotificationHandler { | ||
| 204 | "CheckOutDocument" => _kt('Document checked out'), | 206 | "CheckOutDocument" => _kt('Document checked out'), |
| 205 | "MovedDocument" => _kt('Document moved'), | 207 | "MovedDocument" => _kt('Document moved'), |
| 206 | "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?) | 208 | "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?) |
| 207 | - "RestoredArchivedDocument" => _kt('Document restored') | 209 | + "RestoredArchivedDocument" => _kt('Document restored'), |
| 210 | + "DiscussDocument" => _kt('Document Discussions updated'), | ||
| 208 | ); | 211 | ); |
| 209 | //parent::KTNotificationHandler(); | 212 | //parent::KTNotificationHandler(); |
| 210 | } | 213 | } |
lib/subscriptions/subscriptions.inc.php
| @@ -317,6 +317,59 @@ class SubscriptionEvent { | @@ -317,6 +317,59 @@ class SubscriptionEvent { | ||
| 317 | } | 317 | } |
| 318 | } | 318 | } |
| 319 | } | 319 | } |
| 320 | + | ||
| 321 | + function DiscussDocument($oModifiedDocument, $oParentFolder) { | ||
| 322 | + $content = new SubscriptionContent(); // needed for i18n | ||
| 323 | + // OK: two actions: document registrants, folder registrants. | ||
| 324 | + $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); | ||
| 325 | + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. | ||
| 326 | + foreach ($aUsers as $oSubscriber) { | ||
| 327 | + | ||
| 328 | + // notification object first. | ||
| 329 | + $aNotificationOptions = array(); | ||
| 330 | + $aNotificationOptions['target_user'] = $oSubscriber->getID(); | ||
| 331 | + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. | ||
| 332 | + $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); | ||
| 333 | + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); | ||
| 334 | + $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. | ||
| 335 | + $aNotificationOptions['event_type'] = "DiscussDocument"; | ||
| 336 | + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); | ||
| 337 | + | ||
| 338 | + // now the email content. | ||
| 339 | + // FIXME this needs to be handled entirely within notifications from now on. | ||
| 340 | + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { | ||
| 341 | + $emailContent = $content->getEmailAlertContent($oNotification); | ||
| 342 | + $emailSubject = $content->getEmailAlertSubject($oNotification); | ||
| 343 | + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); | ||
| 344 | + $oEmail->send(); | ||
| 345 | + } | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); | ||
| 349 | + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. | ||
| 350 | + foreach ($aUsers as $oSubscriber) { | ||
| 351 | + | ||
| 352 | + // notification object first. | ||
| 353 | + $aNotificationOptions = array(); | ||
| 354 | + $aNotificationOptions['target_user'] = $oSubscriber->getID(); | ||
| 355 | + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. | ||
| 356 | + $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); | ||
| 357 | + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); | ||
| 358 | + $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. | ||
| 359 | + $aNotificationOptions['event_type'] = "DiscussDocument"; | ||
| 360 | + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); | ||
| 361 | + | ||
| 362 | + // now the email content. | ||
| 363 | + // FIXME this needs to be handled entirely within notifications from now on. | ||
| 364 | + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { | ||
| 365 | + $emailContent = $content->getEmailAlertContent($oNotification); | ||
| 366 | + $emailSubject = $content->getEmailAlertSubject($oNotification); | ||
| 367 | + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); | ||
| 368 | + $oEmail->send(); | ||
| 369 | + } | ||
| 370 | + } | ||
| 371 | + } | ||
| 372 | + | ||
| 320 | function CheckInDocument($oModifiedDocument, $oParentFolder) { | 373 | function CheckInDocument($oModifiedDocument, $oParentFolder) { |
| 321 | $content = new SubscriptionContent(); // needed for i18n | 374 | $content = new SubscriptionContent(); // needed for i18n |
| 322 | // OK: two actions: document registrants, folder registrants. | 375 | // OK: two actions: document registrants, folder registrants. |
| @@ -677,7 +730,8 @@ class SubscriptionContent { | @@ -677,7 +730,8 @@ class SubscriptionContent { | ||
| 677 | "CheckOutDocument" => _kt('Document checked out'), | 730 | "CheckOutDocument" => _kt('Document checked out'), |
| 678 | "MovedDocument" => _kt('Document moved'), | 731 | "MovedDocument" => _kt('Document moved'), |
| 679 | "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?) | 732 | "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?) |
| 680 | - "RestoredArchivedDocument" => _kt('Document restored') | 733 | + "RestoredArchivedDocument" => _kt('Document restored'), |
| 734 | + "DiscussDocument" => _kt('Document Discussions updated'), | ||
| 681 | ); | 735 | ); |
| 682 | } | 736 | } |
| 683 | 737 | ||
| @@ -729,7 +783,8 @@ class SubscriptionContent { | @@ -729,7 +783,8 @@ class SubscriptionContent { | ||
| 729 | "CheckOutDocument" => 'document', | 783 | "CheckOutDocument" => 'document', |
| 730 | "MovedDocument" => 'document', | 784 | "MovedDocument" => 'document', |
| 731 | "ArchivedDocument" => 'document', // can go through and request un-archival (?) | 785 | "ArchivedDocument" => 'document', // can go through and request un-archival (?) |
| 732 | - "RestoredArchivedDocument" => 'document'); | 786 | + "RestoredArchivedDocument" => 'document', |
| 787 | + "DiscussDocument" => 'document'); | ||
| 733 | 788 | ||
| 734 | 789 | ||
| 735 | 790 |
plugins/ktstandard/KTDiscussion.php
| @@ -191,6 +191,22 @@ class KTDocumentDiscussionAction extends KTDocumentAction { | @@ -191,6 +191,22 @@ class KTDocumentDiscussionAction extends KTDocumentAction { | ||
| 191 | $res = $oThread->update(); | 191 | $res = $oThread->update(); |
| 192 | $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment"); | 192 | $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment"); |
| 193 | $this->oValidator->notError($res, $aErrorOptions); | 193 | $this->oValidator->notError($res, $aErrorOptions); |
| 194 | + | ||
| 195 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | ||
| 196 | + $aTriggers = $oKTTriggerRegistry->getTriggers('discussion', 'postValidate'); | ||
| 197 | + foreach ($aTriggers as $aTrigger) { | ||
| 198 | + $sTrigger = $aTrigger[0]; | ||
| 199 | + $oTrigger = new $sTrigger; | ||
| 200 | + $aInfo = array( | ||
| 201 | + "document" => $this->oDocument, | ||
| 202 | + "comment" => $oComment, | ||
| 203 | + ); | ||
| 204 | + $oTrigger->setInfo($aInfo); | ||
| 205 | + $ret = $oTrigger->postValidate(); | ||
| 206 | + if (PEAR::isError($ret)) { | ||
| 207 | + $this->oValidator->notError($res, $aErrorOptions); | ||
| 208 | + } | ||
| 209 | + } | ||
| 194 | 210 | ||
| 195 | // Thread and comment created correctly, commit to database | 211 | // Thread and comment created correctly, commit to database |
| 196 | $this->commitTransaction(); | 212 | $this->commitTransaction(); |
| @@ -303,7 +319,21 @@ class KTDocumentDiscussionAction extends KTDocumentAction { | @@ -303,7 +319,21 @@ class KTDocumentDiscussionAction extends KTDocumentAction { | ||
| 303 | $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment"); | 319 | $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment"); |
| 304 | $this->oValidator->notError($res, $aErrorOptions); | 320 | $this->oValidator->notError($res, $aErrorOptions); |
| 305 | 321 | ||
| 306 | - | 322 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 323 | + $aTriggers = $oKTTriggerRegistry->getTriggers('discussion', 'postValidate'); | ||
| 324 | + foreach ($aTriggers as $aTrigger) { | ||
| 325 | + $sTrigger = $aTrigger[0]; | ||
| 326 | + $oTrigger = new $sTrigger; | ||
| 327 | + $aInfo = array( | ||
| 328 | + "document" => $this->oDocument, | ||
| 329 | + "comment" => $oComment, | ||
| 330 | + ); | ||
| 331 | + $oTrigger->setInfo($aInfo); | ||
| 332 | + $ret = $oTrigger->postValidate(); | ||
| 333 | + if (PEAR::isError($ret)) { | ||
| 334 | + $this->oValidator->notError($res, $aErrorOptions); | ||
| 335 | + } | ||
| 336 | + } | ||
| 307 | 337 | ||
| 308 | // Thread and comment created correctly, commit to database | 338 | // Thread and comment created correctly, commit to database |
| 309 | $this->commitTransaction(); | 339 | $this->commitTransaction(); |
plugins/ktstandard/KTSubscriptions.php
| @@ -63,6 +63,8 @@ class KTSubscriptionPlugin extends KTPlugin { | @@ -63,6 +63,8 @@ class KTSubscriptionPlugin extends KTPlugin { | ||
| 63 | 'ktstandard.triggers.subscription.moveDocument'); | 63 | 'ktstandard.triggers.subscription.moveDocument'); |
| 64 | $this->registerTrigger('archive', 'postValidate', 'KTArchiveSubscriptionTrigger', | 64 | $this->registerTrigger('archive', 'postValidate', 'KTArchiveSubscriptionTrigger', |
| 65 | 'ktstandard.triggers.subscription.archive'); | 65 | 'ktstandard.triggers.subscription.archive'); |
| 66 | + $this->registerTrigger('discussion', 'postValidate', 'KTDiscussionSubscriptionTrigger', | ||
| 67 | + 'ktstandard.triggers.subscription.archive'); | ||
| 66 | $this->registerAction('foldersubscriptionaction', 'KTFolderSubscriptionAction', | 68 | $this->registerAction('foldersubscriptionaction', 'KTFolderSubscriptionAction', |
| 67 | 'ktstandard.subscription.foldersubscription'); | 69 | 'ktstandard.subscription.foldersubscription'); |
| 68 | $this->registerAction('foldersubscriptionaction', 'KTFolderUnsubscriptionAction', | 70 | $this->registerAction('foldersubscriptionaction', 'KTFolderUnsubscriptionAction', |
| @@ -299,6 +301,24 @@ class KTArchiveSubscriptionTrigger { | @@ -299,6 +301,24 @@ class KTArchiveSubscriptionTrigger { | ||
| 299 | } | 301 | } |
| 300 | // }}} | 302 | // }}} |
| 301 | 303 | ||
| 304 | + | ||
| 305 | + | ||
| 306 | +class KTDiscussionSubscriptionTrigger { | ||
| 307 | + var $aInfo = null; | ||
| 308 | + function setInfo(&$aInfo) { | ||
| 309 | + $this->aInfo =& $aInfo; | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + function postValidate() { | ||
| 313 | + $oDocument =& $this->aInfo["document"]; | ||
| 314 | + $oSubscriptionEvent = new SubscriptionEvent(); | ||
| 315 | + $oFolder = Folder::get($oDocument->getFolderID()); | ||
| 316 | + | ||
| 317 | + $oSubscriptionEvent->DiscussDocument($oDocument, $oFolder); | ||
| 318 | + } | ||
| 319 | +} | ||
| 320 | +// }}} | ||
| 321 | + | ||
| 302 | // {{{ KTFolderSubscriptionAction | 322 | // {{{ KTFolderSubscriptionAction |
| 303 | class KTFolderSubscriptionAction extends KTFolderAction { | 323 | class KTFolderSubscriptionAction extends KTFolderAction { |
| 304 | var $sName = 'ktstandard.subscription.foldersubscription'; | 324 | var $sName = 'ktstandard.subscription.foldersubscription'; |
templates/kt3/notifications/subscriptions.DiscussDocument.smarty
0 → 100644
| 1 | +<dt class="actionitem subscription">{$info.title}</dt> | ||
| 2 | +<dd class="actionmessage"> | ||
| 3 | +<!-- could break this up. --> | ||
| 4 | + {if ($info.has_actor)} | ||
| 5 | + {$info.actor_name} has added to the discussion around document "{$info.object_name}". | ||
| 6 | + {else} | ||
| 7 | + The discussion around document "{$info.object_name}" has been updated. | ||
| 8 | + {/if} | ||
| 9 | + <div class="actionoptions"> | ||
| 10 | + {if !$is_broken} | ||
| 11 | + <a href="{ktLink base="notify.php" query="id=`$info.notify_id`"}">{i18n}View Document{/i18n}</a> | ||
| 12 | + {else} | ||
| 13 | + <span class="descriptiveText">{i18n}Document is no longer available{/i18n}</span> | ||
| 14 | + {/if} | ||
| 15 | + | <a href="{ktLink base="notify.php" query="id=`$info.notify_id`¬ify_action=clear"}">{i18n}Clear Alert{/i18n}</a> | ||
| 16 | + </div> | ||
| 17 | +</dd> |