} } if (!empty($twfmenu)) { echo '<div class="movediscussionoption">'; $select = new url_select($twfmenu, '', array('' => get_string("movethisdiscussionto", "twf")), 'twfmenu', get_string('move')); echo $OUTPUT->render($select); echo "</div>"; } } echo "</div>"; } echo '<div class="clearfloat"> </div>'; echo "</div>"; if (!empty($twf->blockafter) && !empty($twf->blockperiod)) { $a = new stdClass(); $a->blockafter = $twf->blockafter; $a->blockperiod = get_string('secondstotime' . $twf->blockperiod); echo $OUTPUT->notification(get_string('thistwfisthrottled', 'twf', $a)); } if ($twf->type == 'qanda' && !has_capability('mod/twf:viewqandawithoutposting', $modcontext) && !twf_user_has_posted($twf->id, $discussion->id, $USER->id)) { echo $OUTPUT->notification(get_string('qandanotify', 'twf')); } if ($move == -1 and confirm_sesskey()) { echo $OUTPUT->notification(get_string('discussionmoved', 'twf', format_string($twf->name, true))); } $canrate = has_capability('mod/twf:rate', $modcontext); twf_print_discussion($course, $cm, $twf, $discussion, $post, $displaymode, $canreply, $canrate); echo $neighbourlinks; // Add the subscription toggle JS. $PAGE->requires->yui_module('moodle-mod_twf-subscriptiontoggle', 'Y.M.mod_twf.subscriptiontoggle.init'); echo $OUTPUT->footer();
/** * Prints the discussion view screen for a twf. * * @global object * @global object * @param object $course The current course object. * @param object $twf Forum to be printed. * @param int $maxdiscussions . * @param string $displayformat The display format to use (optional). * @param string $sort Sort arguments for database query (optional). * @param int $groupmode Group mode of the twf (optional). * @param void $unused (originally current group) * @param int $page Page mode, page to display (optional). * @param int $perpage The maximum number of discussions per page(optional) * @param boolean $subscriptionstatus Whether the user is currently subscribed to the discussion in some fashion. * */ function twf_print_latest_discussions($course, $twf, $maxdiscussions = -1, $displayformat = 'plain', $sort = '', $currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = null) { global $CFG, $USER, $OUTPUT; //return; if (!$cm) { if (!($cm = get_coursemodule_from_instance('twf', $twf->id, $twf->course))) { print_error('invalidcoursemodule'); } } $context = context_module::instance($cm->id); if (empty($sort)) { $sort = "d.timemodified DESC"; } $olddiscussionlink = false; // Sort out some defaults if ($perpage <= 0) { $perpage = 0; $page = -1; } if ($maxdiscussions == 0) { // all discussions - backwards compatibility $page = -1; $perpage = 0; if ($displayformat == 'plain') { $displayformat = 'header'; // Abbreviate display by default } } else { if ($maxdiscussions > 0) { $page = -1; $perpage = $maxdiscussions; } } $fullpost = false; if ($displayformat == 'plain') { $fullpost = true; } // Decide if current user is allowed to see ALL the current discussions or not // First check the group stuff if ($currentgroup == -1 or $groupmode == -1) { $groupmode = groups_get_activity_groupmode($cm, $course); $currentgroup = groups_get_activity_group($cm); } $groups = array(); //cache // If the user can post discussions, then this is a good place to put the // button for it. We do not show the button if we are showing site news // and the current user is a guest. $canstart = twf_user_can_post_discussion($twf, $currentgroup, $groupmode, $cm, $context); if (!$canstart and $twf->type !== 'news') { if (isguestuser() or !isloggedin()) { $canstart = true; } if (!is_enrolled($context) and !is_viewing($context)) { // allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link // normal users with temporary guest access see this button too, they are asked to enrol instead // do not show the button to users with suspended enrolments here $canstart = enrol_selfenrol_available($course->id); } } if ($canstart) { echo '<div class="singlebutton twfaddnew">'; echo "<form id=\"newdiscussionform\" method=\"get\" action=\"{$CFG->wwwroot}/mod/twf/post.php\">"; echo '<div>'; echo "<input type=\"hidden\" name=\"twf\" value=\"{$twf->id}\" />"; switch ($twf->type) { case 'news': case 'blog': $buttonadd = get_string('addanewtopic', 'twf'); break; case 'qanda': $buttonadd = get_string('addanewquestion', 'twf'); break; default: $buttonadd = get_string('addanewdiscussion', 'twf'); break; } echo '<input type="submit" value="' . $buttonadd . '" />'; echo '</div>'; echo '</form>'; echo "</div>\n"; } else { if (isguestuser() or !isloggedin() or $twf->type == 'news' or $twf->type == 'qanda' and !has_capability('mod/twf:addquestion', $context) or $twf->type != 'qanda' and !has_capability('mod/twf:startdiscussion', $context)) { // no button and no info } else { if ($groupmode and !has_capability('moodle/site:accessallgroups', $context)) { // inform users why they can not post new discussion if (!$currentgroup) { echo $OUTPUT->notification(get_string('cannotadddiscussionall', 'twf')); } else { if (!groups_is_member($currentgroup)) { echo $OUTPUT->notification(get_string('cannotadddiscussion', 'twf')); } } } } } // Get all the recent discussions we're allowed to see $getuserlastmodified = $displayformat == 'header'; if (!($discussions = twf_get_discussions($cm, $sort, $fullpost, null, $maxdiscussions, $getuserlastmodified, $page, $perpage))) { echo '<div class="twfnodiscuss">'; if ($twf->type == 'news') { echo '(' . get_string('nonews', 'twf') . ')'; } else { if ($twf->type == 'qanda') { echo '(' . get_string('noquestions', 'twf') . ')'; } else { echo '(' . get_string('nodiscussions', 'twf') . ')'; } } echo "</div>\n"; return; } // If we want paging if ($page != -1) { ///Get the number of discussions found $numdiscussions = twf_get_discussions_count($cm); ///Show the paging bar echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$twf->id}"); if ($numdiscussions > 1000) { // saves some memory on sites with very large twfs $replies = twf_count_discussion_replies($twf->id, $sort, $maxdiscussions, $page, $perpage); } else { $replies = twf_count_discussion_replies($twf->id); } } else { $replies = twf_count_discussion_replies($twf->id); if ($maxdiscussions > 0 and $maxdiscussions <= count($discussions)) { $olddiscussionlink = true; } } $canviewparticipants = has_capability('moodle/course:viewparticipants', $context); $strdatestring = get_string('strftimerecentfull'); // Check if the twf is tracked. if ($cantrack = twf_tp_can_track_twfs($twf)) { $twftracked = twf_tp_is_tracked($twf); } else { $twftracked = false; } if ($twftracked) { $unreads = twf_get_discussions_unread($cm); } else { $unreads = array(); } if ($displayformat == 'header') { echo '<table cellspacing="0" class="forumheaderlist">'; echo '<thead>'; echo '<tr>'; echo '<th class="header topic" scope="col">' . get_string('discussion', 'twf') . '</th>'; echo '<th class="header author" colspan="2" scope="col">' . get_string('startedby', 'twf') . '</th>'; if ($groupmode > 0) { echo '<th class="header group" scope="col">' . get_string('group') . '</th>'; } if (has_capability('mod/twf:viewdiscussion', $context)) { echo '<th class="header replies" scope="col">' . get_string('replies', 'twf') . '</th>'; // If the twf can be tracked, display the unread column. if ($cantrack) { echo '<th class="header replies" scope="col">' . get_string('unread', 'twf'); if ($twftracked) { echo '<a title="' . get_string('markallread', 'twf') . '" href="' . $CFG->wwwroot . '/mod/twf/markposts.php?f=' . $twf->id . '&mark=read&returnpage=view.php">' . '<img src="' . $OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="' . get_string('markallread', 'twf') . '" /></a>'; } echo '</th>'; } } echo '<th class="header lastpost" scope="col">' . get_string('lastpost', 'twf') . '</th>'; if (!is_guest($context, $USER) && isloggedin() && has_capability('mod/twf:viewdiscussion', $context)) { if (\mod_twf\subscriptions::is_subscribable($twf)) { echo '<th class="header discussionsubscription" scope="col">'; echo twf_get_discussion_subscription_icon_preloaders(); echo '</th>'; } } echo '</tr>'; echo '</thead>'; echo '<tbody>'; } foreach ($discussions as $discussion) { if ($twf->type == 'qanda' && !has_capability('mod/twf:viewqandawithoutposting', $context) && !twf_user_has_posted($twf->id, $discussion->discussion, $USER->id)) { $canviewparticipants = false; } if (!empty($replies[$discussion->discussion])) { $discussion->replies = $replies[$discussion->discussion]->replies; $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid; } else { $discussion->replies = 0; } // SPECIAL CASE: The front page can display a news item post to non-logged in users. // All posts are read in this case. if (!$twftracked) { $discussion->unread = '-'; } else { if (empty($USER)) { $discussion->unread = 0; } else { if (empty($unreads[$discussion->discussion])) { $discussion->unread = 0; } else { $discussion->unread = $unreads[$discussion->discussion]; } } } if (isloggedin()) { $ownpost = $discussion->userid == $USER->id; } else { $ownpost = false; } // Use discussion name instead of subject of first post $discussion->subject = $discussion->name; switch ($displayformat) { case 'header': if ($groupmode > 0) { if (isset($groups[$discussion->groupid])) { $group = $groups[$discussion->groupid]; } else { $group = $groups[$discussion->groupid] = groups_get_group($discussion->groupid); } } else { $group = -1; } twf_print_discussion_header($discussion, $twf, $group, $strdatestring, $cantrack, $twftracked, $canviewparticipants, $context); break; default: $link = false; if ($discussion->replies) { $link = true; } else { $modcontext = context_module::instance($cm->id); $link = twf_user_can_see_discussion($twf, $discussion, $modcontext, $USER); } $discussion->twf = $twf->id; twf_print_post($discussion, $discussion, $twf, $cm, $course, $ownpost, 0, $link, false, '', null, true, $twftracked); break; } } if ($displayformat == "header") { echo '</tbody>'; echo '</table>'; } if ($olddiscussionlink) { if ($twf->type == 'news') { $strolder = get_string('oldertopics', 'twf'); } else { $strolder = get_string('olderdiscussions', 'twf'); } echo '<div class="forumolddiscuss">'; echo '<a href="' . $CFG->wwwroot . '/mod/twf/view.php?f=' . $twf->id . '&showall=1">'; echo $strolder . '</a> ...</div>'; } if ($page != -1) { ///Show the paging bar echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$twf->id}"); } }