Beispiel #1
0
 public function updateNotificationSettingsObject()
 {
     /**
      * @var $ilAccess ilAccessHandler
      * @var $ilErr		ilErr
      */
     global $ilAccess, $ilErr;
     if (!$ilAccess->checkAccess('write', '', $this->ref_id)) {
         $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
     }
     // instantiate the property form
     $this->initNotificationSettingsForm();
     // check input
     if ($this->notificationSettingsForm->checkInput()) {
         if (isset($_POST['notification_type']) && $_POST['notification_type'] == 'all_users') {
             // set values and call update
             $this->objProperties->setAdminForceNoti(1);
             $this->objProperties->setUserToggleNoti((int) $this->notificationSettingsForm->getInput('usr_toggle'));
             $this->objProperties->setNotificationType('all_users');
             $this->updateUserNotifications(true);
         } else {
             if ($_POST['notification_type'] == 'per_user') {
                 $this->objProperties->setNotificationType('per_user');
                 $this->objProperties->setAdminForceNoti(1);
                 $this->objProperties->setUserToggleNoti(0);
                 $this->updateUserNotifications();
             } else {
                 $this->objProperties->setNotificationType('default');
                 $this->objProperties->setAdminForceNoti(0);
                 $this->objProperties->setUserToggleNoti(0);
                 include_once 'Modules/Forum/classes/class.ilForumNotification.php';
                 $frm_noti = new ilForumNotification($this->object->getRefId());
                 $frm_noti->deleteNotificationAllUsers();
             }
         }
         $this->objProperties->update();
         // print success message
         ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
     }
     $this->notificationSettingsForm->setValuesByPost();
     return $this->showMembersObject();
 }
 public function showMembersObject()
 {
     /**
      * @var $tree ilTree
      * @var $tpl ilTemplate
      * @var $ilTabs ilTabsGUI
      * @var $ilAccess ilAccessHandler
      * @var $ilErr		ilErr
      */
     global $tree, $tpl, $ilTabs, $ilAccess, $ilErr;
     if (!$ilAccess->checkAccess('write', '', $this->ref_id)) {
         $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
     }
     $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_members_list.html', 'Modules/Forum');
     $ilTabs->setTabActive('settings');
     $this->settingsTabs();
     // instantiate the property form
     if (!$this->initNotificationSettingsForm()) {
         // if the form was just created set the values fetched from database
         $this->notificationSettingsForm->setValuesByArray(array('notification_type' => $this->objProperties->getNotificationType(), 'adm_force' => (bool) $this->objProperties->isAdminForceNoti(), 'usr_toggle' => (bool) $this->objProperties->isUserToggleNoti()));
     }
     // set form html into template
     $tpl->setVariable('NOTIFICATIONS_SETTINGS_FORM', $this->notificationSettingsForm->getHTML());
     include_once 'Modules/Forum/classes/class.ilForumNotification.php';
     include_once 'Modules/Forum/classes/class.ilObjForum.php';
     $frm_noti = new ilForumNotification($this->object->getRefId());
     // check if there a parent-node is a grp or crs
     $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
     $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
     if ($grp_ref_id == 0 && $crs_ref_id == 0) {
         $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
     }
     /**
      * @var $oParticipants ilParticipants
      */
     $oParticipants = null;
     if ($grp_ref_id > 0) {
         $parent_obj = ilObjectFactory::getInstanceByRefId($grp_ref_id);
         include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
         $oParticipants = ilGroupParticipants::_getInstanceByObjId($parent_obj->getId());
     } else {
         if ($crs_ref_id > 0) {
             $parent_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id);
             include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
             $oParticipants = ilCourseParticipants::_getInstanceByObjId($parent_obj->getId());
         }
     }
     $moderator_ids = $frm_noti->_getModerators($this->object->getRefId());
     $admin_ids = $oParticipants->getAdmins();
     $member_ids = $oParticipants->getMembers();
     $tutor_ids = $oParticipants->getTutors();
     $moderators = array();
     $admins = array();
     $members = array();
     $tutors = array();
     $all_forum_users = array_merge($moderator_ids, $admin_ids, $member_ids, $tutor_ids);
     $all_forum_users = array_unique($all_forum_users);
     if ($this->objProperties->getNotificationType() == 'default') {
         // update forum_notification table
         include_once 'Modules/Forum/classes/class.ilForumNotification.php';
         $forum_noti = new ilForumNotification($this->object->getRefId());
         $forum_noti->setAdminForce($this->objProperties->isAdminForceNoti());
         $forum_noti->setUserToggle($this->objProperties->isUserToggleNoti());
         $forum_noti->setForumId($this->objProperties->getObjId());
         if (isset($_POST['notification_type']) && $_POST['notification_type'] == 'default') {
             // delete all notifications set by admin
             $forum_noti->deleteNotificationAllUsers();
         }
     } else {
         if ($this->objProperties->getNotificationType() == 'per_user') {
             $counter = 0;
             foreach ($moderator_ids as $user_id) {
                 $frm_noti->setUserId($user_id);
                 #$admin_force_noti = $frm_noti->isAdminForceNotification();
                 $user_toggle_noti = $frm_noti->isUserToggleNotification();
                 $icon_ok = $this->getIcon(!$user_toggle_noti);
                 $moderators[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
                 $moderators[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
                 $name = ilObjUser::_lookupName($user_id);
                 $moderators[$counter]['firstname'] = $name['firstname'];
                 $moderators[$counter]['lastname'] = $name['lastname'];
                 $moderators[$counter]['user_toggle_noti'] = $icon_ok;
                 $counter++;
             }
             $counter = 0;
             foreach ($admin_ids as $user_id) {
                 $frm_noti->setUserId($user_id);
                 #$admin_force_noti = $frm_noti->isAdminForceNotification();
                 $user_toggle_noti = $frm_noti->isUserToggleNotification();
                 $icon_ok = $this->getIcon(!$user_toggle_noti);
                 $admins[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
                 $admins[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
                 $name = ilObjUser::_lookupName($user_id);
                 $admins[$counter]['firstname'] = $name['firstname'];
                 $admins[$counter]['lastname'] = $name['lastname'];
                 $admins[$counter]['user_toggle_noti'] = $icon_ok;
                 $counter++;
             }
             $counter = 0;
             foreach ($member_ids as $user_id) {
                 $frm_noti->setUserId($user_id);
                 #$admin_force_noti = $frm_noti->isAdminForceNotification();
                 $user_toggle_noti = $frm_noti->isUserToggleNotification();
                 $icon_ok = $this->getIcon(!$user_toggle_noti);
                 $members[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
                 $members[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
                 $name = ilObjUser::_lookupName($user_id);
                 $members[$counter]['firstname'] = $name['firstname'];
                 $members[$counter]['lastname'] = $name['lastname'];
                 $members[$counter]['user_toggle_noti'] = $icon_ok;
                 $counter++;
             }
             $counter = 0;
             foreach ($tutor_ids as $user_id) {
                 $frm_noti->setUserId($user_id);
                 #$admin_force_noti = $frm_noti->isAdminForceNotification();
                 $user_toggle_noti = $frm_noti->isUserToggleNotification();
                 $icon_ok = $this->getIcon(!$user_toggle_noti);
                 $tutors[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
                 $tutors[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
                 $name = ilObjUser::_lookupName($user_id);
                 $tutors[$counter]['firstname'] = $name['firstname'];
                 $tutors[$counter]['lastname'] = $name['lastname'];
                 $tutors[$counter]['user_toggle_noti'] = $icon_ok;
                 $counter++;
             }
             $this->__showMembersTable($moderators, $admins, $members, $tutors);
         } else {
             $frm_noti = new ilForumNotification($this->object->getRefId());
             $all_notis = $frm_noti->read();
             foreach ($all_forum_users as $user_id) {
                 $frm_noti->setUserId($user_id);
                 $frm_noti->setAdminForce(1);
                 $frm_noti->setUserToggle($this->objProperties->isUserToggleNoti());
                 if (array_key_exists($user_id, $all_notis)) {
                     $frm_noti->update();
                 } else {
                     if ($frm_noti->existsNotification() == false && !in_array($user_id, $moderator_ids)) {
                         $frm_noti->insertAdminForce();
                     }
                 }
             }
         }
     }
 }