/**
  * Creates the user notifications and send them. If processAsync is true
  * the notifications will be serialized and persisted to the database
  * 
  * @param ilNotificationConfig $notification
  * @param type $users
  * @param type $processAsync 
  */
 private function toUsers(ilNotificationConfig $notification, $users, $processAsync = false)
 {
     require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
     require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
     // if async processing is disabled send them immediately
     if ($processAsync == false) {
         // loading the default configuration
         $adminConfig = ilNotificationDatabaseHandler::loadUserConfig(-1);
         $usersWithCustomConfig = ilNotificationDatabaseHandler::getUsersWithCustomConfig($users);
         // @todo this loop might be obsolet :)
         foreach ($users as $user_id) {
             if ($usersWithCustomConfig[$user_id]) {
                 /** @todo was ist hier? **/
             }
         }
         // load all available channels
         $channels = ilNotificationDatabaseHandler::getAvailableChannels();
         // load all available types
         $types = ilNotificationDatabaseHandler::getAvailableTypes();
         // preload translation vars
         $lang = ilNotificationDatabaseHandler::getTranslatedLanguageVariablesOfNotificationParameters($notification->getLanguageParameters());
         $user_by_handler = array();
         // check if the type allows custom user configurations for determining
         // the output channel (e.g. send chat notifications only via osd)
         if ($types[$notification->getType()]['config_type'] == 'set_by_user') {
             $it = new ilNotificationUserIterator($notification->getType(), $users);
             $channelsByAdmin = false;
             // add the user to each channel he configured in his own configuration
             foreach ($it as $usr_id => $data) {
                 // the configured user channel is (currently) not known
                 if (!$channels[$data['channel']]) {
                     continue;
                 }
                 if (!$user_by_handler[$data['channel']]) {
                     $user_by_handler[$data['channel']] = array();
                 }
                 $user_by_handler[$data['channel']][] = $usr_id;
             }
         } else {
             if ($types[$notification->getType()]['config_type'] != 'disabled') {
                 $channelsByAdmin = true;
                 //$user_by_handler = array();
                 if (isset($adminConfig[$notification->getType()])) {
                     foreach ($adminConfig[$notification->getType()] as $channel) {
                         if (!$channels[$channel]) {
                             continue;
                         }
                         $user_by_handler[$channel] = $users;
                     }
                 }
             }
         }
         $userCache = array();
         // process the notifications for each output channel
         foreach ($user_by_handler as $handler => $users) {
             $handler = $this->handler[$handler];
             // and process each user for the current output channel
             foreach ($users as $userId) {
                 if (!$userCache[$userId]) {
                     $userCache[$userId] = new ilObjUser($userId);
                 }
                 $user = $userCache[$userId];
                 // optain the message instance for the user
                 // @todo this step could be cached on a per user basis
                 //       as it is independed from the output handler
                 $instance = $notification->getUserInstance($user, $lang, $this->defaultLanguage);
                 foreach ($handler as $h) {
                     // fire the notification
                     $h->notify($instance);
                 }
             }
         }
     } else {
         // just enque the current configuration
         ilNotificationDatabaseHandler::enqueueByUsers($notification, $users);
     }
 }