本文整理汇总了PHP中course_modinfo::get_cm方法的典型用法代码示例。如果您正苦于以下问题:PHP course_modinfo::get_cm方法的具体用法?PHP course_modinfo::get_cm怎么用?PHP course_modinfo::get_cm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_modinfo
的用法示例。
在下文中一共展示了course_modinfo::get_cm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render_subpage
/**
* Render contents of main part of subpage
* @param mod_subpage $subpage
* @param course_modinfo $modinfo
* @param array $sections
* @param boolean $editing whether the user is allowed to edit this page
* @param int $moveitem (currently not used)
* @param boolean $movesection whether the user is allowed to move sections
* @return string html for display
*/
public function render_subpage($subpage, $modinfo, $sections, $editing, $moveitem, $movesection)
{
global $PAGE, $OUTPUT, $CFG, $USER;
$this->subpagecm = $subpage->get_course_module()->id;
if (!empty($USER->activitycopy) && $movesection) {
$content = $this->render_cancel_link($this->subpagecm);
} else {
$content = '';
}
$content .= $this->render_intro($subpage);
$streditsummary = get_string('editsummary');
$strdelete = get_string('delete');
if ($editing) {
$strmoveup = get_string('moveup');
$strmovedown = get_string('movedown');
$strhide = get_string('hide');
$strshow = get_string('show');
$strstealth = get_string('stealth', 'subpage');
$strunstealth = get_string('unstealth', 'subpage');
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $subpage->get_course()->id);
get_all_mods($subpage->get_course()->id, $mods, $modnames, $modnamesplural, $modnamesused);
foreach ($mods as $modid => $unused) {
if (!isset($modinfo->cms[$modid])) {
rebuild_course_cache($subpage->get_course()->id);
$modinfo =& get_fast_modinfo($subpage->get_course());
debugging('Rebuilding course cache', DEBUG_DEVELOPER);
break;
}
}
$lastpageorder = $subpage->get_last_section_pageorder();
if ($subpage->get_course()->format == 'weeks') {
$content .= html_writer::start_tag('ul', array('class' => 'weeks'));
} else {
$content .= html_writer::start_tag('ul', array('class' => 'topics'));
}
foreach ($sections as $section) {
// Check to see whether cms within the section are visible or not
// If all cms are not visible then we don't show the section at all,
// unless editing
$visible = false;
if ($section->sequence) {
// get cm_info for this resources
$instances = explode(',', $section->sequence);
} else {
$instances = array();
}
foreach ($instances as $instance) {
$cm = $modinfo->get_cm($instance);
// check to see whether cm is visible
if ($cm->uservisible) {
$visible = true;
break;
}
}
// If section is empty so should be hidden, record that in object
$section->autohide = !$visible;
$content .= html_writer::start_tag('li', array('class' => 'section main clearfix', 'id' => 'section-' . $section->section));
$content .= html_writer::tag('div', ' ', array('class' => 'left side'));
$content .= html_writer::start_tag('div', array('class' => 'right side'));
if ($editing && has_capability('moodle/course:update', $coursecontext)) {
// Show the hide/show eye
if ($section->visible) {
$content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&hide=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strhide));
$content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/hide'), 'class' => 'icon hide', 'alt' => $strhide));
$content .= html_writer::end_tag('a');
} else {
$content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&show=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strshow));
$content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/show'), 'class' => 'icon show', 'alt' => $strshow));
$content .= html_writer::end_tag('a');
}
// Show the stealth/unstealth section link
if ($section->stealth) {
$content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php'));
$content .= html_writer::start_tag('div');
$content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'unstealth', 'value' => $section->id, 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('unstealth', 'mod_subpage'), 'type' => 'image', 'title' => $strunstealth, 'alt' => $strunstealth));
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('form');
} else {
$content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php'));
$content .= html_writer::start_tag('div');
$content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'stealth', 'value' => $section->id, 'type' => 'hidden'));
$content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('stealth', 'mod_subpage'), 'type' => 'image', 'title' => $strstealth, 'alt' => $strstealth));
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('form');
//.........这里部分代码省略.........
示例2: moveable_modules
/**
* Return an array of modules that can be moved in this situation
* The Array is keyed first with sections (subpage or main course)
* and then the modules within each section by cmid
* @param Object $subpage current subpage
* @param Array $allsubpages
* @param Array $coursesections
* @param Object $modinfo
* @param String $move to or from
* @return Array mixed
*/
public static function moveable_modules($subpage, $allsubpages, $coursesections, course_modinfo $modinfo, $move)
{
global $OUTPUT;
get_all_mods($subpage->get_course()->id, $allmods, $modnames, $modnamesplural, $modnamesused);
$mods = array();
$subsections = array();
if (!empty($allsubpages) && $move === 'to') {
foreach ($allsubpages as $sub) {
$subsections += $sub->get_sections();
}
$sections = $coursesections;
} else {
$subsections = $subpage->get_sections();
$sections = $subsections;
}
if ($sections) {
foreach ($sections as $section) {
if (!empty($section->sequence)) {
if ($move === 'to' && array_key_exists($section->id, $subsections)) {
continue;
}
$sectionalt = isset($section->pageorder) ? $section->pageorder : $section->section;
if ($move === 'to') {
// Include the required course/format library.
global $CFG;
require_once "{$CFG->dirroot}/course/format/" . $subpage->get_course()->format . "/lib.php";
$callbackfunction = 'callback_' . $subpage->get_course()->format . '_get_section_name';
if (function_exists($callbackfunction)) {
$name = $callbackfunction($subpage->get_course(), $section);
} else {
$name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt;
}
} else {
$name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt;
}
$sectionmods = explode(',', $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($allmods[$modnumber]) || $modnumber === $subpage->get_course_module()->id) {
continue;
}
$instancename = format_string($modinfo->cms[$modnumber]->name, true, $subpage->get_course()->id);
$icon = $modinfo->get_cm($modnumber)->get_icon_url();
$mod = $allmods[$modnumber];
$mods[$section->section]['section'] = $name;
$mods[$section->section]['pageorder'] = $sectionalt;
$mods[$section->section]['mods'][$modnumber] = "<span><img src='{$icon}' /> " . $instancename . "</span>";
}
}
}
}
return $mods;
}