/** * Generate the section title (with link if section is collapsed) * * @param int|section_info $section * @param stdClass $course The course entry from DB * @return string HTML to output. */ public function section_title($section, $course, $supresslink = false) { $title = get_section_name($course, $section); if (!$supresslink) { $url = course_get_url($course, $section, array('navigation' => true)); if ($url) { $title = html_writer::link($url, $title); } } return $title; }
function equella_get_course_contents($courseid, $sectionid) { global $DB, $CFG; $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); if ($course->format != 'site') { if (!file_exists($CFG->dirroot . '/course/format/' . $course->format . '/lib.php')) { throw new moodle_exception('cannotgetcoursecontents', 'webservice', '', null, get_string('courseformatnotfound', 'error', '', $course->format)); } else { require_once $CFG->dirroot . '/course/format/' . $course->format . '/lib.php'; } } $context = context_course::instance($course->id, IGNORE_MISSING); $coursecontents = new stdClass(); $coursecontents->id = $course->id; $coursecontents->code = $course->idnumber; $coursecontents->name = $course->fullname; $coursecontents->targetable = false; $coursecontents->folders = array(); if ($course->visible or has_capability('moodle/course:viewhiddencourses', $context)) { // retrieve sections $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); // for each sections (first displayed to last displayed) foreach ($sections as $key => $section) { $sectionvalues = new stdClass(); if ((int) $section->section == (int) $sectionid) { $sectionvalues->selected = true; } $sectionvalues->id = $section->section; $sectionvalues->name = get_section_name($course, $section); $sectionvalues->folders = array(); $sectioncontents = array(); // foreach ($modinfo->sections[$section->section] as $cmid) { // $cm = $modinfo->cms[$cmid]; // if (!$cm->uservisible) { // continue; // } // $module = array(); // $module['id'] = $cm->id; // $module['name'] = format_string($cm->name, true); // $sectioncontents[] = $module; // } // $sectionvalues->folders = $sectioncontents; $coursecontents->folders[] = $sectionvalues; } } return $coursecontents; }
/** * Function that creates an object \intuitel\SectionLO from the info of the Moodle section (corresponding to a row of table course_sections). If the section summary or sequence of cmids are empty, the function returns NULL * @see \intuitel\LOFactory::createLOFromNative() * @param stdClass object $section_info corresponding to a row of course_section table in Moodle * @return \intuitel\SectionLO | NULL */ function createLOFromNative($section_info) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; // for get_section_name() $loId = Intuitel::getIDFactory()->getLoIdfromId('section', $section_info->id); if ($this->isSectionEmpty($section_info)) { //throw new EmptySectionException('The section is empty'); $LOsection = null; } else { $hasParent = Intuitel::getIDFactory()->getLoIdfromId('course', $section_info->course); //LOId of the course where the section is global $CFG; $name = \get_section_name($section_info->course, $section_info); // get the previous not empty section id $precedingSibId = $this->getPrecedingSib($section_info); if ($precedingSibId == null) { $hasPrecedingSib = null; } else { $hasPrecedingSib = Intuitel::getIDFactory()->getLoIdfromId('section', $precedingSibId); } //create the object with mandatory attributes $LOsection = new SectionLO($loId, $name, $hasParent, $hasPrecedingSib); //OPTIONAL ATTRIBUTES //Get an array with children of the section $childrenids = $this->getChildren($section_info); $hasChildren = array(); foreach ($childrenids as $child) { $hasChildren[] = Intuitel::getIDFactory()->getLoIdfromId('module', $child); } $LOsection->sethasChildren($hasChildren); //Get the following not empty section $followingSibId = $this->getFollowingSib($section_info); if ($followingSibId == null) { $hasfollowingSib = null; } else { $hasfollowingSib = Intuitel::getIDFactory()->getLoIdfromId('section', $followingSibId); } $LOsection->sethasFollowingsib($hasfollowingSib); $lang = $this->getLang($section_info); $LOsection->setLang($lang); } return $LOsection; }
/** * get_activity_tree :: course_modinfo -> integer -> context -> array * @param \course_modinfo $modinfo * @param integer $section_number * @param \context $context * @return array */ function get_activity_tree(\course_modinfo $modinfo, $section_number, \context $context) { $completion_info = new \completion_info($modinfo->get_course()); return F\map(F\filter($modinfo->get_section_info_all(), function (\section_info $section_info) { return $section_info->visible; }), function (\section_info $section_info) use($completion_info, $section_number, $context) { $mods = F\map(F\filter($section_info->modinfo->cms, function (\cm_info $cm_info) use($section_info) { global $CFG; return ($cm_info->uservisible || $CFG->enableavailability && !empty($cm_info->availableinfo)) && (int) $cm_info->sectionnum === (int) $section_info->section; }), function (\cm_info $cm_info) use($completion_info, $context) { global $CFG; $canComplete = $CFG->enablecompletion && isloggedin() && !isguestuser() && (int) $completion_info->is_enabled($cm_info) === COMPLETION_TRACKING_MANUAL; $hasCompleted = false; if ($canComplete) { $completion_data = $completion_info->get_data($cm_info, true); $hasCompleted = F\contains([COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS], (int) $completion_data->completionstate); } return (object) ['id' => (int) $cm_info->id, 'name' => $cm_info->name, 'modname' => $cm_info->modname, 'current' => is_current_mod($cm_info, $context), 'available' => $cm_info->available, 'canComplete' => $canComplete, 'hasCompleted' => $hasCompleted]; }); return (object) ['id' => (int) $section_info->id, 'section' => (int) $section_info->section, 'name' => \get_section_name($section_info->modinfo->courseid, $section_info->section), 'current' => is_current_section($section_info, $section_number, $context), 'activities' => array_values($mods)]; }); }
$strsectionname = get_string('sectionname', 'format_' . $course->format); $table->head = array($strsectionname, $strname, $strintro); $table->align = array('center', 'left', 'left'); } else { $table->head = array($strlastmodified, $strname, $strintro); $table->align = array('left', 'left', 'left'); } $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($books as $book) { $cm = $modinfo->get_cm($book->coursemodule); if ($usesections) { $printsection = ''; if ($book->section !== $currentsection) { if ($book->section) { $printsection = get_section_name($course, $book->section); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $book->section; } } else { $printsection = html_writer::tag('span', userdate($book->timemodified), array('class' => 'smallinfo')); } $class = $book->visible ? null : array('class' => 'dimmed'); // hidden modules are dimmed $table->data[] = array($printsection, html_writer::link(new moodle_url('view.php', array('id' => $cm->id)), format_string($book->name), $class), format_module_intro('book', $book, $cm->id)); } echo html_writer::table($table); echo $OUTPUT->footer();
function definition() { global $CFG, $COURSE, $USER; $mform =& $this->_form; $context = context_course::instance($COURSE->id); $modinfo = get_fast_modinfo($COURSE); $sections = get_all_sections($COURSE->id); $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string $groupoptions = array(); if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { // limited group access $groups = groups_get_user_groups($COURSE->id); $allgroups = groups_get_all_groups($COURSE->id); if (!empty($groups[$COURSE->defaultgroupingid])) { foreach ($groups[$COURSE->defaultgroupingid] as $groupid) { $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context' => $context)); } } } else { $groupoptions = array('0' => get_string('allgroups')); if (has_capability('moodle/site:accessallgroups', $context)) { // user can see all groups $allgroups = groups_get_all_groups($COURSE->id); } else { // user can see course level groups $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid); } foreach ($allgroups as $group) { $groupoptions[$group->id] = format_string($group->name, true, array('context' => $context)); } } if ($COURSE->id == SITEID) { $viewparticipants = has_capability('moodle/site:viewparticipants', context_system::instance()); } else { $viewparticipants = has_capability('moodle/course:viewparticipants', $context); } if ($viewparticipants) { $viewfullnames = has_capability('moodle/site:viewfullnames', context_course::instance($COURSE->id)); $options = array(); $options[0] = get_string('allparticipants'); $options[$CFG->siteguest] = get_string('guestuser'); if (isset($groupoptions[0])) { // can see all enrolled users if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) { foreach ($enrolled as $euser) { $options[$euser->id] = fullname($euser, $viewfullnames); } } } else { // can see users from some groups only foreach ($groupoptions as $groupid => $unused) { if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) { foreach ($enrolled as $euser) { if (!array_key_exists($euser->id, $options)) { $options[$euser->id] = fullname($euser, $viewfullnames); } } } } } $mform->addElement('select', 'user', get_string('participants'), $options); $mform->setAdvanced('user'); } $sectiontitle = get_string('sectionname', 'format_' . $COURSE->format); $options = array('' => get_string('allactivities')); $modsused = array(); foreach ($modinfo->cms as $cm) { if (!$cm->uservisible) { continue; } $modsused[$cm->modname] = true; } foreach ($modsused as $modname => $unused) { $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (!file_exists($libfile)) { unset($modsused[$modname]); continue; } include_once $libfile; $libfunction = $modname . "_get_recent_mod_activity"; if (!function_exists($libfunction)) { unset($modsused[$modname]); continue; } $options["mod/{$modname}"] = get_string('allmods', '', get_string('modulenameplural', $modname)); } foreach ($modinfo->sections as $section => $cmids) { $options["section/{$section}"] = "-- " . get_section_name($COURSE, $sections[$section]) . " --"; foreach ($cmids as $cmid) { $cm = $modinfo->cms[$cmid]; if (empty($modsused[$cm->modname]) or !$cm->uservisible) { continue; } $options[$cm->id] = format_string($cm->name); } } $mform->addElement('select', 'modid', get_string('activities'), $options); $mform->setAdvanced('modid'); if ($groupoptions) { $mform->addElement('select', 'group', get_string('groups'), $groupoptions); $mform->setAdvanced('group'); } else { // no access to groups in separate mode $mform->addElement('hidden', 'group'); $mform->setType('group', PARAM_INT); $mform->setConstants(array('group' => -1)); } $options = array('default' => get_string('bycourseorder'), 'dateasc' => get_string('datemostrecentlast'), 'datedesc' => get_string('datemostrecentfirst')); $mform->addElement('select', 'sortby', get_string('sortby'), $options); $mform->setAdvanced('sortby'); $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional' => true)); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(false, get_string('showrecent')); }
/*$event = \core\event\course_section_updated::create( array( 'objectid' => $data->id, 'courseid' => $course->id, 'context' => $context, 'other' => array('sectionnum' => $data->section) ) ); $event->trigger();*/ require_once $CFG->dirroot . '/calendar/lib.php'; /*if($existentevent = $DB->get_record('event', array('courseid' =>$course->id, 'instance' => $data->section))){ $event->id = $existentevent->id; $DB->update_record('event', $event); }else{ calendar_event::create($event); }*/ $PAGE->navigation->clear_cache(); redirect(course_get_url($course, $section, array('sr' => $sectionreturn))); } } // The edit form is displayed for the first time or if there was validation error on the previous step. $sectionname = get_section_name($course, $sectionnum); $stredit = get_string('edita', '', " {$sectionname}"); $strsummaryof = get_string('summaryof', '', " {$sectionname}"); $PAGE->set_title($stredit); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($stredit); echo $OUTPUT->header(); echo $OUTPUT->heading($strsummaryof); $mform->display(); echo $OUTPUT->footer();
$PAGE->requires->string_for_js('completion-title-manual-n', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion'); $PAGE->requires->js_init_call('M.core_completion.init'); } // We are currently keeping the button here from 1.x to help new teachers figure out // what to do, even though the link also appears in the course admin block. It also // means you can back out of a situation where you removed the admin block. :) if ($PAGE->user_allowed_editing()) { $buttons = $OUTPUT->edit_button($PAGE->url); $PAGE->set_button($buttons); } // If viewing a section, make the title more specific if ($section and $section > 0 and course_format_uses_sections($course->format)) { $sectionname = get_string('sectionname', "format_{$course->format}"); $sectiontitle = get_section_name($course, $section); $PAGE->set_title(get_string('coursesectiontitle', 'moodle', array('course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname))); } else { $PAGE->set_title(get_string('coursetitle', 'moodle', array('course' => $course->fullname))); } $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); if ($completion->is_enabled()) { // This value tracks whether there has been a dynamic change to the page. // It is used so that if a user does this - (a) set some tickmarks, (b) // go to another page, (c) clicks Back button - the page will // automatically reload. Otherwise it would start with the wrong tick // values. echo html_writer::start_tag('form', array('action' => '.', 'method' => 'get')); echo html_writer::start_tag('div'); echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'completion_dynamic_change', 'name' => 'completion_dynamic_change', 'value' => '0'));
} require_login($course->id); // needed to setup proper $COURSE $form->section = $section; // The section number itself $form->course = $course->id; $form->module = $module->id; $form->modulename = $module->name; $form->instance = ""; $form->coursemodule = ""; $form->mode = "add"; $form->sesskey = !empty($USER->id) ? $USER->sesskey : ''; if (!empty($type)) { $form->type = $type; } $sectionname = get_section_name($course->format); $fullmodulename = get_string("modulename", $module->name); if ($form->section && $course->format != 'site') { $heading->what = $fullmodulename; $heading->to = "{$sectionname} {$form->section}"; $pageheading = get_string("addinganewto", "moodle", $heading); } else { $pageheading = get_string("addinganew", "moodle", $fullmodulename); } $strnav = ''; $CFG->pagepath = 'mod/' . $module->name; if (!empty($type)) { $CFG->pagepath .= '/' . $type; } else { $CFG->pagepath .= '/mod'; }
/** * Get course contents * * @param int $courseid course id * @param array $options These options are not used yet, might be used in later version * @return array * @since Moodle 2.2 */ public static function get_course_contents($courseid, $options = array()) { global $CFG, $DB; require_once($CFG->dirroot . "/course/lib.php"); //validate parameter $params = self::validate_parameters(self::get_course_contents_parameters(), array('courseid' => $courseid, 'options' => $options)); //retrieve the course $course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST); //check course format exist if (!file_exists($CFG->dirroot . '/course/format/' . $course->format . '/lib.php')) { throw new moodle_exception('cannotgetcoursecontents', 'webservice', '', null, get_string('courseformatnotfound', 'error', '', $course->format)); } else { require_once($CFG->dirroot . '/course/format/' . $course->format . '/lib.php'); } // now security checks $context = context_course::instance($course->id, IGNORE_MISSING); try { self::validate_context($context); } catch (Exception $e) { $exceptionparam = new stdClass(); $exceptionparam->message = $e->getMessage(); $exceptionparam->courseid = $course->id; throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam); } $canupdatecourse = has_capability('moodle/course:update', $context); //create return value $coursecontents = array(); if ($canupdatecourse or $course->visible or has_capability('moodle/course:viewhiddencourses', $context)) { //retrieve sections $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); //for each sections (first displayed to last displayed) $modinfosections = $modinfo->get_sections(); foreach ($sections as $key => $section) { if (!$section->uservisible) { continue; } // reset $sectioncontents $sectionvalues = array(); $sectionvalues['id'] = $section->id; $sectionvalues['name'] = get_section_name($course, $section); $sectionvalues['visible'] = $section->visible; list($sectionvalues['summary'], $sectionvalues['summaryformat']) = external_format_text($section->summary, $section->summaryformat, $context->id, 'course', 'section', $section->id); $sectioncontents = array(); //for each module of the section if (!empty($modinfosections[$section->section])) { foreach ($modinfosections[$section->section] as $cmid) { $cm = $modinfo->cms[$cmid]; // stop here if the module is not visible to the user if (!$cm->uservisible) { continue; } $module = array(); //common info (for people being able to see the module or availability dates) $module['id'] = $cm->id; $module['name'] = format_string($cm->name, true); $module['modname'] = $cm->modname; $module['modplural'] = $cm->modplural; $module['modicon'] = $cm->get_icon_url()->out(false); $module['indent'] = $cm->indent; $modcontext = context_module::instance($cm->id); if (!empty($cm->showdescription) or $cm->modname == 'label') { // We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML. list($module['description'], $descriptionformat) = external_format_text($cm->content, FORMAT_HTML, $modcontext->id, $cm->modname, 'intro', $cm->id); } //url of the module $url = $cm->url; if ($url) { //labels don't have url $module['url'] = $url->out(false); } $canviewhidden = has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id)); //user that can view hidden module should know about the visibility $module['visible'] = $cm->visible; //availability date (also send to user who can see hidden module when the showavailabilyt is ON) if ($canupdatecourse or ($CFG->enableavailability && $canviewhidden && $cm->showavailability)) { $module['availablefrom'] = $cm->availablefrom; $module['availableuntil'] = $cm->availableuntil; } $baseurl = 'webservice/pluginfile.php'; //call $modulename_export_contents //(each module callback take care about checking the capabilities) require_once($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'); $getcontentfunction = $cm->modname.'_export_contents'; if (function_exists($getcontentfunction)) { if ($contents = $getcontentfunction($cm, $baseurl)) { $module['contents'] = $contents; } } //assign result to $sectioncontents $sectioncontents[] = $module; } } $sectionvalues['modules'] = $sectioncontents; // assign result to $coursecontents $coursecontents[] = $sectionvalues; } } return $coursecontents; }
//Show normal if the mod is visible $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>"; } $cm = get_coursemodule_from_instance('lesson', $lesson->id); $context = context_module::instance($cm->id); if ($lesson->deadline == 0) { $due = $strnodeadline; } else if ($lesson->deadline > $timenow) { $due = userdate($lesson->deadline); } else { $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>"; } if ($usesections) { if (has_capability('mod/lesson:manage', $context)) { $grade_value = $lesson->grade; } else { // it's a student, show their grade $grade_value = 0; if ($return = lesson_get_user_grades($lesson, $USER->id)) { $grade_value = $return[$USER->id]->rawgrade; } } $table->data[] = array (get_section_name($course, $sections[$lesson->section]), $link, $grade_value, $due); } else { $table->data[] = array ($link, $lesson->grade, $due); } } echo html_writer::table($table); echo $OUTPUT->footer();
if ($usesections) { $table->head = array($strsectionname, $strname, $strintro); $table->align = array('center', 'left', 'left'); } else { $table->head = array($strlastmodified, $strname, $strintro); $table->align = array('left', 'left', 'left'); } $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($folders as $folder) { $cm = $modinfo->cms[$folder->coursemodule]; if ($usesections) { $printsection = ''; if ($folder->section !== $currentsection) { if ($folder->section) { $printsection = get_section_name($course, $folder->section); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $folder->section; } } else { $printsection = '<span class="smallinfo">' . userdate($folder->timemodified) . "</span>"; } $class = $folder->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed $table->data[] = array($printsection, "<a {$class} href=\"view.php?id={$cm->id}\">" . format_string($folder->name) . "</a>", format_module_intro('folder', $folder, $cm->id)); } echo html_writer::table($table); echo $OUTPUT->footer();
/** * Renders HTML for the menus to add activities and resources to the current course * * Note, if theme overwrites this function and it does not use modchooser, * see also {@link core_course_renderer::add_modchoosertoggle()} * * @param stdClass $course * @param int $section relative section number (field course_sections.section) * @param int $sectionreturn The section to link back to * @param array $displayoptions additional display options, for example blocks add * option 'inblock' => true, suggesting to display controls vertically * @return string */ function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) { global $CFG; $vertical = !empty($displayoptions['inblock']); // check to see if user can add menus and there are modules to add if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id)) || !$this->page->user_is_editing() || !($modnames = get_module_types_names()) || empty($modnames)) { return ''; } // Retrieve all modules with associated metadata $modules = get_module_metadata($course, $modnames, $sectionreturn); $urlparams = array('section' => $section); // We'll sort resources and activities into two lists $activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array()); foreach ($modules as $module) { if (isset($module->types)) { // This module has a subtype // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!! $subtypes = array(); foreach ($module->types as $subtype) { $link = $subtype->link->out(true, $urlparams); $subtypes[$link] = $subtype->title; } // Sort module subtypes into the list $activityclass = MOD_CLASS_ACTIVITY; if ($module->archetype == MOD_CLASS_RESOURCE) { $activityclass = MOD_CLASS_RESOURCE; } if (!empty($module->title)) { // This grouping has a name $activities[$activityclass][] = array($module->title => $subtypes); } else { // This grouping does not have a name $activities[$activityclass] = array_merge($activities[$activityclass], $subtypes); } } else { // This module has no subtypes $activityclass = MOD_CLASS_ACTIVITY; if ($module->archetype == MOD_ARCHETYPE_RESOURCE) { $activityclass = MOD_CLASS_RESOURCE; } else { if ($module->archetype === MOD_ARCHETYPE_SYSTEM) { // System modules cannot be added by user, do not add to dropdown continue; } } $link = $module->link->out(true, $urlparams); $activities[$activityclass][$link] = $module->title; } } $straddactivity = get_string('addactivity'); $straddresource = get_string('addresource'); $sectionname = get_section_name($course, $section); $strresourcelabel = get_string('addresourcetosection', null, $sectionname); $stractivitylabel = get_string('addactivitytosection', null, $sectionname); $output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section)); if (!$vertical) { $output .= html_writer::start_tag('div', array('class' => 'horizontal')); } if (!empty($activities[MOD_CLASS_RESOURCE])) { $select = new url_select($activities[MOD_CLASS_RESOURCE], '', array('' => $straddresource), "ressection{$section}"); $select->set_help_icon('resources'); $select->set_label($strresourcelabel, array('class' => 'accesshide')); $output .= $this->output->render($select); } if (!empty($activities[MOD_CLASS_ACTIVITY])) { $select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array('' => $straddactivity), "section{$section}"); $select->set_help_icon('activities'); $select->set_label($stractivitylabel, array('class' => 'accesshide')); $output .= $this->output->render($select); } if (!$vertical) { $output .= html_writer::end_tag('div'); } $output .= html_writer::end_tag('div'); if (course_ajax_enabled($course) && $course->id == $this->page->course->id) { // modchooser can be added only for the current course set on the page! $straddeither = get_string('addresourceoractivity'); // The module chooser link $modchooser = html_writer::start_tag('div', array('class' => 'mdl-right')); $modchooser .= html_writer::start_tag('div', array('class' => 'section-modchooser')); $icon = $this->output->pix_icon('t/add', ''); $span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text')); $modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link')); $modchooser .= html_writer::end_tag('div'); $modchooser .= html_writer::end_tag('div'); // Wrap the normal output in a noscript div $usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault); if ($usemodchooser) { $output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown')); $modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser')); } else { // If the module chooser is disabled, we need to ensure that the dropdowns are shown even if javascript is disabled $output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown')); $modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser')); } $output = $this->course_modchooser($modules, $course) . $modchooser . $output; } return $output; }
$timenow = time(); $strsectionname = get_string('sectionname', 'format_' . $course->format); $strname = get_string("name"); $table = new html_table(); if ($usesections) { $table->head = array($strsectionname, $strname); } else { $table->head = array($strname); } foreach ($wikis as $wiki) { $linkcss = null; if (!$wiki->visible) { $linkcss = array('class' => 'dimmed'); } $link = html_writer::link(new moodle_url('/mod/wiki/view.php', array('id' => $wiki->coursemodule)), $wiki->name, $linkcss); if ($usesections) { $table->data[] = array(get_section_name($course, $wiki->section), $link); } else { $table->data[] = array($link); } } echo html_writer::table($table); /// Finish the page echo $OUTPUT->footer();
private static function get_section_name_from_item($item, $fast = false) { if (isset(self::$coursesections[$item->sectionid])) { $section = self::$coursesections[$item->sectionid]; $section_name = $section->sectionname; } else { $section = new stdclass(); $section->course = $item->courseid; $section->section = $item->section; $section->id = $item->sectionid; if ($fast) { $section_name = get_string('sectionname', 'format_' . $item->format) . ' ' . $item->section; } else { $section_name = get_section_name($item->courseid, $section); } $section->sectionname = $section_name; self::$coursesections[$item->sectionid] = $section; } return $section_name; }
$strsectionname = get_string('sectionname', 'format_' . $course->format); $table->head = array($strsectionname, $strname, $strintro); $table->align = array('center', 'left', 'left'); } else { $table->head = array($strlastmodified, $strname, $strintro); $table->align = array('left', 'left', 'left'); } $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($pages as $page) { $cm = $modinfo->cms[$page->coursemodule]; if ($usesections) { $printsection = ''; if ($page->section !== $currentsection) { if ($page->section) { $printsection = get_section_name($course, $page->section); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $page->section; } } else { $printsection = '<span class="smallinfo">' . userdate($page->timemodified) . "</span>"; } $class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed $table->data[] = array($printsection, "<a {$class} href=\"view.php?id={$cm->id}\">" . format_string($page->name) . "</a>", format_module_intro('page', $page, $cm->id)); } echo html_writer::table($table); echo $OUTPUT->footer();
/** * Adds a section to navigation node, loads modules and subsections if necessary * * @param global_navigation $navigation * @param navigation_node $node * @param section_info $section * @return null|navigation_node */ protected function navigation_add_section($navigation, navigation_node $node, $section) { if (!$section->uservisible || !$this->is_section_real_available($section)) { return null; } $sectionname = get_section_name($this->get_course(), $section); $url = course_get_url($this->get_course(), $section->section, array('navigation' => true)); $sectionnode = $node->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id); $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH; $sectionnode->hidden = !$section->visible || !$section->available; if ($section->section == $this->get_viewed_section()) { $sectionnode->force_open(); } if ($this->section_has_parent($navigation->includesectionnum, $section->section) || $navigation->includesectionnum == $section->section) { $modinfo = get_fast_modinfo($this->courseid); if (!empty($modinfo->sections[$section->section])) { foreach ($modinfo->sections[$section->section] as $cmid) { $this->navigation_add_activity($sectionnode, $modinfo->get_cm($cmid)); } } foreach ($modinfo->get_section_info_all() as $subsection) { if ($subsection->parent == $section->section && $subsection->section != 0) { $this->navigation_add_section($navigation, $sectionnode, $subsection); } } } return $sectionnode; }
$table->align = array('center', 'left', 'left'); } else { $table->head = array($strlastmodified, $strname, $strintro); $table->align = array('left', 'left', 'left'); } $currentsection = ''; foreach ($cms as $cm) { if (!isset($resources[$cm->modname][$cm->instance])) { continue; } $resource = $resources[$cm->modname][$cm->instance]; if ($usesections) { $printsection = ''; if ($cm->sectionnum !== $currentsection) { if ($cm->sectionnum) { $printsection = get_section_name($course, $sections[$cm->sectionnum]); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $cm->sectionnum; } } else { $printsection = '<span class="smallinfo">' . userdate($resource->timemodified) . "</span>"; } $extra = empty($cm->extra) ? '' : $cm->extra; if (!empty($cm->icon)) { $icon = '<img src="' . $OUTPUT->pix_url($cm->icon) . '" class="activityicon" alt="' . get_string('modulename', $cm->modname) . '" /> '; } else { $icon = '<img src="' . $OUTPUT->pix_url('icon', $cm->modname) . '" class="activityicon" alt="' . get_string('modulename', $cm->modname) . '" /> '; }
/** * View a summary listing of all assignments in the current course. * * @return string */ private function view_course_index() { global $USER; $o = ''; $course = $this->get_course(); $strplural = get_string('modulenameplural', 'assign'); if (!($cms = get_coursemodules_in_course('assign', $course->id, 'm.duedate'))) { $o .= $this->get_renderer()->notification(get_string('thereareno', 'moodle', $strplural)); $o .= $this->get_renderer()->continue_button(new moodle_url('/course/view.php', array('id' => $course->id))); return $o; } $strsectionname = ''; $usesections = course_format_uses_sections($course->format); $modinfo = get_fast_modinfo($course); if ($usesections) { $strsectionname = get_string('sectionname', 'format_' . $course->format); $sections = $modinfo->get_section_info_all(); } $courseindexsummary = new assign_course_index_summary($usesections, $strsectionname); $timenow = time(); $currentsection = ''; foreach ($modinfo->instances['assign'] as $cm) { if (!$cm->uservisible) { continue; } $timedue = $cms[$cm->id]->duedate; $sectionname = ''; if ($usesections && $cm->sectionnum) { $sectionname = get_section_name($course, $sections[$cm->sectionnum]); } $submitted = ''; $context = context_module::instance($cm->id); $assignment = new assign($context, $cm, $course); if (has_capability('mod/assign:grade', $context)) { $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED); } else { if (has_capability('mod/assign:submit', $context)) { $usersubmission = $assignment->get_user_submission($USER->id, false); if (!empty($usersubmission->status)) { $submitted = get_string('submissionstatus_' . $usersubmission->status, 'assign'); } else { $submitted = get_string('submissionstatus_', 'assign'); } } } $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id); if (isset($gradinginfo->items[0]->grades[$USER->id]) && !$gradinginfo->items[0]->grades[$USER->id]->hidden) { $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade; } else { $grade = '-'; } $courseindexsummary->add_assign_info($cm->id, $cm->name, $sectionname, $timedue, $submitted, $grade); } $o .= $this->get_renderer()->render($courseindexsummary); $o .= $this->view_footer(); return $o; }
exit; } $table = new html_table(); if ($usesections) { $table->head = array($strsectionname, $strname, $strsummary, $strreport); $table->align = array("center", "left", "left", "left"); } else { $table->head = array($strlastmodified, $strname, $strsummary, $strreport); $table->align = array("left", "left", "left", "left"); } foreach ($scorms as $scorm) { $context = get_context_instance(CONTEXT_MODULE, $scorm->coursemodule); $tt = ""; if ($usesections) { if ($scorm->section) { $tt = get_section_name($course, $sections[$scorm->section]); } } else { $tt = userdate($scorm->timemodified); } $report = ' '; $reportshow = ' '; if (has_capability('mod/scorm:viewreport', $context)) { $trackedusers = scorm_get_count_users($scorm->id, $scorm->groupingid); if ($trackedusers > 0) { $reportshow = '<a href="report.php?id=' . $scorm->coursemodule . '">' . get_string('viewallreports', 'scorm', $trackedusers) . '</a></div>'; } else { $reportshow = get_string('noreports', 'scorm'); } } else { if (has_capability('mod/scorm:viewscores', $context)) {
/** * Generically loads the course sections into the course's navigation. * * @param stdClass $course * @param navigation_node $coursenode * @return array An array of course section nodes */ public function load_generic_course_sections(stdClass $course, navigation_node $coursenode) { global $CFG, $DB, $USER, $SITE; require_once $CFG->dirroot . '/course/lib.php'; list($sections, $activities) = $this->generate_sections_and_activities($course); $navigationsections = array(); foreach ($sections as $sectionid => $section) { $section = clone $section; if ($course->id == $SITE->id) { $this->load_section_activities($coursenode, $section->section, $activities); } else { if (!$section->uservisible || !$this->showemptysections && !$section->hasactivites && $this->includesectionnum !== $section->section) { continue; } $sectionname = get_section_name($course, $section); $url = course_get_url($course, $section->section, array('navigation' => true)); $sectionnode = $coursenode->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id); $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH; $sectionnode->hidden = !$section->visible || !$section->available; if ($this->includesectionnum !== false && $this->includesectionnum == $section->section) { $this->load_section_activities($sectionnode, $section->section, $activities); } $section->sectionnode = $sectionnode; $navigationsections[$sectionid] = $section; } } return $navigationsections; }
} $table = new html_table(); if ($usesections) { $strsectionname = get_string('sectionname', 'format_' . $course->format); $table->head = array($strsectionname, $strname, $strsummary, $strreport); $table->align = array("center", "left", "left", "left"); } else { $table->head = array($strlastmodified, $strname, $strsummary, $strreport); $table->align = array("left", "left", "left", "left"); } foreach ($scorms as $scorm) { $context = context_module::instance($scorm->coursemodule); $tt = ""; if ($usesections) { if ($scorm->section) { $tt = get_section_name($course, $scorm->section); } } else { $tt = userdate($scorm->timemodified); } $report = ' '; $reportshow = ' '; if (has_capability('mod/scorm:viewreport', $context)) { $trackedusers = scorm_get_count_users($scorm->id, $scorm->groupingid); if ($trackedusers > 0) { $reportshow = html_writer::link('report.php?id=' . $scorm->coursemodule, get_string('viewallreports', 'scorm', $trackedusers)); } else { $reportshow = get_string('noreports', 'scorm'); } } else { if (has_capability('mod/scorm:viewscores', $context)) {
$table->head = array($strname); $table->align = array('left'); } $currentsection = ''; foreach ($chats as $chat) { if (!$chat->visible) { //Show dimmed if the mod is hidden $link = "<a class=\"dimmed\" href=\"view.php?id={$chat->coursemodule}\">" . format_string($chat->name, true) . "</a>"; } else { //Show normal if the mod is visible $link = "<a href=\"view.php?id={$chat->coursemodule}\">" . format_string($chat->name, true) . "</a>"; } $printsection = ''; if ($chat->section !== $currentsection) { if ($chat->section) { $printsection = get_section_name($course, $chat->section); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $chat->section; } if ($usesections) { $table->data[] = array($printsection, $link); } else { $table->data[] = array($link); } } echo '<br />'; echo html_writer::table($table); /// Finish the page
/** * @see lib/moodleform#definition() */ public function definition() { global $CFG, $COURSE, $DB, $PAGE; $mform = $this->_form; $modinfo = $this->_customdata['modinfo']; $course = $this->_customdata['course']; $activitytype = $this->_customdata['activitytype']; $coursehasavailability = !empty($CFG->enableavailability); $coursehascompletion = !empty($CFG->enablecompletion) && !empty($course->enablecompletion); // Context instance of the course. $coursecontext = context_course::instance($course->id); // Store current activity type. $mform->addElement('hidden', 'activitytype', $activitytype); $mform->setType('activitytype', PARAM_PLUGIN); // Add action button to the top of the form. $addactionbuttons = false; $this->add_action_buttons(); // Course start date. $mform->addElement('header', 'coursestartdateheader', get_string('coursestartdateheader', 'report_editdates')); $mform->setExpanded('coursestartdateheader', false); $mform->addElement('date_selector', 'coursestartdate', get_string('startdate')); $mform->addHelpButton('coursestartdate', 'startdate'); $mform->setDefault('coursestartdate', $course->startdate); // If user is not capable, make it read only. if (!has_capability('moodle/course:update', $coursecontext)) { $mform->hardFreeze('coursestartdate'); } else { $addactionbuttons = true; } // Var to count the number of elements in the course/sections. // It will be used to decide whether to show save action button // at the bottom of the form page. $elementadded = 0; // Default -1 to display header for 0th section. $prevsectionnum = -1; // Cycle through all the sections in the course. $cms = $modinfo->get_cms(); $sections = $modinfo->get_section_info_all(); foreach ($sections as $sectionnum => $section) { $ismodadded = false; $sectionname = ''; // Skip if section isn't visible to the user. if (!$section->uservisible) { continue; } // New section, create header. if ($prevsectionnum != $sectionnum) { $sectionname = get_section_name($course, $section); $headername = 'section' . $sectionnum . 'header'; $mform->addElement('header', $headername, $sectionname); $mform->setExpanded($headername, false); $prevsectionnum = $sectionnum; } if ($coursehasavailability && $section->availability) { // If there are retricted access date settings. if (strpos($section->availability, '"type":"date"') !== false) { $editsettingurl = new moodle_url('/course/editsection.php', array('id' => $section->id)); $editsettingurltext = html_writer::tag('a', get_string('editrestrictedaccess', 'report_editdates'), array('href' => $editsettingurl->out(false), 'target' => '_blank')); $mform->addElement('static', '', get_string('sectionhasrestrictedaccess', 'report_editdates', get_section_name($course, $section)), $editsettingurltext); } } // Cycle through each module in a section. if (isset($modinfo->sections[$sectionnum])) { foreach ($modinfo->sections[$sectionnum] as $cmid) { $cm = $cms[$cmid]; // No need to display/continue if this module is not visible to user. if (!$cm->uservisible) { continue; } // If activity filter is on, then filter module by activity type. if ($activitytype && $cm->modname != $activitytype) { continue; } // Check if the user has capability to edit this module settings. $modulecontext = context_module::instance($cm->id); $ismodreadonly = !has_capability('moodle/course:manageactivities', $modulecontext); // Display activity name. $iconmarkup = html_writer::empty_tag('img', array('src' => $cm->get_icon_url(), 'class' => 'activityicon', 'alt' => '')); $stractivityname = html_writer::tag('strong', $iconmarkup . $cm->name); $mform->addElement('static', 'modname' . $cm->id, $stractivityname); $isdateadded = false; // Call get_settings method for the acitivity/module. // Get instance of the mod's date exractor class. $mod = report_editdates_mod_date_extractor::make($cm->modname, $course); if ($mod && ($cmdatesettings = $mod->get_settings($cm))) { // Added activity name on the form. foreach ($cmdatesettings as $cmdatetype => $cmdatesetting) { $elname = 'date_mod_' . $cm->id . '_' . $cmdatetype; $mform->addElement($cmdatesetting->type, $elname, $cmdatesetting->label, array('optional' => $cmdatesetting->isoptional, 'step' => $cmdatesetting->getstep)); $mform->setDefault($elname, $cmdatesetting->currentvalue); if ($ismodreadonly) { $mform->hardFreeze($elname); } $elementadded++; $isdateadded = true; } } if ($coursehasavailability && $cm->availability) { // If there are retricted access date settings. if (strpos($cm->availability, '"type":"date"') !== false) { $editsettingurl = new moodle_url('/course/modedit.php', array('update' => $cm->id)); $editsettingurltext = html_writer::tag('a', get_string('editrestrictedaccess', 'report_editdates'), array('href' => $editsettingurl->out(false), 'target' => '_blank')); $mform->addElement('static', '', get_string('hasrestrictedaccess', 'report_editdates', $cm->name), $editsettingurltext); } } // Completion tracking. if ($coursehascompletion && $cm->completion) { $elname = 'date_mod_' . $cm->id . '_completionexpected'; $mform->addElement('date_selector', $elname, get_string('completionexpected', 'completion'), array('optional' => true)); $mform->addHelpButton($elname, 'completionexpected', 'completion'); $mform->setDefault($elname, $cm->completionexpected); if ($ismodreadonly) { $mform->hardFreeze($elname); } $elementadded++; $isdateadded = true; } if ($isdateadded) { $ismodadded = true; $addactionbuttons = true; } else { $mform->removeElement('modname' . $cm->id); } } // End of modules loop. if (!$ismodadded && $mform->elementExists($sectionname)) { $mform->removeElement($sectionname); } } } // End of sections loop. // Fetching all the blocks added directly under the course. // That is, parentcontextid = coursecontextid. $courseblocks = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id)); // Check capability of current user. $canmanagesiteblocks = has_capability('moodle/site:manageblocks', $coursecontext); $anyblockadded = false; if ($courseblocks) { // Header for blocks. $mform->addElement('header', 'blockdatesection'); // Iterate though blocks array. foreach ($courseblocks as $blockid => $block) { $blockdatextrator = report_editdates_block_date_extractor::make($block->blockname, $course); if ($blockdatextrator) { // Create the block instance. $blockobj = block_instance($block->blockname, $block, $PAGE); // If get_settings returns a valid array. if ($blockdatesettings = $blockdatextrator->get_settings($blockobj)) { $anyblockadded = true; $addactionbuttons = true; // Adding block's Title on page. $mform->addElement('static', 'blocktitle', $blockobj->title); foreach ($blockdatesettings as $blockdatetype => $blockdatesetting) { $elname = 'date_block_' . $block->id . '_' . $blockdatetype; // Add element. $mform->addElement($blockdatesetting->type, $elname, $blockdatesetting->label, array('optional' => $blockdatesetting->isoptional, 'step' => $blockdatesetting->getstep)); $mform->setDefault($elname, $blockdatesetting->currentvalue); if (!$canmanagesiteblocks || !$blockobj->user_can_edit()) { $mform->hardFreeze($elname); } $elementadded++; } } } } } if (!$anyblockadded && $mform->elementExists('blockdatesection')) { $mform->removeElement('blockdatesection'); } // Adding submit/cancel buttons @ the end of the form. if ($addactionbuttons && $elementadded > 0) { $this->add_action_buttons(); } else { // Remove top action button. $mform->removeElement('buttonar'); } }
if ($forum->trackingtype === FORUM_TRACKING_OFF || $USER->trackforums == 0) { $trackedlink = '-'; } else { $aurl = new moodle_url('/mod/forum/settracking.php', array('id' => $forum->id)); if (!isset($untracked[$forum->id])) { $trackedlink = $OUTPUT->single_button($aurl, $stryes, 'post', array('title' => $strnotrackforum)); } else { $trackedlink = $OUTPUT->single_button($aurl, $strno, 'post', array('title' => $strtrackforum)); } } } } } $forum->intro = shorten_text(format_module_intro('forum', $forum, $cm->id), $CFG->forum_shortpost); if ($cm->sectionnum != $currentsection) { $printsection = get_section_name($course, $cm->sectionnum); if ($currentsection) { $learningtable->data[] = 'hr'; } $currentsection = $cm->sectionnum; } else { $printsection = ''; } $forumname = format_string($forum->name, true); if ($cm->visible) { $style = ''; } else { $style = 'class="dimmed"'; } $forumlink = "<a href=\"view.php?f={$forum->id}\" {$style}>" . format_string($forum->name, true) . "</a>"; $discussionlink = "<a href=\"view.php?f={$forum->id}\" {$style}>" . $count . "</a>";
/** * Get course contents * * @param int $courseid course id * @param array $options Options for filtering the results, used since Moodle 2.9 * @return array * @since Moodle 2.9 Options available * @since Moodle 2.2 */ public static function get_course_contents($courseid, $options = array()) { global $CFG, $DB; require_once $CFG->dirroot . "/course/lib.php"; //validate parameter $params = self::validate_parameters(self::get_course_contents_parameters(), array('courseid' => $courseid, 'options' => $options)); $filters = array(); if (!empty($params['options'])) { foreach ($params['options'] as $option) { $name = trim($option['name']); // Avoid duplicated options. if (!isset($filters[$name])) { switch ($name) { case 'excludemodules': case 'excludecontents': $value = clean_param($option['value'], PARAM_BOOL); $filters[$name] = $value; break; case 'sectionid': case 'sectionnumber': case 'cmid': case 'modid': $value = clean_param($option['value'], PARAM_INT); if (is_numeric($value)) { $filters[$name] = $value; } else { throw new moodle_exception('errorinvalidparam', 'webservice', '', $name); } break; case 'modname': $value = clean_param($option['value'], PARAM_PLUGIN); if ($value) { $filters[$name] = $value; } else { throw new moodle_exception('errorinvalidparam', 'webservice', '', $name); } break; default: throw new moodle_exception('errorinvalidparam', 'webservice', '', $name); } } } } //retrieve the course $course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST); if ($course->id != SITEID) { // Check course format exist. if (!file_exists($CFG->dirroot . '/course/format/' . $course->format . '/lib.php')) { throw new moodle_exception('cannotgetcoursecontents', 'webservice', '', null, get_string('courseformatnotfound', 'error', $course->format)); } else { require_once $CFG->dirroot . '/course/format/' . $course->format . '/lib.php'; } } // now security checks $context = context_course::instance($course->id, IGNORE_MISSING); try { self::validate_context($context); } catch (Exception $e) { $exceptionparam = new stdClass(); $exceptionparam->message = $e->getMessage(); $exceptionparam->courseid = $course->id; throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam); } $canupdatecourse = has_capability('moodle/course:update', $context); //create return value $coursecontents = array(); if ($canupdatecourse or $course->visible or has_capability('moodle/course:viewhiddencourses', $context)) { //retrieve sections $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); //for each sections (first displayed to last displayed) $modinfosections = $modinfo->get_sections(); foreach ($sections as $key => $section) { if (!$section->uservisible) { continue; } // This becomes true when we are filtering and we found the value to filter with. $sectionfound = false; // Filter by section id. if (!empty($filters['sectionid'])) { if ($section->id != $filters['sectionid']) { continue; } else { $sectionfound = true; } } // Filter by section number. Note that 0 is a valid section number. if (isset($filters['sectionnumber'])) { if ($key != $filters['sectionnumber']) { continue; } else { $sectionfound = true; } } // reset $sectioncontents $sectionvalues = array(); $sectionvalues['id'] = $section->id; $sectionvalues['name'] = get_section_name($course, $section); $sectionvalues['visible'] = $section->visible; $options = (object) array('noclean' => true); list($sectionvalues['summary'], $sectionvalues['summaryformat']) = external_format_text($section->summary, $section->summaryformat, $context->id, 'course', 'section', $section->id, $options); $sectionvalues['section'] = $section->section; $sectioncontents = array(); //for each module of the section if (empty($filters['excludemodules']) and !empty($modinfosections[$section->section])) { foreach ($modinfosections[$section->section] as $cmid) { $cm = $modinfo->cms[$cmid]; // stop here if the module is not visible to the user if (!$cm->uservisible) { continue; } // This becomes true when we are filtering and we found the value to filter with. $modfound = false; // Filter by cmid. if (!empty($filters['cmid'])) { if ($cmid != $filters['cmid']) { continue; } else { $modfound = true; } } // Filter by module name and id. if (!empty($filters['modname'])) { if ($cm->modname != $filters['modname']) { continue; } else { if (!empty($filters['modid'])) { if ($cm->instance != $filters['modid']) { continue; } else { // Note that if we are only filtering by modname we don't break the loop. $modfound = true; } } } } $module = array(); $modcontext = context_module::instance($cm->id); //common info (for people being able to see the module or availability dates) $module['id'] = $cm->id; $module['name'] = external_format_string($cm->name, $modcontext->id); $module['instance'] = $cm->instance; $module['modname'] = $cm->modname; $module['modplural'] = $cm->modplural; $module['modicon'] = $cm->get_icon_url()->out(false); $module['indent'] = $cm->indent; if (!empty($cm->showdescription) or $cm->modname == 'label') { // We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML. list($module['description'], $descriptionformat) = external_format_text($cm->content, FORMAT_HTML, $modcontext->id, $cm->modname, 'intro', $cm->id); } //url of the module $url = $cm->url; if ($url) { //labels don't have url $module['url'] = $url->out(false); } $canviewhidden = has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id)); //user that can view hidden module should know about the visibility $module['visible'] = $cm->visible; // Availability date (also send to user who can see hidden module). if ($CFG->enableavailability && ($canviewhidden || $canupdatecourse)) { $module['availability'] = $cm->availability; } $baseurl = 'webservice/pluginfile.php'; //call $modulename_export_contents //(each module callback take care about checking the capabilities) require_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $getcontentfunction = $cm->modname . '_export_contents'; if (function_exists($getcontentfunction)) { if (empty($filters['excludecontents']) and $contents = $getcontentfunction($cm, $baseurl)) { $module['contents'] = $contents; } else { $module['contents'] = array(); } } //assign result to $sectioncontents $sectioncontents[] = $module; // If we just did a filtering, break the loop. if ($modfound) { break; } } } $sectionvalues['modules'] = $sectioncontents; // assign result to $coursecontents $coursecontents[] = $sectionvalues; // Break the loop if we are filtering. if ($sectionfound) { break; } } } return $coursecontents; }
/** * Prepares the templateable object to display section name * * @param \section_info|\stdClass $section * @param bool $linkifneeded * @param bool $editable * @param null|lang_string|string $edithint * @param null|lang_string|string $editlabel * @return \core\output\inplace_editable */ public function inplace_editable_render_section_name($section, $linkifneeded = true, $editable = null, $edithint = null, $editlabel = null) { global $USER, $CFG; require_once $CFG->dirroot . '/course/lib.php'; if ($editable === null) { $editable = !empty($USER->editing) && has_capability('moodle/course:update', context_course::instance($section->course)); } $displayvalue = $title = get_section_name($section->course, $section); if ($linkifneeded) { // Display link under the section name if the course format setting is to display one section per page. $url = course_get_url($section->course, $section->section, array('navigation' => true)); if ($url) { $displayvalue = html_writer::link($url, $title); } $itemtype = 'sectionname'; } else { // If $linkifneeded==false, we never display the link (this is used when rendering the section header). // Itemtype 'sectionnamenl' (nl=no link) will tell the callback that link should not be rendered - // there is no other way callback can know where we display the section name. $itemtype = 'sectionnamenl'; } if (empty($edithint)) { $edithint = new lang_string('editsectionname'); } if (empty($editlabel)) { $editlabel = new lang_string('newsectionname', '', $title); } return new \core\output\inplace_editable('format_' . $this->format, $itemtype, $section->id, $editable, $displayvalue, $section->name, $edithint, $editlabel); }
foreach ($glossarys as $glossary) { if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) { // Show dimmed if the mod is hidden. $link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>"; } else if ($glossary->visible) { // Show normal if the mod is visible. $link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>"; } else { // Don't show the glossary. continue; } $printsection = ""; if ($usesections) { if ($glossary->section !== $currentsection) { if ($glossary->section) { $printsection = get_section_name($course, $sections[$glossary->section]); } if ($currentsection !== "") { $table->data[] = 'hr'; } $currentsection = $glossary->section; } } // TODO: count only approved if not allowed to see them $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id)); //If this glossary has RSS activated, calculate it if ($show_rss) { $rsslink = '';
/** * Adds branches and links to the settings navigation to add course activities * and resources. * * @param stdClass $course */ protected function add_course_editing_links($course) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; // Add `add` resources|activities branches $structurefile = $CFG->dirroot . '/course/format/' . $course->format . '/lib.php'; if (file_exists($structurefile)) { require_once $structurefile; $requestkey = call_user_func('callback_' . $course->format . '_request_key'); $formatidentifier = optional_param($requestkey, 0, PARAM_INT); } else { $requestkey = get_string('section'); $formatidentifier = optional_param($requestkey, 0, PARAM_INT); } $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); $addresource = $this->add(get_string('addresource')); $addactivity = $this->add(get_string('addactivity')); if ($formatidentifier !== 0) { $addresource->force_open(); $addactivity->force_open(); } $this->get_course_modules($course); foreach ($sections as $section) { if ($formatidentifier !== 0 && $section->section != $formatidentifier) { continue; } $sectionurl = new moodle_url('/course/view.php', array('id' => $course->id, $requestkey => $section->section)); if ($section->section == 0) { $sectionresources = $addresource->add(get_string('course'), $sectionurl, self::TYPE_SETTING); $sectionactivities = $addactivity->add(get_string('course'), $sectionurl, self::TYPE_SETTING); } else { $sectionname = get_section_name($course, $section); $sectionresources = $addresource->add($sectionname, $sectionurl, self::TYPE_SETTING); $sectionactivities = $addactivity->add($sectionname, $sectionurl, self::TYPE_SETTING); } foreach ($resources as $value => $resource) { $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section)); $pos = strpos($value, '&type='); if ($pos !== false) { $url->param('add', textlib::substr($value, 0, $pos)); $url->param('type', textlib::substr($value, $pos + 6)); } else { $url->param('add', $value); } $sectionresources->add($resource, $url, self::TYPE_SETTING); } $subbranch = false; foreach ($activities as $activityname => $activity) { if ($activity === '--') { $subbranch = false; continue; } if (strpos($activity, '--') === 0) { $subbranch = $sectionactivities->add(trim($activity, '-')); continue; } $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section)); $pos = strpos($activityname, '&type='); if ($pos !== false) { $url->param('add', textlib::substr($activityname, 0, $pos)); $url->param('type', textlib::substr($activityname, $pos + 6)); } else { $url->param('add', $activityname); } if ($subbranch !== false) { $subbranch->add($activity, $url, self::TYPE_SETTING); } else { $sectionactivities->add($activity, $url, self::TYPE_SETTING); } } } }
/** * Prepares the templateable object to display section name * * @param \section_info|\stdClass $section * @param bool $linkifneeded * @param bool $editable * @param null|lang_string|string $edithint * @param null|lang_string|string $editlabel * @return \core\output\inplace_editable */ public function inplace_editable_render_section_name($section, $linkifneeded = true, $editable = null, $edithint = null, $editlabel = null) { if (empty($edithint)) { $edithint = new lang_string('editsectionname', 'format_topics'); } if (empty($editlabel)) { $title = get_section_name($section->course, $section); $editlabel = new lang_string('newsectionname', 'format_topics', $title); } return parent::inplace_editable_render_section_name($section, $linkifneeded, $editable, $edithint, $editlabel); }