本文整理汇总了PHP中completion_info::is_enabled_for_site方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::is_enabled_for_site方法的具体用法?PHP completion_info::is_enabled_for_site怎么用?PHP completion_info::is_enabled_for_site使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类completion_info
的用法示例。
在下文中一共展示了completion_info::is_enabled_for_site方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_is_enabled
function test_is_enabled() {
global $CFG;
// Config alone
$CFG->enablecompletion = COMPLETION_DISABLED;
$this->assertEquals(COMPLETION_DISABLED, completion_info::is_enabled_for_site());
$CFG->enablecompletion = COMPLETION_ENABLED;
$this->assertEquals(COMPLETION_ENABLED, completion_info::is_enabled_for_site());
// Course
$course = (object)array('id' =>13);
$c = new completion_info($course);
$course->enablecompletion = COMPLETION_DISABLED;
$this->assertEquals(COMPLETION_DISABLED, $c->is_enabled());
$course->enablecompletion = COMPLETION_ENABLED;
$this->assertEquals(COMPLETION_ENABLED, $c->is_enabled());
$CFG->enablecompletion = COMPLETION_DISABLED;
$this->assertEquals(COMPLETION_DISABLED, $c->is_enabled());
// Course and CM
$cm = new stdClass();
$cm->completion = COMPLETION_TRACKING_MANUAL;
$this->assertEquals(COMPLETION_DISABLED, $c->is_enabled($cm));
$CFG->enablecompletion = COMPLETION_ENABLED;
$course->enablecompletion = COMPLETION_DISABLED;
$this->assertEquals(COMPLETION_DISABLED, $c->is_enabled($cm));
$course->enablecompletion = COMPLETION_ENABLED;
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $c->is_enabled($cm));
$cm->completion = COMPLETION_TRACKING_NONE;
$this->assertEquals(COMPLETION_TRACKING_NONE, $c->is_enabled($cm));
$cm->completion = COMPLETION_TRACKING_AUTOMATIC;
$this->assertEquals(COMPLETION_TRACKING_AUTOMATIC, $c->is_enabled($cm));
}
示例2: get_content
public function get_content()
{
global $CFG, $USER;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
// Create empty content
$this->content = new stdClass();
// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
// Get course completion data
$info = new completion_info($this->page->course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Get this user's data
$completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
// Check if self completion is one of this course's criteria
if (empty($completion)) {
if ($can_edit) {
$this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
}
return $this->content;
}
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}
// Is course complete?
if ($info->is_course_complete($USER->id)) {
$this->content->text = get_string('coursealreadycompleted', 'completion');
return $this->content;
// Check if the user has already marked themselves as complete
} else {
if ($completion->is_complete()) {
$this->content->text = get_string('alreadyselfcompleted', 'block_selfcompletion');
return $this->content;
// If user is not complete, or has not yet self completed
} else {
$this->content->text = '';
$this->content->footer = '<br /><a href="' . $CFG->wwwroot . '/course/togglecompletion.php?course=' . $this->page->course->id . '">';
$this->content->footer .= get_string('completecourse', 'block_selfcompletion') . '</a>...';
}
}
return $this->content;
}
示例3: definition
//.........这里部分代码省略.........
$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);
}
示例4: notify_changed
/**
* Used to notify the completion system (if necessary) that a user's grade
* has changed, and clear up a possible score cache.
*
* @param bool $deleted True if grade was actually deleted
*/
protected function notify_changed($deleted)
{
global $CFG;
// Condition code may cache the grades for conditional availability of
// modules or sections. (This code should use a hook for communication
// with plugin, but hooks are not implemented at time of writing.)
if (!empty($CFG->enableavailability) && class_exists('\\availability_grade\\callbacks')) {
\availability_grade\callbacks::grade_changed($this->userid);
}
require_once $CFG->libdir . '/completionlib.php';
// Bail out immediately if completion is not enabled for site (saves loading
// grade item & requiring the restore stuff).
if (!completion_info::is_enabled_for_site()) {
return;
}
// Ignore during restore, as completion data will be updated anyway and
// doing it now will result in incorrect dates (it will say they got the
// grade completion now, instead of the correct time).
if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
return;
}
// Load information about grade item
$this->load_grade_item();
// Only course-modules have completion data
if ($this->grade_item->itemtype != 'mod') {
return;
}
// Use $COURSE if available otherwise get it via item fields
$course = get_course($this->grade_item->courseid, false);
// Bail out if completion is not enabled for course
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
return;
}
// Get course-module
$cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid);
// If the course-module doesn't exist, display a warning...
if (!$cm) {
// ...unless the grade is being deleted in which case it's likely
// that the course-module was just deleted too, so that's okay.
if (!$deleted) {
debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'");
}
return;
}
// Pass information on to completion system
$completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted);
}
示例5: get_content
public function get_content()
{
global $USER, $CFG, $DB, $COURSE;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
// Create empty content
$this->content = new stdClass();
// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
// Get course completion data
$info = new completion_info($this->page->course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Load criteria to display
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria
if (empty($completions)) {
if ($can_edit) {
$this->content->text = get_string('nocriteriaset', 'completion');
}
return $this->content;
}
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
// If not enrolled, but are can view the report:
if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
$this->content->text = '<a href="' . $CFG->wwwroot . '/report/completion/index.php?course=' . $COURSE->id . '">' . get_string('viewcoursereport', 'completion') . '</a>';
return $this->content;
}
// Otherwise, show error
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}
// Generate markup for criteria statuses
$shtml = '';
// For aggregating activity completion
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites
$prerequisites = array();
$prerequisites_complete = 0;
// Flag to set if current completion data is inconsistent with
// what is stored in the database
$pending_update = false;
// Loop through course criteria
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
if ($complete) {
$activities_complete++;
}
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;
if ($complete) {
$prerequisites_complete++;
}
continue;
}
$shtml .= '<tr><td>';
$shtml .= $criteria->get_title();
$shtml .= '</td><td style="text-align: right">';
$shtml .= $completion->get_status();
$shtml .= '</td></tr>';
}
// Aggregate activities
if (!empty($activities)) {
$shtml .= '<tr><td>';
$shtml .= get_string('activitiescompleted', 'completion');
$shtml .= '</td><td style="text-align: right">';
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
$shtml .= '</td></tr>';
}
// Aggregate prerequisites
if (!empty($prerequisites)) {
//.........这里部分代码省略.........
示例6: definition
//.........这里部分代码省略.........
//default groupings selector
$options = array();
$options[0] = get_string('none');
$mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
//--------------------------------------------------------------------------------
$mform->addElement('header','', get_string('availability'));
$choices = array();
$choices['0'] = get_string('courseavailablenot');
$choices['1'] = get_string('courseavailable');
$mform->addElement('select', 'visible', get_string('availability'), $choices);
$mform->addHelpButton('visible', 'availability');
$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', $category->visible);
}
}
//--------------------------------------------------------------------------------
$mform->addElement('header','', get_string('language'));
$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);
//--------------------------------------------------------------------------------
if (completion_info::is_enabled_for_site()) {
$mform->addElement('header','', get_string('progress','completion'));
$mform->addElement('select', 'enablecompletion', get_string('completion','completion'),
array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion')));
$mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
$mform->addElement('checkbox', 'completionstartonenrol', get_string('completionstartonenrol', 'completion'));
$mform->setDefault('completionstartonenrol', $courseconfig->completionstartonenrol);
$mform->disabledIf('completionstartonenrol', 'enablecompletion', 'eq', 0);
} else {
$mform->addElement('hidden', 'enablecompletion');
$mform->setType('enablecompletion', PARAM_INT);
$mform->setDefault('enablecompletion',0);
$mform->addElement('hidden', 'completionstartonenrol');
$mform->setType('completionstartonenrol', PARAM_INT);
$mform->setDefault('completionstartonenrol',0);
}
//--------------------------------------------------------------------------------
if (has_capability('moodle/site:config', $systemcontext)) {
if (((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
$mform->addElement('header', '', get_string('restrictmodules'));
$options = array();
$options['0'] = get_string('no');
$options['1'] = get_string('yes');
$mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
if (!empty($CFG->restrictbydefault)) {
$mform->setDefault('restrictmodules', 1);
}
$mods = array(0=>get_string('allownone'));
示例7: notify_changed
/**
* Used to notify the completion system (if necessary) that a user's grade
* has changed, and clear up a possible score cache.
*
* @param bool $deleted True if grade was actually deleted
*/
function notify_changed($deleted)
{
global $CFG;
// Ignore during restore
// TODO There should be a proper way to determine when we are in restore
// so that this hack looking for a $restore global is not needed.
global $restore;
if (!empty($restore->backup_unique_code)) {
return;
}
// Inform conditionlib since it may cache the grades for conditional availability of modules or sections.
if (!empty($CFG->enableavailability)) {
require_once $CFG->libdir . '/conditionlib.php';
condition_info_base::inform_grade_changed($this, $deleted);
}
require_once $CFG->libdir . '/completionlib.php';
// Bail out immediately if completion is not enabled for site (saves loading
// grade item below)
if (!completion_info::is_enabled_for_site()) {
return;
}
// Load information about grade item
$this->load_grade_item();
// Only course-modules have completion data
if ($this->grade_item->itemtype != 'mod') {
return;
}
// Use $COURSE if available otherwise get it via item fields
$course = get_course($this->grade_item->courseid, false);
// Bail out if completion is not enabled for course
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
return;
}
// Get course-module
$cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid);
// If the course-module doesn't exist, display a warning...
if (!$cm) {
// ...unless the grade is being deleted in which case it's likely
// that the course-module was just deleted too, so that's okay.
if (!$deleted) {
debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'");
}
return;
}
// Pass information on to completion system
$completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted);
}
示例8: update_courses
/**
* Update courses
*
* @param array $courses
* @since Moodle 2.5
*/
public static function update_courses($courses) {
global $CFG, $DB;
require_once($CFG->dirroot . "/course/lib.php");
$warnings = array();
$params = self::validate_parameters(self::update_courses_parameters(),
array('courses' => $courses));
$availablethemes = core_component::get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();
foreach ($params['courses'] as $course) {
// Catch any exception while updating course and return as warning to user.
try {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($course['id'], MUST_EXIST);
self::validate_context($context);
$oldcourse = course_get_format($course['id'])->get_course();
require_capability('moodle/course:update', $context);
// Check if user can change category.
if (array_key_exists('categoryid', $course) && ($oldcourse->category != $course['categoryid'])) {
require_capability('moodle/course:changecategory', $context);
$course['category'] = $course['categoryid'];
}
// Check if the user can change fullname.
if (array_key_exists('fullname', $course) && ($oldcourse->fullname != $course['fullname'])) {
require_capability('moodle/course:changefullname', $context);
}
// Check if the user can change shortname.
if (array_key_exists('shortname', $course) && ($oldcourse->shortname != $course['shortname'])) {
require_capability('moodle/course:changeshortname', $context);
}
// Check if the user can change the idnumber.
if (array_key_exists('idnumber', $course) && ($oldcourse->idnumber != $course['idnumber'])) {
require_capability('moodle/course:changeidnumber', $context);
}
// Check if user can change summary.
if (array_key_exists('summary', $course) && ($oldcourse->summary != $course['summary'])) {
require_capability('moodle/course:changesummary', $context);
}
// Summary format.
if (array_key_exists('summaryformat', $course) && ($oldcourse->summaryformat != $course['summaryformat'])) {
require_capability('moodle/course:changesummary', $context);
$course['summaryformat'] = external_validate_format($course['summaryformat']);
}
// Check if user can change visibility.
if (array_key_exists('visible', $course) && ($oldcourse->visible != $course['visible'])) {
require_capability('moodle/course:visibility', $context);
}
// Make sure lang is valid.
if (array_key_exists('lang', $course) && empty($availablelangs[$course['lang']])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'lang');
}
// Make sure theme is valid.
if (array_key_exists('forcetheme', $course)) {
if (!empty($CFG->allowcoursethemes)) {
if (empty($availablethemes[$course['forcetheme']])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'forcetheme');
} else {
$course['theme'] = $course['forcetheme'];
}
}
}
// Make sure completion is enabled before setting it.
if (array_key_exists('enabledcompletion', $course) && !completion_info::is_enabled_for_site()) {
$course['enabledcompletion'] = 0;
}
// Make sure maxbytes are less then CFG->maxbytes.
if (array_key_exists('maxbytes', $course)) {
$course['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $course['maxbytes']);
}
if (!empty($course['courseformatoptions'])) {
foreach ($course['courseformatoptions'] as $option) {
if (isset($option['name']) && isset($option['value'])) {
$course[$option['name']] = $option['value'];
}
}
}
// Update course if user has all required capabilities.
//.........这里部分代码省略.........
示例9: definition
//.........这里部分代码省略.........
$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);
}
示例10: get_content
public function get_content()
{
global $USER;
$rows = array();
$srows = array();
$prows = array();
// If content is cached.
if ($this->content !== null) {
return $this->content;
}
$course = $this->page->course;
$context = context_course::instance($course->id);
// Create empty content.
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
// Can edit settings?
$can_edit = has_capability('moodle/course:update', $context);
// Get course completion data.
$info = new completion_info($course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Load criteria to display.
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria.
if (empty($completions)) {
if ($can_edit) {
$this->content->text .= get_string('nocriteriaset', 'completion');
}
return $this->content;
}
// Check this user is enroled.
if ($info->is_tracked_user($USER->id)) {
// Generate markup for criteria statuses.
$data = '';
// For aggregating activity completion.
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites.
$prerequisites = array();
$prerequisites_complete = 0;
// Flag to set if current completion data is inconsistent with what is stored in the database.
$pending_update = false;
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
if ($complete) {
$activities_complete++;
}
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;
if ($complete) {
$prerequisites_complete++;
}
continue;
}
$row = new html_table_row();
$row->cells[0] = new html_table_cell($criteria->get_title());
$row->cells[1] = new html_table_cell($completion->get_status());
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate activities.
if (!empty($activities)) {
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('activitiescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate prerequisites.
if (!empty($prerequisites)) {
$a = new stdClass();
$a->first = $prerequisites_complete;
$a->second = count($prerequisites);
//.........这里部分代码省略.........
示例11: moodle_course_create_courses
function moodle_course_create_courses($client) {
global $DB, $CFG;
///Test data
$courseconfig = get_config('moodlecourse');
$themeobjects = get_list_of_themes();
$theme = key($themeobjects);
$categoryid = $DB->get_record('course_categories', array(), '*', IGNORE_MULTIPLE)->id;
$categoryid = empty($categoryid) ? 0 : $categoryid;
$course1 = new stdClass();
$course1->fullname = 'Test Data create course 1';
$course1->shortname = 'testdatacourse1';
$course1->categoryid = $categoryid;
$course1->idnumber = '328327982372342343234';
$course1->summary = 'This is a summary';
$course1->summaryformat = FORMAT_HTML;
$course1->format = $courseconfig->format;
$course1->showgrades = $courseconfig->showgrades;
$course1->showreports = $courseconfig->showreports;
$course1->newsitems = $courseconfig->newsitems;
$course1->startdate = time();
$course1->numsections = $courseconfig->numsections;
$course1->maxbytes = $courseconfig->maxbytes;
$course1->visible = $courseconfig->visible;
$course1->hiddensections = $courseconfig->hiddensections;
$course1->groupmode = $courseconfig->groupmode;
$course1->groupmodeforce = $courseconfig->groupmodeforce;
$course1->defaultgroupingid = 0;
if (!empty($courseconfig->lang)) {
$course1->lang = $courseconfig->lang;
}
$course1->enablecompletion = $courseconfig->enablecompletion;
$course1->completionstartonenrol = $courseconfig->completionstartonenrol;
$course1->completionnotify = 0;
$course1->forcetheme = $theme;
$course2 = new stdClass();
$course2->fullname = 'Test Data create course 2';
$course2->shortname = 'testdatacourse2';
$course2->categoryid = $categoryid;
$courses = array($course1, $course2);
//do not run the test if course1 or course2 already exists
$existingcourses = $DB->get_records_list('course', 'fullname',
array($course1->fullname, $course2->fullname));
if (!empty($existingcourses)) {
throw new moodle_exception('testdatacoursesalreadyexist');
}
$function = 'moodle_course_create_courses';
$params = array('courses' => $courses);
$resultcourses = $client->call($function, $params);
$this->assertEqual(count($courses), count($resultcourses));
//retrieve user1 from the DB and check values
$dbcourse1 = $DB->get_record('course', array('fullname' => $course1->fullname));
$this->assertEqual($dbcourse1->fullname, $course1->fullname);
$this->assertEqual($dbcourse1->shortname, $course1->shortname);
$this->assertEqual($dbcourse1->category, $course1->categoryid);
$this->assertEqual($dbcourse1->idnumber, $course1->idnumber);
$this->assertEqual($dbcourse1->summary, $course1->summary);
$this->assertEqual($dbcourse1->summaryformat, $course1->summaryformat);
$this->assertEqual($dbcourse1->format, $course1->format);
$this->assertEqual($dbcourse1->showgrades, $course1->showgrades);
$this->assertEqual($dbcourse1->showreports, $course1->showreports);
$this->assertEqual($dbcourse1->newsitems, $course1->newsitems);
$this->assertEqual($dbcourse1->startdate, $course1->startdate);
$this->assertEqual($dbcourse1->numsections, $course1->numsections);
$this->assertEqual($dbcourse1->maxbytes, $course1->maxbytes);
$this->assertEqual($dbcourse1->visible, $course1->visible);
$this->assertEqual($dbcourse1->hiddensections, $course1->hiddensections);
$this->assertEqual($dbcourse1->groupmode, $course1->groupmode);
$this->assertEqual($dbcourse1->groupmodeforce, $course1->groupmodeforce);
$this->assertEqual($dbcourse1->defaultgroupingid, $course1->defaultgroupingid);
if (!empty($courseconfig->lang)) {
$this->assertEqual($dbcourse1->lang, $course1->lang);
}
if (completion_info::is_enabled_for_site()) {
$this->assertEqual($dbcourse1->enablecompletion, $course1->enablecompletion);
$this->assertEqual($dbcourse1->completionstartonenrol, $course1->completionstartonenrol);
}
$this->assertEqual($dbcourse1->completionnotify, $course1->completionnotify);
if (!empty($CFG->allowcoursethemes)) {
$this->assertEqual($dbcourse1->theme, $course1->forcetheme);
}
//retrieve user2 from the DB and check values
$dbcourse2 = $DB->get_record('course', array('fullname' => $course2->fullname));
$this->assertEqual($dbcourse2->fullname, $course2->fullname);
$this->assertEqual($dbcourse2->shortname, $course2->shortname);
$this->assertEqual($dbcourse2->category, $course2->categoryid);
$this->assertEqual($dbcourse2->summaryformat, FORMAT_MOODLE);
$this->assertEqual($dbcourse2->format, $courseconfig->format);
$this->assertEqual($dbcourse2->showgrades, $courseconfig->showgrades);
$this->assertEqual($dbcourse2->showreports, $courseconfig->showreports);
$this->assertEqual($dbcourse2->newsitems, $courseconfig->newsitems);
$this->assertEqual($dbcourse2->numsections, $courseconfig->numsections);
//.........这里部分代码省略.........
示例12: test_create_courses
/**
* Test create_courses
*/
public function test_create_courses()
{
global $DB;
$this->resetAfterTest(true);
// Set the required capabilities by the external function
$contextid = context_system::instance()->id;
$roleid = $this->assignUserCapability('moodle/course:create', $contextid);
$this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);
$category = self::getDataGenerator()->create_category();
// Create base categories.
$course1['fullname'] = 'Test course 1';
$course1['shortname'] = 'Testcourse1';
$course1['categoryid'] = $category->id;
$course2['fullname'] = 'Test course 2';
$course2['shortname'] = 'Testcourse2';
$course2['categoryid'] = $category->id;
$course2['idnumber'] = 'testcourse2idnumber';
$course2['summary'] = 'Description for course 2';
$course2['summaryformat'] = FORMAT_MOODLE;
$course2['format'] = 'weeks';
$course2['showgrades'] = 1;
$course2['newsitems'] = 3;
$course2['startdate'] = 1420092000;
// 01/01/2015
$course2['numsections'] = 4;
$course2['maxbytes'] = 100000;
$course2['showreports'] = 1;
$course2['visible'] = 0;
$course2['hiddensections'] = 0;
$course2['groupmode'] = 0;
$course2['groupmodeforce'] = 0;
$course2['defaultgroupingid'] = 0;
$course2['enablecompletion'] = 1;
$course2['completionstartonenrol'] = 1;
$course2['completionnotify'] = 1;
$course2['lang'] = 'en';
$course2['forcetheme'] = 'base';
$courses = array($course1, $course2);
$createdcourses = core_course_external::create_courses($courses);
// Check that right number of courses were created.
$this->assertEquals(2, count($createdcourses));
// Check that the courses were correctly created.
foreach ($createdcourses as $createdcourse) {
$dbcourse = $DB->get_record('course', array('id' => $createdcourse['id']));
if ($createdcourse['shortname'] == $course2['shortname']) {
$this->assertEquals($dbcourse->fullname, $course2['fullname']);
$this->assertEquals($dbcourse->shortname, $course2['shortname']);
$this->assertEquals($dbcourse->category, $course2['categoryid']);
$this->assertEquals($dbcourse->idnumber, $course2['idnumber']);
$this->assertEquals($dbcourse->summary, $course2['summary']);
$this->assertEquals($dbcourse->summaryformat, $course2['summaryformat']);
$this->assertEquals($dbcourse->format, $course2['format']);
$this->assertEquals($dbcourse->showgrades, $course2['showgrades']);
$this->assertEquals($dbcourse->newsitems, $course2['newsitems']);
$this->assertEquals($dbcourse->startdate, $course2['startdate']);
$this->assertEquals($dbcourse->numsections, $course2['numsections']);
$this->assertEquals($dbcourse->maxbytes, $course2['maxbytes']);
$this->assertEquals($dbcourse->showreports, $course2['showreports']);
$this->assertEquals($dbcourse->visible, $course2['visible']);
$this->assertEquals($dbcourse->hiddensections, $course2['hiddensections']);
$this->assertEquals($dbcourse->groupmode, $course2['groupmode']);
$this->assertEquals($dbcourse->groupmodeforce, $course2['groupmodeforce']);
$this->assertEquals($dbcourse->defaultgroupingid, $course2['defaultgroupingid']);
$this->assertEquals($dbcourse->completionnotify, $course2['completionnotify']);
$this->assertEquals($dbcourse->lang, $course2['lang']);
if (!empty($CFG->allowcoursethemes)) {
$this->assertEquals($dbcourse->theme, $course2['forcetheme']);
}
if (completion_info::is_enabled_for_site()) {
$this->assertEquals($dbcourse->enablecompletion, $course2['enabledcompletion']);
$this->assertEquals($dbcourse->completionstartonenrol, $course2['completionstartonenrol']);
} else {
$this->assertEquals($dbcourse->enablecompletion, 0);
$this->assertEquals($dbcourse->completionstartonenrol, 0);
}
} else {
if ($createdcourse['shortname'] == $course1['shortname']) {
$courseconfig = get_config('moodlecourse');
$this->assertEquals($dbcourse->fullname, $course1['fullname']);
$this->assertEquals($dbcourse->shortname, $course1['shortname']);
$this->assertEquals($dbcourse->category, $course1['categoryid']);
$this->assertEquals($dbcourse->summaryformat, FORMAT_HTML);
$this->assertEquals($dbcourse->format, $courseconfig->format);
$this->assertEquals($dbcourse->showgrades, $courseconfig->showgrades);
$this->assertEquals($dbcourse->newsitems, $courseconfig->newsitems);
$this->assertEquals($dbcourse->numsections, $courseconfig->numsections);
$this->assertEquals($dbcourse->maxbytes, $courseconfig->maxbytes);
$this->assertEquals($dbcourse->showreports, $courseconfig->showreports);
$this->assertEquals($dbcourse->hiddensections, $courseconfig->hiddensections);
$this->assertEquals($dbcourse->groupmode, $courseconfig->groupmode);
$this->assertEquals($dbcourse->groupmodeforce, $courseconfig->groupmodeforce);
$this->assertEquals($dbcourse->defaultgroupingid, 0);
} else {
throw moodle_exception('Unexpected shortname');
}
}
}
//.........这里部分代码省略.........
示例13: notify_changed
/**
* Used to notify the completion system (if necessary) that a user's grade
* has changed, and clear up a possible score cache.
*
* @param bool $deleted True if grade was actually deleted
*/
function notify_changed($deleted)
{
global $USER, $SESSION, $CFG, $COURSE, $DB;
// Grades may be cached in user session
if ($USER->id == $this->userid) {
unset($SESSION->gradescorecache[$this->itemid]);
}
require_once $CFG->libdir . '/completionlib.php';
// Bail out immediately if completion is not enabled for site (saves loading
// grade item & requiring the restore stuff).
if (!completion_info::is_enabled_for_site()) {
return;
}
// Ignore during restore, as completion data will be updated anyway and
// doing it now will result in incorrect dates (it will say they got the
// grade completion now, instead of the correct time).
if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
return;
}
// Load information about grade item
$this->load_grade_item();
// Only course-modules have completion data
if ($this->grade_item->itemtype != 'mod') {
return;
}
// Use $COURSE if available otherwise get it via item fields
if (!empty($COURSE) && $COURSE->id == $this->grade_item->courseid) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id' => $this->grade_item->courseid));
}
// Bail out if completion is not enabled for course
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
return;
}
// Get course-module
$cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid);
// If the course-module doesn't exist, display a warning...
if (!$cm) {
// ...unless the grade is being deleted in which case it's likely
// that the course-module was just deleted too, so that's okay.
if (!$deleted) {
debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'");
}
return;
}
// Pass information on to completion system
$completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted);
}
示例14: xmldb_core_install
//.........这里部分代码省略.........
assign_capability('moodle/comment:post', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
$systemcontext->mark_dirty();
set_role_contextlevels($assessorrole, get_default_contextlevels('teacher'));
$role_to_modify = array(
'editingteacher' => 'editingtrainer',
'teacher' => 'trainer',
'student' => 'learner'
);
$DB->update_record('role', array('id' => $assessorrole, 'archetype' => 'assessor'));
assign_capability('moodle/user:editownprofile', CAP_ALLOW, $assessorrole, $systemcontext->id, true);
assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionalmanagerrole, $systemcontext->id, true);
assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionaltrainerrole, $systemcontext->id, true);
foreach ($role_to_modify as $old => $new) {
if ($old_role = $DB->get_record('role', array('shortname' => $old))) {
$new_role = new stdClass();
$new_role->id = $old_role->id;
$new_role->name = '';
$new_role->description = '';
$DB->update_record('role', $new_role);
}
}
// Set up frontpage.
set_config('frontpage', '');
set_config('frontpageloggedin', '');
require_once($CFG->dirroot . '/lib/completionlib.php');
if(!completion_info::is_enabled_for_site()){
set_config('coreinstallation', 1);
set_config('enablecompletion', 1);
set_config('enablecompletion', 1, 'moodlecourse');
set_config('completionstartonenrol', 1, 'moodlecourse');
}
// Add completionstartonenrol column to course table.
$table = new xmldb_table('course');
// Define field completionstartonenrol to be added to course.
$field = new xmldb_field('completionstartonenrol', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
// Conditionally launch add field completionstartonenrol.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add RPL column to course_completions table
$table = new xmldb_table('course_completions');
// Define field rpl to be added to course_completions
$field = new xmldb_field('rpl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'reaggregate');
// Conditionally launch add field rpl
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field rplgrade to be added to course_completions
$field = new xmldb_field('rplgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'rpl');
// Conditionally launch add field rpl
if (!$dbman->field_exists($table, $field)) {
示例15: completion_can_view_data
/**
* Utility function for checking if the logged in user can view
* another's completion data for a particular course
*
* @access public
* @param int $userid Completion data's owner
* @param mixed $course Course object or Course ID (optional)
* @return boolean
*/
function completion_can_view_data($userid, $course = null)
{
global $USER;
if (!isloggedin()) {
return false;
}
if (!is_object($course)) {
$cid = $course;
$course = new object();
$course->id = $cid;
}
// Check if this is the site course
if ($course->id == SITEID) {
$course = null;
}
// Check if completion is enabled
if ($course) {
$cinfo = new completion_info($course);
if (!$cinfo->is_enabled()) {
return false;
}
} else {
if (!completion_info::is_enabled_for_site()) {
return false;
}
}
// Is own user's data?
if ($USER->id == $userid) {
return true;
}
// Check capabilities
$personalcontext = context_user::instance($userid);
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
return true;
} elseif (has_capability('report/completion:view', $personalcontext)) {
return true;
}
if ($course->id) {
$coursecontext = context_course::instance($course->id);
} else {
$coursecontext = context_system::instance();
}
if (has_capability('report/completion:view', $coursecontext)) {
return true;
}
return false;
}