/**
  * 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);
     }
 }
 public function showConfigMatrixObject()
 {
     global $ilTabs;
     $ilTabs->activateSubTab('notification_admin_matrix');
     require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
     require_once 'Services/Notifications/classes/class.ilNotificationSettingsTable.php';
     global $ilCtrl, $lng;
     $userdata = ilNotificationDatabaseHandler::loadUserConfig(-1);
     $table = new ilNotificationSettingsTable($this, 'a title', ilNotificationDatabaseHandler::getAvailableChannels(), $userdata, true);
     $table->setFormAction($ilCtrl->getFormAction($this, 'saveConfigMatrix'));
     $table->setData(ilNotificationDatabaseHandler::getAvailableTypes());
     $table->setDescription($lng->txt('notification_admin_matrix_settings_table_desc'));
     $table->addCommandButton('saveConfigMatrix', $lng->txt('save'));
     $table->addCommandButton('showConfigMatrix', $lng->txt('cancel'));
     $this->tpl->setContent($table->getHtml());
 }
 public function showSettingsObject()
 {
     global $tpl, $ilCtrl, $ilUser, $lng;
     require_once 'Services/Notifications/classes/class.ilNotificationSettingsTable.php';
     require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
     $userTypes = ilNotificationDatabaseHandler::loadUserConfig($ilUser->getId());
     $lng->loadLanguageModule('notification');
     require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
     $form = new ilPropertyFormGUI();
     $chk = new ilCheckboxInputGUI($lng->txt('enable_custom_notification_configuration'), 'enable_custom_notification_configuration');
     $chk->setValue('1');
     $chk->setChecked($ilUser->getPref('use_custom_notification_setting') == 1);
     $form->addItem($chk);
     $form->setFormAction($ilCtrl->getFormAction($this, 'showSettingsObject'));
     $form->addCommandButton('saveCustomizingOption', $lng->txt('save'));
     $form->addCommandButton('showSettings', $lng->txt('cancel'));
     $table = new ilNotificationSettingsTable($this, 'a title', $this->getAvailableChannels(array('set_by_user')), $userTypes);
     $table->setFormAction($ilCtrl->getFormAction($this, 'saveSettings'));
     $table->setData($this->getAvailableTypes(array('set_by_user')));
     if ($ilUser->getPref('use_custom_notification_setting') == 1) {
         $table->addCommandButton('saveSettings', $lng->txt('save'));
         $table->addCommandButton('showSettings', $lng->txt('cancel'));
         $table->setEditable(true);
     } else {
         $table->setEditable(false);
     }
     $tpl->setContent($form->getHtml() . $table->getHTML());
 }