/** * Gathers and returns the information about all plugins of the given type * * @param string $type the name of the plugintype, eg. mod, auth or workshopform * @param string $typerootdir full path to the location of the plugin dir * @param string $typeclass the name of the actually called class * @param core_plugin_manager $pluginman the plugin manager calling this method * @return array of plugintype classes, indexed by the plugin name */ public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; $formats = parent::get_plugins($type, $typerootdir, $typeclass, $pluginman); $order = get_sorted_course_formats(); $sortedformats = array(); foreach ($order as $formatname) { $sortedformats[$formatname] = $formats[$formatname]; } return $sortedformats; }
/** * Validates that course format exists and enabled and returns either itself or default format * * @param string $format * @return string */ protected static final function get_format_or_default($format) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; if (array_key_exists($format, self::$classesforformat)) { return self::$classesforformat[$format]; } $plugins = get_sorted_course_formats(); foreach ($plugins as $plugin) { self::$classesforformat[$plugin] = $plugin; } if (array_key_exists($format, self::$classesforformat)) { return self::$classesforformat[$format]; } if (PHPUNIT_TEST && class_exists('format_' . $format)) { // Allow unittests to use non-existing course formats. return $format; } // Else return default format $defaultformat = get_config('moodlecourse', 'format'); if (!in_array($defaultformat, $plugins)) { // when default format is not set correctly, use the first available format $defaultformat = reset($plugins); } debugging('Format plugin format_' . $format . ' is not found. Using default format_' . $defaultformat, DEBUG_DEVELOPER); self::$classesforformat[$format] = $defaultformat; return $defaultformat; }
function definition() { global $USER, $CFG, $DB, $PAGE; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; /// form definition with new course defaults //-------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); if (!isset($displaylist[$course->category])) { //always keep current $displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name(); } $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!has_capability('moodle/course:visibility', $context)) { $mform->hardFreeze('visible'); if (!empty($course->id)) { $mform->setConstant('visible', $course->visible); } else { $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes = array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key => $theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages = array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0' => get_string('no'), '2' => get_string('yes')); } else { $choices = array('1' => get_string('no'), '2' => get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } //-------------------------------------------------------------------------------- enrol_course_edit_form($mform, $course, $context); //-------------------------------------------------------------------------------- $mform->addElement('header', 'groups', get_string('groups', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); //-------------------------------------------------------------------------------- /// customizable role names in this course //-------------------------------------------------------------------------------- $mform->addElement('header', 'rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_' . $role->id, PARAM_TEXT); } } //-------------------------------------------------------------------------------- $this->add_action_buttons(); //-------------------------------------------------------------------------------- $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); /// finally set the current form data //-------------------------------------------------------------------------------- $this->set_data($course); }
// Speedup for non-admins, add all caps used on this page. $ADMIN->add('courses', new admin_externalpage('coursemgmt', new lang_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/management.php', array('moodle/category:manage', 'moodle/course:create'))); $ADMIN->add('courses', new admin_externalpage('addcategory', new lang_string('addcategory', 'admin'), new moodle_url('/course/editcategory.php', array('parent' => 0)), array('moodle/category:manage'))); $ADMIN->add('courses', new admin_externalpage('restorecourse', new lang_string('restorecourse', 'admin'), new moodle_url('/backup/restorefile.php', array('contextid' => context_system::instance()->id)), array('moodle/restore:restorecourse'))); // Course Default Settings Page. // NOTE: these settings must be applied after all other settings because they depend on them. // Main course settings. $temp = new admin_settingpage('coursesettings', new lang_string('coursesettings')); require_once $CFG->dirroot . '/course/lib.php'; $choices = array(); $choices['0'] = new lang_string('hide'); $choices['1'] = new lang_string('show'); $temp->add(new admin_setting_configselect('moodlecourse/visible', new lang_string('visible'), new lang_string('visible_help'), 1, $choices)); // Course format. $temp->add(new admin_setting_heading('courseformathdr', new lang_string('type_format', 'plugin'), '')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = new lang_string('pluginname', "format_{$courseformat}"); } $temp->add(new admin_setting_configselect('moodlecourse/format', new lang_string('format'), new lang_string('coursehelpformat'), 'weeks', $formcourseformats)); $temp->add(new admin_setting_configtext('moodlecourse/maxsections', new lang_string('maxnumberweeks'), new lang_string('maxnumberweeks_desc'), 52)); $temp->add(new admin_settings_num_course_sections('moodlecourse/numsections', new lang_string('numberweeks'), new lang_string('coursehelpnumberweeks'), 10)); $choices = array(); $choices['0'] = new lang_string('hiddensectionscollapsed'); $choices['1'] = new lang_string('hiddensectionsinvisible'); $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', new lang_string('hiddensections'), new lang_string('coursehelphiddensections'), 0, $choices)); $choices = array(); $choices[COURSE_DISPLAY_SINGLEPAGE] = new lang_string('coursedisplay_single'); $choices[COURSE_DISPLAY_MULTIPAGE] = new lang_string('coursedisplay_multi'); $temp->add(new admin_setting_configselect('moodlecourse/coursedisplay', new lang_string('coursedisplay'), new lang_string('coursedisplay_help'), COURSE_DISPLAY_SINGLEPAGE, $choices));
/** * Form definition. */ function definition() { global $CFG, $PAGE,$USER,$DB; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form //print_object($course); $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; // Form definition with new course defaults. $mform->addElement('header','general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); /* * EA_NK23-02-2015 * Added cost center field */ $is_manager = $DB->record_exists_sql("SELECT ra.userid FROM {role_assignments} as ra JOIN {role} as r ON ra.roleid=r.id WHERE r.archetype='manager' AND ra.userid={$USER->id}"); if(is_siteadmin()) { /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $admincostcenters=user_wise_department(); //print_object($admincostcenters); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }elseif(!is_siteadmin()){ $admincostcenters=user_wise_department(); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); } //$costcenter = $DB->get_records_sql_menu("SELECT cc.id,cc.fullname FROM mdl_local_userdata ud JOIN mdl_local_costcenter cc ON ud.costcenterid=cc.id WHERE ud.userid={$USER->id}"); //$mform->addElement('hidden','costcenter'); //$mform->setDefault('costcenter',$costcenter->id); //$mform->addElement('static', 'costcenterid', get_string('pluginname', 'local_costcenter'), $costcenter->fullname); $mform->setType('costcenter', PARAM_RAW); /* EA_NK23-02-2015 Customization ends here */ $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); /*======================Started By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ if(is_siteadmin()){ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }else{ /*======================Ended By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ } $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!empty($course->id)) { if (!has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } } else { if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_'.$course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes=array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key=>$theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_'.$theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages=array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $calendars = array(); $calendars[''] = get_string('forceno'); $calendars += $calendartypes; $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars); } $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0'=>get_string('no'), '2'=>get_string('yes')); } else { $choices = array('1'=>get_string('no'), '2'=>get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } enrol_course_edit_form($mform, $course, $context); $mform->addElement('header','groups', get_string('groupsettingsheader', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); // Customizable role names in this course. $mform->addElement('header','rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_'.$role->id, PARAM_TEXT); } } $this->add_action_buttons(); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($course); }
/** * Validates that course format exists and enabled and returns either itself or default format * * @param string $format * @return string */ protected static final function get_format_or_default($format) { if (array_key_exists($format, self::$classesforformat)) { return self::$classesforformat[$format]; } $plugins = get_sorted_course_formats(); foreach ($plugins as $plugin) { self::$classesforformat[$plugin] = $plugin; } if (array_key_exists($format, self::$classesforformat)) { return self::$classesforformat[$format]; } // Else return default format $defaultformat = get_config('moodlecourse', 'format'); if (!in_array($defaultformat, $plugins)) { // when default format is not set correctly, use the first available format $defaultformat = reset($plugins); } debugging('Format plugin format_' . $format . ' is not found. Using default format_' . $defaultformat, DEBUG_DEVELOPER); self::$classesforformat[$format] = $defaultformat; return $defaultformat; }
/** * The standard form definiton. * @return void. */ public function definition() { global $CFG; $mform = $this->_form; $data = $this->_customdata['data']; $courseconfig = get_config('moodlecourse'); // Import options. $this->add_import_options(); // Course options. $mform->addElement('header', 'courseoptionshdr', get_string('courseprocess', 'tool_uploadcourse')); $mform->setExpanded('courseoptionshdr', true); $mform->addElement('text', 'options[shortnametemplate]', get_string('shortnametemplate', 'tool_uploadcourse'), 'maxlength="100" size="20"'); $mform->setType('options[shortnametemplate]', PARAM_RAW); $mform->addHelpButton('options[shortnametemplate]', 'shortnametemplate', 'tool_uploadcourse'); $mform->disabledIf('options[shortnametemplate]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE); $mform->disabledIf('options[shortnametemplate]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_UPDATE_ONLY); // Restore file is not in the array options on purpose, because formslib can't handle it! $contextid = $this->_customdata['contextid']; $mform->addElement('hidden', 'contextid', $contextid); $mform->setType('contextid', PARAM_INT); $mform->addElement('filepicker', 'restorefile', get_string('templatefile', 'tool_uploadcourse')); $mform->addHelpButton('restorefile', 'templatefile', 'tool_uploadcourse'); $mform->addElement('text', 'options[templatecourse]', get_string('coursetemplatename', 'tool_uploadcourse')); $mform->setType('options[templatecourse]', PARAM_TEXT); $mform->addHelpButton('options[templatecourse]', 'coursetemplatename', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[reset]', get_string('reset', 'tool_uploadcourse')); $mform->setDefault('options[reset]', 0); $mform->disabledIf('options[reset]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->disabledIf('options[reset]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->disabledIf('options[reset]', 'options[allowresets]', 'eq', 0); $mform->addHelpButton('options[reset]', 'reset', 'tool_uploadcourse'); // Default values. $mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'tool_uploadcourse')); $mform->setExpanded('defaultheader', true); $displaylist = coursecat::make_categories_list('moodle/course:create'); $mform->addElement('select', 'defaults[category]', get_string('coursecategory'), $displaylist); $mform->addHelpButton('defaults[category]', 'coursecategory'); $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'defaults[visible]', get_string('visible'), $choices); $mform->addHelpButton('defaults[visible]', 'visible'); $mform->setDefault('defaults[visible]', $courseconfig->visible); $mform->addElement('date_selector', 'defaults[startdate]', get_string('startdate')); $mform->addHelpButton('defaults[startdate]', 'startdate'); $mform->setDefault('defaults[startdate]', time() + 3600 * 24); $mform->addElement('date_selector', 'defaults[enddate]', get_string('enddate'), array('optional' => true)); $mform->addHelpButton('defaults[enddate]', 'enddate'); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}"); } $mform->addElement('select', 'defaults[format]', get_string('format'), $formcourseformats); $mform->addHelpButton('defaults[format]', 'format'); $mform->setDefault('defaults[format]', $courseconfig->format); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes = array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key => $theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'defaults[theme]', get_string('forcetheme'), $themes); } $languages = array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'defaults[lang]', get_string('forcelanguage'), $languages); $mform->setDefault('defaults[lang]', $courseconfig->lang); $options = range(0, 10); $mform->addElement('select', 'defaults[newsitems]', get_string('newsitemsnumber'), $options); $mform->addHelpButton('defaults[newsitems]', 'newsitemsnumber'); $mform->setDefault('defaults[newsitems]', $courseconfig->newsitems); $mform->addElement('selectyesno', 'defaults[showgrades]', get_string('showgrades')); $mform->addHelpButton('defaults[showgrades]', 'showgrades'); $mform->setDefault('defaults[showgrades]', $courseconfig->showgrades); $mform->addElement('selectyesno', 'defaults[showreports]', get_string('showreports')); $mform->addHelpButton('defaults[showreports]', 'showreports'); $mform->setDefault('defaults[showreports]', $courseconfig->showreports); if (!empty($CFG->legacyfilesinnewcourses)) { $mform->addElement('select', 'defaults[legacyfiles]', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('defaults[legacyfiles]', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { $courseconfig->legacyfiles = 0; } $mform->setDefault('defaults[legacyfiles]', $courseconfig->legacyfiles); } $choices = get_max_upload_sizes($CFG->maxbytes); $mform->addElement('select', 'defaults[maxbytes]', get_string('maximumupload'), $choices); $mform->addHelpButton('defaults[maxbytes]', 'maximumupload'); $mform->setDefault('defaults[maxbytes]', $courseconfig->maxbytes); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'defaults[groupmode]', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('defaults[groupmode]', 'groupmode', 'group'); $mform->setDefault('defaults[groupmode]', $courseconfig->groupmode); $mform->addElement('selectyesno', 'defaults[groupmodeforce]', get_string('groupmodeforce', 'group')); $mform->addHelpButton('defaults[groupmodeforce]', 'groupmodeforce', 'group'); $mform->setDefault('defaults[groupmodeforce]', $courseconfig->groupmodeforce); // Hidden fields. $mform->addElement('hidden', 'importid'); $mform->setType('importid', PARAM_INT); $mform->addElement('hidden', 'previewrows'); $mform->setType('previewrows', PARAM_INT); $this->add_action_buttons(true, get_string('uploadcourses', 'tool_uploadcourse')); $this->set_data($data); }
/** * Validates that course format exists and enabled and returns either itself or default format * * @param string $format * @return string */ protected static final function get_format_or_default($format) { if ($format === 'site') { return $format; } $plugins = get_sorted_course_formats(); if (in_array($format, $plugins)) { return $format; } // Else return default format $defaultformat = get_config('moodlecourse', 'format'); if (!in_array($defaultformat, $plugins)) { // when default format is not set correctly, use the first available format $defaultformat = reset($plugins); } static $warningprinted = array(); if (empty($warningprinted[$format])) { debugging('Format plugin format_' . $format . ' is not found. Using default format_' . $defaultformat, DEBUG_DEVELOPER); $warningprinted[$format] = true; } return $defaultformat; }