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); $modinfo = get_fast_modinfo($course); /// extra fast view mode if (!$isediting) { 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); $section = get_course_section(0, $course->id); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); $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 . ' (<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&sesskey=' . sesskey() . '">' . $strcancel . '</a>)'; } if (!empty($section->sequence)) { $sectionmods = explode(',', $section->sequence); $options = array('overflowdiv' => true); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; 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 . '&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; } } } } if ($ismoving) { $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } if (!empty($modnames)) { $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true); } else { $this->content->footer = ''; } return $this->content; }
function link_to_gdoc($name, $link, $type = null, $modtype = 'url') { global $COURSE, $DB, $CFG, $USER; require_once "{$CFG->dirroot}/mod/{$modtype}/lib.php"; //add $fromform = new stdClass(); $newform = new stdClass(); $mform = new MoodleQuickForm(null, 'POST', 'nothing'); $module = $DB->get_record("modules", array('name' => $modtype)); $course = $COURSE; $cw = get_course_section(0, $course->id); $cm = null; // fields for mdl_url $fromform->course = $course->id; $fromform->name = $name; $fromform->introformat = 0; $fromform->introeditor = 0; $fromform->externalurl = $link; /* if ($type !== 'dir') { $fromform->display = 6; $fromform->displayoptions = 'a:2:{s:10:"popupwidth";i:1024;s:11:"popupheight";i:768;}'; } else { */ $fromform->display = 0; $fromform->popupwidth = 1024; $fromform->popupheight = 768; $fromform->popupwidth = null; $fromform->popupheight = null; $fromform->displayoptions = 'a:1:{s:10:"printintro";i:0;}'; // } // fields for mdl_course_module $fromform->module = $module->id; $fromform->instance = ''; $fromform->section = 0; // The section number itself - relative!!! (section column in course_sections) $fromform->idnumber = null; $fromform->score = 0; $fromform->indent = 0; $fromform->visible = 1; $fromform->visibleold = 1; $fromform->groupmode = $course->groupmode; $fromform->groupingid = 0; $fromform->groupmembersonly = 0; $fromform->completion = 0; $fromform->completionview = 0; $fromform->completionexpected = 0; $fromform->availablefrom = 0; $fromform->availableuntil = 0; $fromform->showavailability = 0; $fromform->showdescription = 0; $fromform->conditiongradegroup = array(); $fromform->conditionfieldgroup = array(); // fields for mdl_course_sections $fromform->summaryformat = 0; $fromform->modulename = clean_param($module->name, PARAM_SAFEDIR); // For safety // $fromform->add = 'resource'; // $fromform->type = $type == 'dir' ? 'collection' : 'file'; // $fromform->return = 0; //must be false if this is an add, go back to course view on cancel // $fromform->coursemodule = ''; // $fromform->popup = 'resizable=1,scrollbars=1,directories=1,location=1,menubar=1,toolbar=1,status=1,width=1024,height=768'; // require_login($course->id); // needed to setup proper $COURSE $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { $fromform->groupmode = 0; // do not set groupmode } if (!course_allowed_module($course, $fromform->modulename)) { print_error('moduledisable', '', '', $fromform->modulename); } // first add course_module record because we need the context $newcm = new stdClass(); $newcm->course = $course->id; $newcm->module = $fromform->module; $newcm->instance = 0; // not known yet, will be updated later (this is similar to restore code) $newcm->visible = $fromform->visible; $newcm->groupmode = $fromform->groupmode; $newcm->groupingid = $fromform->groupingid; $newcm->groupmembersonly = $fromform->groupmembersonly; $completion = new completion_info($course); if ($completion->is_enabled()) { $newcm->completion = $fromform->completion; $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber; $newcm->completionview = $fromform->completionview; $newcm->completionexpected = $fromform->completionexpected; } if (!empty($CFG->enableavailability)) { $newcm->availablefrom = $fromform->availablefrom; $newcm->availableuntil = $fromform->availableuntil; $newcm->showavailability = $fromform->showavailability; } if (isset($fromform->showdescription)) { $newcm->showdescription = $fromform->showdescription; } else { $newcm->showdescription = 0; } if (!($fromform->coursemodule = add_course_module($newcm))) { print_error('cannotaddcoursemodule'); } if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { $draftid_editor = file_get_submitted_draft_itemid('introeditor'); file_prepare_draft_area($draftid_editor, null, null, null, null); $fromform->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor); // TODO: add better default } if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { $introeditor = $fromform->introeditor; unset($fromform->introeditor); $fromform->intro = $introeditor['text']; $fromform->introformat = $introeditor['format']; } $addinstancefunction = $fromform->modulename . "_add_instance"; $updateinstancefunction = $fromform->modulename . "_update_instance"; $returnfromfunc = $addinstancefunction($fromform, $mform); // $returnfromfunc = url_add_instance($fromform, $mform); if (!$returnfromfunc or !is_number($returnfromfunc)) { // undo everything we can $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); delete_context(CONTEXT_MODULE, $fromform->coursemodule); $DB->delete_records('course_modules', array('id' => $fromform->coursemodule)); if (!is_number($returnfromfunc)) { print_error('invalidfunction', '', course_get_url($course, $cw->section)); } else { print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename); } } $fromform->instance = $returnfromfunc; $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $fromform->coursemodule)); // update embedded links and save files $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); if (!empty($introeditor)) { $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $fromform->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']); $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id' => $fromform->instance)); } // course_modules and course_sections each contain a reference // to each other, so we have to update one of them twice. $sectionid = add_mod_to_section($fromform); $DB->set_field('course_modules', 'section', $sectionid, array('id' => $fromform->coursemodule)); // make sure visibility is set correctly (in particular in calendar) set_coursemodule_visible($fromform->coursemodule, $fromform->visible); if (isset($fromform->cmidnumber)) { //label // set cm idnumber set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); } // Set up conditions if ($CFG->enableavailability) { condition_info::update_cm_from_form((object) array('id' => $fromform->coursemodule), $fromform, false); } $eventname = 'mod_created'; add_to_log($course->id, "course", "add mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}"); add_to_log($course->id, $fromform->modulename, "add", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule); // Trigger mod_created/mod_updated event with information about this module. $eventdata = new stdClass(); $eventdata->modulename = $fromform->modulename; $eventdata->name = $fromform->name; $eventdata->cmid = $fromform->coursemodule; $eventdata->courseid = $course->id; $eventdata->userid = $USER->id; events_trigger($eventname, $eventdata); rebuild_course_cache($course->id); return 1; }
/** * Setup the DB fixture data */ public function setup() { parent::setUp(); $tables = array('block_instance', 'cache_flags', 'capabilities', 'context', 'context_temp', 'course', 'course_modules', 'course_categories', 'course_sections', 'files', 'files_cleanup', 'grade_items', 'grade_categories', 'groups', 'groups_members', 'modules', 'role', 'role_names', 'role_context_levels', 'role_assignments', 'role_capabilities', 'user'); $this->create_test_tables($tables, 'lib'); $this->create_test_table('forum', 'mod/forum'); $this->switch_to_test_db(); global $DB, $CFG; // Insert needed capabilities $DB->insert_record('capabilities', array('id' => 45, 'name' => 'moodle/course:update', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4)); $DB->insert_record('capabilities', array('id' => 14, 'name' => 'moodle/site:backup', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28)); $DB->insert_record('capabilities', array('id' => 17, 'name' => 'moodle/site:restore', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28)); $DB->insert_record('capabilities', array('id' => 52, 'name' => 'moodle/course:managefiles', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4)); $DB->insert_record('capabilities', array('id' => 73, 'name' => 'moodle/user:editownprofile', 'cattype' => 'write', 'contextlevel' => 10, 'component' => 'moodle', 'riskbitmask' => 16)); // Insert system context $DB->insert_record('context', array('id' => 1, 'contextlevel' => 10, 'instanceid' => 0, 'path' => '/1', 'depth' => 1)); $DB->insert_record('context', array('id' => 2, 'contextlevel' => 50, 'instanceid' => 1, 'path' => '/1/2', 'depth' => 2)); // Insert site course $DB->insert_record('course', array('category' => 0, 'sortorder' => 1, 'fullname' => 'Test site', 'shortname' => 'test', 'format' => 'site', 'modinfo' => 'a:0:{}')); // User and capability stuff (stolen from testaccesslib.php) $syscontext = get_system_context(false); $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin'); /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id); update_capabilities('moodle'); update_capabilities('mod/forum'); $contexts = $this->load_test_data('context', array('contextlevel', 'instanceid', 'path', 'depth'), array(1 => array(40, 666, '', 2))); $contexts[0] = $syscontext; $contexts[1]->path = $contexts[0]->path . '/' . $contexts[1]->id; $this->testdb->set_field('context', 'path', $contexts[1]->path, array('id' => $contexts[1]->id)); $users = $this->load_test_data('user', array('username', 'confirmed', 'deleted'), array('a' => array('a', 1, 0))); $admin = $this->testdb->get_record('role', array('shortname' => 'admin')); $ras = $this->load_test_data('role_assignments', array('userid', 'roleid', 'contextid'), array('a' => array($users['a']->id, $admin->id, $contexts[0]->id))); $this->switch_global_user_id(1); accesslib_clear_all_caches_for_unit_testing(); // Create a coursecat $newcategory = new stdClass(); $newcategory->name = 'test category'; $newcategory->sortorder = 999; if (!($newcategory->id = $DB->insert_record('course_categories', $newcategory))) { print_error('cannotcreatecategory', '', '', format_string($newcategory->name)); } $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id); mark_context_dirty($newcategory->context->path); fix_course_sortorder(); // Required to build course_categories.depth and .path. $this->coursecat = $DB->get_record('course_categories', array('id' => $newcategory->id)); // Create a course $coursedata = new stdClass(); $coursedata->category = $newcategory->id; $coursedata->shortname = 'testcourse'; $coursedata->fullname = 'Test Course'; try { $this->course = create_course($coursedata); } catch (moodle_exception $e) { // Most likely the result of an aborted unit test: the test course was not correctly deleted $this->course = $DB->get_record('course', array('shortname' => $coursedata->shortname)); } // Create a user $this->user = new stdClass(); $this->user->username = '******'; $this->user->password = '******'; $this->user->firstname = 'TestUser'; $this->user->lastname = 'TestUser'; $this->user->email = '*****@*****.**'; try { $this->user->id = create_user($this->user); } catch (moodle_exception $e) { // Most likely the result of an aborted unit test: the test user was not correctly deleted $this->user->id = $DB->get_field('user', 'id', array('username' => $this->user->username)); } // Assign user to course // role_assign(5, $this->user->id, 0, get_context_instance(CONTEXT_COURSE, $this->course->id)->id); // Create a module $module = new stdClass(); $module->intro = 'Forum used for testing filelib API'; $module->type = 'general'; $module->forcesubscribe = 1; $module->format = 1; $module->name = 'Test Forum'; $module->module = $DB->get_field('modules', 'id', array('name' => 'forum')); $module->modulename = 'forum'; $module->add = 'forum'; $module->cmidnumber = ''; $module->course = $this->course->id; $module->instance = forum_add_instance($module, ''); $this->section = get_course_section(1, $this->course->id); $module->section = $this->section->id; $module->coursemodule = add_course_module($module); add_mod_to_section($module); $module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, ''); rebuild_course_cache($this->course->id); $this->module = $DB->get_record('forum', array('id' => $module->instance)); $this->module->instance = $module->instance; // Update local copy of course $this->course = $DB->get_record('course', array('id' => $this->course->id)); }
/** * コースファイルのコピー * * @param object $restore * @return */ function project_restore_course_files(&$restore) { global $CFG; $status = true; $counter = 0; // 対象のコース情報の取得 if (!($course = get_record("course", "id", $restore->course_id))) { error("Course ID was incorrect (can't find it)"); } // 対象のセクション情報の取得 if (!($section = get_course_section($restore->section, $restore->course_id))) { error("Section data was incorrect (can't find it)"); } // 現在のセクションのディレクトリ名を取得 if (!($sectiontitle = project_format_get_title($course, $section->id))) { error("Section directory was incorrect"); } //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id . '/' . $restore->newdirectoryname; $status = check_dir_exists($dest_dir, true); //Now, we iterate over "course_files" records to check if that file/dir must be //copied to the "dest_dir" dir. $rootdir = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/course_files/" . $restore->olddirectoryname; // ディレクトリをまるごとコピーする if (is_dir($rootdir)) { $status = backup_copy_file($rootdir, $dest_dir); } return $status; }
public function generate_modules($courses) { global $DB, $CFG; // Parse the modules-list variable $this->verbose("Generating " . $this->get('number_of_sections') . " sections with " . $this->get('number_of_modules') . " modules in each section, for each course..."); list($modules_list_sql, $modules_params) = $DB->get_in_or_equal($this->get('modules_list'), SQL_PARAMS_NAMED, 'param0000', true); list($modules_ignored_sql, $ignore_params) = $DB->get_in_or_equal($this->modules_to_ignore, SQL_PARAMS_NAMED, 'param2000', false); $wheresql = "name {$modules_list_sql} AND name {$modules_ignored_sql}"; $modules = $DB->get_records_select('modules', $wheresql, array_merge($modules_params, $ignore_params)); foreach ($modules as $key => $module) { $module->count = 0; // Scorm, lams and hotpot are too complex to set up, remove them if (in_array($module->name, $this->modules_to_ignore) || !in_array($module->name, $this->modules_list)) { unset($modules[$key]); } } // Dirty hack for renumbering the modules array's keys $first_module = reset($modules); array_shift($modules); array_unshift($modules, $first_module); $modules_array = array(); if (count($courses) > 0) { $libraries = array(); foreach ($courses as $courseid) { // Text resources for ($i = 1; $i <= $this->get('number_of_sections'); $i++) { for ($j = 0; $j < $this->get('number_of_modules'); $j++) { $module = new stdClass(); // If only one module is created, and we also need to add a question to a quiz, create only a quiz if ($this->get('number_of_modules') == 1 && $this->get('questions_per_quiz') > 0 && !empty($modules[8])) { $moduledata = $modules[8]; } else { $moduledata = $modules[array_rand($modules)]; } $libfile = "{$CFG->dirroot}/mod/{$moduledata->name}/lib.php"; if (file_exists($libfile)) { if (!in_array($libfile, $libraries)) { $this->verbose("Including library for {$moduledata->name}..."); $libraries[] = $libfile; require_once $libfile; } } else { $this->verbose("Could not load lib file for module {$moduledata->name}!"); if (!$this->get('ignore_errors')) { die; } } // Basically 2 types of text fields: description and content $description = "This {$moduledata->name} has been randomly generated by a very useful script, " . "for the purpose of testing " . "the boundaries of Moodle in various contexts. Moodle should be able to scale to " . "any size without " . "its speed and ease of use being affected dramatically."; $content = 'Very useful content, I am sure you would agree'; $module_type_index = 0; $module->introformat = FORMAT_MOODLE; $module->messageformat = FORMAT_MOODLE; // Special module-specific config switch ($moduledata->name) { case 'assignment': $module->intro = $description; $module->assignmenttype = $this->get_module_type('assignment'); $module->timedue = mktime() + 89487321; $module->grade = rand(50, 100); break; case 'chat': $module->intro = $description; $module->schedule = 1; $module->chattime = 60 * 60 * 4; break; case 'data': $module->intro = $description; $module->name = 'test'; break; case 'choice': $module->intro = $description; $module->text = $content; $module->option = array('Good choice', 'Bad choice', 'No choice'); $module->limit = array(1, 5, 0); break; case 'comments': $module->intro = $description; $module->comments = $content; break; case 'feedback': $module->intro = $description; $module->page_after_submit = $description; $module->comments = $content; break; case 'forum': $module->intro = $description; $module->type = $this->get_module_type('forum'); $module->forcesubscribe = rand(0, 1); $module->format = 1; break; case 'glossary': $module->intro = $description; $module->displayformat = $this->glossary_formats[rand(0, count($this->glossary_formats) - 1)]; $module->cmidnumber = rand(0, 999999); break; case 'label': $module->content = $content; $module->intro = $description; break; case 'lesson': $module->lessondefault = 1; $module->available = mktime(); $module->deadline = mktime() + 719891987; $module->grade = 100; break; case 'quiz': $module->intro = $description; $module->feedbacktext = 'blah'; $module->feedback = 1; $module->feedbackboundaries = array(2, 1); $module->grade = 10; $module->timeopen = time(); $module->timeclose = time() + 68854; $module->shufflequestions = true; $module->shuffleanswers = true; $module->quizpassword = ''; break; case 'resource': $module->type = $this->get_module_type('resource'); $module->alltext = $content; $module->summary = $description; $module->windowpopup = rand(0, 1); $module->display = rand(0, 1); $module->resizable = rand(0, 1); $module->scrollbars = rand(0, 1); $module->directories = rand(0, 1); $module->location = 'file.txt'; $module->menubar = rand(0, 1); $module->toolbar = rand(0, 1); $module->status = rand(0, 1); $module->width = rand(200, 600); $module->height = rand(200, 600); $module->directories = rand(0, 1); $module->files = false; $module->param_navigationmenu = rand(0, 1); $module->param_navigationbuttons = rand(0, 1); $module->reference = 1; $module->forcedownload = 1; break; case 'survey': $module->template = rand(1, 5); $module->intro = $description; break; case 'wiki': $module->intro = $description; $module->summary = $description; break; } $module->name = ucfirst($moduledata->name) . ' ' . $moduledata->count++; $module->course = $courseid; $module->section = $i; $module->module = $moduledata->id; $module->modulename = $moduledata->name; $module->add = $moduledata->name; $module->cmidnumber = ''; $module->coursemodule = ''; $add_instance_function = $moduledata->name . '_add_instance'; $section = get_course_section($i, $courseid); $module->section = $section->id; $module->coursemodule = add_course_module($module); $module->section = $i; if (function_exists($add_instance_function)) { $this->verbose("Calling module function {$add_instance_function}"); $module->instance = $add_instance_function($module, ''); $DB->set_field('course_modules', 'instance', $module->instance, array('id' => $module->coursemodule)); } else { $this->verbose("Function {$add_instance_function} does not exist!"); if (!$this->get('ignore_errors')) { die; } } add_mod_to_section($module); $module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, ''); $this->verbose("A {$moduledata->name} module was added to section {$i} (id {$module->section}) " . "of course {$courseid}."); rebuild_course_cache($courseid); $module_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule)); $module_record = $DB->get_record($moduledata->name, array('id' => $module_instance)); $module_record->instance = $module_instance; if (empty($modules_array[$moduledata->name])) { $modules_array[$moduledata->name] = array(); } // TODO Find out why some $module_record end up empty here... (particularly quizzes) if (!empty($module_record->instance)) { $modules_array[$moduledata->name][] = $module_record; } } } } if (!$this->get('quiet')) { echo "Successfully generated " . $this->get('number_of_modules') * $this->get('number_of_sections') . " modules in each course!{$this->eolchar}"; } return $modules_array; } return null; }
/** * Output the html for a multiple section page * * @param stdClass $course The course entry from DB * @param array $sections The course_sections entries from the DB * @param array $mods used for print_section() * @param array $modnames used for print_section() * @param array $modnamesused used for print_section() */ public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) { global $PAGE; $context = context_course::instance($course->id); // Title with completion help icon. $completioninfo = new completion_info($course); echo $completioninfo->display_help_icon(); echo $this->output->heading($this->page_title(), 2, 'accesshide'); // Copy activity clipboard.. echo $this->course_activity_clipboard($course); // Now the list of sections.. echo $this->start_section_list(); // General section if non-empty. $thissection = $sections[0]; unset($sections[0]); if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) { echo $this->section_header($thissection, $course, true); print_section($course, $thissection, $mods, $modnamesused, true); if ($PAGE->user_is_editing()) { print_section_add_menus($course, 0, $modnames); } echo $this->section_footer(); } $canviewhidden = has_capability('moodle/course:viewhiddensections', $context); for ($section = 1; $section <= $course->numsections; $section++) { if (!empty($sections[$section])) { $thissection = $sections[$section]; } else { // This will create a course section if it doesn't exist.. $thissection = get_course_section($section, $course->id); // The returned section is only a bare database object rather than // a section_info object - we will need at least the uservisible // field in it. $thissection->uservisible = true; $thissection->availableinfo = null; $thissection->showavailability = 0; } // Show the section if the user is permitted to access it, OR if it's not available // but showavailability is turned on $showsection = $thissection->uservisible || $thissection->visible && !$thissection->available && $thissection->showavailability; if (!$showsection) { // Hidden section message is overridden by 'unavailable' control // (showavailability option). if (!$course->hiddensections && $thissection->available) { echo $this->section_hidden($section); } unset($sections[$section]); continue; } if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) { // Display section summary only. echo $this->section_summary($thissection, $course); } else { echo $this->section_header($thissection, $course, false); if ($thissection->uservisible) { print_section($course, $thissection, $mods, $modnamesused); if ($PAGE->user_is_editing()) { print_section_add_menus($course, $section, $modnames); } } echo $this->section_footer(); } unset($sections[$section]); } if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) { // Print stealth sections if present. $modinfo = get_fast_modinfo($course); foreach ($sections as $section => $thissection) { if (empty($modinfo->sections[$section])) { continue; } echo $this->stealth_section_header($section); print_section($course, $thissection, $mods, $modnamesused); echo $this->stealth_section_footer(); } echo $this->end_section_list(); echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right')); // Increase number of sections. $straddsection = get_string('increasesections', 'moodle'); $url = new moodle_url('/course/changenumsections.php', array('courseid' => $course->id, 'increase' => true, 'sesskey' => sesskey())); $icon = $this->output->pix_icon('t/switch_plus', $straddsection); echo html_writer::link($url, $icon . get_accesshide($straddsection), array('class' => 'increase-sections')); if ($course->numsections > 0) { // Reduce number of sections sections. $strremovesection = get_string('reducesections', 'moodle'); $url = new moodle_url('/course/changenumsections.php', array('courseid' => $course->id, 'increase' => false, 'sesskey' => sesskey())); $icon = $this->output->pix_icon('t/switch_minus', $strremovesection); echo html_writer::link($url, $icon . get_accesshide($strremovesection), array('class' => 'reduce-sections')); } echo html_writer::end_tag('div'); } else { echo $this->end_section_list(); } }
function RWSSQDMoodle(&$r_qiz) { global $DB; global $CFG; if (!empty($r_qiz->coursemodule)) { if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) { $r_ctx = context_module::instance($r_qiz->coursemodule); } else { $r_ctx = get_context_instance(CONTEXT_MODULE, $r_qiz->coursemodule); } $r_ctxi = $r_ctx->id; } else { if (!empty($r_qiz->course)) { if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) { $r_ctx = context_course::instance($r_qiz->course); } else { $r_ctx = get_context_instance(CONTEXT_COURSE, $r_qiz->course); } $r_ctxi = $r_ctx->id; } else { $r_ctxi = null; } } $r_dfs = get_config("quiz"); $r_qiz->intro = ""; $r_qiz->introformat = FORMAT_HTML; $r_qiz->timeopen = 0; $r_qiz->timeclose = 0; if ($r_dfs->timelimit > 0) { $r_qiz->timelimitenable = 1; } else { $r_qiz->timelimitenable = 0; } $r_qiz->timelimit = $r_dfs->timelimit; $r_qiz->attempts = $r_dfs->attempts; $r_qiz->grademethod = $r_dfs->grademethod; if (respondusws_floatcompare($CFG->version, 2012040205, 2) >= 0) { $r_qiz->overduehandling = $r_dfs->overduehandling; } if (respondusws_floatcompare($CFG->version, 2012040206, 2) >= 0) { $r_qiz->graceperiod = $r_dfs->graceperiod; } $r_qiz->questionsperpage = $r_dfs->questionsperpage; $r_qiz->shufflequestions = $r_dfs->shufflequestions; if (respondusws_floatcompare($CFG->version, 2012030901, 2) >= 0) { $r_qiz->navmethod = $r_dfs->navmethod; } $r_qiz->shuffleanswers = $r_dfs->shuffleanswers; if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qiz->preferredbehaviour = $r_dfs->preferredbehaviour; } else { $r_qiz->adaptive = $r_dfs->optionflags & RWSQAD; $r_qiz->penaltyscheme = $r_dfs->penaltyscheme; } $r_qiz->attemptonlast = $r_dfs->attemptonlast; if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qiz->attemptduring = $r_dfs->reviewattempt & RWSRDU; if (!$r_qiz->attemptduring) { unset($r_qiz->attemptduring); } $r_qiz->correctnessduring = $r_dfs->reviewcorrectness & RWSRDU; if (!$r_qiz->correctnessduring) { unset($r_qiz->correctnessduring); } $r_qiz->marksduring = $r_dfs->reviewmarks & RWSRDU; if (!$r_qiz->marksduring) { unset($r_qiz->marksduring); } $r_qiz->specificfeedbackduring = $r_dfs->reviewspecificfeedback & RWSRDU; if (!$r_qiz->specificfeedbackduring) { unset($r_qiz->specificfeedbackduring); } $r_qiz->generalfeedbackduring = $r_dfs->reviewgeneralfeedback & RWSRDU; if (!$r_qiz->generalfeedbackduring) { unset($r_qiz->generalfeedbackduring); } $r_qiz->rightanswerduring = $r_dfs->reviewrightanswer & RWSRDU; if (!$r_qiz->rightanswerduring) { unset($r_qiz->rightanswerduring); } $r_qiz->overallfeedbackduring = $r_dfs->reviewoverallfeedback & RWSRDU; if (!$r_qiz->overallfeedbackduring) { unset($r_qiz->overallfeedbackduring); } } if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qiz->attemptimmediately = $r_dfs->reviewattempt & RWSRIA; if (!$r_qiz->attemptimmediately) { unset($r_qiz->attemptimmediately); } $r_qiz->correctnessimmediately = $r_dfs->reviewcorrectness & RWSRIA; if (!$r_qiz->correctnessimmediately) { unset($r_qiz->correctnessimmediately); } $r_qiz->marksimmediately = $r_dfs->reviewmarks & RWSRIA; if (!$r_qiz->marksimmediately) { unset($r_qiz->marksimmediately); } $r_qiz->specificfeedbackimmediately = $r_dfs->reviewspecificfeedback & RWSRIA; if (!$r_qiz->specificfeedbackimmediately) { unset($r_qiz->specificfeedbackimmediately); } $r_qiz->generalfeedbackimmediately = $r_dfs->reviewgeneralfeedback & RWSRIA; if (!$r_qiz->generalfeedbackimmediately) { unset($r_qiz->generalfeedbackimmediately); } $r_qiz->rightanswerimmediately = $r_dfs->reviewrightanswer & RWSRIA; if (!$r_qiz->rightanswerimmediately) { unset($r_qiz->rightanswerimmediately); } $r_qiz->overallfeedbackimmediately = $r_dfs->reviewoverallfeedback & RWSRIA; if (!$r_qiz->overallfeedbackimmediately) { unset($r_qiz->overallfeedbackimmediately); } } else { $r_qiz->responsesimmediately = $r_dfs->review & RWSRRE & RWSRIM; if (!$r_qiz->responsesimmediately) { unset($r_qiz->responsesimmediately); } $r_qiz->answersimmediately = $r_dfs->review & RWSRAN & RWSRIM; if (!$r_qiz->answersimmediately) { unset($r_qiz->answersimmediately); } $r_qiz->feedbackimmediately = $r_dfs->review & RWSRFE & RWSRIM; if (!$r_qiz->feedbackimmediately) { unset($r_qiz->feedbackimmediately); } $r_qiz->generalfeedbackimmediately = $r_dfs->review & RWSRGE & RWSRIM; if (!$r_qiz->generalfeedbackimmediately) { unset($r_qiz->generalfeedbackimmediately); } $r_qiz->scoreimmediately = $r_dfs->review & RWSRSC & RWSRIM; if (!$r_qiz->scoreimmediately) { unset($r_qiz->scoreimmediately); } $r_qiz->overallfeedbackimmediately = $r_dfs->review & RWSROV & RWSRIM; if (!$r_qiz->overallfeedbackimmediately) { unset($r_qiz->overallfeedbackimmediately); } } if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qiz->attemptopen = $r_dfs->reviewattempt & RWSRLA; if (!$r_qiz->attemptopen) { unset($r_qiz->attemptopen); } $r_qiz->correctnessopen = $r_dfs->reviewcorrectness & RWSRLA; if (!$r_qiz->correctnessopen) { unset($r_qiz->correctnessopen); } $r_qiz->marksopen = $r_dfs->reviewmarks & RWSRLA; if (!$r_qiz->marksopen) { unset($r_qiz->marksopen); } $r_qiz->specificfeedbackopen = $r_dfs->reviewspecificfeedback & RWSRLA; if (!$r_qiz->specificfeedbackopen) { unset($r_qiz->specificfeedbackopen); } $r_qiz->generalfeedbackopen = $r_dfs->reviewgeneralfeedback & RWSRLA; if (!$r_qiz->generalfeedbackopen) { unset($r_qiz->generalfeedbackopen); } $r_qiz->rightansweropen = $r_dfs->reviewrightanswer & RWSRLA; if (!$r_qiz->rightansweropen) { unset($r_qiz->rightansweropen); } $r_qiz->overallfeedbackopen = $r_dfs->reviewoverallfeedback & RWSRLA; if (!$r_qiz->overallfeedbackopen) { unset($r_qiz->overallfeedbackopen); } } else { $r_qiz->responsesopen = $r_dfs->review & RWSRRE & RWSROP; if (!$r_qiz->responsesopen) { unset($r_qiz->responsesopen); } $r_qiz->answersopen = $r_dfs->review & RWSRAN & RWSROP; if (!$r_qiz->answersopen) { unset($r_qiz->answersopen); } $r_qiz->feedbackopen = $r_dfs->review & RWSRFE & RWSROP; if (!$r_qiz->feedbackopen) { unset($r_qiz->feedbackopen); } $r_qiz->generalfeedbackopen = $r_dfs->review & RWSRGE & RWSROP; if (!$r_qiz->generalfeedbackopen) { unset($r_qiz->generalfeedbackopen); } $r_qiz->scoreopen = $r_dfs->review & RWSRSC & RWSROP; if (!$r_qiz->scoreopen) { unset($r_qiz->scoreopen); } $r_qiz->overallfeedbackopen = $r_dfs->review & RWSROV & RWSROP; if (!$r_qiz->overallfeedbackopen) { unset($r_qiz->overallfeedbackopen); } } if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qiz->attemptclosed = $r_dfs->reviewattempt & RWSRAF; if (!$r_qiz->attemptclosed) { unset($r_qiz->attemptclosed); } $r_qiz->correctnessclosed = $r_dfs->reviewcorrectness & RWSRAF; if (!$r_qiz->correctnessclosed) { unset($r_qiz->correctnessclosed); } $r_qiz->marksclosed = $r_dfs->reviewmarks & RWSRAF; if (!$r_qiz->marksclosed) { unset($r_qiz->marksclosed); } $r_qiz->specificfeedbackclosed = $r_dfs->reviewspecificfeedback & RWSRAF; if (!$r_qiz->specificfeedbackclosed) { unset($r_qiz->specificfeedbackclosed); } $r_qiz->generalfeedbackclosed = $r_dfs->reviewgeneralfeedback & RWSRAF; if (!$r_qiz->generalfeedbackclosed) { unset($r_qiz->generalfeedbackclosed); } $r_qiz->rightanswerclosed = $r_dfs->reviewrightanswer & RWSRAF; if (!$r_qiz->rightanswerclosed) { unset($r_qiz->rightanswerclosed); } $r_qiz->overallfeedbackclosed = $r_dfs->reviewoverallfeedback & RWSRAF; if (!$r_qiz->overallfeedbackclosed) { unset($r_qiz->overallfeedbackclosed); } } else { $r_qiz->responsesclosed = $r_dfs->review & RWSRRE & RWSRCL; if (!$r_qiz->responsesclosed) { unset($r_qiz->responsesclosed); } $r_qiz->answersclosed = $r_dfs->review & RWSRAN & RWSRCL; if (!$r_qiz->answersclosed) { unset($r_qiz->answersclosed); } $r_qiz->feedbackclosed = $r_dfs->review & RWSRFE & RWSRCL; if (!$r_qiz->feedbackclosed) { unset($r_qiz->feedbackclosed); } $r_qiz->generalfeedbackclosed = $r_dfs->review & RWSRGE & RWSRCL; if (!$r_qiz->generalfeedbackclosed) { unset($r_qiz->generalfeedbackclosed); } $r_qiz->scoreclosed = $r_dfs->review & RWSRSC & RWSRCL; if (!$r_qiz->scoreclosed) { unset($r_qiz->scoreclosed); } $r_qiz->overallfeedbackclosed = $r_dfs->review & RWSROV & RWSRCL; if (!$r_qiz->overallfeedbackclosed) { unset($r_qiz->overallfeedbackclosed); } } $r_qiz->showuserpicture = $r_dfs->showuserpicture; $r_qiz->decimalpoints = $r_dfs->decimalpoints; $r_qiz->questiondecimalpoints = $r_dfs->questiondecimalpoints; $r_qiz->showblocks = $r_dfs->showblocks; $r_qiz->quizpassword = $r_dfs->password; $r_qiz->subnet = $r_dfs->subnet; $r_qiz->delay1 = $r_dfs->delay1; $r_qiz->delay2 = $r_dfs->delay2; if (isset($r_dfs->browsersecurity)) { $r_qiz->browsersecurity = $r_dfs->browsersecurity; } else { $r_qiz->popup = $r_dfs->popup; } $r_nf = 5; for ($r_i = 0; $r_i < $r_nf; $r_i++) { $r_drf = 0; $r_cmp = "mod_quiz"; $r_far = "feedback"; $r_iti = null; $r_op = null; $r_txt = ""; $r_qiz->feedbacktext[$r_i]["text"] = file_prepare_draft_area($r_drf, $r_ctxi, $r_cmp, $r_far, $r_iti, $r_op, $r_txt); $r_qiz->feedbacktext[$r_i]["format"] = FORMAT_HTML; $r_qiz->feedbacktext[$r_i]["itemid"] = $r_drf; if ($r_i < $r_nf - 1) { $r_qiz->feedbackboundaries[$r_i] = ""; } } $r_qiz->groupmode = NOGROUPS; $r_qiz->groupingid = 0; $r_qiz->visible = 1; $r_qiz->cmidnumber = ""; if (!empty($r_qiz->course)) { $r_crs = $DB->get_record("course", array("id" => $r_qiz->course)); if ($r_crs !== false) { $r_qiz->groupmode = $r_crs->groupmode; $r_qiz->groupingid = $r_crs->defaultgroupingid; if (!empty($r_qiz->section)) { if (respondusws_floatcompare($CFG->version, 2012120300, 2) >= 0) { $modinfo = get_fast_modinfo($r_qiz->course); $r_sec = $modinfo->get_section_info($r_qiz->section); } else { $r_sec = get_course_section($r_qiz->section, $r_qiz->course); } $r_qiz->visible = $r_sec->visible; } } } $r_qiz->grade = $r_dfs->maximumgrade; }
if (!empty($return)) { $url->param('return', $return); } if (!empty($add)) { $section = required_param('section', PARAM_INT); $course = required_param('course', PARAM_INT); $url->param('add', $add); $url->param('section', $section); $url->param('course', $course); $PAGE->set_url($url); $course = $DB->get_record('course', array('id' => $course), '*', MUST_EXIST); $module = $DB->get_record('modules', array('name' => $add), '*', MUST_EXIST); require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); $cw = get_course_section($section, $course->id); if (!course_allowed_module($course, $module->id)) { print_error('moduledisable'); } $cm = null; $data = new stdClass(); $data->section = $section; // The section number itself - relative!!! (section column in course_sections) $data->visible = $cw->visible; $data->course = $course->id; $data->module = $module->id; $data->modulename = $module->name; $data->groupmode = $course->groupmode; $data->groupingid = $course->defaultgroupingid; $data->groupmembersonly = 0; $data->id = '';
/** * Adds a new section object to be used by this subpage * * @return object */ public function add_section($name = '', $summary = '') { global $DB, $CFG; require_once $CFG->dirroot . '/course/lib.php'; // Needed for get_course_section. $transaction = $DB->start_delegated_transaction(); // Extra condition if the oucontent module (which has similar but simpler // behaviour) is installed, so they don't tread on each others' toes. $oucontentjoin = ''; $oucontentwhere = ''; if (file_exists($CFG->dirroot . '/mod/oucontent')) { $oucontentjoin = 'LEFT JOIN {oucontent} o ' . 'ON o.course = cs.course AND o.coursesectionid = cs2.id'; $oucontentwhere = 'AND o.id IS NULL'; } // Pick a section number. This query finds the first section // on the course that is at least the minimum number, and does not have // a used section in the following number, and returns that following // section number. (This means it can fill up gaps if sections are // deleted.) $sql = "\nSELECT\n cs.section+1 AS num\nFROM\n {course_sections} cs\n LEFT JOIN {course_sections} cs2 ON cs2.course = cs.course AND cs2.section = cs.section+1\n LEFT JOIN {subpage_sections} ss2 ON ss2.sectionid = cs2.id\n {$oucontentjoin}\nWHERE\n cs.course = ?\n AND cs.section >= ?\n AND ss2.id IS NULL\n {$oucontentwhere}\nORDER BY\n cs.section"; $result = $DB->get_records_sql($sql, array($this->course->id, self::SECTION_NUMBER_MIN), 0, 1); if (count($result) == 0) { // If no existing sections, use the min number. $sectionnum = self::SECTION_NUMBER_MIN; } else { $sectionnum = reset($result)->num; } // Create a section entry with this section number - this function creates // and returns the section. $section = get_course_section($sectionnum, $this->course->id); // Now update summary/name if set above. if (!empty($name) or !empty($summary)) { $section->name = format_string($name); $section->summary = format_text($summary); $DB->update_record('course_sections', $section); } $sql = "SELECT MAX(pageorder) FROM {subpage_sections} WHERE subpageid = ?"; // Get highest pageorder and add 1. $pageorder = $DB->get_field_sql($sql, array($this->subpage->id)) + 1; $subpage_section = new stdClass(); $subpage_section->subpageid = $this->subpage->id; $subpage_section->sectionid = $section->id; $subpage_section->pageorder = $pageorder; $subpage_section->stealth = 0; $ss = $DB->insert_record('subpage_sections', $subpage_section); $transaction->allow_commit(); return array('subpagesectionid' => $ss, 'sectionid' => $section->id); }
$module->course = $courseid; $module->section = $i; $module->module = $moduledata->id; $module->modulename = $moduledata->name; $module->add = $moduledata->name; $module->cmidnumber = ''; $add_instance_function = $moduledata->name . '_add_instance'; if (function_exists($add_instance_function)) { $module->instance = $add_instance_function($module, ''); } else { verbose("Function {$add_instance_function} does not exist!"); if (!$settings['ignore-errors']) { die; } } $section = get_course_section($i, $courseid); $module->section = $section->id; $module->coursemodule = add_course_module($module); $module->section = $i; add_mod_to_section($module); $module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, ''); verbose("A {$moduledata->name} module was added to section {$i} (id {$module->section}) of course {$courseid}."); rebuild_course_cache($courseid); if ($moduledata->name == 'quiz') { $quiz_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule)); $quiz = $DB->get_record('quiz', array('id' => $quiz_instance)); $quiz->instance = $quiz_instance; $quizzes[] = $quiz; } elseif ($moduledata->name == 'assignment') { $assignment_instance = $DB->get_field('course_modules', 'instance', array('id' => $module->coursemodule)); $assignment = $DB->get_record('assignment', array('id' => $assignment_instance));
function get_content() { global $USER, $CFG, $COURSE; if ($this->content !== NULL) { return $this->content; } $this->content = new object(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } if ($COURSE->id == $this->instance->pageid) { $course = $COURSE; } else { $course = get_record('course', 'id', $this->instance->pageid); } require_once $CFG->dirroot . '/course/lib.php'; $context = get_context_instance(CONTEXT_COURSE, $course->id); $isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context); $modinfo =& get_fast_modinfo($course); /// extra fast view mode if (!$isediting) { if (!empty($modinfo->sections[0])) { foreach ($modinfo->sections[0] as $cmid) { $cm = $modinfo->cms[$cmid]; if (!$cm->uservisible) { continue; } if ($cm->modname == 'label') { $this->content->items[] = format_text($cm->extra, FORMAT_HTML); $this->content->icons[] = ''; } else { $linkcss = $cm->visible ? '' : ' class="dimmed" '; $instancename = format_string($cm->name, true, $course->id); $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $CFG->wwwroot . '/mod/' . $cm->modname . '/view.php?id=' . $cm->id . '">' . $instancename . '</a>'; //Accessibility: incidental image - should be empty Alt text if (!empty($cm->icon)) { $icon = $CFG->pixpath . '/' . $cm->icon; } else { $icon = $CFG->modpixpath . '/' . $cm->modname . '/icon.gif'; } $this->content->icons[] = '<img src="' . $icon . '" class="icon" alt="" />'; } } } return $this->content; } /// slow & hacky editing mode $ismoving = ismoving($this->instance->pageid); $section = get_course_section(0, $this->instance->pageid); get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused); $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="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="" />'; $this->content->items[] = $USER->activitycopyname . ' (<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&sesskey=' . $USER->sesskey . '">' . $strcancel . '</a>)'; } if (!empty($section->sequence)) { $sectionmods = explode(',', $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; 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 . '&sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } $instancename = $modinfo->cms[$modnumber]->name; $instancename = format_string($instancename, true, $this->instance->pageid); $linkcss = $mod->visible ? '' : ' class="dimmed" '; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } else { $extra = ''; } if (!empty($modinfo->cms[$modnumber]->icon)) { $icon = $CFG->pixpath . '/' . $modinfo->cms[$modnumber]->icon; } else { $icon = $CFG->modpixpath . '/' . $mod->modname . '/icon.gif'; } if ($mod->modname == 'label') { $this->content->items[] = format_text($extra, FORMAT_HTML) . $editbuttons; $this->content->icons[] = ''; } else { $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . $instancename . '</a>' . $editbuttons; //Accessibility: incidental image - should be empty Alt text $this->content->icons[] = '<img src="' . $icon . '" class="icon" alt="" />'; } } } } if ($ismoving) { $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } if (!empty($modnames)) { $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true); } else { $this->content->footer = ''; } return $this->content; }
/** * バックアップするセクションファイルのチェック * * Calculate the number of course files to backup * under $CFG->dataroot/$course, except $CFG->moddata, and backupdata * and put them (their path) in backup_ids * Return an array of info (name,value) */ function project_course_files_check_backup($courseid, $sectionnumber, $backup_unique_code) { global $CFG; // 対象のコース情報の取得 if (!($course = get_record("course", "id", $courseid))) { error("Course ID was incorrect (can't find it)"); } // セクション情報の取得 if (!($section = get_course_section($sectionnumber, $course->id))) { error("Section data was incorrect (can't find it)"); } // セクションタイトルの取得 if (!($sectiontitle = get_record('course_project_title', 'sectionid', $section->id))) { error("Could not find section title"); } // バックアップ対象ディレクトリ $rootdir = $CFG->dataroot . "/{$courseid}/" . $sectiontitle->directoryname; //Check if directory exists if (is_dir($rootdir)) { //Get files and directories without descend $coursedirs = get_directory_list($rootdir, $CFG->moddata, false, true, true); $backupdata_dir = "backupdata"; foreach ($coursedirs as $dir) { //Check it isn't backupdata_dir if (strpos($dir, $backupdata_dir) !== 0) { //Insert them into backup_files $status = execute_sql("INSERT INTO {$CFG->prefix}backup_files\r\n (backup_code, file_type, path)\r\n VALUES\r\n ('{$backup_unique_code}','course','" . addslashes($dir) . "')", false); } //Do some output backup_flush(30); } } //Now execute the select $ids = get_records_sql("SELECT DISTINCT b.path, b.old_id\r\n FROM {$CFG->prefix}backup_files b\r\n WHERE backup_code = '{$backup_unique_code}' AND\r\n file_type = 'course'"); // Gets the user data $info = array(); // ディレクトリ名 $info[0] = array(); $info[0][0] = get_string('directoryname', 'format_project'); $info[0][1] = $sectiontitle->directoryname; // ファイル数 $info[1] = array(); $info[1][0] = get_string("files"); if ($ids) { $info[1][1] = count($ids); } else { $info[1][1] = 0; } return $info; }