当前位置: 首页>>代码示例>>PHP>>正文


PHP course_create_sections_if_missing函数代码示例

本文整理汇总了PHP中course_create_sections_if_missing函数的典型用法代码示例。如果您正苦于以下问题:PHP course_create_sections_if_missing函数的具体用法?PHP course_create_sections_if_missing怎么用?PHP course_create_sections_if_missing使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了course_create_sections_if_missing函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * Setup test data.
  */
 public function setUp()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     // Create course and wiki.
     $this->course = $this->getDataGenerator()->create_course();
     course_create_sections_if_missing($this->course, array(1, 2, 3, 4, 5, 6, 7, 8));
 }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:11,代码来源:course_test.php

示例2: test_create_course_sections

 public function test_create_course_sections()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course(array('shortname' => 'GrowingCourse', 'fullname' => 'Growing Course', 'numsections' => 5), array('createsections' => true));
     // Ensure all 6 (0-5) sections were created and modinfo/sectioninfo cache works properly
     $sectionscreated = array_keys(get_fast_modinfo($course)->get_section_info_all());
     $this->assertEquals(range(0, $course->numsections), $sectionscreated);
     // this will do nothing, section already exists
     $this->assertFalse(course_create_sections_if_missing($course, $course->numsections));
     // this will create new section
     $this->assertTrue(course_create_sections_if_missing($course, $course->numsections + 1));
     // Ensure all 7 (0-6) sections were created and modinfo/sectioninfo cache works properly
     $sectionscreated = array_keys(get_fast_modinfo($course)->get_section_info_all());
     $this->assertEquals(range(0, $course->numsections + 1), $sectionscreated);
 }
开发者ID:Burick,项目名称:moodle,代码行数:16,代码来源:courselib_test.php

示例3: __construct

 /**
  * course_toc constructor.
  * @param null $course
  */
 function __construct($course = null)
 {
     global $COURSE;
     if (empty($course)) {
         $course = $COURSE;
     }
     $supportedformats = ['weeks', 'topics'];
     if (!in_array($course->format, $supportedformats)) {
         return;
     } else {
         $this->formatsupportstoc = true;
     }
     $this->format = course_get_format($course);
     $this->course = $this->format->get_course();
     // Has additional fields.
     course_create_sections_if_missing($course, range(0, $this->course->numsections));
     $this->set_modules();
     $this->set_chapters();
     $this->set_footer();
 }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:24,代码来源:course_toc.php

示例4: addsection_action

 /**
  * Add a new section with the provided title and (optional) summary
  *
  * @return string
  */
 public function addsection_action()
 {
     global $CFG, $PAGE, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     $sectioname = required_param('newsection', PARAM_TEXT);
     $summary = optional_param('summary', '', PARAM_RAW);
     require_sesskey();
     $courseid = $PAGE->context->get_course_context()->instanceid;
     $course = course_get_format($courseid)->get_course();
     $course->numsections++;
     course_get_format($course)->update_course_format_options(array('numsections' => $course->numsections));
     course_create_sections_if_missing($course, range(0, $course->numsections));
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info($course->numsections, MUST_EXIST);
     $DB->set_field('course_sections', 'name', $sectioname, array('id' => $section->id));
     $DB->set_field('course_sections', 'summary', $summary, array('id' => $section->id));
     $DB->set_field('course_sections', 'summaryformat', FORMAT_HTML, array('id' => $section->id));
     rebuild_course_cache($course->id);
     redirect(course_get_url($course, $section->section));
 }
开发者ID:nadavkav,项目名称:moodle-theme_snap,代码行数:25,代码来源:addsection_controller.php

示例5: block_side_bar_create_section

/**
 * Setup the section that is meant to contain the activities added via a given sidebar instance.
 *
 * @param object $course The course DB record object
 * @return object|null An object representing the created section or null on error
 */
function block_side_bar_create_section($course)
{
    global $CFG, $DB;
    if (!is_object($course)) {
        throw new coding_exception('$course must be an object');
    }
    // What is the configured number of sections in this course?
    $formatoptions = course_get_format($course)->get_format_options();
    // Make sure the value we need was actually returned
    if (!isset($formatoptions['numsections'])) {
        return null;
    }
    // This is what the maximum section number for this course should be.
    $sectioncount = $formatoptions['numsections'];
    // This is what the new section number should be if we are simply appending a new section to the course.
    $sectionnum = $sectioncount + 1;
    // Check if there are already any "orphaned" sections in this course
    $sql = "SELECT MAX(section)\n              FROM {course_sections}\n             WHERE course = :courseid";
    $maxsection = $DB->get_field_sql($sql, array('courseid' => $course->id));
    // We have orphaned sections in the course so let's just add our new section after the last one
    if ($maxsection >= $sectionnum) {
        $sectionnum = $maxsection + 1;
    }
    // Just make sure that our section actually exists
    course_create_sections_if_missing($course->id, $sectionnum);
    rebuild_course_cache($course->id);
    // Update the Side Bar section with the required values to make it work
    $reseturl = new moodle_url('/blocks/side_bar/reset.php?cid=' . $course->id);
    $section = $DB->get_record('course_sections', array('course' => $course->id, 'section' => $sectionnum), 'id, section, name, visible');
    $section->name = get_string('sidebar', 'block_side_bar');
    $section->summary = get_string('sectionsummary', 'block_side_bar', (string) html_writer::link($reseturl, $reseturl));
    $section->summaryformat = FORMAT_HTML;
    $section->visible = true;
    $DB->update_record('course_sections', $section);
    rebuild_course_cache($course->id, true);
    $sectioninfo = new stdClass();
    $sectioninfo->id = $section->id;
    $sectioninfo->section = $section->section;
    return $sectioninfo;
}
开发者ID:bostelm,项目名称:moodle-block_side_bar,代码行数:46,代码来源:locallib.php

示例6: get_content

 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     /// extra fast view mode
     if (!$isediting) {
         $modinfo = get_fast_modinfo($course);
         if (!empty($modinfo->sections[0])) {
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 if ($cm->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $cm->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
                 if (!empty($cm->url)) {
                     $attrs = array();
                     $attrs['title'] = $cm->modfullname;
                     $attrs['class'] = $cm->extraclasses . ' activity-action';
                     if ($cm->onclick) {
                         $attrs['id'] = html_writer::random_id('onclick');
                         $OUTPUT->add_action_handler(new component_action('click', $cm->onclick), $attrs['id']);
                     }
                     if (!$cm->visible) {
                         $attrs['class'] .= ' dimmed';
                     }
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
                     $content = html_writer::link($cm->url, $icon . $cm->get_formatted_name(), $attrs);
                 } else {
                     $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 }
                 $this->content->items[] = $indent . html_writer::div($content, 'main-menu-content');
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     /** @var core_course_renderer $courserenderer */
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     course_create_sections_if_missing($course, 0);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     } else {
         $strmove = get_string('move');
     }
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, $mod->indent);
                 // Prepend list of actions with the 'move' action.
                 $actions = array('move' => new action_menu_link_primary(new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $strmove)) + $actions;
                 $editbuttons = html_writer::tag('div', $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 if ($mod->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $mod->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
//.........这里部分代码省略.........
开发者ID:Keneth1212,项目名称:moodle,代码行数:101,代码来源:block_site_main_menu.php

示例7: can_add_moduleinfo

/**
 * Check that the user can add a module. Also returns some information like the module, context and course section info.
 * The fucntion create the course section if it doesn't exist.
 *
 * @param object $course the course of the module
 * @param object $modulename the module name
 * @param object $section the section of the module
 * @return array list containing module, context, course section.
 * @throws moodle_exception if user is not allowed to perform the action or module is not allowed in this course
 */
function can_add_moduleinfo($course, $modulename, $section)
{
    global $DB;
    $module = $DB->get_record('modules', array('name' => $modulename), '*', MUST_EXIST);
    $context = context_course::instance($course->id);
    require_capability('moodle/course:manageactivities', $context);
    course_create_sections_if_missing($course, $section);
    $cw = get_fast_modinfo($course)->get_section_info($section);
    if (!course_allowed_module($course, $module->name)) {
        print_error('moduledisable');
    }
    return array($module, $context, $cw);
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:23,代码来源:modlib.php

示例8: test_available_hook

 public function test_available_hook()
 {
     global $DB;
     $this->resetAfterTest();
     // Generate a course with two sections (0 and 1) and two modules. Course format is set to 'theunittest'.
     $generator = $this->getDataGenerator();
     $course1 = $generator->create_course(array('format' => 'theunittest'));
     $this->assertEquals('theunittest', $course1->format);
     course_create_sections_if_missing($course1, array(0, 1));
     $assign0 = $generator->create_module('assign', array('course' => $course1, 'section' => 0));
     $assign1 = $generator->create_module('assign', array('course' => $course1, 'section' => 1));
     // Enrol student and teacher.
     $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
     $student = $generator->create_user();
     $generator->enrol_user($student->id, $course1->id, $roleids['student']);
     $teacher = $generator->create_user();
     $generator->enrol_user($teacher->id, $course1->id, $roleids['editingteacher']);
     // Make sure that initially both sections and both modules are available and visible for a student.
     $modinfostudent = get_fast_modinfo($course1, $student->id);
     $this->assertTrue($modinfostudent->get_section_info(1)->available);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
     $this->assertTrue($modinfostudent->get_cm($assign1->cmid)->available);
     $this->assertTrue($modinfostudent->get_cm($assign1->cmid)->uservisible);
     // Set 'hideoddsections' for the course to 1.
     // Section1 and assign1 will be unavailable, uservisible will be false for student and true for teacher.
     $data = (object) array('id' => $course1->id, 'hideoddsections' => 1);
     course_get_format($course1)->update_course_format_options($data);
     $modinfostudent = get_fast_modinfo($course1, $student->id);
     $this->assertFalse($modinfostudent->get_section_info(1)->available);
     $this->assertEmpty($modinfostudent->get_section_info(1)->availableinfo);
     $this->assertFalse($modinfostudent->get_section_info(1)->uservisible);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
     $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->available);
     $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->uservisible);
     $modinfoteacher = get_fast_modinfo($course1, $teacher->id);
     $this->assertFalse($modinfoteacher->get_section_info(1)->available);
     $this->assertEmpty($modinfoteacher->get_section_info(1)->availableinfo);
     $this->assertTrue($modinfoteacher->get_section_info(1)->uservisible);
     $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->available);
     $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->uservisible);
     $this->assertFalse($modinfoteacher->get_cm($assign1->cmid)->available);
     $this->assertTrue($modinfoteacher->get_cm($assign1->cmid)->uservisible);
     // Set 'hideoddsections' for the course to 2.
     // Section1 and assign1 will be unavailable, uservisible will be false for student and true for teacher.
     // Property availableinfo will be not empty.
     $data = (object) array('id' => $course1->id, 'hideoddsections' => 2);
     course_get_format($course1)->update_course_format_options($data);
     $modinfostudent = get_fast_modinfo($course1, $student->id);
     $this->assertFalse($modinfostudent->get_section_info(1)->available);
     $this->assertNotEmpty($modinfostudent->get_section_info(1)->availableinfo);
     $this->assertFalse($modinfostudent->get_section_info(1)->uservisible);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->available);
     $this->assertTrue($modinfostudent->get_cm($assign0->cmid)->uservisible);
     $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->available);
     $this->assertFalse($modinfostudent->get_cm($assign1->cmid)->uservisible);
     $modinfoteacher = get_fast_modinfo($course1, $teacher->id);
     $this->assertFalse($modinfoteacher->get_section_info(1)->available);
     $this->assertNotEmpty($modinfoteacher->get_section_info(1)->availableinfo);
     $this->assertTrue($modinfoteacher->get_section_info(1)->uservisible);
     $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->available);
     $this->assertTrue($modinfoteacher->get_cm($assign0->cmid)->uservisible);
     $this->assertFalse($modinfoteacher->get_cm($assign1->cmid)->available);
     $this->assertTrue($modinfoteacher->get_cm($assign1->cmid)->uservisible);
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:66,代码来源:courseformat_test.php

示例9: array

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'));
    echo html_writer::end_tag('div');
    echo html_writer::end_tag('form');
}
// Course wrapper start.
echo html_writer::start_tag('div', array('class' => 'course-content'));
// make sure that section 0 exists (this function will create one if it is missing)
course_create_sections_if_missing($course, 0);
// get information about course modules and existing module types
// format.php in course formats may rely on presence of these variables
$modinfo = get_fast_modinfo($course);
$modnames = get_module_types_names();
$modnamesplural = get_module_types_names(true);
$modnamesused = $modinfo->get_used_module_names();
$mods = $modinfo->get_cms();
$sections = $modinfo->get_section_info_all();
// CAUTION, hacky fundamental variable defintion to follow!
// Note that because of the way course fromats are constructed though
// inclusion we pass parameters around this way..
$displaysection = $section;
// Include the actual course format.
require $CFG->dirroot . '/course/format/' . $course->format . '/format.php';
/**
开发者ID:dibarbado,项目名称:moodle,代码行数:31,代码来源:view.php

示例10: reorder_activities

 /**
  * Make sure that current active activity is in section 0
  *
  * All other activities are moved to section 1 that will be displayed as 'Orphaned'.
  * It may be needed after the course format was changed or activitytype in
  * course settings has been changed.
  *
  * @return null|cm_info current activity
  */
 public function reorder_activities()
 {
     course_create_sections_if_missing($this->courseid, array(0, 1));
     foreach ($this->get_sections() as $sectionnum => $section) {
         if ($sectionnum && $section->visible || !$sectionnum && !$section->visible) {
             // Make sure that 0 section is visible and all others are hidden.
             set_section_visible($this->courseid, $sectionnum, $sectionnum == 0);
         }
     }
     $modinfo = get_fast_modinfo($this->courseid);
     // Find the current activity (first activity with the specified type in all course activities).
     $activitytype = $this->get_activitytype();
     $activity = null;
     if (!empty($activitytype)) {
         foreach ($modinfo->sections as $sectionnum => $cmlist) {
             foreach ($cmlist as $cmid) {
                 if ($modinfo->cms[$cmid]->modname === $activitytype) {
                     $activity = $modinfo->cms[$cmid];
                     break 2;
                 }
             }
         }
     }
     // Make sure the current activity is in the 0-section.
     if ($activity && $activity->sectionnum != 0) {
         moveto_module($activity, $modinfo->get_section_info(0));
         // Cache was reset so get modinfo again.
         $modinfo = get_fast_modinfo($this->courseid);
     }
     // Move all other activities into section 1 (the order must be kept).
     $hasvisibleactivities = false;
     $firstorphanedcm = null;
     foreach ($modinfo->sections as $sectionnum => $cmlist) {
         if ($sectionnum && !empty($cmlist) && $firstorphanedcm === null) {
             $firstorphanedcm = reset($cmlist);
         }
         foreach ($cmlist as $cmid) {
             if ($sectionnum > 1) {
                 moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1));
             } else {
                 if (!$hasvisibleactivities && $sectionnum == 1 && $modinfo->get_cm($cmid)->visible) {
                     $hasvisibleactivities = true;
                 }
             }
         }
     }
     if (!empty($modinfo->sections[0])) {
         foreach ($modinfo->sections[0] as $cmid) {
             if (!$activity || $cmid != $activity->id) {
                 moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1), $firstorphanedcm);
             }
         }
     }
     if ($hasvisibleactivities) {
         set_section_visible($this->courseid, 1, false);
     }
     return $activity;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:67,代码来源:lib.php

示例11: debugging

// Horrible backwards compatible parameter aliasing..
if ($topic = optional_param('topic', 0, PARAM_INT)) {
    $url = $PAGE->url;
    $url->param('section', $topic);
    debugging('Outdated topic param passed to course/view.php', DEBUG_DEVELOPER);
    redirect($url);
}
// End backwards-compatible aliasing..
$context = context_course::instance($course->id);
if ($marker >= 0 && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
    $course->marker = $marker;
    course_set_marker($course->id, $marker);
}
// make sure all sections are created
$course = course_get_format($course)->get_course();
course_create_sections_if_missing($course, range(0, $course->numsections));
//onetopic format is always multipage
$course->realcoursedisplay = $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE;
$course->coursedisplay = COURSE_DISPLAY_MULTIPAGE;
$renderer = $PAGE->get_renderer('format_onetopic');
$section = optional_param('section', -1, PARAM_INT);
if (isset($section) && $section >= 0 && $course->numsections >= $section) {
    $USER->display[$course->id] = $section;
    $displaysection = $section;
} else {
    if (isset($USER->display[$course->id]) && $course->numsections >= $USER->display[$course->id]) {
        $displaysection = $USER->display[$course->id];
    } else {
        $USER->display[$course->id] = 0;
        $displaysection = 0;
    }
开发者ID:dibarbado,项目名称:moodle,代码行数:31,代码来源:format.php

示例12: get_content

 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     /// extra fast view mode
     if (!$isediting) {
         $modinfo = get_fast_modinfo($course);
         if (!empty($modinfo->sections[0])) {
             $options = array('overflowdiv' => true);
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $cm->get_formatted_name();
                 if (!($url = $cm->get_url())) {
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $linkcss = $cm->visible ? '' : ' class="dimmed" ';
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
                     $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>';
                 }
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     /** @var core_course_renderer $courserenderer */
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     course_create_sections_if_missing($course, 0);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     }
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, -1);
                 $editbuttons = html_writer::tag('div', $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $mod->get_formatted_name();
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!($url = $mod->get_url())) {
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, 0, null, array('inblock' => true));
//.........这里部分代码省略.........
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:101,代码来源:block_site_main_menu.php

示例13: create_course

/**
 * Create a course and either return a $course object
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param array $editoroptions course description editor options
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @return object new course instance
 */
function create_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    //check the categoryid - must be given for all new courses
    $category = $DB->get_record('course_categories', array('id' => $data->category), '*', MUST_EXIST);
    //check if the shortname already exist
    if (!empty($data->shortname)) {
        if ($DB->record_exists('course', array('shortname' => $data->shortname))) {
            throw new moodle_exception('shortnametaken');
        }
    }
    //check if the id number already exist
    if (!empty($data->idnumber)) {
        if ($DB->record_exists('course', array('idnumber' => $data->idnumber))) {
            throw new moodle_exception('idnumbertaken');
        }
    }
    $data->timecreated = time();
    $data->timemodified = $data->timecreated;
    // place at beginning of any category
    $data->sortorder = 0;
    if ($editoroptions) {
        // summary text is updated later, we need context to store the files first
        $data->summary = '';
        $data->summary_format = FORMAT_HTML;
        $data->coursepreview = '';
        $data->coursepreview_format = FORMAT_HTML;
    }
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $category->visible;
    }
    $data->visibleold = $data->visible;
    $newcourseid = $DB->insert_record('course', $data);
    $context = context_course::instance($newcourseid, MUST_EXIST);
    if ($editoroptions) {
        // Save the files used in the summary editor and store
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
        $DB->set_field('course', 'summary', $data->summary, array('id' => $newcourseid));
        $DB->set_field('course', 'summaryformat', $data->summary_format, array('id' => $newcourseid));
        $data = file_postupdate_standard_editor($data, 'coursepreview', $editoroptions, $context, 'course', 'coursepreview', 0);
        $DB->set_field('course', 'coursepreview', $data->coursepreview, array('id' => $newcourseid));
        $DB->set_field('course', 'previewformat', $data->coursepreview_format, array('id' => $newcourseid));
    }
    // update course format options
    course_get_format($newcourseid)->update_course_format_options($data);
    $course = course_get_format($newcourseid)->get_course();
    // Setup the blocks
    blocks_add_default_course_blocks($course);
    // Create a default section.
    course_create_sections_if_missing($course, 0);
    fix_course_sortorder();
    // new context created - better mark it as dirty
    mark_context_dirty($context->path);
    // Save any custom role names.
    save_local_role_names($course->id, (array) $data);
    // set up enrolments
    enrol_course_updated(true, $course, $data);
    add_to_log(SITEID, 'course', 'new', 'view.php?id=' . $course->id, $data->fullname . ' (ID ' . $course->id . ')');
    // Trigger events
    events_trigger('course_created', $course);
    return $course;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:73,代码来源:lib.php

示例14: get_content

 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     /// extra fast view mode
     if (!$isediting) {
         $modinfo = get_fast_modinfo($course);
         if (!empty($modinfo->sections[0])) {
             $options = array('overflowdiv' => true);
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 list($content, $instancename) = get_print_section_cm_text($cm, $course);
                 if (!($url = $cm->get_url())) {
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $linkcss = $cm->visible ? '' : ' class="dimmed" ';
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
                     $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>';
                 }
             }
         }
         return $this->content;
     }
     /// slow & hacky editing mode
     $ismoving = ismoving($course->id);
     course_create_sections_if_missing($course, 0);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     $groupbuttons = $course->groupmode;
     $groupbuttonslink = !$course->groupmodeforce;
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     }
     /// Casting $course->modinfo to string prevents one notice when the field is null
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 if ($groupbuttons) {
                     if (!($mod->groupmodelink = $groupbuttonslink)) {
                         $mod->groupmode = $course->groupmode;
                     }
                 } else {
                     $mod->groupmode = false;
                 }
                 $editbuttons = '<div class="buttons">' . make_editing_buttons($mod, true, true) . '</div>';
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course);
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!($url = $mod->get_url())) {
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
                 }
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:block_site_main_menu.php

示例15: test_move_module_in_course

 public function test_move_module_in_course()
 {
     $this->resetAfterTest(true);
     // Setup fixture
     $course = $this->getDataGenerator()->create_course(array('numsections' => 5));
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $cms = get_fast_modinfo($course)->get_cms();
     $cm = reset($cms);
     course_create_sections_if_missing($course, 3);
     $section3 = get_fast_modinfo($course)->get_section_info(3);
     moveto_module($cm, $section3);
     $modinfo = get_fast_modinfo($course);
     $this->assertTrue(empty($modinfo->sections[0]));
     $this->assertFalse(empty($modinfo->sections[3]));
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:15,代码来源:courselib_test.php


注:本文中的course_create_sections_if_missing函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。