📄 notification.inc.php.svn-base
字号:
); //parent::KTNotificationHandler(); } // helper method to extract / set the various pieces of information function _getSubscriptionData($oKTNotification) { $info = array( 'object_name' => $oKTNotification->getLabel(), 'event_type' => $oKTNotification->getStrData1(), 'location_name' => $oKTNotification->getStrData2(), 'object_id' => $oKTNotification->getIntData1(), 'actor_id' => $oKTNotification->getIntData2(), '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)) { // no-act $info['actor'] = null; } else { $info['actor'] = $oTempUser; $info['has_actor'] = true; } } 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; } else { return $o; } } else if ($t == 'folder') { $o = Folder::get($id); if (PEAR::isError($o) || ($o == false)) { return null; } else { return $o; } } else { return null; } } function _getEventObjectType($sAlertType) { return KTUtil::arrayGet($this->_eventObjectMap, $sAlertType ,''); } function handleNotification($oKTNotification) { $oSubscriptionContent = new SubscriptionContent(); return $oSubscriptionContent->getNotificationAlertContent($oKTNotification); } // helper to _create_ a notification, in a way that is slightly less opaque. function &generateSubscriptionNotification($aOptions) { $creationInfo = array(); /* "iId" => "id", "iUserId" => "user_id", "sLabel" => "label", "sType" => "type", "dCreationDate" => "creation_date", "iData1" => "data_int_1", "iData2" => "data_int_2", "sData1" => "data_str_1", "sData2" => "data_str_2", 'object_name' => $oKTNotification->getLabel(), 'event_type' => $oKTNotification->getStrData1(), 'location_name' => $oKTNotification->getStrData2(), 'object_id' => $oKTNotification->getIntData1(), 'actor_id' => $oKTNotification->getIntData2(), 'has_actor' => false, */ $creationInfo['sLabel'] = $aOptions['target_name']; $creationInfo['sData1'] = $aOptions['event_type']; $creationInfo['sData2'] = $aOptions['location_name']; $creationInfo['iData1'] = $aOptions['object_id']; $creationInfo['iData2'] = $aOptions['actor_id']; $creationInfo['iUserId'] = $aOptions['target_user']; $creationInfo['sType'] = 'ktcore/subscriptions'; $creationInfo['dCreationDate'] = getCurrentDateTime(); // erk. global $default; //$default->log->debug('subscription notification: from ' . print_r($aOptions, true)); $default->log->debug('subscription notification: using ' . print_r($creationInfo, true)); $oNotification =& KTNotification::createFromArray($creationInfo); $default->log->debug('subscription notification: created ' . print_r($oNotification, true)); return $oNotification; // $res. } /** * View the notification, and clear if requested * * @param unknown_type $oKTNotification */ function resolveNotification($oKTNotification) { $notify_action = KTUtil::arrayGet($_REQUEST, 'notify_action', null); if ($notify_action == 'clear') { $_SESSION['KTInfoMessage'][] = _kt('Cleared notification.'); $oKTNotification->delete(); exit(redirect(generateControllerLink('dashboard'))); } // otherwise, we want to redirect the to object represented by the item. // - viewDocument and viewFolder are the appropriate items. // - object_id $info = $this->_getSubscriptionData($oKTNotification); $object_type = $this->_getEventObjectType($info['event_type']); if ($object_type == '') { $_SESSION['KTErrorMessage'][] = 'This notification has no "target". Please report as a bug that this subscription should only have a clear action.' . $object_type; exit(redirect(generateControllerLink('dashboard'))); } if ($object_type == 'document') { if ($info['object_id'] !== null) { // fails and generates an error with no doc-id. $params = 'fDocumentId=' . $info['object_id']; $url = generateControllerLink('viewDocument', $params); //$oKTNotification->delete(); // clear the alert. exit(redirect($url)); } } else if ($object_type == 'folder') { if ($info['object_id'] !== null) { // fails and generates an error with no doc-id. $params = 'fFolderId=' . $info['object_id']; $url = generateControllerLink('browse', $params); //$oKTNotification->delete(); // clear the alert. exit(redirect($url)); } } $_SESSION['KTErrorMessage'][] = sprintf('This notification has no "target". Please inform the %s developers that there is a target bug with type: ' . $info['event_type'], APP_NAME); exit(redirect(generateControllerLink('dashboard'))); }}class KTWorkflowNotification extends KTNotificationHandler { function & clearNotificationsForDocument($oDocument) { $aNotifications = KTNotification::getList('data_int_1 = ' . $oDocument->getId()); foreach ($aNotifications as $oNotification) { $oNotification->delete(); } } function & newNotificationForDocument($oDocument, $oUser, $oState, $oActor, $sComments) { $aInfo = array(); $aInfo['sData1'] = $oState->getName(); $aInfo['sData2'] = $sComments; $aInfo['iData1'] = $oDocument->getId(); $aInfo['iData2'] = $oActor->getId(); $aInfo['sType'] = 'ktcore/workflow'; $aInfo['dCreationDate'] = getCurrentDateTime(); $aInfo['iUserId'] = $oUser->getId(); $aInfo['sLabel'] = $oDocument->getName(); $oNotification = KTNotification::createFromArray($aInfo); $handler = new KTWorkflowNotification(); if ($oUser->getEmailNotification() && (strlen($oUser->getEmail()) > 0)) { $emailContent = $handler->handleNotification($oNotification); $emailSubject = sprintf(_kt('Workflow Notification: %s'), $oDocument->getName()); $oEmail = new EmailAlert($oUser->getEmail(), $emailSubject, $emailContent); $oEmail->send(); } return $oNotification; } function handleNotification($oKTNotification) { $oTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oTemplating->loadTemplate('ktcore/workflow/workflow_notification'); $oDoc = Document::get($oKTNotification->getIntData1()); $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE)); $oTemplate->setData(array( 'context' => $this, 'document_id' => $oKTNotification->getIntData1(), 'state_name' => $oKTNotification->getStrData1(), 'actor' => User::get($oKTNotification->getIntData2()), 'document_name' => $oKTNotification->getLabel(), 'notify_id' => $oKTNotification->getId(), 'document' => $oDoc, 'is_broken' => $isBroken, )); return $oTemplate->render(); } function resolveNotification($oKTNotification) { $notify_action = KTUtil::arrayGet($_REQUEST, 'notify_action', null); if ($notify_action == 'clear') { $_SESSION['KTInfoMessage'][] = _kt('Workflow Notification cleared.'); $oKTNotification->delete(); exit(redirect(generateControllerLink('dashboard'))); } $params = 'fDocumentId=' . $oKTNotification->getIntData1(); $url = generateControllerLink('viewDocument', $params); //$oKTNotification->delete(); // clear the alert. exit(redirect($url)); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -