public function testGetSubscriptionsWithProperInput() { $methods = array('apples', 'bananas'); $queryResult = array($this->createObjectFromArray(array('guid' => '22', 'methods' => 'notifyapples')), $this->createObjectFromArray(array('guid' => '567', 'methods' => 'notifybananas,notifyapples'))); $subscriptions = array(22 => array('apples'), 567 => array('bananas', 'apples')); $this->db->expects($this->once())->method('getData')->will($this->returnValue($queryResult)); $service = new Elgg_Notifications_SubscriptionsService($this->db); $service->methods = $methods; $this->assertEquals($subscriptions, $service->getSubscriptions($this->event)); }
/** * Pull notification events from queue until stop time is reached * * @param int $stopTime The Unix time to stop sending notifications * @return int The number of notification events handled * @access private */ public function processQueue($stopTime) { $this->subscriptions->methods = $this->methods; $count = 0; // @todo grab mutex $ia = $this->access->setIgnoreAccess(true); while (time() < $stopTime) { // dequeue notification event $event = $this->queue->dequeue(); if (!$event) { break; } // test for usage of the deprecated override hook if ($this->existsDeprecatedNotificationOverride($event)) { continue; } $subscriptions = $this->subscriptions->getSubscriptions($event); // return false to stop the default notification sender $params = array('event' => $event, 'subscriptions' => $subscriptions); if ($this->hooks->trigger('send:before', 'notifications', $params, true)) { $this->sendNotifications($event, $subscriptions); } $this->hooks->trigger('send:after', 'notifications', $params); $count++; } // release mutex $this->access->setIgnoreAccess($ia); return $count; }
/** * Get the subscriptions for the content created inside this container. * * The return array is of the form: * * array( * <user guid> => array('email', 'sms', 'ajax'), * ); * * @param int $container_guid GUID of the entity acting as a container * @return array User GUIDs (keys) and their subscription types (values). * @since 1.9 * @todo deprecate once new subscriptions system has been added */ function elgg_get_subscriptions_for_container($container_guid) { $methods = _elgg_services()->notifications->getMethods(); $db = _elgg_services()->db; $subs = new Elgg_Notifications_SubscriptionsService($db, $methods); return $subs->getSubscriptionsForContainer($container_guid); }
/** * Unsubscribe a user to notifications about a target entity * * @param int $user_guid The GUID of the user to unsubscribe to notifications * @param string $method The delivery method of the notifications to stop * @param int $target_guid The entity to stop receiving notifications about * @return bool * @since 1.9 */ function elgg_remove_subscription($user_guid, $method, $target_guid) { $methods = _elgg_services()->notifications->getMethods(); $db = _elgg_services()->db; $subs = new Elgg_Notifications_SubscriptionsService($db, $methods); return $subs->removeSubscription($user_guid, $method, $target_guid); }