function onPublish($attribute, $contentObject, $publishedNodes) { $user = eZUser::currentUser(); $address = $user->attribute('email'); $userID = $user->attribute('contentobject_id'); $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID($user->attribute('contentobject_id'), false); if ($attribute->attribute('data_int') == '1') { $newSubscriptions = array(); foreach ($publishedNodes as $node) { if (!in_array($node->attribute('node_id'), $nodeIDList)) { $newSubscriptions[] = $node->attribute('node_id'); } } foreach ($newSubscriptions as $nodeID) { $rule = eZSubtreeNotificationRule::create($nodeID, $userID); $rule->store(); } } else { foreach ($publishedNodes as $node) { if (in_array($node->attribute('node_id'), $nodeIDList)) { eZSubtreeNotificationRule::removeByNodeAndUserID($user->attribute('contentobject_id'), $node->attribute('node_id')); } } } return true; }
function notification_addtonotification($nodeID) { // code mostly stolen from notification/addtonotification view $user = eZUSer::currentUser(); $contentNode = eZContentObjectTreeNode::fetch($nodeID); if (!$contentNode) { eZDebug::writeError('The nodeID parameter was empty or wrong, user ID: ' . $user->attribute('contentobject_id'), __METHOD__); throw new Exception('The nodeID parameter was empty or wrong', -10123); } if (!$contentNode->attribute('can_read')) { eZDebug::writeError('User does not have access to subscribe for notification, node ID: ' . $nodeID . ', user ID: ' . $user->attribute('contentobject_id'), __METHOD__); throw new Exception('User does not have access to subscribe for notification', -10234); } $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID($user->attribute('contentobject_id'), false); if (!in_array($nodeID, $nodeIDList)) { $rule = eZSubtreeNotificationRule::create($nodeID, $user->attribute('contentobject_id')); $rule->store(); return 1; } // notification already exists return 2; }
function fetchHttpInput($http, $module) { if ($http->hasPostVariable('NewRule_' . self::NOTIFICATION_HANDLER_ID)) { eZContentBrowse::browse(array('action_name' => 'AddSubtreeSubscribingNode', 'from_page' => '/notification/settings/'), $module); } else { if ($http->hasPostVariable('RemoveRule_' . self::NOTIFICATION_HANDLER_ID) and $http->hasPostVariable('SelectedRuleIDArray_' . self::NOTIFICATION_HANDLER_ID)) { $user = eZUser::currentUser(); $userList = eZSubtreeNotificationRule::fetchList($user->attribute('contentobject_id'), false); foreach ($userList as $userRow) { $listID[] = $userRow['id']; } $ruleIDList = $http->postVariable('SelectedRuleIDArray_' . self::NOTIFICATION_HANDLER_ID); foreach ($ruleIDList as $ruleID) { if (in_array($ruleID, $listID)) { eZPersistentObject::removeObject(eZSubtreeNotificationRule::definition(), array('id' => $ruleID)); } } } else { if ($http->hasPostVariable("BrowseActionName") and $http->postVariable("BrowseActionName") == "AddSubtreeSubscribingNode" and !$http->hasPostVariable('BrowseCancelButton')) { $selectedNodeIDArray = $http->postVariable("SelectedNodeIDArray"); $user = eZUser::currentUser(); $existingNodes = eZSubtreeNotificationRule::fetchNodesForUserID($user->attribute('contentobject_id'), false); foreach ($selectedNodeIDArray as $nodeID) { if (!in_array($nodeID, $existingNodes)) { $rule = eZSubtreeNotificationRule::create($nodeID, $user->attribute('contentobject_id')); $rule->store(); } } // $Module->redirectTo( "//list/" ); } } } }
return; } $contentNode = eZContentObjectTreeNode::fetch($nodeID); if (!$contentNode) { eZDebug::writeError('The nodeID parameter was empty, user ID: ' . $user->attribute('contentobject_id'), 'kernel/content/action.php'); $module->redirectTo($redirectURI); return; } if (!$contentNode->attribute('can_read')) { eZDebug::writeError('User does not have access to subscribe for notification, node ID: ' . $nodeID . ', user ID: ' . $user->attribute('contentobject_id'), 'kernel/content/action.php'); $module->redirectTo($redirectURI); return; } $tpl = eZTemplate::factory(); if ($http->hasSessionVariable("LastAccessesURI", false)) { $tpl->setVariable('redirect_url', $http->sessionVariable("LastAccessesURI")); } //else // $tpl->setVariable( 'redirect_url', $module->functionURI( 'view' ) . '/full/2' ); $alreadyExists = true; $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID($user->attribute('contentobject_id'), false); if (!in_array($nodeID, $nodeIDList)) { $rule = eZSubtreeNotificationRule::create($nodeID, $user->attribute('contentobject_id')); $rule->store(); $alreadyExists = false; } $tpl->setVariable('already_exists', $alreadyExists); $tpl->setVariable('node_id', $nodeID); $Result = array(); $Result['content'] = $tpl->fetch('design:notification/addingresult.tpl'); $Result['path'] = array(array('text' => ezpI18n::tr('kernel/notification', $alreadyExists ? 'Notification already exists.' : 'Notification was added successfully!'), 'url' => false));
function createNotificationRuleIfNeeded($userID, $nodeID) { include_once 'kernel/classes/notification/handler/ezsubtree/ezsubtreenotificationrule.php'; $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID($userID, false); if (!in_array($nodeID, $nodeIDList)) { $rule = eZSubtreeNotificationRule::create($nodeID, $userID); $rule->store(); } }