Commit 3192045499ba1156cf6b66c8cdf00d18a68d6a3d

Authored by bshuttle
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
lib/dashboard/Notification.inc.php
... ... @@ -189,7 +189,9 @@ class KTSubscriptionNotification extends KTNotificationHandler {
189 189 "CheckOutDocument" => 'document',
190 190 "MovedDocument" => 'document',
191 191 "ArchivedDocument" => 'document', // can go through and request un-archival (?)
192   - "RestoredArchivedDocument" => 'document');
  192 + "RestoredArchivedDocument" => 'document',
  193 + "DiscussDocument" => 'document',
  194 + );
193 195  
194 196 function KTSubscriptionNotification() {
195 197 $this->_eventTypeNames = array(
... ... @@ -204,7 +206,8 @@ class KTSubscriptionNotification extends KTNotificationHandler {
204 206 "CheckOutDocument" => _kt('Document checked out'),
205 207 "MovedDocument" => _kt('Document moved'),
206 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 212 //parent::KTNotificationHandler();
210 213 }
... ...
lib/subscriptions/subscriptions.inc.php
... ... @@ -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 373 function CheckInDocument($oModifiedDocument, $oParentFolder) {
321 374 $content = new SubscriptionContent(); // needed for i18n
322 375 // OK: two actions: document registrants, folder registrants.
... ... @@ -677,7 +730,8 @@ class SubscriptionContent {
677 730 "CheckOutDocument" => _kt('Document checked out'),
678 731 "MovedDocument" => _kt('Document moved'),
679 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 783 "CheckOutDocument" => 'document',
730 784 "MovedDocument" => 'document',
731 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 191 $res = $oThread->update();
192 192 $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment");
193 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 211 // Thread and comment created correctly, commit to database
196 212 $this->commitTransaction();
... ... @@ -303,7 +319,21 @@ class KTDocumentDiscussionAction extends KTDocumentAction {
303 319 $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment");
304 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 338 // Thread and comment created correctly, commit to database
309 339 $this->commitTransaction();
... ...
plugins/ktstandard/KTSubscriptions.php
... ... @@ -63,6 +63,8 @@ class KTSubscriptionPlugin extends KTPlugin {
63 63 'ktstandard.triggers.subscription.moveDocument');
64 64 $this->registerTrigger('archive', 'postValidate', 'KTArchiveSubscriptionTrigger',
65 65 'ktstandard.triggers.subscription.archive');
  66 + $this->registerTrigger('discussion', 'postValidate', 'KTDiscussionSubscriptionTrigger',
  67 + 'ktstandard.triggers.subscription.archive');
66 68 $this->registerAction('foldersubscriptionaction', 'KTFolderSubscriptionAction',
67 69 'ktstandard.subscription.foldersubscription');
68 70 $this->registerAction('foldersubscriptionaction', 'KTFolderUnsubscriptionAction',
... ... @@ -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 322 // {{{ KTFolderSubscriptionAction
303 323 class KTFolderSubscriptionAction extends KTFolderAction {
304 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`&notify_action=clear"}">{i18n}Clear Alert{/i18n}</a>
  16 + </div>
  17 +</dd>
... ...