} if ($post->parent) { $PAGE->navbar->add(get_string('reply', 'twf')); } if ($edit) { $PAGE->navbar->add(get_string('edit', 'twf')); } $PAGE->set_title("{$course->shortname}: {$strdiscussionname} " . format_string($toppost->subject)); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($twf->name), 2); // checkup if (!empty($parent) && !twf_user_can_see_post($twf, $discussion, $post, null, $cm)) { print_error('cannotreply', 'twf'); } if (empty($parent) && empty($edit) && !twf_user_can_post_discussion($twf, $groupid, -1, $cm, $modcontext)) { print_error('cannotcreatediscussion', 'twf'); } if ($twf->type == 'qanda' && !has_capability('mod/twf:viewqandawithoutposting', $modcontext) && !empty($discussion->id) && !twf_user_has_posted($twf->id, $discussion->id, $USER->id)) { echo $OUTPUT->notification(get_string('qandanotify', 'twf')); } // If there is a warning message and we are not editing a post we need to handle the warning. if (!empty($thresholdwarning) && !$edit) { // Here we want to throw an exception if they are no longer allowed to post. twf_check_blocking_threshold($thresholdwarning); } if (!empty($parent)) { if (!($discussion = $DB->get_record('twf_discussions', array('id' => $parent->discussion)))) { print_error('notpartofdiscussion', 'twf'); } twf_print_post($parent, $discussion, $twf, $cm, $course, false, false, false);
/** * Form definition * * @return void */ function definition() { global $CFG, $OUTPUT; $mform =& $this->_form; //var_dump($this->_customdata);die; $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $coursecontext = $this->_customdata['coursecontext']; $modcontext = $this->_customdata['modcontext']; $twf = $this->_customdata['twf']; $post = $this->_customdata['post']; $subscribe = $this->_customdata['subscribe']; $edit = $this->_customdata['edit']; $thresholdwarning = $this->_customdata['thresholdwarning']; $syx_newdiscussion = $this->_customdata['syx_newdiscussion']; $syx_phase = $this->_customdata['syx_phase']; $syx_instance = $this->_customdata['syx_instance']; $syx_teamwork = $this->_customdata['syx_teamwork']; $mform->addElement('header', 'general', ''); //fill in the data depending on page params later using set_data // If there is a warning message and we are not editing a post we need to handle the warning. if (!empty($thresholdwarning) && !$edit) { // Here we want to display a warning if they can still post but have reached the warning threshold. if ($thresholdwarning->canpost) { $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional); $mform->addElement('html', $OUTPUT->notification($message)); } } $mform->addElement('text', 'subject', get_string('subject', 'twf'), 'size="48"'); $mform->setType('subject', PARAM_TEXT); $mform->addRule('subject', get_string('required'), 'required', null, 'client'); $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); if ($syx_newdiscussion) { $mform->addElement('text', 'score', get_string('score', 'twf')); $mform->setType('score', PARAM_INT); $mform->addRule('score', get_string('required'), 'required', null, 'client'); $mform->addHelpButton('score', 'score_rules', 'twf'); } $mform->addElement('editor', 'message', get_string('message', 'twf'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id)); $mform->setType('message', PARAM_RAW); $mform->addRule('message', get_string('required'), 'required', null, 'client'); $manageactivities = has_capability('moodle/course:manageactivities', $coursecontext); if (\mod_twf\subscriptions::is_forcesubscribed($twf)) { $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf')); $mform->freeze('discussionsubscribe'); $mform->setDefaults('discussionsubscribe', 0); $mform->addHelpButton('discussionsubscribe', 'forcesubscribed', 'twf'); } else { if (\mod_twf\subscriptions::subscription_disabled($twf) && !$manageactivities) { $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf')); $mform->freeze('discussionsubscribe'); $mform->setDefaults('discussionsubscribe', 0); $mform->addHelpButton('discussionsubscribe', 'disallowsubscription', 'twf'); } else { $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf')); $mform->addHelpButton('discussionsubscribe', 'discussionsubscription', 'twf'); } } if (!empty($twf->maxattachments) && $twf->maxbytes != 1 && has_capability('mod/twf:createattachment', $modcontext)) { // 1 = No attachments at all $mform->addElement('filemanager', 'attachments', get_string('attachment', 'twf'), null, self::attachment_options($twf)); $mform->addHelpButton('attachments', 'attachment', 'twf'); } if (empty($post->id) && $manageactivities) { $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'twf')); } if (!empty($CFG->twf_enabletimedposts) && !$post->parent && has_capability('mod/twf:viewhiddentimedposts', $coursecontext)) { // hack alert $mform->addElement('header', 'displayperiod', get_string('displayperiod', 'twf')); $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'twf'), array('optional' => true)); $mform->addHelpButton('timestart', 'displaystart', 'twf'); $mform->addElement('date_selector', 'timeend', get_string('displayend', 'twf'), array('optional' => true)); $mform->addHelpButton('timeend', 'displayend', 'twf'); } else { $mform->addElement('hidden', 'timestart'); $mform->setType('timestart', PARAM_INT); $mform->addElement('hidden', 'timeend'); $mform->setType('timeend', PARAM_INT); $mform->setConstants(array('timestart' => 0, 'timeend' => 0)); } if ($groupmode = groups_get_activity_groupmode($cm, $course)) { $groupdata = groups_get_activity_allowed_groups($cm); $groupinfo = array(); foreach ($groupdata as $groupid => $group) { // Check whether this user can post in this group. // We must make this check because all groups are returned for a visible grouped activity. if (twf_user_can_post_discussion($twf, $groupid, null, $cm, $modcontext)) { // Build the data for the groupinfo select. $groupinfo[$groupid] = $group->name; } else { unset($groupdata[$groupid]); } } $groupcount = count($groupinfo); // Check whether a user can post to all of their own groups. // Posts to all of my groups are copied to each group that the user is a member of. Certain conditions must be met. // 1) It only makes sense to allow this when a user is in more than one group. // Note: This check must come before we consider adding accessallgroups, because that is not a real group. $canposttoowngroups = empty($post->edit) && $groupcount > 1; // 2) Important: You can *only* post to multiple groups for a top level post. Never any reply. $canposttoowngroups = $canposttoowngroups && empty($post->parent); // 3) You also need the canposttoowngroups capability. $canposttoowngroups = $canposttoowngroups && has_capability('mod/twf:canposttomygroups', $modcontext); if ($canposttoowngroups) { // This user is in multiple groups, and can post to all of their own groups. // Note: This is not the same as accessallgroups. This option will copy a post to all groups that a // user is a member of. $mform->addElement('checkbox', 'posttomygroups', get_string('posttomygroups', 'twf')); $mform->addHelpButton('posttomygroups', 'posttomygroups', 'twf'); $mform->disabledIf('groupinfo', 'posttomygroups', 'checked'); } // Check whether this user can post to all groups. // Posts to the 'All participants' group go to all groups, not to each group in a list. // It makes sense to allow this, even if there currently aren't any groups because there may be in the future. if (twf_user_can_post_discussion($twf, -1, null, $cm, $modcontext)) { // Note: We must reverse in this manner because array_unshift renumbers the array. $groupinfo = array_reverse($groupinfo, true); $groupinfo[-1] = get_string('allparticipants'); $groupinfo = array_reverse($groupinfo, true); $groupcount++; } // Determine whether the user can select a group from the dropdown. The dropdown is available for several reasons. // 1) This is a new post (not an edit), and there are at least two groups to choose from. $canselectgroupfornew = empty($post->edit) && $groupcount > 1; // 2) This is editing of an existing post and the user is allowed to movediscussions. // We allow this because the post may have been moved from another twf where groups are not available. // We show this even if no groups are available as groups *may* have been available but now are not. $canselectgroupformove = $groupcount && !empty($post->edit) && has_capability('mod/twf:movediscussions', $modcontext); // Important: You can *only* change the group for a top level post. Never any reply. $canselectgroup = empty($post->parent) && ($canselectgroupfornew || $canselectgroupformove); if ($canselectgroup) { $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo); $mform->setDefault('groupinfo', $post->groupid); $mform->setType('groupinfo', PARAM_INT); } else { if (empty($post->groupid)) { $groupname = get_string('allparticipants'); } else { $groupname = format_string($groupdata[$post->groupid]->name); } $mform->addElement('static', 'groupinfo', get_string('group'), $groupname); } } //------------------------------------------------------------------------------- // buttons if (isset($post->edit)) { // hack alert $submit_string = get_string('savechanges'); } else { $submit_string = get_string('posttotwf', 'twf'); } $this->add_action_buttons(true, $submit_string); //var_dump($syx_teamwork);die; $mform->addElement('hidden', 'teamwork', $syx_teamwork); $mform->setType('teamwork', PARAM_INT); $mform->addElement('hidden', 'phase', $syx_phase); $mform->setType('phase', PARAM_INT); $mform->addElement('hidden', 'instace', $syx_instance); $mform->setType('instace', PARAM_INT); $mform->addElement('hidden', 'course'); $mform->setType('course', PARAM_INT); $mform->addElement('hidden', 'twf'); $mform->setType('twf', PARAM_INT); $mform->addElement('hidden', 'discussion'); $mform->setType('discussion', PARAM_INT); $mform->addElement('hidden', 'parent'); $mform->setType('parent', PARAM_INT); $mform->addElement('hidden', 'userid'); $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'groupid'); $mform->setType('groupid', PARAM_INT); $mform->addElement('hidden', 'edit'); $mform->setType('edit', PARAM_INT); $mform->addElement('hidden', 'reply'); $mform->setType('reply', PARAM_INT); }
/** * 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}"); } }