$userid = optional_param('user', 0, PARAM_INT);
$params = array();
$params['id'] = $id;
$params['group'] = $groupid;
$url = new moodle_url('/mod/oublog/savegrades.php');
if ($id) {
    $cm = get_coursemodule_from_id('oublog', $id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $oublog = $DB->get_record('oublog', array('id' => $cm->instance), '*', MUST_EXIST);
    $PAGE->set_cm($cm);
}
$context = context_module::instance($cm->id);
require_course_login($course, true, $cm);
require_sesskey();
// participation capability check
$canview = oublog_can_view_participation($course, $oublog, $cm, $groupid);
if ($canview != OUBLOG_USER_PARTICIPATION) {
    print_error('nopermissiontoshow');
}
// grading capability check
if (!oublog_can_grade($course, $oublog, $cm, $groupid)) {
    print_error('nopermissiontoshow');
}
$mode = '';
if (!empty($_POST['menu'])) {
    $gradeinfo = $_POST['menu'];
    $oldgrades = oublog_get_participation($oublog, $context, $groupid, $cm, $course);
} else {
    if ($userid && !empty($_POST['grade'])) {
        $gradeinfo[$userid] = $_POST['grade'];
        $user = oublog_get_user_participation($oublog, $context, $userid, $groupid, $cm, $course);
/**
 * Generates oublog single user participation statistics output.
 * @param object $oublog
 * @param object $cm
 * @param mod_oublog_renderer $renderer
 * @param bool $ajax true to return data object rather than html
 */
function oublog_stats_output_myparticipation($oublog, $cm, $renderer = null, $course, $currentindividual, $globalindividual = null)
{
    global $PAGE, $DB, $USER, $OUTPUT;
    if (!isloggedin()) {
        // My participation is only visible to actual users.
        return;
    }
    if (!$renderer) {
        $renderer = $PAGE->get_renderer('mod_oublog');
    }
    // Setup My Participation capability check.
    $curgroup = oublog_get_activity_group($cm);
    $canview = oublog_can_view_participation($course, $oublog, $cm, $curgroup);
    if ($oublog->global) {
        $currentindividual = $globalindividual;
    }
    // Dont show the 'block' if user cant participate.
    if ($oublog->global && $currentindividual != $USER->id || $oublog->individual > OUBLOG_NO_INDIVIDUAL_BLOGS && $currentindividual != $USER->id) {
        return;
    }
    if (!$oublog->global && $canview == OUBLOG_NO_PARTICIPATION) {
        return;
    }
    $context = context_module::instance($cm->id);
    // Get the participation object containing User, Posts and Comments.
    $participation = oublog_get_user_participation($oublog, $context, $USER->id, $curgroup, $cm, $course, null, null, true, true, null, 8);
    // Generate content data to send to renderer.
    $maintitle = get_string('myparticipation', 'oublog');
    // The title of the block 'section'.
    $content = '';
    $postedcount = $commentedcount = $commenttotal = 0;
    $postshow = 8;
    $postscount = $participation->numposts;
    if ($participation->numcomments <= 4) {
        $commenttotal = $participation->numcomments;
    } else {
        $commenttotal = 4;
    }
    if (!$participation->posts) {
        $content .= html_writer::tag('p', get_string('nouserposts', 'oublog'));
    } else {
        $percent = $stat = null;
        $content .= html_writer::tag('h3', get_string('numberposts', 'oublog', $participation->numposts));
        foreach ($participation->posts as $post) {
            if ($postedcount >= $postshow - $commenttotal) {
                break;
            }
            $url = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
            $postname = !empty($post->title) ? $post->title : get_string('untitledpost', 'oublog');
            $label = html_writer::div(html_writer::link($url, $postname), 'oublogstats_posts_posttitle');
            $label .= html_writer::div(oublog_date($post->timeposted), 'oublogstats_commentposts_blogname');
            $statinfo = new oublog_statsinfo($participation->user, $percent, $stat, $url, $label);
            $content .= $renderer->render($statinfo);
            $postedcount++;
        }
    }
    // Pre test the numbers of posts/comments for display upto max.
    $postspluscount = $participation->numposts - $postedcount;
    if ($postspluscount >= 1) {
        $content .= html_writer::tag('p', get_string('numberpostsmore', 'oublog', $postspluscount));
    }
    if (!$participation->comments) {
        $content .= html_writer::tag('p', get_string('nousercomments', 'oublog'));
    } else {
        $percent = $stat = null;
        // Removing all stats div.
        $content .= html_writer::tag('h3', get_string('numbercomments', 'oublog', $participation->numcomments));
        foreach ($participation->comments as $comment) {
            if ($commentedcount + $postedcount >= $postshow) {
                break;
            }
            $url = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid));
            $lnkurl = $url->out() . '#cid' . $comment->id;
            $commentname = !empty($comment->title) ? $comment->title : get_string('untitledcomment', 'oublog');
            $label = html_writer::div(html_writer::link($lnkurl, $commentname), 'oublogstats_commentposts_posttitle');
            $label .= html_writer::div(oublog_date($comment->timeposted), 'oublogstats_commentposts_blogname');
            $statinfo = new oublog_statsinfo($participation->user, $percent, $stat, $url, $label);
            $content .= $renderer->render($statinfo);
            $commentedcount++;
        }
    }
    // If the number of comments is more than can be shown.
    $commentspluscount = $participation->numcomments - $commentedcount;
    if ($commentspluscount >= 1) {
        $content .= html_writer::tag('p', get_string('numbercommentsmore', 'oublog', $commentspluscount));
    }
    $params = array('id' => $cm->id, 'group' => $curgroup, 'user' => $participation->user->id);
    $url = new moodle_url('/mod/oublog/userparticipation.php', $params);
    $viewmyparticipation = html_writer::link($url, get_string('viewmyparticipation', 'oublog'));
    $content .= html_writer::start_tag('div', array('class' => 'oublog-post-content'));
    $content .= html_writer::tag('h3', $viewmyparticipation, array('class' => 'oublog-post-title'));
    $content .= html_writer::end_tag('div');
    return $renderer->render_stats_view('myparticipation', $maintitle, $content, null, null, null, false);
}
 public function test_userparticipation_access()
 {
     global $SITE, $USER;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     // Whole course.
     $course = $this->get_new_course();
     $grp1 = $this->get_new_group($course->id);
     $oublog = $this->get_new_oublog($course->id);
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     // Separate groups.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => SEPARATEGROUPS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm, $grp1->id));
     // Visible groups.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => VISIBLEGROUPS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm, $grp1->id));
     // Separate groups, separate individuals.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => SEPARATEGROUPS, 'individual' => OUBLOG_SEPARATE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm, $grp1->id));
     // Separate groups, visible individuals.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => SEPARATEGROUPS, 'individual' => OUBLOG_VISIBLE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm, $grp1->id));
     // Visble groups, visible individuals.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => VISIBLEGROUPS, 'individual' => OUBLOG_VISIBLE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm, $grp1->id));
     // Visble individuals.
     $oublog = $this->get_new_oublog($course->id, array('individual' => OUBLOG_VISIBLE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     // Separate individuals.
     $oublog = $this->get_new_oublog($course->id, array('individual' => OUBLOG_SEPARATE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_USER_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
     // Global blog (oublog_can_view_participation() always returns OUBLOG_NO_PARTICIPATION).
     $oublog = $this->get_new_oublog($SITE->id, array('global' => 1));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $this->assertEquals(OUBLOG_NO_PARTICIPATION, oublog_can_view_participation($course, $oublog, $cm));
 }
Beispiel #4
0
    $showpostbutton = $canpost;
} else {
    $showpostbutton = $canpost && ($currentgroup || !$groupmode);
}
if ($showpostbutton) {
    echo '<div id="addpostbutton">';
    echo $OUTPUT->single_button(new moodle_url('/mod/oublog/editpost.php', array('blog' => $cm->instance)), $straddpost, 'get');
    echo '</div>';
    if ($oublog->allowimport && ($oublog->global || $oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS)) {
        echo '<div class="oublog_importpostbutton">';
        echo $OUTPUT->single_button(new moodle_url('/mod/oublog/import.php', array('id' => $cm->id)), get_string('import', 'oublog'), 'get');
        echo '</div>';
    }
}
// View participation button.
$canview = oublog_can_view_participation($course, $oublog, $cm, $currentgroup);
if ($canview) {
    if ($canview == OUBLOG_USER_PARTICIPATION) {
        $strparticipation = get_string('participationbyuser', 'oublog');
        $participationurl = new moodle_url('participation.php', array('id' => $cm->id, 'group' => $currentgroup));
        echo '<div class="participationbutton">';
        echo $OUTPUT->single_button($participationurl, $strparticipation, 'get');
        echo '</div>';
    }
}
echo '</div>';
// Print blog posts.
if ($posts) {
    echo '<div id="oublog-posts">';
    $rowcounter = 1;
    foreach ($posts as $post) {