예제 #1
0
echo $OUTPUT->header();
echo $OUTPUT->heading($strunsubscribeall);
if (data_submitted() and $confirm and confirm_sesskey()) {
    $twfs = \mod_twf\subscriptions::get_unsubscribable_twfs();
    foreach ($twfs as $twf) {
        \mod_twf\subscriptions::unsubscribe_user($USER->id, $twf, context_module::instance($twf->cm), true);
    }
    $DB->delete_records('twf_discussion_subs', array('userid' => $USER->id));
    $DB->set_field('user', 'autosubscribe', 0, array('id' => $USER->id));
    echo $OUTPUT->box(get_string('unsubscribealldone', 'twf'));
    echo $OUTPUT->continue_button($return);
    echo $OUTPUT->footer();
    die;
} else {
    $count = new stdClass();
    $count->twfs = count(\mod_twf\subscriptions::get_unsubscribable_twfs());
    $count->discussions = $DB->count_records('twf_discussion_subs', array('userid' => $USER->id));
    if ($count->twfs || $count->discussions) {
        if ($count->twfs && $count->discussions) {
            $msg = get_string('unsubscribeallconfirm', 'twf', $count);
        } else {
            if ($count->twfs) {
                $msg = get_string('unsubscribeallconfirmtwfs', 'twf', $count);
            } else {
                if ($count->discussions) {
                    $msg = get_string('unsubscribeallconfirmdiscussions', 'twf', $count);
                }
            }
        }
        echo $OUTPUT->confirm($msg, new moodle_url('unsubscribeall.php', array('confirm' => 1)), $return);
        echo $OUTPUT->footer();
예제 #2
0
 /**
  * Test fetching unsubscribable twfs.
  */
 public function test_unsubscribable_twfs()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create a course, with a twf.
     $course = $this->getDataGenerator()->create_course();
     // Create a user enrolled in the course as a student.
     list($user) = $this->helper_create_users($course, 1);
     // Must be logged in as the current user.
     $this->setUser($user);
     // Without any subscriptions, there should be nothing returned.
     $result = \mod_twf\subscriptions::get_unsubscribable_twfs();
     $this->assertEquals(0, count($result));
     // Create the twfs.
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
     $forcetwf = $this->getDataGenerator()->create_module('twf', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE);
     $disallowtwf = $this->getDataGenerator()->create_module('twf', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
     $choosetwf = $this->getDataGenerator()->create_module('twf', $options);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
     $initialtwf = $this->getDataGenerator()->create_module('twf', $options);
     // At present the user is only subscribed to the initial twf.
     $result = \mod_twf\subscriptions::get_unsubscribable_twfs();
     $this->assertEquals(1, count($result));
     // Ensure that the user is enrolled in all of the twfs except force subscribed.
     \mod_twf\subscriptions::subscribe_user($user->id, $disallowtwf);
     \mod_twf\subscriptions::subscribe_user($user->id, $choosetwf);
     $result = \mod_twf\subscriptions::get_unsubscribable_twfs();
     $this->assertEquals(3, count($result));
     // Hide the twfs.
     set_coursemodule_visible($forcetwf->cmid, 0);
     set_coursemodule_visible($disallowtwf->cmid, 0);
     set_coursemodule_visible($choosetwf->cmid, 0);
     set_coursemodule_visible($initialtwf->cmid, 0);
     $result = \mod_twf\subscriptions::get_unsubscribable_twfs();
     $this->assertEquals(0, count($result));
     // Add the moodle/course:viewhiddenactivities capability to the student user.
     $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
     $context = \context_course::instance($course->id);
     assign_capability('moodle/course:viewhiddenactivities', CAP_ALLOW, $roleids['student'], $context);
     $context->mark_dirty();
     // All of the unsubscribable twfs should now be listed.
     $result = \mod_twf\subscriptions::get_unsubscribable_twfs();
     $this->assertEquals(3, count($result));
 }
예제 #3
0
/**
 * Returns an array of twfs that the current user is subscribed to and is allowed to unsubscribe from
 *
 * @return array An array of unsubscribable twfs
 * @deprecated since Moodle 2.8 use \mod_twf\subscriptions::get_unsubscribable_twfs() instead
 */
function twf_get_optional_subscribed_twfs()
{
    debugging("twf_get_optional_subscribed_twfs() has been deprecated, please use \\mod_twf\\subscriptions::get_unsubscribable_twfs() instead.", DEBUG_DEVELOPER);
    return \mod_twf\subscriptions::get_unsubscribable_twfs();
}