/** * Prints detailed summary information about what a user has done, * for user activity reports. * * @param stdClass $course * @param stdClass $user * @param stdClass $mod * @param stdClass $wiki */ function ouwiki_user_complete($course, $user, $mod, $wiki) { global $DB, $CFG, $OUTPUT, $USER, $PAGE; require_once "{$CFG->libdir}/gradelib.php"; require_once "{$CFG->dirroot}/mod/ouwiki/locallib.php"; $grades = grade_get_grades($course->id, 'mod', 'ouwiki', $wiki->id, $user->id); if (!empty($grades->items[0]->grades)) { $grade = reset($grades->items[0]->grades); if ($grade != '-') { echo $OUTPUT->container(get_string('grade') . ': ' . $grade->str_long_grade); if ($grade->str_feedback) { echo $OUTPUT->container(get_string('feedback') . ': ' . $grade->str_feedback); } } } $usergroups = array(); if ($wiki->subwikis == 1) { $wikigroups = groups_get_activity_allowed_groups($mod); foreach ($wikigroups as $mygroup) { if (groups_is_member($mygroup->id, $user->id)) { $usergroups[] = $mygroup; } } } $context = context_module::instance($mod->id); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); $ouwikioutput = $PAGE->get_renderer('mod_ouwiki'); echo '<div class="ouwiki_user_complete_report">'; if (empty($usergroups)) { $subwiki = ouwiki_get_subwiki($course, $wiki, $mod, $context, 0, $user->id, true); $canview = ouwiki_can_view_participation($course, $wiki, $subwiki, $mod, $USER->id); list($newuser, $changes) = ouwiki_get_user_participation($user->id, $subwiki); echo $ouwikioutput->ouwiki_render_user_participation($user, $changes, $mod, $course, $wiki, $subwiki, '', 0, '', $canview, $context, $fullname, false, ''); } else { foreach ($usergroups as $group) { $subwiki = ouwiki_get_subwiki($course, $wiki, $mod, $context, $group->id, $user->id, true); $canview = ouwiki_can_view_participation($course, $wiki, $subwiki, $mod, $USER->id); list($newuser, $changes) = ouwiki_get_user_participation($user->id, $subwiki); echo $OUTPUT->heading(get_string('group') . ': ' . $group->name, 5); echo $ouwikioutput->ouwiki_render_user_participation($user, $changes, $mod, $course, $wiki, $subwiki, '', $group->id, '', $canview, $context, $fullname, false, $group->name); } } echo '</div>'; }
$url = new moodle_url('/mod/ouwiki/participation.php', $params); $PAGE->set_url($url); if (!($cm = get_coursemodule_from_id('ouwiki', $id))) { print_error('invalidcoursemodule'); } // Checking course instance $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); if (!($ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance)))) { print_error('invalidcoursemodule'); } $PAGE->set_cm($cm); $context = context_module::instance($cm->id); $PAGE->set_pagelayout('incourse'); require_course_login($course, true, $cm); // participation capability check $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); if ($canview != OUWIKI_USER_PARTICIPATION) { print_error('nopermissiontoshow'); } $viewfullnames = has_capability('moodle/site:viewfullnames', $context); $groupname = ''; if ($groupid) { $groupname = $DB->get_field('groups', 'name', array('id' => $groupid)); } // all enrolled users for table pagination $coursecontext = context_course::instance($course->id); $participation = ouwiki_get_participation($ouwiki, $subwiki, $context, $groupid); // is grading enabled and available for the current user $grading_info = array(); if ($ouwiki->grade != 0 && has_capability('mod/ouwiki:grade', $context) && (!$groupid || ($groupid && has_capability('moodle/site:accessallgroups', $context) || $groupid && groups_is_member($groupid)))) { $grading_info = grade_get_grades($course->id, 'mod', 'ouwiki', $ouwiki->id, array_keys($participation));
public function test_canview_group_wiki() { global $USER; $this->resetAfterTest(true); $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(array('groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1)); $ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_GROUPS); $cm = get_coursemodule_from_instance('ouwiki', $ouwiki->id); $this->assertNotEmpty($cm); $context = context_module::instance($cm->id); $group = $this->get_new_group($course->id); $subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $group->id, $USER->id, true); // Can view all user participation. $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); $this->assertEquals(OUWIKI_USER_PARTICIPATION, $canview); // Can only view own participation. $student = $this->get_new_user('student', $course->id); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm, $student->id); $this->assertEquals(OUWIKI_NO_PARTICIPATION, $canview); $this->setUser($student); // Testing when logged in a s student. $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); $this->assertEquals(OUWIKI_NO_PARTICIPATION, $canview); // Check when student is a member of the group. $this->get_new_group_member($group->id, $student->id); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm, $student->id); $this->assertEquals(OUWIKI_MY_PARTICIPATION, $canview); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); $this->assertEquals(OUWIKI_MY_PARTICIPATION, $canview); }
/** * Prints the header and (if applicable) group selector. * * @param object $ouwiki Wiki object * @param object $cm Course-modules object * @param object $course * @param object $subwiki Subwiki objecty * @param string $pagename Name of page * @param object $context Context object * @param string $afterpage If included, extra content for navigation string after page link * @param bool $hideindex If true, doesn't show the index/recent pages links * @param bool $notabs If true, prints the after-tabs div here * @param string $head Things to include inside html head * @param string $title */ public function ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, $afterpage = null, $hideindex = null, $notabs = null, $head = '', $title = '') { global $USER; $output = ''; ouwiki_print_header($ouwiki, $cm, $subwiki, $pagename, $afterpage, $head, $title); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); $page = basename($_SERVER['PHP_SELF']); // Print group/user selector $showselector = true; if ($page == 'userparticipation.php' && $canview != OUWIKI_USER_PARTICIPATION || $page == 'participation.php' && (int) $ouwiki->subwikis == OUWIKI_SUBWIKIS_INDIVIDUAL) { $showselector = false; } if ($showselector) { $selector = ouwiki_display_subwiki_selector($subwiki, $ouwiki, $cm, $context, $course, $page); $output .= $selector; } // Print index link if (!$hideindex) { $output .= html_writer::start_tag('div', array('id' => 'ouwiki_indexlinks')); $output .= html_writer::start_tag('ul'); if ($page == 'wikiindex.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index')); $output .= html_writer::start_tag('span'); $output .= get_string('index', 'ouwiki'); $output .= html_writer::end_tag('span'); $output .= html_writer::end_tag('li'); } else { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index')); $output .= html_writer::tag('a', get_string('index', 'ouwiki'), array('href' => 'wikiindex.php?' . ouwiki_display_wiki_parameters('', $subwiki, $cm, OUWIKI_PARAMS_URL))); $output .= html_writer::end_tag('li'); } if ($page == 'wikihistory.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_history')); $output .= html_writer::start_tag('span'); $output .= get_string('wikirecentchanges', 'ouwiki'); $output .= html_writer::end_tag('span'); $output .= html_writer::end_tag('li'); } else { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_history')); $output .= html_writer::tag('a', get_string('wikirecentchanges', 'ouwiki'), array('href' => 'wikihistory.php?' . ouwiki_display_wiki_parameters('', $subwiki, $cm, OUWIKI_PARAMS_URL))); $output .= html_writer::end_tag('li'); } if ($canview == OUWIKI_USER_PARTICIPATION) { $participationstr = get_string('participationbyuser', 'ouwiki'); $participationpage = 'participation.php?' . ouwiki_display_wiki_parameters('', $subwiki, $cm, OUWIKI_PARAMS_URL); } else { if ($canview == OUWIKI_MY_PARTICIPATION) { $participationstr = get_string('myparticipation', 'ouwiki'); $participationpage = 'userparticipation.php?' . ouwiki_display_wiki_parameters('', $subwiki, $cm, OUWIKI_PARAMS_URL); $participationpage .= '&user='******'&group=' . $subwiki->groupid; } if ($canview > OUWIKI_NO_PARTICIPATION) { if ($page == 'participation.php' || $page == 'userparticipation.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_participation')); $output .= html_writer::start_tag('span'); $output .= $participationstr; $output .= html_writer::end_tag('span'); $output .= html_writer::end_tag('li'); } else { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_participation')); $output .= html_writer::tag('a', $participationstr, array('href' => $participationpage)); $output .= html_writer::end_tag('li'); } } $output .= html_writer::end_tag('ul'); $output .= html_writer::end_tag('div'); } else { $output .= html_writer::start_tag('div', array('id' => 'ouwiki_noindexlink')); $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'clearer')); $output .= html_writer::end_tag('div'); if ($notabs) { $extraclass = $selector ? ' ouwiki_gotselector' : ''; $output .= html_writer::start_tag('div', array('id' => 'ouwiki_belowtabs', 'class' => 'ouwiki_notabs' . $extraclass)); $output .= html_writer::end_tag('div'); } return $output; }
/** * Prints the header and (if applicable) group selector. * * @param object $ouwiki Wiki object * @param object $cm Course-modules object * @param object $course * @param object $subwiki Subwiki objecty * @param string $pagename Name of page * @param object $context Context object * @param string $afterpage If included, extra content for navigation string after page link * @param bool $hideindex If true, doesn't show the index/recent pages links * @param bool $notabs If true, prints the after-tabs div here * @param string $head Things to include inside html head * @param string $title * @param string $querytext for use when changing groups against search criteria */ public function ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, $afterpage = null, $hideindex = null, $notabs = null, $head = '', $title = '', $querytext = '') { $output = ''; if ($pagename == null) { $pagename = ''; } ouwiki_print_header($ouwiki, $cm, $subwiki, $pagename, $afterpage, $head, $title); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm); $page = basename($_SERVER['PHP_SELF']); // Gather params for later use - saves passing as attributes within the renderer. $this->params = new StdClass(); $this->params->ouwiki = $ouwiki; $this->params->cm = $cm; $this->params->subwiki = $subwiki; $this->params->course = $course; $this->params->pagename = $pagename; $this->params->hideindex = $hideindex; $this->params->canview = $canview; $this->params->page = $page; // Add wiki name header. $output .= $this->get_wiki_heading_text(); // Add rss and atom feeds. $output .= $this->get_feeds_section(); // Add group/user selector. $showselector = true; if ($page == 'userparticipation.php' && $canview != OUWIKI_MY_PARTICIPATION || $page == 'participation.php' && (int) $ouwiki->subwikis == OUWIKI_SUBWIKIS_INDIVIDUAL) { $showselector = false; } if ($showselector) { $selector = ouwiki_display_subwiki_selector($subwiki, $ouwiki, $cm, $context, $course, $page, $querytext); $output .= $selector; } // Add index links. list($content, $participationstr) = $this->ouwiki_get_links(); $output .= $content; // Add page heading. $output .= $this->ouwiki_get_page_heading($participationstr); $output .= html_writer::div('', 'clearer'); if ($notabs) { $extraclass = $selector ? ' ouwiki_gotselector' : ''; $output .= html_writer::div('', 'ouwiki_notabs' . $extraclass, array('id' => 'ouwiki_belowtabs')); } return $output; }
public function test_canview_group_wiki() { $ouwiki = $this->get_new_ouwiki($this->courses['group']->id, OUWIKI_SUBWIKIS_GROUPS); $cm = $this->get_new_course_module($this->courses['group']->id, $ouwiki->id, SEPARATEGROUPS); $context = get_context_instance(CONTEXT_MODULE, $cm->instance); $group = $this->get_new_group($this->courses['group']->id); $subwiki = ouwiki_get_subwiki($this->courses['group'], $ouwiki, $cm, $context, $group->id, $this->admin->id, true); // student is a member of the group $member = $this->get_new_group_member($group->id, $this->student->id); // can only view own participation $canview = ouwiki_can_view_participation($this->courses['group'], $ouwiki, $subwiki, $cm, $this->student->id); $this->assertEqual($canview, OUWIKI_MY_PARTICIPATION); // can view all user participation $canview = ouwiki_can_view_participation($this->courses['group'], $ouwiki, $subwiki, $cm, $this->admin->id); $this->assertEqual($canview, OUWIKI_USER_PARTICIPATION); }
$params = array('id' => $id, 'user' => $userid, 'group' => $groupid, 'pagename' => $pagename, 'download' => $download); $url = new moodle_url('/mod/ouwiki/userparticipation.php', $params); $PAGE->set_url($url); if (!($cm = get_coursemodule_from_id('ouwiki', $id))) { print_error('invalidcoursemodule'); } // Checking course instance $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); if (!($ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance)))) { print_error('invalidcoursemodule'); } $PAGE->set_cm($cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $PAGE->set_pagelayout('incourse'); require_course_login($course, true, $cm); $canview = ouwiki_can_view_participation($course, $ouwiki, $subwiki, $cm, $USER->id); if ($canview == OUWIKI_NO_PARTICIPATION || $USER->id != $userid && $canview == OUWIKI_MY_PARTICIPATION) { print_error('nopermissiontoshow'); } list($user, $changes) = ouwiki_get_user_participation($userid, $subwiki); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); $cangrade = has_capability('mod/ouwiki:grade', $context); $groupname = ''; if ($groupid) { $groupname = $DB->get_field('groups', 'name', array('id' => $groupid)); } $ouwikioutput = $PAGE->get_renderer('mod_ouwiki'); // Headers if (empty($download)) { $nav = array(); $groupparams = $groupid ? '&group=' . $groupid : '';