本文整理汇总了PHP中course_overviewfiles_options函数的典型用法代码示例。如果您正苦于以下问题:PHP course_overviewfiles_options函数的具体用法?PHP course_overviewfiles_options怎么用?PHP course_overviewfiles_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了course_overviewfiles_options函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_course
/**
* Update a course.
*
* Please note this functions does not verify any access control,
* the calling code is responsible for all validation (usually it is the form definition).
*
* @param object $data - all the data needed for an entry in the 'course' table
* @param array $editoroptions course description editor options
* @return void
*/
function update_course($data, $editoroptions = NULL)
{
global $DB;
$data->timemodified = time();
$oldcourse = course_get_format($data->id)->get_course();
$context = context_course::instance($oldcourse->id);
if ($editoroptions) {
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
}
if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
$data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
}
// Check we don't have a duplicate shortname.
if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
throw new moodle_exception('shortnametaken', '', '', $data->shortname);
}
}
// Check we don't have a duplicate idnumber.
if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
}
}
if (!isset($data->category) or empty($data->category)) {
// prevent nulls and 0 in category field
unset($data->category);
}
$changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
if (!isset($data->visible)) {
// data not from form, add missing visibility info
$data->visible = $oldcourse->visible;
}
if ($data->visible != $oldcourse->visible) {
// reset the visibleold flag when manually hiding/unhiding course
$data->visibleold = $data->visible;
$changesincoursecat = true;
} else {
if ($movecat) {
$newcategory = $DB->get_record('course_categories', array('id' => $data->category));
if (empty($newcategory->visible)) {
// make sure when moving into hidden category the course is hidden automatically
$data->visible = 0;
}
}
}
// Update with the new data
$DB->update_record('course', $data);
// make sure the modinfo cache is reset
rebuild_course_cache($data->id);
// update course format options with full course data
course_get_format($data->id)->update_course_format_options($data, $oldcourse);
$course = $DB->get_record('course', array('id' => $data->id));
if ($movecat) {
$newparent = context_coursecat::instance($course->category);
$context->update_moved($newparent);
}
$fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
if ($fixcoursesortorder) {
fix_course_sortorder();
}
// purge appropriate caches in case fix_course_sortorder() did not change anything
cache_helper::purge_by_event('changesincourse');
if ($changesincoursecat) {
cache_helper::purge_by_event('changesincoursecat');
}
// Test for and remove blocks which aren't appropriate anymore
blocks_remove_inappropriate($course);
// Save any custom role names.
save_local_role_names($course->id, $data);
// update enrol settings
enrol_course_updated(false, $course, $data);
// Trigger a course updated event.
$event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
$event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
$event->trigger();
if ($oldcourse->format !== $course->format) {
// Remove all options stored for the previous format
// We assume that new course format migrated everything it needed watching trigger
// 'course_updated' and in method format_XXX::update_course_format_options()
$DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
}
}
示例2: get_course_overviewfiles
/**
* Returns all course overview files
*
* @return array array of stored_file objects
*/
public function get_course_overviewfiles()
{
global $CFG;
if (empty($CFG->courseoverviewfileslimit)) {
return array();
}
require_once $CFG->libdir . '/filestorage/file_storage.php';
require_once $CFG->dirroot . '/course/lib.php';
$fs = get_file_storage();
$context = context_course::instance($this->id);
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
if (count($files)) {
$overviewfilesoptions = course_overviewfiles_options($this->id);
$acceptedtypes = $overviewfilesoptions['accepted_types'];
if ($acceptedtypes !== '*') {
// Filter only files with allowed extensions.
require_once $CFG->libdir . '/filelib.php';
foreach ($files as $key => $file) {
if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
unset($files[$key]);
}
}
}
if (count($files) > $CFG->courseoverviewfileslimit) {
// Return no more than $CFG->courseoverviewfileslimit files.
$files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
}
}
return $files;
}
示例3: definition
//.........这里部分代码省略.........
}
}
$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');
示例4: update_course
/**
* Update a course.
*
* Please note this functions does not verify any access control,
* the calling code is responsible for all validation (usually it is the form definition).
*
* @param object $data - all the data needed for an entry in the 'course' table
* @param array $editoroptions course description editor options
* @return void
*/
function update_course($data, $editoroptions = NULL)
{
global $CFG, $DB;
$data->timemodified = time();
$oldcourse = course_get_format($data->id)->get_course();
$context = context_course::instance($oldcourse->id);
if ($editoroptions) {
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
}
if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
$data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
}
if (!isset($data->category) or empty($data->category)) {
// prevent nulls and 0 in category field
unset($data->category);
}
$changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
if (!isset($data->visible)) {
// data not from form, add missing visibility info
$data->visible = $oldcourse->visible;
}
if ($data->visible != $oldcourse->visible) {
// reset the visibleold flag when manually hiding/unhiding course
$data->visibleold = $data->visible;
$changesincoursecat = true;
} else {
if ($movecat) {
$newcategory = $DB->get_record('course_categories', array('id' => $data->category));
if (empty($newcategory->visible)) {
// make sure when moving into hidden category the course is hidden automatically
$data->visible = 0;
}
}
}
// Update with the new data
$DB->update_record('course', $data);
// make sure the modinfo cache is reset
rebuild_course_cache($data->id);
// update course format options with full course data
course_get_format($data->id)->update_course_format_options($data, $oldcourse);
$course = $DB->get_record('course', array('id' => $data->id));
if ($movecat) {
$newparent = context_coursecat::instance($course->category);
context_moved($context, $newparent);
}
fix_course_sortorder();
// purge appropriate caches in case fix_course_sortorder() did not change anything
cache_helper::purge_by_event('changesincourse');
if ($changesincoursecat) {
cache_helper::purge_by_event('changesincoursecat');
}
// Test for and remove blocks which aren't appropriate anymore
blocks_remove_inappropriate($course);
// Save any custom role names.
save_local_role_names($course->id, $data);
// update enrol settings
enrol_course_updated(false, $course, $data);
add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
// Trigger events
events_trigger('course_updated', $course);
if ($oldcourse->format !== $course->format) {
// Remove all options stored for the previous format
// We assume that new course format migrated everything it needed watching trigger
// 'course_updated' and in method format_XXX::update_course_format_options()
$DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
}
}
示例5: require_login
if ($categoryid) {
// Creating new course in this category.
$course = null;
require_login();
$category = $DB->get_record('course_categories', array('id' => $categoryid), '*', MUST_EXIST);
$catcontext = context_coursecat::instance($category->id);
require_capability('moodle/course:create', $catcontext);
$PAGE->set_context($catcontext);
} else {
require_login();
print_error('needcoursecategroyid');
}
}
// Prepare course and the editor.
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'noclean' => true);
$overviewfilesoptions = course_overviewfiles_options($course);
if (!empty($course)) {
// Add context for editor.
$editoroptions['context'] = $coursecontext;
$editoroptions['subdirs'] = file_area_contains_subdirs($coursecontext, 'course', 'summary', 0);
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course', 'summary', 0);
if ($overviewfilesoptions) {
file_prepare_standard_filemanager($course, 'overviewfiles', $overviewfilesoptions, $coursecontext, 'course', 'overviewfiles', 0);
}
// Inject current aliases.
$aliases = $DB->get_records('role_names', array('contextid' => $coursecontext->id));
foreach ($aliases as $alias) {
$course->{'role_' . $alias->roleid} = $alias->name;
}
// Populate course tags.
$course->tags = core_tag_tag::get_item_tags_array('core', 'course', $course->id);
示例6: definition
//.........这里部分代码省略.........
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);
示例7: array
<?php
global $CFG, $COURSE;
if (empty($CFG->courseoverviewfileslimit)) {
return array();
}
require_once $CFG->libdir . '/filestorage/file_storage.php';
require_once $CFG->dirroot . '/course/lib.php';
$fs = get_file_storage();
$context = context_course::instance($COURSE->id);
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
if (count($files)) {
$overviewfilesoptions = course_overviewfiles_options($COURSE->id);
$acceptedtypes = $overviewfilesoptions['accepted_types'];
if ($acceptedtypes !== '*') {
// Filter only files with allowed extensions.
require_once $CFG->libdir . '/filelib.php';
foreach ($files as $key => $file) {
if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
unset($files[$key]);
}
}
}
if (count($files) > $CFG->courseoverviewfileslimit) {
// Return no more than $CFG->courseoverviewfileslimit files.
$files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
}
}
// Display course overview files.
$courseimage = '';
foreach ($files as $file) {