/** * Prüfen, ob ein Knoten im Netz für den aktuellen Benutzer sichtbar ist. * * @param int $nodeid Die id des zu prüfenden Knotens * @return bool Gibt wahr oder falsch zurück */ function node_visible_for_user($nodeid) { global $DB, $CFG; $cm = get_coursemodule_from_id($modname = 0, $nodeid, $courseid = 0, $sectionnum = false, $strictness = IGNORE_MISSING); if (coursemodule_visible_for_user($cm, $userid = 0)) { return true; } return false; }
/** * Prints a section full of activity modules */ function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%", $hidecompletion = false) { global $CFG, $USER, $DB, $PAGE, $OUTPUT; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $groupings; static $modulenames; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = $PAGE->user_is_editing(); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } $modulenames = array(); $initialised = true; } $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); //Accessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } /** * @var cm_info */ $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { // We can continue (because it will not be displayed at all) // if: // 1) The activity is not visible to users // and // 2a) The 'showavailability' option is not set (if that is set, // we need to display the activity so we can show // availability info) // or // 2b) The 'availableinfo' is empty, i.e. the activity was // hidden in a way that leaves no info, such as using the // eye icon. if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) { // full visibility check continue; } } if (!isset($modulenames[$mod->modname])) { $modulenames[$mod->modname] = get_string('modulename', $mod->modname); } $modulename = $modulenames[$mod->modname]; // In some cases the activity is visible to user, but it is // dimmed. This is done if viewhiddenactivities is true and if: // 1. the activity is not visible, or // 2. the activity has dates set which do not include current, or // 3. the activity has any other conditions set (regardless of whether // current user meets them) $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)); $accessiblebutdim = false; if ($canviewhidden) { $accessiblebutdim = !$mod->visible; if (!empty($CFG->enableavailability)) { $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || $mod->availableuntil && $mod->availableuntil < time() || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0; } } $liclasses = array(); $liclasses[] = 'activity'; $liclasses[] = $mod->modname; $liclasses[] = 'modtype_' . $mod->modname; $extraclasses = $mod->get_extra_classes(); if ($extraclasses) { $liclasses = array_merge($liclasses, explode(' ', $extraclasses)); } echo html_writer::start_tag('li', array('class' => join(' ', $liclasses), 'id' => 'module-' . $modnumber)); if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } $classes = array('mod-indent'); if (!empty($mod->indent)) { $classes[] = 'mod-indent-' . $mod->indent; if ($mod->indent > 15) { $classes[] = 'mod-indent-huge'; } } echo html_writer::start_tag('div', array('class' => join(' ', $classes))); // Get data about this course-module list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course); //Accessibility: for files get description via icon, this is very ugly hack! $altname = ''; $altname = $mod->modfullname; if (!empty($customicon)) { $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype == MOD_ARCHETYPE_RESOURCE) { $mimetype = mimeinfo_from_icon('type', $customicon); $altname = get_mimetype_description($mimetype); } } // Avoid unnecessary duplication: if e.g. a forum name already // includes the word forum (or Forum, etc) then it is unhelpful // to include that in the accessible description that is added. if (false !== strpos(textlib::strtolower($instancename), textlib::strtolower($altname))) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } // We may be displaying this just in order to show information // about visibility, without the actual link $contentpart = ''; if ($mod->uservisible) { // Nope - in this case the link is fully working for user $linkclasses = ''; $textclasses = ''; if ($accessiblebutdim) { $linkclasses .= ' dimmed'; $textclasses .= ' dimmed_text'; $accesstext = '<span class="accesshide">' . get_string('hiddenfromstudents') . ': </span>'; } else { $accesstext = ''; } if ($linkclasses) { $linkcss = 'class="' . trim($linkclasses) . '" '; } else { $linkcss = ''; } if ($textclasses) { $textcss = 'class="' . trim($textclasses) . '" '; } else { $textcss = ''; } // Get on-click attribute value if specified $onclick = $mod->get_on_click(); if ($onclick) { $onclick = ' onclick="' . $onclick . '"'; } if ($url = $mod->get_url()) { // Display link itself echo '<a ' . $linkcss . $mod->extra . $onclick . ' href="' . $url . '"><img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> ' . $accesstext . '<span class="instancename">' . $instancename . $altname . '</span></a>'; // If specified, display extra content after link if ($content) { $contentpart = '<div class="' . trim('contentafterlink' . $textclasses) . '">' . $content . '</div>'; } } else { // No link, so display only content $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>'; } if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { $textclasses = $extraclasses; $textclasses .= ' dimmed_text'; if ($textclasses) { $textcss = 'class="' . trim($textclasses) . '" '; } else { $textcss = ''; } $accesstext = '<span class="accesshide">' . get_string('notavailableyet', 'condition') . ': </span>'; if ($url = $mod->get_url()) { // Display greyed-out text of link echo '<div ' . $textcss . $mod->extra . ' >' . '<img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> <span>' . $instancename . $altname . '</span></div>'; // Do not display content after link when it is greyed out like this. } else { // No link, so display only content (also greyed) $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>'; } } // Module can put text after the link (e.g. forum unread) echo $mod->get_after_link(); // If there is content but NO link (eg label), then display the // content here (BEFORE any icons). In this case cons must be // displayed after the content so that it makes more sense visually // and for accessibility reasons, e.g. if you have a one-line label // it should work similarly (at least in terms of ordering) to an // activity. if (empty($url)) { echo $contentpart; } if ($isediting) { if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); echo $mod->get_after_edit_icons(); } // Completion $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod); if ($completion != COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) { $completiondata = $completioninfo->get_data($mod, true); $completionicon = ''; if ($isediting) { switch ($completion) { case COMPLETION_TRACKING_MANUAL: $completionicon = 'manual-enabled'; break; case COMPLETION_TRACKING_AUTOMATIC: $completionicon = 'auto-enabled'; break; default: // wtf } } else { if ($completion == COMPLETION_TRACKING_MANUAL) { switch ($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'manual-n'; break; case COMPLETION_COMPLETE: $completionicon = 'manual-y'; break; } } else { // Automatic switch ($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'auto-n'; break; case COMPLETION_COMPLETE: $completionicon = 'auto-y'; break; case COMPLETION_COMPLETE_PASS: $completionicon = 'auto-pass'; break; case COMPLETION_COMPLETE_FAIL: $completionicon = 'auto-fail'; break; } } } if ($completionicon) { $imgsrc = $OUTPUT->pix_url('i/completion-' . $completionicon); $imgalt = s(get_string('completion-alt-' . $completionicon, 'completion', $mod->name)); if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) { $imgtitle = s(get_string('completion-title-' . $completionicon, 'completion', $mod->name)); $newstate = $completiondata->completionstate == COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE; // In manual mode the icon is a toggle form... // If this completion state is used by the // conditional activities system, we need to turn // off the JS. if (!empty($CFG->enableavailability) && condition_info::completion_value_used_as_condition($course, $mod)) { $extraclass = ' preventjs'; } else { $extraclass = ''; } echo "\n<form class='togglecompletion{$extraclass}' method='post' action='" . $CFG->wwwroot . "/course/togglecompletion.php'><div>\n<input type='hidden' name='id' value='{$mod->id}' />\n<input type='hidden' name='modulename' value='" . s($mod->name) . "' />\n<input type='hidden' name='sesskey' value='" . sesskey() . "' />\n<input type='hidden' name='completionstate' value='{$newstate}' />\n<input type='image' src='{$imgsrc}' alt='{$imgalt}' title='{$imgtitle}' />\n</div></form>"; } else { // In auto mode, or when editing, the icon is just an image echo "<span class='autocompletion'>"; echo "<img src='{$imgsrc}' alt='{$imgalt}' title='{$imgalt}' /></span>"; } } } // If there is content AND a link, then display the content here // (AFTER any icons). Otherwise it was displayed before if (!empty($url)) { echo $contentpart; } // Show availability information (for someone who isn't allowed to // see the activity itself, or for staff) if (!$mod->uservisible) { echo '<div class="availabilityinfo">' . $mod->availableinfo . '</div>'; } else { if ($canviewhidden && !empty($CFG->enableavailability)) { $ci = new condition_info($mod); $fullinfo = $ci->get_full_information(); if ($fullinfo) { echo '<div class="availabilityinfo">' . get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden', 'condition', $fullinfo) . '</div>'; } } } echo html_writer::end_tag('div'); echo html_writer::end_tag('li') . "\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * Prints a section full of activity modules * @Overrides course/lib.php=>print_section */ function ss_print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) { #print_r($mods); global $CFG, $USER, $DB, $PAGE, $OUTPUT; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); $groupbuttonslink = (!$course->groupmodeforce); $isediting = $PAGE->user_is_editing(); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); } include_once($CFG->dirroot.'/mod/forum/lib.php'); if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new stdClass(); $labelformatoptions->noclean = true; $labelformatoptions->overflowdiv = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); //Accessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { // We can continue (because it will not be displayed at all) // if: // 1) The activity is not visible to users // and // 2a) The 'showavailability' option is not set (if that is set, // we need to display the activity so we can show // availability info) // or // 2b) The 'availableinfo' is empty, i.e. the activity was // hidden in a way that leaves no info, such as using the // eye icon. if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) { // visibility shortcut continue; } } else { if (!file_exists("$CFG->dirroot/mod/$mod->modname/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) { // full visibility check continue; } } // In some cases the activity is visible to user, but it is // dimmed. This is done if viewhiddenactivities is true and if: // 1. the activity is not visible, or // 2. the activity has dates set which do not include current, or // 3. the activity has any other conditions set (regardless of whether // current user meets them) $canviewhidden = has_capability( 'moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)); $accessiblebutdim = false; if ($canviewhidden) { $accessiblebutdim = !$mod->visible; if (!empty($CFG->enableavailability)) { $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || ($mod->availableuntil && $mod->availableuntil < time()) || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0; } } $liclasses = array(); $liclasses[] = 'activity'; $liclasses[] = $mod->modname; $liclasses[] = 'modtype_'.$mod->modname; echo html_writer::start_tag('li', array('class'=>join(' ', $liclasses), 'id'=>'module-'.$modnumber)); if ($ismoving) { echo '<a title="'.$strmovefull.'"'. ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.sesskey().'">'. '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '. ' alt="'.$strmovehere.'" /></a><br /> '; } $classes = array('mod-indent'); if (!empty($mod->indent)) { $classes[] = 'mod-indent-'.$mod->indent; if ($mod->indent > 15) { $classes[] = 'mod-indent-huge'; } } echo html_writer::start_tag('div', array('class'=>join(' ', $classes))); $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { if ($accessiblebutdim || !$mod->uservisible) { echo '<div class="dimmed_text"><span class="accesshide">'. get_string('hiddenfromstudents').'</span>'; } else { echo '<div>'; } echo format_text($extra, FORMAT_HTML, $labelformatoptions); echo "</div>"; if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); # echo format_string($modinfo->cms[$modnumber]->intro, true, $course->id); # echo format_string($modinfo->cms[$modnumber]->name, true, $course->id); # print_r($modinfo->cms[$modnumber]); $customicon = $modinfo->cms[$modnumber]->icon; if (!empty($customicon)) { if (substr($customicon, 0, 4) === 'mod/') { list($modname, $iconname) = explode('/', substr($customicon, 4), 2); $icon = $OUTPUT->pix_url($iconname, $modname); } else { $icon = $OUTPUT->pix_url($customicon); } } else { $icon = $OUTPUT->pix_url('icon', $mod->modname); } //Accessibility: for files get description via icon, this is very ugly hack! $altname = ''; $altname = $mod->modfullname; if (!empty($customicon)) { $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype == MOD_ARCHETYPE_RESOURCE) { $mimetype = mimeinfo_from_icon('type', $customicon); $altname = get_mimetype_description($mimetype); } } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' '.$altname); } // We may be displaying this just in order to show information // about visibility, without the actual link if ($mod->uservisible) { // Display normal module link if (!$accessiblebutdim) { $linkcss = ''; $accesstext =''; } else { $linkcss = ' class="dimmed" '; $accesstext = '<span class="accesshide">'. get_string('hiddenfromstudents').': </span>'; } echo '<a '.$linkcss.' '.$extra. ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'. '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename',$mod->modname).'" /> '. $accesstext.'<span class="instancename">'.$instancename.$altname.'</span></a>'; if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>'; } } else { // Display greyed-out text of link echo '<span class="dimmed_text" '.$extra.' ><span class="accesshide">'. get_string('notavailableyet','condition').': </span>'. '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename', $mod->modname).'" /> <span>'. $instancename.$altname.'</span></span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } if ($isediting) { if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { if (! $mod->groupmodelink = $groupbuttonslink) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); hook_make_edit_icon_button($mod, $OUTPUT); } // Completion $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod); if ($completion!=COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) { $completiondata = $completioninfo->get_data($mod,true); $completionicon = ''; if ($isediting) { switch ($completion) { case COMPLETION_TRACKING_MANUAL : $completionicon = 'manual-enabled'; break; case COMPLETION_TRACKING_AUTOMATIC : $completionicon = 'auto-enabled'; break; default: // wtf } } else if ($completion==COMPLETION_TRACKING_MANUAL) { switch($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'manual-n'; break; case COMPLETION_COMPLETE: $completionicon = 'manual-y'; break; } } else { // Automatic switch($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'auto-n'; break; case COMPLETION_COMPLETE: $completionicon = 'auto-y'; break; case COMPLETION_COMPLETE_PASS: $completionicon = 'auto-pass'; break; case COMPLETION_COMPLETE_FAIL: $completionicon = 'auto-fail'; break; } } if ($completionicon) { $imgsrc = $OUTPUT->pix_url('i/completion-'.$completionicon); $imgalt = s(get_string('completion-alt-'.$completionicon, 'completion')); if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) { $imgtitle = s(get_string('completion-title-'.$completionicon, 'completion')); $newstate = $completiondata->completionstate==COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE; // In manual mode the icon is a toggle form... // If this completion state is used by the // conditional activities system, we need to turn // off the JS. if (!empty($CFG->enableavailability) && condition_info::completion_value_used_as_condition($course, $mod)) { $extraclass = ' preventjs'; } else { $extraclass = ''; } echo " <form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div> <input type='hidden' name='id' value='{$mod->id}' /> <input type='hidden' name='sesskey' value='".sesskey()."' /> <input type='hidden' name='completionstate' value='$newstate' /> <input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' /> </div></form>"; } else { // In auto mode, or when editing, the icon is just an image echo "<span class='autocompletion'>"; echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>"; } } } // Show availability information (for someone who isn't allowed to // see the activity itself, or for staff) if (!$mod->uservisible) { echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>'; } else if ($canviewhidden && !empty($CFG->enableavailability)) { $ci = new condition_info($mod); $fullinfo = $ci->get_full_information(); if($fullinfo) { echo '<div class="availabilityinfo">'.get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden','condition', $fullinfo).'</div>'; } } echo hook_show_activity_intro($mod); echo html_writer::end_tag('div'); echo html_writer::end_tag('li')."\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="'.$strmovefull.'"'. ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.sesskey().'">'. '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '. ' alt="'.$strmovehere.'" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * @global object * @global object * @param object $forum * @param object $discussion * @param object $post * @param object $user * @param object $cm * @return bool */ function forum_user_can_see_post($forum, $discussion, $post, $user = NULL, $cm = NULL) { global $CFG, $USER, $DB; // retrieve objects (yuk) if (is_numeric($forum)) { debugging('missing full forum', DEBUG_DEVELOPER); if (!($forum = $DB->get_record('forum', array('id' => $forum)))) { return false; } } if (is_numeric($discussion)) { debugging('missing full discussion', DEBUG_DEVELOPER); if (!($discussion = $DB->get_record('forum_discussions', array('id' => $discussion)))) { return false; } } if (is_numeric($post)) { debugging('missing full post', DEBUG_DEVELOPER); if (!($post = $DB->get_record('forum_posts', array('id' => $post)))) { return false; } } if (!isset($post->id) && isset($post->parent)) { $post->id = $post->parent; } if (!$cm) { debugging('missing cm', DEBUG_DEVELOPER); if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) { print_error('invalidcoursemodule'); } } if (empty($user) || empty($user->id)) { $user = $USER; } if (isset($cm->cache->caps['mod/forum:viewdiscussion'])) { if (!$cm->cache->caps['mod/forum:viewdiscussion']) { return false; } } else { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('mod/forum:viewdiscussion', $modcontext, $user->id)) { return false; } } if (isset($cm->uservisible)) { if (!$cm->uservisible) { return false; } } else { if (!coursemodule_visible_for_user($cm, $user->id)) { return false; } } if ($forum->type == 'qanda') { $firstpost = forum_get_firstpost_from_discussion($discussion->id); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $userfirstpost = forum_get_user_posted_time($discussion->id, $user->id); return $userfirstpost !== false && time() - $userfirstpost >= $CFG->maxeditingtime || $firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id || has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id, false); } return true; }
if ($move > 0 and confirm_sesskey()) { $return = $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $discussion->id; require_capability('mod/forum:movediscussions', $modcontext); if ($forum->type == 'single') { print_error('cannotmovefromsingleforum', 'forum', $return); } if (!($forumto = $DB->get_record('forum', array('id' => $move)))) { print_error('cannotmovetonotexist', 'forum', $return); } if ($forumto->type == 'single') { print_error('cannotmovetosingleforum', 'forum', $return); } if (!($cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id))) { print_error('cannotmovetonotfound', 'forum', $return); } if (!coursemodule_visible_for_user($cmto)) { print_error('cannotmovenotvisible', 'forum', $return); } require_capability('mod/forum:startdiscussion', get_context_instance(CONTEXT_MODULE, $cmto->id)); if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) { echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); } $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d={$discussion->id}", $discussion->id, $cmto->id); require_once $CFG->libdir . '/rsslib.php'; require_once $CFG->dirroot . '/mod/forum/rsslib.php'; // Delete the RSS files for the 2 forums to force regeneration of the feeds forum_rss_delete_file($forum); forum_rss_delete_file($forumto); redirect($return . '&moved=-1&sesskey=' . sesskey());
function print_section_newsroom($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new object(); $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } } // The magic! ... if indent == 1 then ... hide module if ($mod->indent == 1) { $hiddemodule = 'hidden'; } else { $hiddemodule = ''; } echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">'; // Unique ID if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { echo "<span class=\""; if (!$mod->visible) { echo 'dimmed_text'; } else { echo 'label'; } echo '">'; echo format_text($extra, FORMAT_HTML, $labelformatoptions); echo "</span>"; if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); if (!empty($modinfo->cms[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon; } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo->cms[$modnumber]->icon)) { $possaltname = $modinfo->cms[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; //echo " $mod->modname "; // Special NEWSPAPER magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav) if ($mod->modname == 'resource') { $article = get_record('resource', 'id', $mod->instance); //print_r($article ); echo "{$article->summary}"; } if ($mod->modname == 'oublog') { require_once $CFG->dirroot . '/mod/oublog/locallib.php'; $oublog = get_record('oublog', 'id', $mod->instance); if (!($oublogcm = get_coursemodule_from_instance('oublog', $oublog->id))) { //error("Course module ID was incorrect"); } $oublogcontext = get_context_instance(CONTEXT_MODULE, $oublogcm->id); //oublog_check_view_permissions($oublog, $oublogcontext, $oublogcm); $currentgroup = oublog_get_activity_group($oublogcm, true); echo '<br/>'; /// Get Posts list($posts, $recordcount) = oublog_get_posts($oublog, $oublogcontext, 0, $oublogcm, $currentgroup); //, -1, $oubloguser->id, $tag, $canaudit); $i = 0; foreach ($posts as $post) { if ($i < 3) { echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>'; $summaryformatoptions->noclean = false; echo mb_substr(format_text($post->message, FORMAT_HTML, $summaryformatoptions), 1, 600) . "<hr/>"; } if ($i > 2 and $i < 6) { echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>'; } $i++; } //print_r($article ); //echo "$article->summary"; echo '<br/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_newsroom') . '</span></a>'; } if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } if ($isediting) { // TODO: we must define this as mod property! if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); } echo "</li>\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * */ function forum_user_can_see_post($forum, $discussion, $post, $user = NULL, $cm = NULL) { global $USER; // retrieve objects (yuk) if (is_numeric($forum)) { debugging('missinf full forum', DEBUG_DEVELOPER); if (!($forum = get_record('forum', 'id', $forum))) { return false; } } if (is_numeric($discussion)) { debugging('missinf full discussion', DEBUG_DEVELOPER); if (!($discussion = get_record('forum_discussions', 'id', $discussion))) { return false; } } if (is_numeric($post)) { debugging('missinf full post', DEBUG_DEVELOPER); if (!($post = get_record('forum_posts', 'id', $post))) { return false; } } if (!isset($post->id) && isset($post->parent)) { $post->id = $post->parent; } if (!$cm) { debugging('missing cm', DEBUG_DEVELOPER); if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) { error('Course Module ID was incorrect'); } } if (empty($user) || empty($user->id)) { $user = $USER; } if (isset($cm->cache->caps['mod/forum:viewdiscussion'])) { if (!$cm->cache->caps['mod/forum:viewdiscussion']) { return false; } } else { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('mod/forum:viewdiscussion', $modcontext, $user->id)) { return false; } } if (isset($cm->uservisible)) { if (!$cm->uservisible) { return false; } } else { if (!coursemodule_visible_for_user($cm, $user->id)) { return false; } } if ($forum->type == 'qanda') { $firstpost = forum_get_firstpost_from_discussion($discussion->id); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); return forum_user_has_posted($forum->id, $discussion->id, $user->id) || $firstpost->id == $post->id || has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id, false); } return true; }
function fix_condition_targetid($labelmods, $resourcemods, $course, $cm, $targetid, $includeungraded = false, $includeresources = false, $includelabels = false, $requirecompletion = false) { global $DB; if ($targetid >= 0) { return intval($targetid); } if (!($modinfo = get_fast_modinfo($course))) { return 0; // shouldn't happen !! } // set default search values $id = 0; $modname = ''; $sectionnum = -1; $requiregraded = false; // restrict search values if ($targetid > 0) { // specific activity $id = $targetid; } else { if ($targetid == PREVIOUS_SAME_COURSE || $targetid == PREVIOUS_SAME_SECTION || $targetid == NEXT_SAME_COURSE || $targetid == NEXT_SAME_SECTION) { // same type of activity $modname = $cm->modname; } if ($targetid == PREVIOUS_ANY_SECTION || $targetid == PREVIOUS_SAME_SECTION || $targetid == NEXT_ANY_SECTION || $targetid == NEXT_SAME_SECTION) { // same section $sectionnum = $cm->sectionnum; } if ($includeungraded == false) { $requiregraded = true; } } // get grade info, if required (we just need to know if an activity has a grade or not) if ($requiregraded) { // basic SQL to get grade items for graded activities $select = 'cm.id, gi.id AS gradeitemid, gi.itemtype, gi.itemmodule, gi.iteminstance, gi.gradetype'; $from = '{grade_items} gi' . ' LEFT JOIN {modules} m ON gi.itemmodule = m.name' . ' LEFT JOIN {course_modules} cm ON m.id = cm.module AND gi.iteminstance = cm.instance'; $where = "gi.courseid = ? AND gi.itemtype = ? AND gi.gradetype <> ?"; $params = array($course->id, 'mod', GRADE_TYPE_NONE); // restrict results to single module, if we can if ($modname) { $where .= ' AND gi.itemmodule = ?'; $params[] = $modname; } // restrict results to current section, if we can if ($sectionnum >= 0) { $from .= ' LEFT JOIN {course_sections} cs ON cs.id = cm.section'; $where .= ' AND cs.section = ?'; $params[] = $sectionnum; } $gradedcms = $DB->get_records_sql("SELECT {$select} FROM {$from} WHERE {$where}", $params); } // are we searching for a PREVIOUS activity (usually we are) $previous = $targetid == PREVIOUS_ANY_COURSE || $targetid == PREVIOUS_ANY_SECTION || $targetid == PREVIOUS_SAME_COURSE || $targetid == PREVIOUS_SAME_SECTION; // get cm ids (reverse order if necessary) $coursemoduleids = array_keys($modinfo->cms); if ($previous) { $coursemoduleids = array_reverse($coursemoduleids); } // search for next, previous or specific course module $found = false; foreach ($coursemoduleids as $coursemoduleid) { if (method_exists($modinfo, 'get_cm')) { $coursemodule = $modinfo->get_cm($coursemoduleid); } else { $coursemodule = $modinfo->cms[$coursemoduleid]; } if ($id && $coursemoduleid != $id) { continue; // wrong activity } if ($sectionnum >= 0) { if ($previous) { if ($coursemodule->sectionnum > $sectionnum) { continue; // later section } if ($coursemodule->sectionnum < $sectionnum) { return 0; // previous section } } else { if ($coursemodule->sectionnum < $sectionnum) { continue; // earlier section } if ($coursemodule->sectionnum > $sectionnum) { return 0; // later section } } } if ($requirecompletion && empty($coursemodule->completion)) { continue; // cm does not have completion conditions } if ($requiregraded && empty($gradedcms[$coursemoduleid])) { continue; // skip ungraded activity } if ($modname && $coursemodule->modname != $modname) { continue; // wrong module } if ($includelabels == false && in_array($coursemodule->modname, $labelmods)) { continue; // skip labels } if ($includeresources == false && in_array($coursemodule->modname, $resourcemods)) { continue; // skip resources } if ($found || $coursemoduleid == $id) { if (class_exists('\\core_availability\\info_module')) { // Moodle >= 2.7 $is_visible = \core_availability\info_module::is_user_visible($coursemodule); } else { // Moodle <= 2.6 // Indirect modification of overloaded property // cm_info::$availableinfo has no effect // lib/datalib.php on line 1588 $is_visible = coursemodule_visible_for_user($coursemodule); } if ($is_visible) { if ($requirecompletion) { // return cm id return intval($coursemoduleid); } else { // return grade item id return intval($gradedcms[$coursemoduleid]->gradeitemid); } } if ($coursemoduleid == $id) { // required cm is not visible to this user return 0; } } if ($coursemoduleid == $cm->id) { $found = true; } } // next/prev cm not found return 0; }
function RWSGUVQList($r_cid) { global $RWSUID; $r_vqms = array(); $r_qzms = get_coursemodules_in_course("quiz", $r_cid); if ($r_qzms === false || count($r_qzms) == 0) { return $r_vqms; } foreach ($r_qzms as $r_qzm) { if (coursemodule_visible_for_user($r_qzm, $RWSUID)) { $r_vqms[] = $r_qzm; } } return $r_vqms; }
/** * This function will preprocess all the mods in section, adding the required stuff to be able to * output them later in a nested lists behaviour */ function preprocessmods4topicstree($sectionmods, &$mods, &$modinfo) { global $CFG; $prev = null; $next = null; $tree = array(); /// To create the tree structure while $parents = array(); /// iterating. Needed to detect last items array_push($parents, 0); /// Initial parent foreach ($sectionmods as $key => $modnumber) { $treeized = false; /// To know if we have inserted one module /// in the $tree/$parents structures if (empty($mods[$modnumber])) { continue; } /// Calculate current $mod = $mods[$modnumber]; /// Calculate next if (isset($sectionmods[$key + 1])) { $next = $mods[$sectionmods[$key + 1]]; } else { $next = null; } /// Code goes here /// First item cannot have indent, reset it if (empty($prev) && $mod->indent > 0) { $mod->indent = 0; } /// Any difference > 1 isn't accepted, reduce it to 1 if (!empty($next) && $next->indent - $mod->indent > 1) { $next->indent = $mod->indent + 1; } /// If prev is more indented than current, annotate it if (!empty($prev) && $prev->indent > $mod->indent) { $mod->closelevel = $prev->indent - $mod->indent; /// Delete from list of parent for ($n = 0; $n < $mod->closelevel; $n++) { $last = array_pop($parents); } /// Assign current mod to current parent if (!$treeized) { $tree[end($parents)][$modnumber] = $modnumber; $treeized = true; } } /// If next is more indented than current, annotate it if (!empty($next) && $next->indent > $mod->indent) { $mod->openlevel = $next->indent; /// Assign current mod to current parent if (!$treeized) { $tree[end($parents)][$modnumber] = $modnumber; $treeized = true; } /// Now add mod to list of parents and start new list in tree for it array_push($parents, $modnumber); $tree[end($parents)] = array(); } /// Assign current mod to current parent if not done before (in opening/closing) if (!$treeized) { $tree[end($parents)][$modnumber] = $modnumber; $treeized = true; } /// Just to be sure changes apply if ($mod) { $mods[$modnumber] = $mod; } if ($next) { $mods[$sectionmods[$key + 1]] = $next; } /// Calculate new previous $prev = $mods[$modnumber]; } /// Now iterate over all the arrays in tree, getting last elements and /// marking them as last in $mods foreach ($tree as $list) { $mods[end($list)]->islast = true; } /// Finally, iterate over all the arrays in tree, looking for hidden parents /// and replacing that module by a custom label to respect the tree format foreach ($tree as $key => $list) { /// Skip 0 (virtual) tree if ($key == 0) { continue; } /// Check user visibility, and replace module by hand-made label if it isn't visible if (!coursemodule_visible_for_user($mods[$key])) { $mods[$key]->modname = 'label'; $mods[$key]->visible = 1; $modinfo->cms[$key]->uservisible = 1; $modinfo->cms[$key]->modname = 'label'; $modinfo->cms[$key]->name = ''; $modinfo->cms[$key]->extra = '<img src="' . $CFG->pixpath . '/f/folder.gif" alt="" />'; } } }
/** * get_cm * * @param xxx $type * @return xxx */ public function get_cm($type) { // gets the next, previous or specific Moodle activity // get entry/exit cm id $cm_field = $type . 'cm'; $cmid = $this->{$cm_field}; if ($cmid == self::ACTIVITY_NONE) { return false; } if (!($modinfo = get_fast_modinfo($this->course))) { return false; // no modinfo - shouldn't happen !! } if (method_exists($modinfo, 'get_cm')) { if (!$modinfo->get_cm($this->cm->id)) { return false; // target cm not found - shouldn't happen !! } } else { if (!isset($modinfo->cms[$this->cm->id])) { return false; // target cm not found - shouldn't happen !! } } // set default search values $id = 0; $modname = ''; $sectionnum = -1; // restrict search values if ($cmid > 0) { $id = $cmid; } else { if ($cmid == self::ACTIVITY_COURSE_HOTPOT || $cmid == self::ACTIVITY_SECTION_HOTPOT) { $modname = 'hotpot'; } if ($cmid == self::ACTIVITY_SECTION_ANY || $cmid == self::ACTIVITY_SECTION_HOTPOT) { $sectionnum = $modinfo->get_cm($this->cm->id)->sectionnum; } } // get cm ids (reverse order if necessary) $cmids = array_keys($modinfo->cms); if ($type == 'entry') { $cmids = array_reverse($cmids); } // search for next, previous or specific course module $found = false; foreach ($cmids as $cmid) { if (method_exists($modinfo, 'get_cm')) { $cm = $modinfo->get_cm($cmid); } else { $cm = $modinfo->cms[$cmid]; } if ($id && $cm->id != $id) { continue; // wrong activity } if ($sectionnum >= 0) { if ($type == 'entry') { if ($cm->sectionnum > $sectionnum) { continue; // later section } if ($cm->sectionnum < $sectionnum) { return false; // previous section } } else { // exit (=next) if ($cm->sectionnum < $sectionnum) { continue; // earlier section } if ($cm->sectionnum > $sectionnum) { return false; // later section } } } if ($modname && $cm->modname != $modname) { continue; // wrong module } if ($cm->modname == 'label') { continue; // skip labels } if ($found || $cm->id == $id) { if (coursemodule_visible_for_user($cm)) { return $cm; } if ($cm->id == $id) { // required cm is not visible to this user return false; } } if ($cm->id == $this->cm->id) { $found = true; } } // next cm not found return false; }
function get_course_mods($id, $username = '') { global $CFG, $DB; $username = utf8_decode($username); $username = strtolower($username); if ($username) { $user = get_complete_user_data('username', $username); } $sections = get_all_sections($id); $forum = forum_get_course_forum($id, 'news'); $news_forum_id = $forum->id; get_all_mods($id, $mods, $modnames, $modnamesplural, $modnamesused); $context = get_context_instance(CONTEXT_COURSE, $id); $e = array(); foreach ($sections as $section) { if (!$section->visible) { continue; } $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; $resource['completion_info'] = ''; if ($username) { $cm = get_coursemodule_from_id(false, $mod->id); if (!coursemodule_visible_for_user($cm, $user->id)) { if (!$mod->showavailability) { // Mod not visible, and no completion info to show continue; } $resource['available'] = 0; $ci = new condition_info($mod); $resource['completion_info'] = $ci->get_full_information(); } else { $resource['available'] = 1; } } else { $resource['available'] = 1; } $e[$section->section]['section'] = $section->section; $e[$section->section]['name'] = $section->name; $e[$section->section]['summary'] = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); $e[$section->section]['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $e[$section->section]['summary']); $resource['id'] = $mod->id; $resource['name'] = $mod->name; $resource['mod'] = $mod->modname; // Format for mod->icon is: f/type-24 $type = substr($mod->icon, 2); $parts = explode('-', $type); $type = $parts[0]; $resource['type'] = $type; //In forum, type is unused, so we use it for forum type: news/general if ($mod->modname == 'forum') { $cm = get_coursemodule_from_id('forum', $mod->id); if ($cm->instance == $news_forum_id) { $resource['type'] = 'news'; } } $e[$section->section]['mods'][] = $resource; } } return $e; }
function print_section_dblistview($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new object(); $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } } // The magic! ... if indent == 1 then ... hide module // if ($mod->indent == 1) { // $hiddemodule = 'hidden'; // } else { // $hiddemodule = ''; // } echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">'; // Unique ID if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { echo "<span class=\""; if (!$mod->visible) { echo 'dimmed_text'; } else { echo 'label'; } echo '">'; echo format_text($extra, FORMAT_HTML, $labelformatoptions); echo "</span>"; if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); if (!empty($modinfo->cms[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon; } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo->cms[$modnumber]->icon)) { $possaltname = $modinfo->cms[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; if ($mod->modname != 'data') { echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; } //echo " $mod->modname "; // Special DBLISTVIEW magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav) if ($mod->modname == 'resource') { $article = get_record('resource', 'id', $mod->instance); //print_r($article ); echo "{$article->summary}"; } if ($mod->modname == 'data') { require_once $CFG->dirroot . '/mod/data/lib.php'; if (!($data = get_record('data', 'id', $mod->instance))) { //error('Course module is incorrect'); } $sort = 0; $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname '; $count = ' COUNT(DISTINCT c.recordid) '; $tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r,' . $CFG->prefix . 'data_content cs, ' . $CFG->prefix . 'user u '; $where = 'WHERE c.recordid = r.id AND r.dataid = ' . $data->id . ' AND r.userid = u.id '; $sortorder = ' ORDER BY r.id ASC '; $searchselect = ''; // If requiredentries is not reached, only show current user's entries //if (!$requiredentries_allowed) { // $where .= ' AND u.id = ' . $USER->id; //} /// To actually fetch the records //$fromsql = "FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect"; $fromsql = "FROM {$tables} {$where} "; $sqlselect = "SELECT {$what} {$fromsql} {$sortorder}"; /// Get the actual records if (!($records = get_records_sql($sqlselect))) { // Nothing to show! } if (empty($data->listtemplate)) { //notify(get_string('nolisttemplate','data')); //data_generate_default_template($data, 'listtemplate', 0, false, false); } echo $data->listtemplateheader; data_print_template('listtemplate', $records, $data); echo $data->listtemplatefooter; //print_r($article ); //echo "$article->summary"; echo '<hr/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_dblistview') . '</span></a>'; if (!empty($data->csstemplate)) { echo '<style>' . $data->csstemplate . '</style>'; } } if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } if ($isediting) { // TODO: we must define this as mod property! if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); } echo "</li>\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime = 0) { global $CFG, $COURSE; $display = new stdClass(); $display->range = $daysinfuture; // How many days in the future we 'll look $display->maxevents = $maxevents; $output = array(); // Prepare "course caching", since it may save us a lot of queries $coursecache = array(); $processed = 0; $now = time(); // We 'll need this later $usermidnighttoday = usergetmidnight($now); if ($fromtime) { $display->tstart = $fromtime; } else { $display->tstart = $usermidnighttoday; } // This works correctly with respect to the user's DST, but it is accurate // only because $fromtime is always the exact midnight of some day! $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1; // Get the events matching our criteria $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses); // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $morehref = ''; if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $morehref = '&course=' . reset($courses); } } if ($events !== false) { $modinfo =& get_fast_modinfo($COURSE); foreach ($events as $event) { if (!empty($event->modulename)) { if ($event->courseid == $COURSE->id) { if (isset($modinfo->instances[$event->modulename][$event->instance])) { $cm = $modinfo->instances[$event->modulename][$event->instance]; if (!$cm->uservisible) { continue; } } } else { if (!($cm = get_coursemodule_from_instance($event->modulename, $event->instance))) { continue; } if (!coursemodule_visible_for_user($cm)) { continue; } } if ($event->modulename == 'assignment') { // TODO: rewrite this hack somehow if (!calendar_edit_event_allowed($event)) { // cannot manage entries, eg. student if (!($assignment = get_record('assignment', 'id', $event->instance))) { // error("assignment ID was incorrect"); continue; } // assign assignment to assignment object to use hidden_is_hidden method require_once $CFG->dirroot . '/mod/assignment/lib.php'; if (!file_exists($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php')) { continue; } require_once $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'; $assignmentclass = 'assignment_' . $assignment->assignmenttype; $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm); if ($assignmentinstance->description_is_hidden()) { //force not to show description before availability $event->description = get_string('notavailableyet', 'assignment'); } } } } if ($processed >= $display->maxevents) { break; } $event->time = calendar_format_event_time($event, $now, $morehref); $output[] = $event; ++$processed; } } return $output; }
function fetchcourseitems($courseid) { global $CFG, $DB; $xml_output = ""; if (!($course = $DB->get_record('course', array('id' => $courseid)))) { print_error('invalidcourseid'); } require_course_login($course); //$modinfo =& get_fast_modinfo($course); $modinfo = get_fast_modinfo($course); get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused); if (!($sections = get_all_sections($courseid))) { $xml_output .= 'Error finding or creating section structures for this course'; } //loop through the sections foreach ($sections as $thissection) { //display a section seperator for each secton if (!$thissection->visible) { $xml_output .= "\t<item label='---------(hidden)" . "' url='' />\n"; continue; } else { $xml_output .= "\t<item label='-----------------" . "' url='' />\n"; } //loop through all the mods for each section $sectionmods = explode(",", $thissection->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } //here we get the name of the mod. We need to encode it //because the xml breaks otherwise when there arequotes etc. $instancename = htmlspecialchars($modinfo->cms[$modnumber]->name, ENT_QUOTES); } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } //we have a mod, but for some reasonwe could not establish its name. $instancename = "mod with no name"; } //end of if isset //this works for now, but ultimately we will need to ad the "extra" paramaters from $modinfo $xml_output .= "\t<item label='" . $instancename . "' url='" . urlencode($CFG->wwwroot . "/mod/" . $mod->modname . "/view.php?id=" . $modnumber) . "' />\n"; } //end of for each mod } //end of for each section return $xml_output; }
/** * @global object * @global object * @param object $forum * @param object $discussion * @param object $post * @param object $user * @param object $cm * @return bool */ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) { global $CFG, $USER, $DB; // Context used throughout function. $modcontext = context_module::instance($cm->id); // retrieve objects (yuk) if (is_numeric($forum)) { debugging('missing full forum', DEBUG_DEVELOPER); if (!$forum = $DB->get_record('forum',array('id'=>$forum))) { return false; } } if (is_numeric($discussion)) { debugging('missing full discussion', DEBUG_DEVELOPER); if (!$discussion = $DB->get_record('forum_discussions',array('id'=>$discussion))) { return false; } } if (is_numeric($post)) { debugging('missing full post', DEBUG_DEVELOPER); if (!$post = $DB->get_record('forum_posts',array('id'=>$post))) { return false; } } if (!isset($post->id) && isset($post->parent)) { $post->id = $post->parent; } if (!$cm) { debugging('missing cm', DEBUG_DEVELOPER); if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) { print_error('invalidcoursemodule'); } } if (empty($user) || empty($user->id)) { $user = $USER; } $canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', $modcontext, $user->id); if (!$canviewdiscussion && !has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), context_user::instance($post->userid))) { return false; } if (isset($cm->uservisible)) { if (!$cm->uservisible) { return false; } } else { if (!coursemodule_visible_for_user($cm, $user->id)) { return false; } } if (!forum_user_can_see_timed_discussion($discussion, $user, $modcontext)) { return false; } if (!forum_user_can_see_group_discussion($discussion, $cm, $modcontext)) { return false; } if ($forum->type == 'qanda') { $firstpost = forum_get_firstpost_from_discussion($discussion->id); $userfirstpost = forum_get_user_posted_time($discussion->id, $user->id); return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) || $firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id || has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id)); } return true; }
/** * Gets the calendar upcoming event * * @param array $courses array of courses * @param array|int|bool $groups array of groups, group id or boolean for all/no group events * @param array|int|bool $users array of users, user id or boolean for all/no user events * @param int $daysinfuture number of days in the future we 'll look * @param int $maxevents maximum number of events * @param int $fromtime start time * @return array $output array of upcoming events */ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) { global $CFG, $COURSE, $DB; $display = new stdClass; $display->range = $daysinfuture; // How many days in the future we 'll look $display->maxevents = $maxevents; $output = array(); // Prepare "course caching", since it may save us a lot of queries $coursecache = array(); $processed = 0; $now = time(); // We 'll need this later $usermidnighttoday = usergetmidnight($now); if ($fromtime) { $display->tstart = $fromtime; } else { $display->tstart = $usermidnighttoday; } // This works correctly with respect to the user's DST, but it is accurate // only because $fromtime is always the exact midnight of some day! $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1; // Get the events matching our criteria $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses); // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $hrefparams = array(); if(!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if(count($courses) == 1) { $hrefparams['course'] = reset($courses); } } if ($events !== false) { $modinfo = get_fast_modinfo($COURSE); foreach($events as $event) { if (!empty($event->modulename)) { if ($event->courseid == $COURSE->id) { if (isset($modinfo->instances[$event->modulename][$event->instance])) { $cm = $modinfo->instances[$event->modulename][$event->instance]; if (!$cm->uservisible) { continue; } } } else { if (!$cm = get_coursemodule_from_instance($event->modulename, $event->instance)) { continue; } if (!coursemodule_visible_for_user($cm)) { continue; } } } if ($processed >= $display->maxevents) { break; } $event->time = calendar_format_event_time($event, $now, $hrefparams); $output[] = $event; ++$processed; } } return $output; }