コード例 #1
0
 public function display($forum)
 {
     $params = $forum->get_link_params_array();
     if ($forum->get_group_mode()) {
         $params['group'] = mod_forumng::get_activity_group($forum->get_course_module());
     }
     return parent::get_button($forum, get_string('markallread', 'forumngfeature_markallread'), 'markread.php', true, $params);
 }
コード例 #2
0
 public function load_choices()
 {
     global $CFG;
     require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
     $options = mod_forumng::get_feeditems_options();
     $options[-1] = get_string('perforumoption', 'forumng');
     $this->choices = $options;
     return true;
 }
コード例 #3
0
 public function get_form($discussion, $all, $selected = array())
 {
     global $CFG, $PAGE;
     foreach ($selected as $postid) {
         $params['selectd' . $postid] = $postid;
     }
     $params['id'] = $discussion->get_course_module_id();
     $params['group'] = mod_forumng::get_activity_group($discussion->get_course_module());
     $params['clone'] = optional_param('clone', 0, PARAM_INT);
     $params['fromselect'] = true;
     $customdata = array('params' => $params, 'isdiscussion' => false, 'edit' => false, 'ispost' => true, 'islock' => true, 'post' => null, 'isroot' => true, 'forum' => $discussion);
     return new mod_forumng_editpost_form('lockall.php', $customdata);
 }
コード例 #4
0
 public function display($forum)
 {
     $out = mod_forumng_utils::get_renderer();
     // Work out current status
     $manualmark = !mod_forumng::mark_read_automatically();
     $current = get_string($manualmark ? 'manualmark_manual' : 'manualmark_auto', 'forumngfeature_manualmark');
     // Make a help button
     $change = get_string('manualmark_change', 'forumngfeature_manualmark');
     $helpbutton = $out->help_icon('manualmark_change', 'forumngfeature_manualmark');
     // Get the button form
     $params = $forum->get_link_params_array();
     return parent::get_button($forum, $change, 'feature/manualmark/change.php', true, $params, $helpbutton, 'forumng-manualmark', $current . ' ', 'forumng-button-to-link');
 }
コード例 #5
0
/**
 * Displays the view page (usually showing a list of discussions).
 * @param mod_forumng $forum Forum
 * @param int $groupid Group ID
 */
function print_view_page($forum, $groupid)
{
    global $PAGE;
    $out = mod_forumng_utils::get_renderer();
    $forumngid = $forum->get_id();
    $baseurl = 'list.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN);
    $sortorder = optional_param('sort', '', PARAM_ALPHA);
    if (!$sortorder) {
        $sortlink = optional_param('sortlink', '', PARAM_ALPHA);
        if ($sortlink) {
            $sortorder = $sortlink;
        } else {
            $sortorder = 'd';
        }
    }
    $page = optional_param('page', 0, PARAM_INT);
    if (!$page) {
        $page = 1;
    }
    $baseurl .= '&page=' . $page;
    $sortchar = substr($sortorder, 0, 1);
    if (strlen($sortorder) == 2) {
        $sortreverse = substr($sortorder, 1, 1) == 'r' ? true : false;
    } else {
        $sortreverse = false;
    }
    $baseurl .= '&sort=' . $sortchar;
    $baseurl .= $sortreverse ? 'r' : '';
    $sort = mod_forumng::get_sort_code($sortchar);
    $list = $forum->get_discussion_list($groupid, $forum->can_view_hidden(), $page, $sort, $sortreverse);
    $normal = $list->get_normal_discussions();
    $fg = new forumngtype_general();
    // Remove discussions from list if the forumtype thinks we can't see them or they are not deleted.
    foreach ($normal as $key => $value) {
        if (!$fg->can_view_discussion($value) || !$value->is_deleted()) {
            unset($normal[$key]);
        }
    }
    $pagecount = get_page_count(count($normal), $page);
    // Intro.
    print $out->render_intro($forum);
    print display_paging_bar($baseurl, $pagecount, $page);
    if (count($normal) > 0) {
        print $out->render_discussion_list_start($forum, $groupid, $baseurl, $sort, $sortreverse);
        foreach ($normal as $discussion) {
            if ($discussion->is_deleted()) {
                print $out->render_discussion_list_item($discussion, $groupid, $discussion == end($normal));
            }
        }
        print $out->render_discussion_list_end($forum, $groupid);
    } else {
        print '<p class="forumng-nodiscussions">' . get_string('nodeleteddiscussions', 'forumngfeature_deletedposts') . '</p>';
    }
    print display_paging_bar($baseurl, $pagecount, $page);
}
コード例 #6
0
 public function get_form($forum, $all, $selected = array())
 {
     global $CFG, $PAGE;
     foreach ($selected as $discussionid) {
         $params['selectd' . $discussionid] = $discussionid;
     }
     $params['id'] = $forum->get_course_module_id();
     $params['clone'] = optional_param('clone', 0, PARAM_INT);
     $group = mod_forumng::get_activity_group($forum->get_course_module());
     if (empty($group)) {
         $group = 0;
     }
     $params['group'] = $group;
     $params['multigroups'] = optional_param('multigroups', 0, PARAM_INT);
     $customdata = array('params' => $params, 'forum' => $forum);
     return new mod_forumng_moveall_form('movealltogroups.php', $customdata);
 }
コード例 #7
0
 /**
  * Get forum list for a user on a course.
  *
  * @param string $courseshortname Website shortname.
  * @param string $oucu Username.
  * @return array Forum details objects.
  */
 public static function get_forum_list($courseshortname, $oucu)
 {
     global $DB;
     // Validate the parameters.
     $params = self::validate_parameters(self::get_forum_list_parameters(), array('shortname' => $courseshortname, 'oucu' => $oucu));
     // Get course object from the shortname.
     $course = $DB->get_record('course', array('shortname' => $courseshortname));
     if ($course === false) {
         throw new moodle_exception(get_string('cannotfindcourse', 'error'));
     }
     $forumlist = array();
     // Get the user's id from the supplied username (oucu).
     $userid = $DB->get_field('user', 'id', array('username' => $oucu));
     if ($userid === false) {
         throw new moodle_exception(get_string('cannotfinduser', 'error', $oucu));
     }
     // Get forums for the given course and user.
     $forums = mod_forumng::get_course_forums($course, $userid, mod_forumng::UNREAD_BINARY);
     $modinfo = get_fast_modinfo($course, $userid);
     // Loop through the forum instances, they are correctly ordered by sections.
     foreach ($modinfo->get_instances_of('forumng') as $cm) {
         // Only include this forum if it is visible to the user.
         if ($cm->uservisible) {
             $forum = $forums[$cm->instance];
             if ($forum->is_clone()) {
                 $forum->init_unread_from_original(mod_forumng::UNREAD_BINARY, $userid);
             }
             $forumdetails = new stdClass();
             $forumdetails->name = $forum->get_name();
             if ($forum->has_unread_discussions()) {
                 $forumdetails->unread = 'y';
             } else {
                 $forumdetails->unread = 'n';
             }
             $forumlist[] = $forumdetails;
             unset($forumdetails);
         }
     }
     return $forumlist;
 }
コード例 #8
0
function forumngfeature_usage_show_mostreaders($params, $forum = null)
{
    global $DB, $PAGE;
    $cloneid = empty($params['clone']) ? 0 : $params['clone'];
    if ($forum == null) {
        if (empty($params['id'])) {
            throw new moodle_exception('Missing forum id param');
        }
        $forum = mod_forumng::get_from_cmid($params['id'], $cloneid);
    }
    $groupwhere = '';
    $groupparams = array();
    $groupid = 0;
    if (!empty($params['group']) && $params['group'] != mod_forumng::NO_GROUPS && $params['group'] != mod_forumng::ALL_GROUPS) {
        $groupwhere = 'AND (fd.groupid = :groupid OR fd.groupid IS NULL)';
        $groupid = $params['group'];
        $groupparams = array('groupid' => $groupid);
    }
    if (has_capability('mod/forumng:viewreadinfo', $forum->get_context())) {
        if (!$PAGE->has_set_url()) {
            // Set context when called via ajax.
            $PAGE->set_context($forum->get_context());
        }
        $renderer = $PAGE->get_renderer('forumngfeature_usage');
        // Only get enrolled users - speeds up query significantly on large forums.
        list($sql, $params) = get_enrolled_sql($forum->get_context(), '', $groupid, true);
        // View discussions read.
        $readers = $DB->get_recordset_sql("\n                SELECT COUNT(fr.userid) AS count, fr.discussionid\n                  FROM {forumng_discussions} fd\n            RIGHT JOIN (\n\t\t                SELECT discussionid, userid\n\t\t                  FROM (\n\t\t                        SELECT * FROM {forumng_read}\n\t\t                     UNION ALL\n\t\t                        SELECT frp.id, frp.userid, fp.discussionid, frp.time\n                                  FROM {forumng_posts} fp\n                            RIGHT JOIN {forumng_read_posts} frp ON fp.id = frp.postid\n                                 WHERE fp.deleted = 0 AND fp.oldversion = 0\n                        ) frp GROUP BY discussionid, userid\n                ) fr ON fr.discussionid = fd.id\n                 WHERE fd.forumngid = :courseid\n                   AND fd.deleted = 0\n                {$groupwhere}\n                   AND fr.userid IN({$sql})\n              GROUP BY fr.discussionid\n              ORDER BY count desc, fr.discussionid desc", array_merge(array('courseid' => $forum->get_id()), $groupparams, $params), 0, 5);
        $readerlist = array();
        foreach ($readers as $discuss) {
            $discussion = mod_forumng_discussion::get_from_id($discuss->discussionid, $cloneid);
            list($content, $user) = $renderer->render_usage_discussion_info($forum, $discussion);
            $readerlist[] = $renderer->render_usage_list_item($forum, $discuss->count, $user, $content);
        }
        return $renderer->render_usage_list($readerlist, 'mostreaders', false);
    }
}
コード例 #9
0
    redirect('../../view.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN));
}
$targetgroup = optional_param('group', 0, PARAM_INT);
$target = optional_param('forum', 0, PARAM_INT);
if ($target == 0) {
    $target = required_param('target', PARAM_INT);
}
$targetforum = mod_forumng::get_from_cmid($target, mod_forumng::CLONE_DIRECT);
// Sets up chosen target group.
$chosentargetgroup = optional_param('chosengroup', 0, PARAM_INT);
if (!$targetgroup) {
    $targetgroup = $chosentargetgroup;
}
if (!$targetgroup) {
    $cm = $forum->get_course_module();
    $targetgroup = mod_forumng::get_activity_group($cm, false);
}
// Security check against user and their capabilities.
$forum->require_view($targetgroup);
check_move_permissions($forum, $targetforum);
// If it is a clone, find the original.
$targetforum = $targetforum->get_real_forum();
$targetgroupmode = $targetforum->get_group_mode();
// Get selected ids.
$selectedids = array();
foreach ($_POST as $field => $value) {
    $matches = array();
    if (!is_array($value) && (string) $value !== '0' && preg_match('~^selectd([0-9]+)$~', $field, $matches)) {
        $selectedids[] = $matches[1];
    }
}
コード例 #10
0
     if ($draft->is_reply()) {
         $replytoid = $draft->get_parent_post_id();
     } else {
         $forum = mod_forumng::get_from_id($draft->get_forumng_id(), optional_param('clone', 0, PARAM_INT));
         $groupid = $draft->get_group_id();
     }
 }
 if ($forum || ($cmid = optional_param('id', 0, PARAM_INT))) {
     // For new discussions, id (forum cmid) and groupid are required (groupid
     // may be mod_forumng::ALL_GROUPS if required)
     if ($forum) {
         // Came from draft post
         $cmid = $forum->get_course_module_id();
     } else {
         $pageparams['id'] = $cmid;
         $forum = mod_forumng::get_from_cmid($cmid, $cloneid);
     }
     if ($forum->get_group_mode()) {
         if (!$draft) {
             $groupid = required_param('group', PARAM_INT);
             $pageparams['group'] = $groupid;
         }
         if ($groupid == 0) {
             $groupid = mod_forumng::ALL_GROUPS;
         }
     } else {
         $groupid = mod_forumng::NO_GROUPS;
     }
     $post = null;
     // Handles all access security checks
     $forum->require_start_discussion($groupid);
コード例 #11
0
 * @copyright 2012 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/mod/forumng/lib.php';
require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
require_once $CFG->dirroot . '/mod/forumng/feature/userposts/locallib.php';
$id = required_param('id', PARAM_INT);
// Course Module ID.
$groupid = optional_param('group', 0, PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);
$params = array();
$params['id'] = $id;
$params['group'] = $groupid;
$url = new moodle_url('/mod/forumng/feature/userposts/savegrades.php');
$forum = mod_forumng::get_from_cmid($id, mod_forumng::CLONE_DIRECT);
if (!($cm = $forum->get_course_module())) {
    print_error('invalidcoursemodule');
}
$PAGE->set_cm($cm);
$course = $forum->get_course();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_course_login($course, true, $cm);
// Grading capability check.
if (!$forum->can_grade()) {
    print_error('nopermissiontoshow');
}
$mode = '';
if (!empty($_POST['menu'])) {
    $mode = 'bulk';
    $gradeinfo = $_POST['menu'];
コード例 #12
0
 */
require_once '../../../../config.php';
require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
$d = required_param('d', PARAM_INT);
$target = required_param('target', PARAM_INT);
$pageparams = array('d' => $d, 'target' => $target);
$cloneid = optional_param('clone', 0, PARAM_INT);
if ($cloneid) {
    $pageparams['clone'] = $cloneid;
}
if (!$target) {
    print_error('move_notselected', 'forumng');
}
$discussion = mod_forumng_discussion::get_from_id($d, $cloneid);
// Get target forum
$targetforum = mod_forumng::get_from_cmid($target, mod_forumng::CLONE_DIRECT);
// If it is a clone, find the original
$targetforum = $targetforum->get_real_forum();
// Check permission for move
$discussion->require_view();
require_capability('mod/forumng:movediscussions', $discussion->get_forum()->get_context());
require_capability('mod/forumng:movediscussions', $targetforum->get_context());
$aag = has_capability('moodle/site:accessallgroups', $targetforum->get_context());
// Work out target group for move
$targetgroup = $discussion->get_group_id();
if ($targetforum->get_group_mode() == 0 || !$targetgroup && $aag && $discussion->get_forum()->get_group_mode() != 0) {
    // Either target forum doesn't have groups, or it does have groups but
    // so does the source forum and this is already an all-groups post,
    // and you have access all groups, so it can be all-groups
    $targetgroup = null;
} else {
コード例 #13
0
 /**
  * Display tag filter as a link or dropdown
  * @param array $taglist is array of tags
  * @param mod_forumng $forum
  * @param string $selectid of tag if selected
  * @return string for printing out
  */
 public function render_tag_filter($taglist, $forum, $selectid = null)
 {
     $baseurl = 'view.php?' . $forum->get_link_params(mod_forumng::PARAM_HTML);
     if (isset($selectid)) {
         $tagname = htmlspecialchars($taglist[$selectid]->displayname);
         $taglink = get_string('removefiltering', 'forumng', $tagname);
         $taglink .= '&nbsp;(';
         $taglink .= html_writer::tag('a', get_string('show_all', 'forumng'), array('href' => $baseurl));
         $taglink .= ')';
         $out = html_writer::tag('div', $taglink, array('class' => 'forumng_discuss_tagfilter'));
     } else {
         // Display dropdown.
         foreach ($taglist as $tag) {
             $options[$tag->id] = htmlspecialchars($tag->displayname) . '  (' . $tag->count . ')';
         }
         $tagurl = new moodle_url('/mod/forumng/view.php?', $forum->get_link_params_array(mod_forumng::PARAM_PLAIN));
         $select = new single_select($tagurl, 'tag', $options, '');
         $select->label = get_string('filterdiscussions', 'forumng');
         $select->set_help_icon('forumngdiscusstagfilter', 'forumng');
         $output = $this->render($select);
         $out = '<div class="forumng_discuss_tagfilter">' . $output . '</div>';
     }
     return $out;
 }
コード例 #14
0
 /**
  * Displays the discussion page.
  * @param mod_forumng_discussion $discussion Discussion
  */
 public function print_discussion_page($discussion)
 {
     global $PAGE;
     $out = mod_forumng_utils::get_renderer();
     $previousread = (int) $discussion->get_time_read();
     // 'Read date' option (used when viewing all posts so that they keep
     // their read/unread colouring)
     $timeread = optional_param('timeread', 0, PARAM_INT);
     if ($timeread) {
         $discussion->pretend_time_read($timeread);
         $previousread = $timeread;
     }
     // 'Expand all' option (always chosen for non-JS browsers)
     $expandall = optional_param('expand', 0, PARAM_INT) || $PAGE->devicetypeinuse == 'legacy';
     // 'Expand all' option (always chosen for non-JS browsers)
     $collapseall = optional_param('collapse', 0, PARAM_INT);
     if (!$collapseall && !$expandall && $PAGE->devicetypeinuse == 'mobile') {
         $collapseall = 1;
     }
     // Link back to first unread post if there is one
     print $discussion->display_unread_skip_link();
     // Magic expand tracker (for use in JS only, never set server-side).
     // This tracks expanded posts, and makes the Back button 'work' in
     // the sense that it will expand these posts again.
     print '<form method="post" action="."><div>' . '<input type="hidden" id="expanded_posts" name="expanded_posts" ' . 'value="" /></div></form>';
     // Get content for all posts in the discussion
     $options = array();
     if ($expandall) {
         $options[mod_forumng_post::OPTION_CHILDREN_EXPANDED] = true;
     }
     if ($collapseall) {
         $options[mod_forumng_post::OPTION_CHILDREN_COLLAPSED] = true;
     }
     $content = $out->render_discussion($discussion, $options);
     // Some post display options use the read time to construct links
     // (usually for non-JS version) so that unread state is maintained.
     $options[mod_forumng_post::OPTION_READ_TIME] = $previousread;
     // Display expand all option if there are any 'Expand' links in content
     $fakedate = '&amp;timeread=' . $previousread;
     print '<div id="forumng-expandall">';
     $showexpandall = preg_match('~<a [^>]*href="discuss\\.php\\?d=[0-9]+[^"]*&amp;expand=1#p[0-9]+">~', $content);
     // Note: On bad browsers we always expand all posts
     $showcollapseall = preg_match('~<div class="forumng-post forumng-full.*<div class="forumng-post forumng-full~s', $content) && $PAGE->devicetypeinuse != 'legacy';
     if ($showexpandall) {
         print '<a class="forumng-expandall-link" href="' . $discussion->get_url(mod_forumng::PARAM_HTML) . '&amp;expand=1' . $fakedate . '">' . get_string('expandall', 'forumng') . '</a>';
         if ($showcollapseall) {
             print '<span class="forumng-dot-separator"> &#x2022; </span>';
         }
     }
     if ($showcollapseall) {
         print '<a class="forumng-collapseall-link" href="' . $discussion->get_url(mod_forumng::PARAM_HTML) . '&amp;collapse=1' . $fakedate . '">' . get_string('collapseall', 'forumng') . '</a> ';
     }
     print '</div>';
     // Display content
     print $content;
     // Link back to forum
     print $discussion->display_link_back_to_forum();
     // Display discussion features (row of buttons)
     print $discussion->display_forumngfeature_discussions();
     // Display the subscription options to this disucssion if available
     print $discussion->display_subscribe_options();
     // Atom/RSS links
     print $discussion->display_feed_links();
     // Set read data [shouldn't this logic be somewhere else as it is not
     // part of display?]
     if (mod_forumng::mark_read_automatically()) {
         $discussion->mark_read();
     }
 }
コード例 #15
0
 /**
  * Prints the content of this draft as a JavaScript variable (including
  * surrounding script tag).
  * @param mod_forumng $forum Forum object
  * @return string HTML (including JS) code to place in page
  */
 public function prepare_edit_js($forum)
 {
     global $USER;
     // Copy fields
     $fields = clone $this->draftfields;
     // Prepare file areas
     $fileoptions = array('subdirs' => false, 'maxbytes' => $forum->get_max_bytes());
     $filecontext = $forum->get_context(true);
     // Prepare draft area for attachments
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $filecontext->id, 'mod_forumng', 'draft', $this->get_id(), $fileoptions);
     // Prepare draft area for message files
     $messagedraftitemid = 0;
     $fields->message = file_prepare_draft_area($messagedraftitemid, $filecontext->id, 'mod_forumng', 'draftmessage', $this->get_id(), $fileoptions, $fields->message);
     // Get list of files for main attachment area
     $options = file_get_drafarea_files($draftitemid, '/');
     $usercontext = context_user::instance($USER->id);
     $fs = get_file_storage();
     $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
     $options->filecount = count($files);
     $fields->attachmentoptions = $options;
     // Get list of files for message area
     $messageoptions = file_get_drafarea_files($messagedraftitemid, '/');
     $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $messageoptions->itemid, 'id', false);
     $messageoptions->filecount = count($files);
     $fields->messageoptions = $messageoptions;
     // Unset things we don't need in JS
     unset($fields->discussionid);
     unset($fields->discussionsubject);
     unset($fields->courseid);
     unset($fields->replytouser);
     unset($fields->options);
     unset($fields->attachments);
     // Add options
     foreach ((array) $this->get_options() as $key => $value) {
         $fields->{$key} = $value;
     }
     return "<script type='text/javascript'>\n" . "var forumng_draft = " . json_encode($fields) . ";\n</script>\n";
 }
コード例 #16
0
 * @package mod
 * @subpackage forumng
 * @copyright 2011 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once 'mod_forumng.php';
$draftid = required_param('draft', PARAM_INT);
$pageparams = array('draft' => $draftid);
$cloneid = optional_param('clone', 0, PARAM_INT);
if ($cloneid) {
    $pageparams['clone'] = $cloneid;
}
// Load draft and forum
$draft = mod_forumng_draft::get_from_id($draftid);
$forum = mod_forumng::get_from_id($draft->get_forumng_id(), $cloneid);
$course = $forum->get_course();
$cm = $forum->get_course_module();
$pagename = get_string('deletedraft', 'forumng');
$out = $forum->init_page(new moodle_url('/mod/forumng/deletedraft.php', $pageparams), $pagename);
// Check it belongs to current user
if ($USER->id != $draft->get_user_id()) {
    print_error('draft_mismatch', 'forumng');
}
// If they are actually deleting it, go ahead
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $draft->delete($forum->get_context(true));
    redirect($forum->get_url(mod_forumng::PARAM_PLAIN));
}
// Confirm page. Work out navigation for header
print $out->header();
コード例 #17
0
 protected function after_execute()
 {
     global $DB, $CFG;
     // Add forumng related files, no need to match by
     // itemname (just internally handled context)
     $this->add_related_files('mod_forumng', 'intro', null);
     // Add post related files, matching by itemname = 'forumng_post'
     $this->add_related_files('mod_forumng', 'message', 'forumng_post');
     $this->add_related_files('mod_forumng', 'attachment', 'forumng_post');
     $this->add_related_files('mod_forumng', 'draft', 'forumng_draft');
     // Now fix the lastpostid for each discussion
     // TODO Does this work on MySQL? No idea.
     $DB->execute("\nUPDATE {forumng_discussions} SET lastpostid=(\n    SELECT\n        MAX(id)\n    FROM\n        {forumng_posts} fp\n    WHERE\n        fp.discussionid = {forumng_discussions}.id\n        AND fp.oldversion=0\n        AND fp.deleted=0\n) WHERE forumngid = ?", array($this->forumngid));
     require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
     // Create search index if user data restored.
     if ($this->get_setting_value('userinfo') && mod_forumng::search_installed()) {
         mod_forumng::search_update_all(false, $this->get_courseid(), $this->task->get_moduleid());
     }
 }
コード例 #18
0
 /**
  * Either delete or archive old discussions based on the forum setting
  */
 public static function archive_old_discussions()
 {
     global $CFG, $DB;
     $now = time();
     $housekeepingquery = "\nFROM\n    {forumng_discussions} fd\n    INNER JOIN {forumng_posts} fp ON fd.lastpostid = fp.id\n    INNER JOIN {forumng} f ON fd.forumngid = f.id\nWHERE\n    f.removeafter<>0 AND fd.sticky<>1 AND fp.modified<? - f.removeafter\n";
     $housekeepingparams = array($now);
     $count = $DB->count_records_sql("SELECT COUNT(1) {$housekeepingquery}", $housekeepingparams);
     if ($count) {
         if (!PHPUNIT_TEST) {
             mtrace("\nBeginning processing {$count} discussion archiving/deleting requests");
         }
         $housekeepingrs = $DB->get_recordset_sql("\nSELECT\n    fd.id AS discussionid, f.id AS forumngid, f.removeafter, f.removeto\n{$housekeepingquery}\nORDER BY f.removeto", $housekeepingparams);
         $targetforum = null;
         $targetcourseid = null;
         $cronlog = '';
         $discussionmovecount = 0;
         $discussiondeletecount = 0;
         $discussionautolocked = 0;
         foreach ($housekeepingrs as $rec) {
             $discussion = mod_forumng_discussion::get_from_id($rec->discussionid, mod_forumng::CLONE_DIRECT);
             if ($rec->removeto) {
                 if ($rec->removeto == -1) {
                     // Locked record or discussion deleted.
                     if ($discussion->is_locked() || $discussion->is_auto_locked() || $discussion->is_deleted()) {
                         continue;
                     } else {
                         $end = $discussion->get_time_end();
                         $canautolock = true;
                         // Check to see whether time now is beyond the end time.
                         if ($end > $now) {
                             $canautolock = false;
                         }
                         if ($canautolock) {
                             // Lock record.
                             $discussion->auto_lock();
                             $discussionautolocked++;
                         } else {
                             continue;
                         }
                     }
                 } else {
                     // Moving to a different forum.
                     $forum = $discussion->get_forum();
                     $course = $forum->get_course();
                     $modinfo = get_fast_modinfo($course);
                     if ($forum->can_archive_forum($modinfo, $cronlog)) {
                         // Do not get the target forum and course id again
                         // if the target forum is the same.
                         if (!$targetforum || $targetforum->get_id() != $rec->removeto) {
                             $targetforum = mod_forumng::get_from_id($rec->removeto, mod_forumng::CLONE_DIRECT);
                             $targetforum = $targetforum->get_real_forum();
                         }
                         // Target discussion groupid must be the same as the original groupid.
                         $targetgroupmode = $targetforum->get_group_mode();
                         $targetgroupid = $targetgroupmode ? $discussion->get_group_id() : null;
                         $discussion->move($targetforum, $targetgroupid);
                         $discussionmovecount++;
                     }
                 }
             } else {
                 // Delete all discussions and relevant data permanently.
                 $discussion->permanently_delete();
                 $discussiondeletecount++;
             }
         }
         $housekeepingrs->close();
         if (!PHPUNIT_TEST) {
             mtrace("\n {$discussionmovecount} discussions have been archived and " . "{$discussiondeletecount} discussions have been deleted permanently and " . "{$discussionautolocked} discussions have been automatically locked");
         }
     }
 }
コード例 #19
0
 /**
  * Checks whether this feature should be displayed for the given user
  * in current forum.
  * By default, this checks the discussions's can_manage function and that
  * the discussion isn't deleted.
  * @param mod_forumng $forum Forum object
  * @param int $groupid Group id
  * @return bool True if this should display
  */
 public function should_display($forum)
 {
     return $forum->can_manage_discussions();
 }
コード例 #20
0
 /**
  * Internal method. Queries for a number of forums, including additional
  * data about unread posts etc. Returns the database result.
  * @param array $cmids If specified, array of course-module IDs of desired
  *   forums
  * @param object $course If specified, course object
  * @param int $userid User ID, 0 = current user
  * @param int $unread Type of unread data to obtain (UNREAD_xx constant).
  * @param array $groups Array of group IDs to which the given user belongs
  *   (may be null if unread data not required)
  * @param array $aagforums Array of forums in which the user has
  *   'access all groups' (may be null if unread data not required)
  * @param array $viewhiddenforums Array of forums in which the user has
  *   'view hidden discussions' (may be null if unread data not required)
  * @return array Array of row objects
  */
 private static function query_forums($cmids = array(), $course = null, $userid, $unread, $groups, $aagforums, $viewhiddenforums)
 {
     global $DB, $CFG, $USER;
     if (!count($cmids) && !$course) {
         throw new coding_exception("mod_forumng::query_forums requires course id or cmids");
     }
     if (count($cmids)) {
         list($in, $conditionsparams) = mod_forumng_utils::get_in_array_sql('cm.id', $cmids);
         $conditions = $in;
     } else {
         $conditions = "f.course = ?";
         $conditionsparams = array($course->id);
     }
     $singleforum = count($cmids) == 1 ? reset($cmids) : false;
     list($inviewhiddenforums, $inviewhiddenforumsparams) = mod_forumng_utils::get_in_array_sql('fd.forumngid', $viewhiddenforums);
     list($cfdinviewhiddenforums, $inviewhiddenforumsparams) = mod_forumng_utils::get_in_array_sql('cfd.forumngid', $viewhiddenforums);
     // This array of additional results is used later if combining
     // standard results with single-forum calls.
     $plusresult = array();
     // For read tracking, we get a count of total number of posts in
     // forum, and total number of read posts in the forum (this
     // is so we can display the number of UNread posts, but the query
     // works that way around because it will return 0 if no read
     // information is stored).
     if ($unread != self::UNREAD_NONE && self::enabled_read_tracking()) {
         // Work out when unread status ends
         $endtime = time() - $CFG->forumng_readafterdays * 24 * 3600;
         if (!$userid) {
             $userid = $USER->id;
         }
         list($ingroups, $ingroupsparams) = mod_forumng_utils::get_in_array_sql('fd.groupid', $groups);
         list($inaagforums, $inaagforumsparams) = mod_forumng_utils::get_in_array_sql('fd.forumngid', $aagforums);
         $restrictionsql = '';
         $restrictionparams = array();
         if ($singleforum) {
             // If it is for a single forum, get the restriction from the
             // forum type
             $forum = self::get_from_cmid($singleforum, self::CLONE_DIRECT);
             $type = $forum->get_type();
             if ($type->has_unread_restriction()) {
                 list($value, $restrictionparams) = $type->get_unread_restriction_sql($forum);
                 if ($value) {
                     $restrictionsql = 'AND ' . $value;
                 }
             }
         } else {
             // When it is not for a single forum, we can only group together
             // results for types that do not place restrictions on the
             // unread count.
             $modinfo = get_fast_modinfo($course);
             $okayids = array();
             if (array_key_exists('forumng', $modinfo->instances)) {
                 foreach ($modinfo->instances['forumng'] as $info) {
                     if (count($cmids) && !in_array($info->id, $cmids)) {
                         continue;
                     }
                     $type = self::get_type_from_modinfo_info($info);
                     if (forumngtype::get_new($type)->has_unread_restriction()) {
                         // This one's a problem! Do it individually
                         $problemresults = self::query_forums(array($info->id), null, $userid, $unread, $groups, $aagforums, $viewhiddenforums);
                         foreach ($problemresults as $problemresult) {
                             $plusresult[$problemresult->f_id] = $problemresult;
                         }
                     } else {
                         $okayids[] = $info->id;
                     }
                 }
             }
             if (count($okayids) == 0) {
                 // There are no 'normal' forums, so return result so far
                 // after sorting it
                 uasort($plusresult, 'mod_forumng::sort_mod_forumng_result');
                 return $plusresult;
             } else {
                 // Fall through to normal calculation, but change conditions
                 // to include only the 'normal' forums
                 list($in, $inparams) = mod_forumng_utils::get_in_array_sql('cm.id', $okayids);
                 $conditions .= " AND " . $in;
                 $conditionsparams = array_merge($conditionsparams, $inparams);
             }
         }
         $indreadpart = '';
         $indreadparms = array();
         $indreadwhere = '';
         // Get individual posts unread if manual read marking (on unread discussions only).
         if (!mod_forumng::mark_read_automatically($userid)) {
             $indreadpart = "INNER JOIN {forumng_posts} fp ON fp.discussionid = discussions.id\n                                 LEFT JOIN {forumng_read_posts} frp ON frp.postid = fp.id AND frp.userid = ?";
             $indreadwhere = "AND frp.id IS NULL\n                                 AND ((fp.edituserid IS NOT NULL AND fp.edituserid <> ?)\n                                       OR (fp.edituserid IS NULL AND fp.userid <> ?))\n                                 AND fp.deleted = ?\n                                 AND fp.oldversion = ?\n                                 AND fp.modified > ?\n                                 AND (discussions.time IS NULL OR fp.modified > discussions.time)";
             $indreadparms = array($userid, $userid, $userid, 0, 0, $endtime);
         }
         // NOTE fpfirst is used only by forum types, not here
         $now = time();
         $sharedquerypart = "\n        FROM\n     (SELECT fd.id, fr.time, fd.forumngid\n        FROM {forumng_discussions} fd\n  INNER JOIN {forumng_posts} fplast ON fd.lastpostid = fplast.id\n  INNER JOIN {forumng_posts} fpfirst ON fd.postid = fpfirst.id\n   LEFT JOIN {forumng_read} fr ON fd.id = fr.discussionid AND fr.userid = ?\n  INNER JOIN {course_modules} cm2 ON cm2.instance = fd.forumngid\n             AND cm2.module = (SELECT id FROM {modules} WHERE name = 'forumng')\n       WHERE fplast.modified > ?\n         AND (\n             (fd.groupid IS NULL)\n             OR ({$ingroups})\n             OR cm2.groupmode = " . VISIBLEGROUPS . "\n             OR ({$inaagforums})\n         )\n         AND fd.deleted = 0\n         AND (\n             ((fd.timestart = 0 OR fd.timestart <= ?)\n             AND (fd.timeend = 0 OR fd.timeend > ? OR ({$inviewhiddenforums})))\n         )\n         AND ((fplast.edituserid IS NOT NULL AND fplast.edituserid <> ?)\n          OR fplast.userid <> ?)\n         AND (fr.time IS NULL OR fplast.modified > fr.time)\n    {$restrictionsql}\n    ) discussions\n    {$indreadpart}\n       WHERE discussions.forumngid = f.id\n    {$indreadwhere}";
         $sharedqueryparams = array_merge(array($userid, $endtime), $ingroupsparams, $inaagforumsparams, array($now, $now), $inviewhiddenforumsparams, array($userid, $userid), $restrictionparams, $indreadparms);
         // Note: There is an unusual case in which this number can
         // be inaccurate. It is to do with ignoring messages the user
         // posted. We consider a discussion as 'not unread' if the last
         // message is by current user. In actual fact, a discussion could
         // contain unread messages if messages were posted by other users
         // after this user viewed the forum last, but before they posted
         // their reply. Since this should be an infrequent occurrence I
         // believe this behaviour is acceptable.
         if ($unread == self::UNREAD_BINARY) {
             // Query to get 0/1 unread discussions count
             $readtracking = self::select_exists("SELECT 1 {$sharedquerypart}") . "AS f_hasunreaddiscussions";
             $readtrackingparams = $sharedqueryparams;
         } else {
             // Query to get full unread discussions count
             $readtracking = "\n(SELECT\n    COUNT(DISTINCT discussions.id)\n{$sharedquerypart}\n) AS f_numunreaddiscussions";
             $readtrackingparams = $sharedqueryparams;
         }
     } else {
         $readtracking = "NULL AS numreadposts, NULL AS timeread";
         $readtrackingparams = array();
     }
     $now = time();
     $orderby = "LOWER(f.name)";
     // Main query. This retrieves:
     // - Full forum fields
     // - Basic course-module and course data (not whole tables)
     // - Discussion count
     // - Unread data, if enabled
     // - User subscription data
     $result = $DB->get_records_sql($sql = "\nSELECT\n    " . mod_forumng_utils::select_mod_forumng_fields('f') . ",\n    " . mod_forumng_utils::select_course_module_fields('cm') . ",\n    " . mod_forumng_utils::select_course_fields('c') . ",\n    (SELECT COUNT(1)\n        FROM {forumng_discussions} cfd\n        WHERE cfd.forumngid = f.id AND cfd.deleted = 0\n        AND (\n            ((cfd.timestart = 0 OR cfd.timestart <= ?)\n            AND (cfd.timeend = 0 OR cfd.timeend > ?))\n            OR ({$cfdinviewhiddenforums})\n        )\n        ) AS f_numdiscussions,\n    {$readtracking}\nFROM\n    {forumng} f\n    INNER JOIN {course_modules} cm ON cm.instance = f.id\n        AND cm.module = (SELECT id from {modules} WHERE name = 'forumng')\n    INNER JOIN {course} c ON c.id = f.course\nWHERE\n    {$conditions}\nORDER BY\n    {$orderby}", array_merge(array($now, $now), $inviewhiddenforumsparams, $readtrackingparams, $conditionsparams));
     if (count($plusresult) > 0) {
         foreach ($plusresult as $key => $value) {
             $result[$key] = $value;
         }
         uasort($result, 'mod_forumng::sort_mod_forumng_result');
     }
     return $result;
 }
コード例 #21
0
function mod_forumng_cm_info_view(cm_info $cm)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
    static $forums = null;
    if ($forums === null) {
        // Read tracking is for real users only
        if (mod_forumng::enabled_read_tracking() && !isguestuser() && isloggedin()) {
            $forums = mod_forumng::get_course_forums($cm->get_course(), 0, mod_forumng::UNREAD_BINARY);
        } else {
            $forums = array();
        }
    }
    // If current forum is listed, check whether it's unread or not
    if (array_key_exists($cm->instance, $forums)) {
        if ($forums[$cm->instance]->has_unread_discussions()) {
            $cm->set_after_link('<span class="unread">' . get_string('hasunreadposts', 'forumng') . '</span>');
        }
    }
}
コード例 #22
0
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This script is for use only temporarily to respond to a glitch in the
 * forum -> ForumNG conversion script where it didn't build search indexes.
 * This file lets the search index be manually rebuilt. We should probably
 * delete it later.
 * @package mod
 * @subpackage forumng
 * @copyright 2011 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
$cmid = required_param('id', PARAM_INT);
$cloneid = optional_param('clone', 0, PARAM_INT);
$forum = mod_forumng::get_from_cmid($cmid, $cloneid);
$cm = $forum->get_course_module();
require_login($cm->course, false, $cm);
require_capability('moodle/restore:restoreactivity', $cm->context);
mod_forumng::search_installed();
$PAGE->set_url('/mod/forumng/rebuildsearchindex.php', array('id' => $cmid, 'clone' => $cloneid));
// This script is not very user friendly. Once it finishes, it's done...
echo $OUTPUT->header();
mod_forumng::search_update_all(true, $cm->course, $cm->id);
echo $OUTPUT->footer();
コード例 #23
0
 /**
  * @return bool True if read tracking is enabled for this discussion
  *   (it is not too old, and read tracking is turned on globally)
  */
 public function is_read_tracked()
 {
     $this->check_full();
     return mod_forumng::enabled_read_tracking() && $this->discussionfields->timemodified >= mod_forumng::get_read_tracking_deadline();
 }
コード例 #24
0
 /**
  * Tests deleting discussion and permanent delete
  * Checks completion
  */
 public function test_delete()
 {
     global $DB, $USER, $SITE, $CFG;
     require_once $CFG->dirroot . '/mod/forumng/mod_forumng_cron.php';
     $CFG->enablecompletion = true;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $course = $this->get_new_course();
     $course->enablecompletion = 1;
     update_course($course);
     $forum = $this->get_new_forumng($course->id, array('removeafter' => 1, 'removeto' => 0, 'completion' => 2, 'completiondiscussions' => 1));
     $completion = new completion_info($forum->get_course());
     $discussion = $this->get_new_discussion($forum, array('userid' => $USER->id));
     $root1 = $discussion->get_root_post();
     // Get completion status.
     $complete = $completion->get_data($forum->get_course_module());
     $this->assertEquals(COMPLETION_COMPLETE, $complete->completionstate);
     $discussion2 = $this->get_new_discussion($forum, array('userid' => $USER->id));
     // Make post old.
     $root2 = $discussion2->get_root_post();
     $dataobject = new stdClass();
     $dataobject->id = $root2->get_id();
     $dataobject->modified = $root2->get_modified() - 100;
     $DB->update_record('forumng_posts', $dataobject);
     // Check perm delete by manual call.
     $discussion->permanently_delete(false);
     $this->assertFalse($DB->get_record('forumng_discussions', array('id' => $discussion->get_id())));
     $this->assertFalse($DB->get_record('forumng_posts', array('id' => $root1->get_id())));
     // Check cron cleanup (Does permanently_delete() on discussion2).
     mod_forumng_cron::archive_old_discussions();
     $this->assertFalse($DB->get_record('forumng_discussions', array('id' => $discussion2->get_id())));
     $this->assertFalse($DB->get_record('forumng_posts', array('id' => $root2->get_id())));
     $complete = $completion->get_data($forum->get_course_module());
     $this->assertEquals(COMPLETION_INCOMPLETE, $complete->completionstate);
     if (mod_forumng::search_installed()) {
         $searchdoc = $root2->search_get_document();
         $this->assertFalse($searchdoc->find());
         $query = new local_ousearch_search('Message for discussion');
         $query->set_coursemodule($forum->get_course_module(true));
         $results = $query->query();
         $this->assertEmpty($results->results);
     }
 }
コード例 #25
0
ファイル: lib.php プロジェクト: unikent/moodle-mod_forumng
/**
 * Update activity grades.
 *
 * @param stdClass $forumng database record
 * @param int $userid specific user only, 0 means all
 * @param bool $nullifnone - not used
 */
function forumng_update_grades($forumng, $userid = 0, $nullifnone = true)
{
    require_once dirname(__FILE__) . '/mod_forumng.php';
    $cm = get_coursemodule_from_instance('forumng', $forumng->id);
    $forum = mod_forumng::get_from_id($forumng->id, mod_forumng::CLONE_DIRECT, true, $cm);
    $forum->update_grades($userid, null);
}
コード例 #26
0
// RSS feeds
if (empty($CFG->enablerssfeeds)) {
    $options = array(0 => get_string('rssglobaldisabled', 'admin'));
    $str = get_string('configenablerssfeeds', 'forumng') . '<br />' . get_string('configenablerssfeedsdisabled2', 'admin');
} else {
    $options = array(0 => get_string('no'), 1 => get_string('yes'));
    $str = get_string('configenablerssfeeds', 'forumng');
}
$settings->add(new admin_setting_configselect('forumng_enablerssfeeds', get_string('enablerssfeeds', 'admin'), $str, 0, $options));
$options = mod_forumng::get_subscription_options();
$options[-1] = get_string('perforumoption', 'forumng');
$settings->add(new admin_setting_configselect('forumng_subscription', get_string('subscription', 'forumng'), get_string('configsubscription', 'forumng'), -1, $options));
$options = mod_forumng::get_feedtype_options();
$options[-1] = get_string('perforumoption', 'forumng');
$settings->add(new admin_setting_configselect('forumng_feedtype', get_string('feedtype', 'forumng'), get_string('configfeedtype', 'forumng'), -1, $options));
$options = mod_forumng::get_feeditems_options();
$options[-1] = get_string('perforumoption', 'forumng');
$settings->add(new admin_setting_configselect('forumng_feeditems', get_string('feeditems', 'forumng'), get_string('configfeeditems', 'forumng'), -1, $options));
$options = array(0 => get_string('permanentdeletion_never', 'forumng'), 1 => get_string('permanentdeletion_soon', 'forumng'), 1 * 60 * 60 * 24 => '1 ' . get_string('day'), 14 * 60 * 60 * 24 => '14 ' . get_string('days'), 30 * 60 * 60 * 24 => '30 ' . get_string('days'), 365 * 60 * 60 * 24 => '1 ' . get_string('year'));
$settings->add(new admin_setting_configselect('forumng_permanentdeletion', get_string('permanentdeletion', 'forumng'), get_string('configpermanentdeletion', 'forumng'), 30 * 60 * 60 * 24, $options));
//Start hour of deleting or archiving old discussions
$options = array();
for ($i = 0; $i < 24; $i++) {
    $options[$i * 3600] = $i;
}
$settings->add(new admin_setting_configselect('forumng_housekeepingstarthour', get_string('housekeepingstarthour', 'forumng'), get_string('confighousekeepingstarthour', 'forumng'), 0, $options));
$settings->add(new admin_setting_configselect('forumng_housekeepingstophour', get_string('housekeepingstophour', 'forumng'), get_string('confighousekeepingstophour', 'forumng'), 5 * 3600, $options));
// Option about read tracking
$settings->add(new admin_setting_configcheckbox('forumng_showusername', get_string('showusername', 'forumng'), get_string('configshowusername', 'forumng'), 0));
$settings->add(new admin_setting_configcheckbox('forumng_showidnumber', get_string('showidnumber', 'forumng'), get_string('configshowidnumber', 'forumng'), 0));
$settings->add(new admin_setting_configtext('forumng_reportunacceptable', get_string('reportunacceptable', 'forumng'), get_string('configreportunacceptable', 'forumng'), '', PARAM_NOTAGS));
コード例 #27
0
 */
require_once '../../config.php';
require_once 'mod_forumng.php';
$cmid = required_param('id', PARAM_INT);
$querytext = required_param('query', PARAM_RAW);
$pageparams = array('id' => $cmid, 'query' => $querytext);
$cloneid = optional_param('clone', 0, PARAM_INT);
if ($cloneid) {
    $pageparams['clone'] = $cloneid;
}
$forum = mod_forumng::get_from_cmid($cmid, $cloneid);
$cm = $forum->get_course_module();
$course = $forum->get_course();
$groupid = mod_forumng::get_activity_group($cm, true);
$forum->require_view($groupid, 0, true);
mod_forumng::search_installed();
// Search form for header
$buttontext = $forum->display_search_form($querytext);
// Display header
$PAGE->set_url(new moodle_url('/mod/forumng/search.php', $pageparams));
$PAGE->set_context($forum->get_context());
$PAGE->set_heading($course->fullname);
$PAGE->set_title($course->shortname . ': ' . format_string($forum->get_name()));
$PAGE->set_button($buttontext);
$PAGE->set_cm($cm, $course);
$PAGE->set_pagelayout('base');
$PAGE->navbar->add(get_string('searchfor', 'local_ousearch', $querytext));
$out = mod_forumng_utils::get_renderer();
print $out->header();
// Display group selector if required
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forumng/search.php?' . $forum->get_link_params(mod_forumng::PARAM_HTML) . '&amp;query=' . rawurlencode($querytext));
コード例 #28
0
$customdata = array('options' => array(), 'id' => $cmid, 'groups' => $groups, 'tags' => $managedtags, 'fid' => $fid, 'params' => $urlparams);
// Set up page.
$pagename = get_string('editsettags', 'forumngfeature_edittags');
$url = new moodle_url('/mod/forumng/feature/edittags/managetags.php', $urlparams);
$out = $forum->init_page($url, $pagename);
$mform = new mod_forumng_managetags_form($url, $customdata);
if ($mform->is_cancelled()) {
    // Form is cancelled, redirect back to the discussion.
    redirect('../../view.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN));
} else {
    if ($fromform = $mform->get_data()) {
        foreach ($groups as $group) {
            $settagsindex = 'settags_' . $group->id;
            if (isset($fromform->{$settagsindex})) {
                if ($group->id) {
                    mod_forumng::set_group_tags($forum->get_id(), $group->id, $fromform->{$settagsindex});
                } else {
                    tag_set('forumng', $fid, $fromform->{$settagsindex}, 'mod_forumng', $context->id);
                }
            }
        }
        redirect('../../view.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN));
    } else {
        $navigation = array();
        print $out->header();
        $mform->display();
        // Log request.
        $params = array('context' => $forum->get_context(), 'objectid' => $forum->get_id(), 'other' => array('url' => 'managetags.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN), 'groupid' => $groupid));
        $event = \forumngfeature_edittags\event\tags_edited::create($params);
        $event->add_record_snapshot('course_modules', $forum->get_course_module());
        $event->add_record_snapshot('course', $forum->get_course());
コード例 #29
0
 */
require_once '../../../../config.php';
require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
require_once $CFG->dirroot . '/mod/forumng/feature/usage/locallib.php';
$cmid = required_param('id', PARAM_INT);
$cloneid = optional_param('clone', 0, PARAM_INT);
$ratings = optional_param('ratings', 0, PARAM_INT);
$pageparams = array('id' => $cmid);
if ($cloneid) {
    $pageparams['clone'] = $cloneid;
}
$forum = mod_forumng::get_from_cmid($cmid, $cloneid);
$course = $forum->get_course();
$cm = $forum->get_course_module();
$context = $forum->get_context();
$groupid = mod_forumng::get_activity_group($cm, true);
if ($groupid != mod_forumng::NO_GROUPS && $groupid != mod_forumng::ALL_GROUPS) {
    $pageparams['group'] = $groupid;
    $groupwhere = 'AND (fd.groupid = ? OR fd.groupid IS NULL)';
    $groupparams = array($groupid);
} else {
    $groupwhere = '';
    $groupparams = array();
}
$ajaxparams = $pageparams;
// Check access.
$forum->require_view($groupid);
require_capability('forumngfeature/usage:view', $forum->get_context());
// Print page header.
$thisurl = new moodle_url('/mod/forumng/feature/usage/usage.php', $pageparams);
$mainrenderer = $forum->init_page($thisurl, get_string('title', 'forumngfeature_usage'));
コード例 #30
0
/**
 * Get search results.
 * @param object $course
 * @param string $author
 * @param int $daterangefrom
 * @param int $daterangeto
 * @param int $page
 * @param int $resultsperpage (FORUMNG_SEARCH_RESULTSPERPAGE used as constant)
 * @return object
 */
function forumng_get_results_for_all_forums($course, $author = null, $daterangefrom = 0, $daterangeto = 0, $page, $asmoderator = false, $resultsperpage = FORUMNG_SEARCH_RESULTSPERPAGE)
{
    $before = microtime(true);
    global $CFG, $DB, $USER;
    require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
    // Get all forums
    $modinfo = get_fast_modinfo($course);
    $visibleforums = array();
    $accessallgroups = array();
    foreach ($modinfo->cms as $cmid => $cm) {
        if ($cm->modname === 'forumng' && $cm->uservisible) {
            $visibleforums[$cm->instance] = $cm->groupmode;
            // Check access all groups for this forum, if they have it, add to list
            $forum = mod_forumng::get_from_id($cm->instance, mod_forumng::CLONE_DIRECT);
            if ($forum->get_group_mode() == SEPARATEGROUPS) {
                if (has_capability('moodle/site:accessallgroups', $forum->get_context())) {
                    $accessallgroups[] = $cm->instance;
                }
            }
        }
    }
    $forumngids = array_keys($visibleforums);
    $separategroupsforumngids = array_keys($visibleforums, SEPARATEGROUPS);
    $params = array();
    list($inforumngids, $moreparams) = mod_forumng_utils::get_in_array_sql('d.forumngid', $forumngids);
    $where = "WHERE {$inforumngids}";
    $params = array_merge($params, $moreparams);
    list($inseparategroups, $moreparams) = mod_forumng_utils::get_in_array_sql('d.forumngid', $separategroupsforumngids);
    $where .= " AND ((NOT ({$inseparategroups}))";
    $params = array_merge($params, $moreparams);
    list($inaccessallgroups, $moreparams) = mod_forumng_utils::get_in_array_sql('d.forumngid', $accessallgroups);
    $where .= " OR {$inaccessallgroups}";
    $params = array_merge($params, $moreparams);
    $where .= " OR gm.id IS NOT NULL";
    $where .= " OR d.groupid IS NULL)";
    // Note: Even if you have capability to view the deleted or timed posts,
    // we don't show them for consistency with the full-text search.
    $currenttime = time();
    $where .= " AND (? >= d.timestart OR d.timestart = 0)";
    $params[] = $currenttime;
    $where .= " AND (? < d.timeend OR d.timeend = 0)";
    $params[] = $currenttime;
    // Exclude older post versions.
    $where .= " AND p.oldversion = 0 ";
    $where .= " AND d.deleted = 0 AND p.deleted = 0 ";
    if (!empty($author)) {
        $coursecontext = context_course::instance($course->id);
        $seeanon = has_capability('mod/forumng:postanon', $coursecontext);
        if ($asmoderator) {
            if ($seeanon) {
                $where .= " AND p.asmoderator > ? ";
                $params[] = mod_forumng::ASMODERATOR_NO;
            } else {
                $where .= " AND p.asmoderator = ? ";
                $params[] = mod_forumng::ASMODERATOR_IDENTIFY;
            }
        } else {
            if (!$seeanon) {
                $where .= " AND p.asmoderator != ? ";
                $params[] = mod_forumng::ASMODERATOR_ANON;
            }
        }
    }
    if ($author) {
        list($morewhere, $moreparams) = forumng_get_author_sql($author);
        $where .= $morewhere;
        $params = array_merge($params, $moreparams);
    }
    if ($daterangefrom && !is_array($daterangefrom)) {
        $where .= " AND p.modified>=?";
        $params[] = $daterangefrom;
    }
    if ($daterangeto && !is_array($daterangeto)) {
        $where .= " AND p.modified<=?";
        $params[] = $daterangeto;
    }
    $sql = "SELECT p.modified, p.id, p.discussionid, gm.id AS useringroup,\n            p.userid, p.parentpostid, p.subject AS title, p.message AS summary, u.username,\n            u.firstname, u.lastname, d.forumngid, d.groupid, p2.subject AS discussionsubject\n            FROM {forumng_posts} p\n            INNER JOIN {forumng_discussions} d ON d.id = p.discussionid\n            INNER JOIN {forumng_posts} p2 ON p2.id = d.postid\n            INNER JOIN {user} u ON p.userid = u.id\n            LEFT JOIN {groups_members} gm ON gm.groupid = d.groupid AND gm.userid = {$USER->id}\n            {$where}\n            ORDER BY p.modified DESC, p.id ASC";
    $results = new stdClass();
    $results->success = 1;
    $results->numberofentries = 0;
    $results->done = 0;
    $posts = $DB->get_records_sql($sql, $params, $page, $resultsperpage);
    foreach ($posts as $post) {
        if (!$post->title) {
            // Ideally we would get the parent post that has a subject, but
            // this could involve a while loop that might make numeroous
            // queries, so instead, let's just use the discussion subject
            $post->title = get_string('re', 'forumng', $post->discussionsubject);
        }
        $post->title = s(strip_tags($post->title));
        $post->summary = s(strip_tags(shorten_text($post->summary, 250)));
        $post->url = $CFG->wwwroot . "/mod/forumng/discuss.php?d={$post->discussionid}" . $forum->get_clone_param(mod_forumng::PARAM_PLAIN) . "#p{$post->id}";
    }
    $results->results = $posts;
    $results->searchtime = microtime(true) - $before;
    $results->numberofentries = count($results->results);
    if (count($results->results) < $resultsperpage) {
        $results->done = 1;
    } else {
        if (!($extrapost = $DB->get_records_sql($sql, $params, $page + $resultsperpage, 1))) {
            $results->done = 1;
        }
    }
    return $results;
}