Example #1
0
 /**
  * Test the logic in the test_twf_tp_get_untracked_twfs() function.
  */
 public function test_twf_tp_get_untracked_twfs()
 {
     global $CFG;
     $this->resetAfterTest();
     $useron = $this->getDataGenerator()->create_user(array('tracktwfs' => 1));
     $useroff = $this->getDataGenerator()->create_user(array('tracktwfs' => 0));
     $course = $this->getDataGenerator()->create_course();
     $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF);
     // Off.
     $twfoff = $this->getDataGenerator()->create_module('twf', $options);
     $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED);
     // On.
     $twfforce = $this->getDataGenerator()->create_module('twf', $options);
     $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL);
     // Optional.
     $twfoptional = $this->getDataGenerator()->create_module('twf', $options);
     // Allow force.
     $CFG->twf_allowforcedreadtracking = 1;
     // On user with force on.
     $result = twf_tp_get_untracked_twfs($useron->id, $course->id);
     $this->assertEquals(1, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     // Off user with force on.
     $result = twf_tp_get_untracked_twfs($useroff->id, $course->id);
     $this->assertEquals(2, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     // Don't allow force.
     $CFG->twf_allowforcedreadtracking = 0;
     // On user with force off.
     $result = twf_tp_get_untracked_twfs($useron->id, $course->id);
     $this->assertEquals(1, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     // Off user with force off.
     $result = twf_tp_get_untracked_twfs($useroff->id, $course->id);
     $this->assertEquals(3, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     $this->assertEquals(true, isset($result[$twfforce->id]));
     // Stop tracking so we can test again.
     twf_tp_stop_tracking($twfforce->id, $useron->id);
     twf_tp_stop_tracking($twfoptional->id, $useron->id);
     twf_tp_stop_tracking($twfforce->id, $useroff->id);
     twf_tp_stop_tracking($twfoptional->id, $useroff->id);
     // Allow force.
     $CFG->twf_allowforcedreadtracking = 1;
     // On user with force on.
     $result = twf_tp_get_untracked_twfs($useron->id, $course->id);
     $this->assertEquals(2, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     // Off user with force on.
     $result = twf_tp_get_untracked_twfs($useroff->id, $course->id);
     $this->assertEquals(2, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     // Don't allow force.
     $CFG->twf_allowforcedreadtracking = 0;
     // On user with force off.
     $result = twf_tp_get_untracked_twfs($useron->id, $course->id);
     $this->assertEquals(3, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     $this->assertEquals(true, isset($result[$twfforce->id]));
     // Off user with force off.
     $result = twf_tp_get_untracked_twfs($useroff->id, $course->id);
     $this->assertEquals(3, count($result));
     $this->assertEquals(true, isset($result[$twfoff->id]));
     $this->assertEquals(true, isset($result[$twfoptional->id]));
     $this->assertEquals(true, isset($result[$twfforce->id]));
 }
Example #2
0
$strunsubscribe = get_string('unsubscribe', 'twf');
$stryes = get_string('yes');
$strno = get_string('no');
$strrss = get_string('rss');
$stremaildigest = get_string('emaildigest');
$searchform = twf_search_form($course);
// Retrieve the list of twf digest options for later.
$digestoptions = twf_get_user_digest_options();
$digestoptions_selector = new single_select(new moodle_url('/mod/twf/maildigest.php', array('backtoindex' => 1)), 'maildigest', $digestoptions, null, '');
$digestoptions_selector->method = 'post';
// Start of the table for General Forums
$generaltable = new html_table();
$generaltable->head = array($strtwf, $strdescription, $strdiscussions);
$generaltable->align = array('left', 'left', 'center');
if ($usetracking = twf_tp_can_track_twfs()) {
    $untracked = twf_tp_get_untracked_twfs($USER->id, $course->id);
    $generaltable->head[] = $strunreadposts;
    $generaltable->align[] = 'center';
    $generaltable->head[] = $strtracking;
    $generaltable->align[] = 'center';
}
// Fill the subscription cache for this course and user combination.
\mod_twf\subscriptions::fill_subscription_cache_for_course($course->id, $USER->id);
$can_subscribe = is_enrolled($coursecontext);
if ($can_subscribe) {
    $generaltable->head[] = $strsubscribed;
    $generaltable->align[] = 'center';
    $generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_twf');
    $generaltable->align[] = 'center';
}
if ($show_rss = ($can_subscribe || $course->id == SITEID) && isset($CFG->enablerssfeeds) && isset($CFG->twf_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->twf_enablerssfeeds) {