/** * Unit test for eZSubtreeNotificationRule::fetchUserList() */ public function testFetchUserList() { // Add a notification rule for admin on root $adminUserID = eZUser::fetchByName( 'admin' )->attribute( 'contentobject_id' ); $rule = new eZSubtreeNotificationRule( array( 'user_id' => $adminUserID, 'use_digest' => 0, 'node_id' => 2 ) ); $rule->store(); // Create a content object below node #2 $article = new ezpObject( 'article', 2 ); $article->title = __FUNCTION__; $article->publish(); $articleContentObject = $article->object; $list = eZSubtreeNotificationRule::fetchUserList( array( 2, 43 ), $articleContentObject ); $this->assertInternalType( 'array', $list, "Return value should have been an array" ); $this->assertEquals( 1, count( $list ), "Return value should have one item" ); $this->assertInternalType( 'array', $list[0] ); $this->assertArrayHasKey( 'user_id', $list[0] ); $this->assertArrayHasKey( 'use_digest', $list[0] ); $this->assertArrayHasKey( 'address', $list[0] ); $this->assertEquals( 14, $list[0]['user_id'] ); $this->assertEquals( 0, $list[0]['use_digest'] ); $this->assertEquals( '*****@*****.**', $list[0]['address'] ); }
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; }
/** * Wrong use of array_intersect() in ezsubtreenotificationrule.php * * @link http://issues.ez.no/16248 */ public function testCorrectUsageArrayIntersect() { $access = eZSubtreeNotificationRule::checkObjectAccess( eZContentObject::fetch( 1 ), $this->policy->attribute( 'id' ), array( 14 ) ); $this->assertEquals( array( 14 ), $access ); }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'is_bookmarked': $bookmarkList = eZPersistentObject::fetchObjectList(eZContentBrowseBookmark::definition(), null, array('user_id' => eZUser::currentUserID(), 'node_id' => $namedParameters['node_id']), array('id' => 'desc'), array('offset' => 0, 'length' => '10'), true); if (count($bookmarkList) > 0) { $operatorValue = 1; } else { $operatorValue = 0; } break; case 'is_in_subscribed_nodes': $subscriptionList = eZPersistentObject::fetchObjectList(eZSubtreeNotificationRule::definition(), array('node_id'), array('user_id' => eZUser::currentUserID(), 'node_id' => $namedParameters['node_id']), null, null, false); if (count($subscriptionList) > 0) { $operatorValue = 1; } else { $operatorValue = 0; } break; } }
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; }
static function removeUser($userID) { $user = eZUser::fetch($userID); if (!$user) { eZDebug::writeError("unable to find user with ID {$userID}", __METHOD__); return false; } eZUser::removeSessionData($userID); eZSubtreeNotificationRule::removeByUserID($userID); eZCollaborationNotificationRule::removeByUserID($userID); eZUserSetting::removeByUserID($userID); eZUserAccountKey::removeByUserID($userID); eZForgotPassword::removeByUserID($userID); eZWishList::removeByUserID($userID); eZGeneralDigestUserSettings::removeByUserId($userID); eZPersistentObject::removeObject(eZUser::definition(), array('contentobject_id' => $userID)); return true; }
static function removeUser($userID) { $user = eZUser::fetch($userID); if (!$user) { eZDebug::writeError("unable to find user with ID {$userID}", __METHOD__); return false; } eZUser::removeSessionData($userID); eZSubtreeNotificationRule::removeByUserID($userID); eZCollaborationNotificationRule::removeByUserID($userID); eZUserSetting::removeByUserID($userID); eZUserAccountKey::removeByUserID($userID); eZForgotPassword::removeByUserID($userID); eZWishList::removeByUserID($userID); // only remove general digest setting if there are no other users with the same e-mail $email = $user->attribute('email'); $usersWithEmailCount = eZPersistentObject::count(eZUser::definition(), array('email' => $email)); if ($usersWithEmailCount == 1) { eZGeneralDigestUserSettings::removeByAddress($email); } eZPersistentObject::removeObject(eZUser::definition(), array('contentobject_id' => $userID)); return true; }
function cleanup() { eZSubtreeNotificationRule::cleanup(); }
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(); } }
static function removeByUserID($userID) { eZPersistentObject::removeObject(eZSubtreeNotificationRule::definition(), array('user_id' => $userID)); }