Beispiel #1
0
 function sendMessages($userId)
 {
     $userDao = $this->_daoFactory->getUserDao();
     $notificationDao = $this->_daoFactory->getNotificationDao();
     if ($userId == 0) {
         $userList = $userDao->getUserList();
     } else {
         $thisUser = $userDao->getUser($userId);
         $userList = array($thisUser);
     }
     # else
     foreach ($userList as $user) {
         # Omdat we vanuit getUserList() niet alle velden meekrijgen
         # vragen we opnieuw het user record op
         $user = $userDao->getUser($user['userid']);
         $security = new SpotSecurity($this->_daoFactory->getUserDao(), $this->_daoFactory->getAuditDao(), $this->_settings, $user, '');
         # Om e-mail te kunnen versturen hebben we iets meer data nodig
         $user['prefs']['notifications']['email']['sender'] = $this->_settings->get('systemfrommail');
         $user['prefs']['notifications']['email']['receiver'] = $user['mail'];
         # Twitter heeft ook extra settings nodig
         $user['prefs']['notifications']['twitter']['consumer_key'] = $this->_settings->get('twitter_consumer_key');
         $user['prefs']['notifications']['twitter']['consumer_secret'] = $this->_settings->get('twitter_consumer_secret');
         # Evenals Boxcar
         $user['prefs']['notifications']['boxcar']['api_key'] = $this->_settings->get('boxcar_api_key');
         $user['prefs']['notifications']['boxcar']['api_secret'] = $this->_settings->get('boxcar_api_secret');
         $newMessages = $notificationDao->getUnsentNotifications($user['userid']);
         foreach ($newMessages as $newMessage) {
             $objectId = $newMessage['objectid'];
             $spotweburl = $this->_settings->get('spotweburl') == 'http://mijnuniekeservernaam/spotweb/' ? '' : $this->_settings->get('spotweburl');
             $notifProviders = Notifications_Factory::getActiveServices();
             foreach ($notifProviders as $notifProvider) {
                 if ($user['prefs']['notifications'][$notifProvider]['enabled'] && $user['prefs']['notifications'][$notifProvider]['events'][$objectId]) {
                     if ($security->allowed(SpotSecurity::spotsec_send_notifications_services, $notifProvider)) {
                         $this->_notificationServices[$notifProvider] = Notifications_Factory::build('Spotweb', $notifProvider, $user['prefs']['notifications'][$notifProvider]);
                     }
                     # if
                 }
                 # if
             }
             # foreach
             # nu wordt het bericht pas echt verzonden
             foreach ($this->_notificationServices as $notificationService) {
                 $notificationService->sendMessage($newMessage['type'], utf8_decode($newMessage['title']), utf8_decode($newMessage['body']), $spotweburl);
             }
             # foreach
             # Alle services resetten, deze mogen niet hergebruikt worden
             $this->_notificationServices = array();
             # Als dit bericht ging over het aanmaken van een nieuwe user, verwijderen we
             # het plaintext wachtwoord uit de database uit veiligheidsoverwegingen.
             if ($objectId == SpotNotifications::notifytype_user_added) {
                 $body = explode(" ", $newMessage['body']);
                 $body[4] = '[deleted]';
                 $newMessage['body'] = implode(" ", $body);
             }
             # if
             $newMessage['sent'] = true;
             $notificationDao->updateNotification($newMessage);
         }
         # foreach message
     }
     # foreach user
 }