diff --git a/lib/subscriptions/subscriptions.inc.php b/lib/subscriptions/subscriptions.inc.php index f69d6fc..6497b90 100644 --- a/lib/subscriptions/subscriptions.inc.php +++ b/lib/subscriptions/subscriptions.inc.php @@ -6,7 +6,7 @@ * License Version 1.1.2 ("License"); You may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.knowledgetree.com/KPL - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and @@ -17,9 +17,9 @@ * (ii) the KnowledgeTree copyright notice * in the same form as they appear in the distribution. See the License for * requirements. - * + * * The Original Code is: KnowledgeTree Open Source - * + * * The Initial Developer of the Original Code is The Jam Warehouse Software * (Pty) Ltd, trading as KnowledgeTree. * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright @@ -30,7 +30,7 @@ * * ------------------------------------------------------------------------- * - * Subscription notification type. + * Subscription notification type. * * To use this, instantiate a SubscriptionEvent, and call the * appropriate "event" method. @@ -60,52 +60,52 @@ class SubscriptionEvent { "ArchivedDocument", "RestoredArchivedDocument", ); - + var $subscriptionTypes = array( "Document" => 1, "Folder" => 2, ); - + function &subTypes($sType) { $subscriptionTypes = array( "Document" => 1, "Folder" => 2, ); - + return KTUtil::arrayGet($subscriptionTypes, $sType, null); } - + var $alertedUsers = array(); // per-instance (e.g. per-event) list of users who were contacted. - var $_parameters = array(); // internal storage for + var $_parameters = array(); // internal storage for var $child = -1; // the child object-id (e.g. which initiated the event: document OR folder) var $parent = -1; // the folder-id of the parent // FIXME stubs. - /* Each of these functions handles appropriate propogation (e.g. both + /* Each of these functions handles appropriate propogation (e.g. both * folder and document subscription) without calling secondary functions. * Every attempt is made to be as explicit as possible. */ - + // alerts users who are subscribed to $iParentFolderId. - function AddFolder($oAddedFolder, $oParentFolder) { + function AddFolder($oAddedFolder, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n - + // only useful for folder subscriptions. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oAddedFolder->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oAddedFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "AddFolder"; + $aNotificationOptions['event_type'] = "AddFolder"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -115,25 +115,25 @@ class SubscriptionEvent { } } } - function AddDocument ($oAddedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n - // two parts to this: + function AddDocument ($oAddedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n + // two parts to this: $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null - is this valid? $aNotificationOptions['target_name'] = $oAddedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oAddedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "AddDocument"; - + $aNotificationOptions['event_type'] = "AddDocument"; + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -144,27 +144,27 @@ class SubscriptionEvent { } } function RemoveFolder($oRemovedFolder, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + $content = new SubscriptionContent(); // needed for i18n // two cases to consider here: // - notify people who are subscribed to the parent folder. // - notify and unsubscribe people who are subscribed to the actual folder. - + // we need to start with the latter, so we don't "lose" any. $aUsers = $this->_getSubscribers($oRemovedFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oRemovedFolder->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveSubscribedFolder"; + $aNotificationOptions['event_type'] = "RemoveSubscribedFolder"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -172,30 +172,30 @@ class SubscriptionEvent { $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); $oEmail->send(); } - + // now grab each oSubscribers oSubscription, and delete. $oSubscription = Subscription::getByIds($oSubscriber->getId(), $oRemovedFolder->getId(), $this->subscriptionTypes["Folder"]); if (!(PEAR::isError($oSubscription) || ($oSubscription == false))) { $oSubscription->delete(); } } - + // now handle (for those who haven't been alerted) users watching the folder. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oRemovedFolder->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveChildFolder"; + $aNotificationOptions['event_type'] = "RemoveChildFolder"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -204,30 +204,30 @@ class SubscriptionEvent { $oEmail->send(); } } - + } function RemoveDocument($oRemovedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + $content = new SubscriptionContent(); // needed for i18n // two cases to consider here: // - notify people who are subscribed to the parent folder. // - notify and unsubscribe people who are subscribed to the actual folder. - + // we need to start with the latter, so we don't "lose" any. $aUsers = $this->_getSubscribers($oRemovedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oRemovedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveSubscribedDocument"; + $aNotificationOptions['event_type'] = "RemoveSubscribedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -235,30 +235,30 @@ class SubscriptionEvent { $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); $oEmail->send(); } - + // now grab each oSubscribers oSubscription, and delete. $oSubscription = Subscription::getByIds($oSubscriber->getId(), $oRemovedDocument->getId(), $this->subscriptionTypes["Document"]); if (!(PEAR::isError($oSubscription) || ($oSubscription == false))) { $oSubscription->delete(); } } - + // now handle (for those who haven't been alerted) users watching the folder. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oRemovedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveChildDocument"; + $aNotificationOptions['event_type'] = "RemoveChildDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -267,26 +267,26 @@ class SubscriptionEvent { $oEmail->send(); } } - + } - function ModifyDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + function ModifyDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ModifyDocument"; + $aNotificationOptions['event_type'] = "ModifyDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -295,23 +295,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ModifyDocument"; + $aNotificationOptions['event_type'] = "ModifyDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -321,25 +321,25 @@ class SubscriptionEvent { } } } - - function DiscussDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + + function DiscussDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DiscussDocument"; + $aNotificationOptions['event_type'] = "DiscussDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -348,22 +348,22 @@ class SubscriptionEvent { $oEmail->send(); } } - + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DiscussDocument"; + $aNotificationOptions['event_type'] = "DiscussDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -373,25 +373,25 @@ class SubscriptionEvent { } } } - - function CheckInDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + + function CheckInDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckInDocument"; + $aNotificationOptions['event_type'] = "CheckInDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -400,23 +400,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckInDocument"; + $aNotificationOptions['event_type'] = "CheckInDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -427,24 +427,24 @@ class SubscriptionEvent { } } } - function CheckOutDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + function CheckOutDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckOutDocument"; + $aNotificationOptions['event_type'] = "CheckOutDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -453,23 +453,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckOutDocument"; + $aNotificationOptions['event_type'] = "CheckOutDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -480,24 +480,24 @@ class SubscriptionEvent { } } - function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder) { - $content = new SubscriptionContent(); // needed for i18n + function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oMovedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - // notification object first. + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oMovedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId()); $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "MovedDocument"; + $aNotificationOptions['event_type'] = "MovedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -506,23 +506,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oFromFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oMovedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId()); $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "MovedDocument"; + $aNotificationOptions['event_type'] = "MovedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -531,22 +531,22 @@ class SubscriptionEvent { $oEmail->send(); } } - + $aUsers = $this->_getSubscribers($oToFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oMovedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "MovedDocument"; + $aNotificationOptions['event_type'] = "MovedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -554,26 +554,26 @@ class SubscriptionEvent { $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); $oEmail->send(); } - } + } } - function ArchivedDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + function ArchivedDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ArchivedDocument"; + $aNotificationOptions['event_type'] = "ArchivedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -582,23 +582,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ArchivedDocument"; + $aNotificationOptions['event_type'] = "ArchivedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -608,25 +608,25 @@ class SubscriptionEvent { } } } - - function RestoreDocument($oModifiedDocument, $oParentFolder) { - $content = new SubscriptionContent(); // needed for i18n + + function RestoreDocument($oModifiedDocument, $oParentFolder) { + $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; + $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -635,23 +635,23 @@ class SubscriptionEvent { $oEmail->send(); } } - - + + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton. foreach ($aUsers as $oSubscriber) { - - // notification object first. + + // notification object first. $aNotificationOptions = array(); $aNotificationOptions['target_user'] = $oSubscriber->getID(); $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; + $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. + + // now the email content. // FIXME this needs to be handled entirely within notifications from now on. if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { $emailContent = $content->getEmailAlertContent($oNotification); @@ -666,11 +666,11 @@ class SubscriptionEvent { function _getKeyForType($sEventType) { foreach ($this->eventTypes as $key => $val) { if ($val == $sSubType) { return $key; } - } + } return -1; } - - // helper function to get & adjust the $alertedUsers + + // helper function to get & adjust the $alertedUsers // note that this has side-effects: $this->alertedUsers is a merged version // after this has been called. function _pruneAlertedUsers($aUserIds) { @@ -678,39 +678,39 @@ class SubscriptionEvent { $this->alertedUsers = kt_array_merge($returnArray, $this->alertedUsers); // now contains all users who will have been alerted. return $returnArray; } - + // gets subscribers to object, with appropriate type (e.g. folder or document). // need the second part because docs and folders have separate ids. // based on the old SubscriptionEngine::retrieveSubscribers. function _getSubscribers($iObjectId, $iSubType) { global $default; // for the logging. $default->log->debug("_getSubscribers(id=$iObjectId, type=$iSubType); table=" .Subscription::getTableName($iSubType). "; id=" .Subscription::getIdFieldName($iSubType)); - - $aUsers = array(); + + $aUsers = array(); $sQuery = "SELECT user_id FROM " . Subscription::getTableName($iSubType) . " WHERE " . Subscription::getIdFieldName($iSubType) . " = ?"; $aParams = array($iObjectId); - + $aNewUsers = DBUtil::getResultArrayKey(array($sQuery, $aParams), "user_id"); - + // notionally less efficient than the old code. if its a big issue, can easily // be refactored. foreach ($aNewUsers as $iUserId) { $oUser = & User::get($iUserId); - + // do a quick prune here, for performance/maintenance reasons. if (PEAR::isError($oUser) || ($oUser == false)) { $sQuery = "DELETE FROM " . Subscription::getTableName($iSubType) . " WHERE user_id = ?"; $aParams = array($iUserId); DBUtil::runQuery(array($sQuery, $sParams)); - $default->log->error("SubscriptionEvent::fireSubscription error removing subscription for user id=$iUserID"); + $default->log->error("SubscriptionEvent::fireSubscription error removing subscription for user id=$iUserId"); } else { $aUsers[] = $oUser; - } + } } - + $default->log->debug('retrieveSubscribers found count=' . count($aUsers)); - return $aUsers; - } + return $aUsers; + } } // interesting: how do we want to generate email & notification content? @@ -735,7 +735,7 @@ class SubscriptionContent { "MovedDocument" => _kt('Document moved'), "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?) "RestoredArchivedDocument" => _kt('Document restored'), - "DiscussDocument" => _kt('Document Discussions updated'), + "DiscussDocument" => _kt('Document Discussions updated'), ); } @@ -745,34 +745,34 @@ class SubscriptionContent { $str = '' . $this->getNotificationAlertContent($oKTNotification) . ''; return $str; } - - function getEmailAlertSubject($oKTNotification) { + + function getEmailAlertSubject($oKTNotification) { $info = $this->_getSubscriptionData($oKTNotification); - return $info["title"]; + return $info["title"]; } - + function getNotificationAlertContent($oKTNotification) { $info = $this->_getSubscriptionData($oKTNotification); $oTemplating =& KTTemplating::getSingleton(); - + $oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions." . $info['event_type']); // if, for some reason, this doesn't actually work, use the "generic" title. if (PEAR::isError($oTemplate)) { $oTemplate = $oTemplating->loadTemplate("kt3/notifications/subscriptions.generic"); } // FIXME we need to specify the i18n by user. - + $isBroken = false; if (PEAR::isError($info['object']) || ($info['object'] === false) || is_null($info['object'])) { $isBroken = true; } - + $aTemplateData = array("context" => $oKTNotification, "info" => $info, "is_broken" => $isBroken, ); return $oTemplate->render($aTemplateData); - } + } // no separate subject function, its rolled into get...Content() var $_eventObjectMap = array( @@ -788,10 +788,10 @@ class SubscriptionContent { "MovedDocument" => 'document', "ArchivedDocument" => 'document', // can go through and request un-archival (?) "RestoredArchivedDocument" => 'document', - "DiscussDocument" => 'document'); + "DiscussDocument" => 'document'); + - function _getSubscriptionData($oKTNotification) { $info = array( 'object_name' => $oKTNotification->getLabel(), @@ -802,9 +802,9 @@ class SubscriptionContent { 'has_actor' => false, 'notify_id' => $oKTNotification->getId(), ); - + $info['title'] = KTUtil::arrayGet($this->_eventTypeNames, $info['event_type'], 'Subscription alert:') .': ' . $info['object_name']; - + if ($info['actor_id'] !== null) { $oTempUser = User::get($info['actor_id']); if (PEAR::isError($oTempUser) || ($oTempUser == false)) { @@ -823,37 +823,37 @@ class SubscriptionContent { $sName .= sprintf(" (%s)", $oUnit->getName()); } } - + $info['actor_name'] = $sName; } } - + if ($info['object_id'] !== null) { $info['object'] = $this->_getEventObject($info['event_type'], $info['object_id']); } - + return $info; - } - + } + // resolve the object type based on the alert type. function _getEventObject($sAlertType, $id) { $t = KTUtil::arrayGet($this->_eventObjectMap, $sAlertType ,''); if ($t == 'document') { $o = Document::get($id); - if (PEAR::isError($o) || ($o == false)) { return null; + if (PEAR::isError($o) || ($o == false)) { return null; } else { return $o; } } else if ($t == 'folder') { $o = Folder::get($id); - if (PEAR::isError($o) || ($o == false)) { return null; + if (PEAR::isError($o) || ($o == false)) { return null; } else { return $o; } } else { return null; } } - + function _getEventObjectType($sAlertType) { return KTUtil::arrayGet($this->_eventObjectMap, $sAlertType ,''); - } + } } ?>