Checks if glossary is available - it should be either located in the same course or be global

@return null|cm_info|stdClass object with properties 'id' (course module id) and 'uservisible'
558188
protected function get_glossary_cm() {
        global $DB;
        if (empty($this->config->glossary)) {
            // No glossary is configured.
            return null;
        }

        if (!empty($this->glossarycm)) {
            return $this->glossarycm;
        }

        if (!empty($this->page->course->id)) {
            // First check if glossary belongs to the current course (we don't need to make any DB queries to find it).
            $modinfo = get_fast_modinfo($this->page->course);
            if (isset($modinfo->instances['glossary'][$this->config->glossary])) {
                $this->glossarycm = $modinfo->instances['glossary'][$this->config->glossary];
                if ($this->glossarycm->uservisible) {
                    // The glossary is in the same course and is already visible to the current user,
                    // no need to check if it is global, save on DB query.
                    return $this->glossarycm;
                }
            }
        }

        // Find course module id for the given glossary, only if it is global.
        $cm = $DB->get_record_sql("SELECT cm.id, cm.visible AS uservisible
              FROM {course_modules} cm
                   JOIN {modules} md ON md.id = cm.module
                   JOIN {glossary} g ON g.id = cm.instance
             WHERE g.id = :instance AND md.name = :modulename AND g.globalglossary = 1",
            ['instance' => $this->config->glossary, 'modulename' => 'glossary']);

        if ($cm) {
            // This is a global glossary, create an object with properties 'id' and 'uservisible'. We don't need any
            // other information so why bother retrieving it. Full access check is skipped for global glossaries for
            // performance reasons.
            $this->glossarycm = $cm;
        } else if (empty($this->glossarycm)) {
            // Glossary does not exist. Remove it in the config so we don't repeat this check again later.
            $this->config->glossary = 0;
            $this->instance_config_commit();
        }

        return $this->glossarycm;
    }
417718
public function check_course_is_mapped() {
        global $DB;
        if ($this->feedback->course != SITEID) {
            return true;
        }
        if ($DB->get_records('feedback_sitecourse_map', array('feedbackid' => $this->feedback->id))) {
            $params = array('feedbackid' => $this->feedback->id, 'courseid' => $this->courseid);
            if (!$DB->get_record('feedback_sitecourse_map', $params)) {
                return false;
            }
        }
        // No mapping means any course is mapped.
        return true;
    }
225318
public function getProcedureDescription()
    {
        if (! (isset($this->_gemsData['gap_id_procedure']) && $this->_gemsData['gap_id_procedure'])) {
            return null;
        }
        if (!array_key_exists('gapr_name', $this->_gemsData)) {
            $sql = "SELECT gapr_name FROM gems__agenda_procedures WHERE gapr_id_procedure = ?";

            $this->_gemsData['gapr_name'] = $this->db->fetchOne($sql, $this->_gemsData['gap_id_procedure']);

            // Cleanup db result
            if (false === $this->_gemsData['gapr_name']) {
                $this->_gemsData['gapr_name'] = null;
            }
        }
        return $this->_gemsData['gapr_name'];
    }
659440
public function getInstancesList() {
		$arr = array();
		foreach ($this->declaredInstances as $instanceName=>$classDesc) {
			//if (!isset($classDesc["class"])) {var_dump($instanceName);var_dump($classDesc);}
			$arr[$instanceName] = isset($classDesc['class'])?$classDesc['class']:null;
		}
		return $arr;
	}
405398
protected static function get_course_concepts($courseid) {
        global $DB;

        if (empty($courseid)) {
            return array(array(), array());
        }

        $courseid = (int)$courseid;

        // Get info on any glossaries in this course.
        $modinfo = get_fast_modinfo($courseid);
        $cminfos = $modinfo->get_instances_of('glossary');
        if (!$cminfos) {
            // No glossaries in this course, so don't do any work.
            return array(array(), array());
        }

        $cache = \cache::make('mod_glossary', 'concepts');
        $data = $cache->get($courseid);
        if (is_array($data)) {
            list($glossaries, $allconcepts) = $data;

        } else {
            // Find all course glossaries.
            $sql = "SELECT g.id, g.name
                      FROM {glossary} g
                      JOIN {course_modules} cm ON (cm.instance = g.id)
                      JOIN {modules} m ON (m.name = 'glossary' AND m.id = cm.module)
                     WHERE g.usedynalink = 1 AND g.course = :course AND cm.visible = 1 AND m.visible = 1
                  ORDER BY g.globalglossary, g.id";
            $glossaries = $DB->get_records_sql_menu($sql, array('course' => $courseid));
            if (!$glossaries) {
                $data = array(array(), array());
                $cache->set($courseid, $data);
                return $data;
            }
            foreach ($glossaries as $id => $name) {
                $name = str_replace(':', '-', $name);
                $glossaries[$id] = replace_ampersands_not_followed_by_entity(strip_tags($name));
            }

            $allconcepts = self::fetch_concepts(array_keys($glossaries));
            foreach ($glossaries as $gid => $unused) {
                if (!isset($allconcepts[$gid])) {
                    unset($glossaries[$gid]);
                }
            }
            if (!$glossaries) {
                // This means there are no interesting concepts in the existing glossaries.
                $data = array(array(), array());
                $cache->set($courseid, $data);
                return $data;
            }
            $cache->set($courseid, array($glossaries, $allconcepts));
        }

        $concepts = $allconcepts;

        // Verify access control to glossary instances.
        foreach ($concepts as $modid => $unused) {
            if (!isset($cminfos[$modid])) {
                // This should not happen.
                unset($concepts[$modid]);
                unset($glossaries[$modid]);
                continue;
            }
            if (!$cminfos[$modid]->uservisible) {
                unset($concepts[$modid]);
                unset($glossaries[$modid]);
                continue;
            }
        }

        return array($glossaries, $concepts);
    }
125665
protected function storeSlugForLanguageId()
    {
        /** @var CmsModel|SluggableTrait $this */

        $config      = $this->getSluggableConfig();
        $languageKey = array_get($config, 'language_key');
        $localeKey   = array_get($config, 'locale_key');

        if ($languageKey) {
            return $this->getAttribute($languageKey);
        }

        if ($localeKey) {
            return $this->lookupLanguageIdForLocale( $this->getAttribute($localeKey) );
        }

        return null;
    }
1013473
public function is_visible() {
        global $USER;

        $context = ($this->userid > 0) ? context_user::instance($this->userid) : context_system::instance();

        switch ($this->field->visible) {
            case PROFILE_VISIBLE_ALL:
                return true;
            case PROFILE_VISIBLE_PRIVATE:
                if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
                    return true;
                } else if ($this->userid == $USER->id) {
                    return true;
                } else {
                    return has_capability('moodle/user:viewalldetails', $context);
                }
            default:
                return has_capability('moodle/user:viewalldetails', $context);
        }
    }
1150955
public function getAvailableFrom()
    {
        if ($this->AvailableFromDate) {
            return $this->dbObject('AvailableFromDate');
        } elseif ($startDate = $this->getEventStartDate()) {
            $lastWeek = new Date();
            $lastWeek->setValue(strtotime(self::config()->get('sale_start_threshold'), strtotime($startDate->value)));
            return $lastWeek;
        }

        return null;
    }
1209695
private function getFromAcceptedLanguagesHeader()
    {
        $matches = $this->getMatchesFromAcceptedLanguages();

        if ($locale = $this->inSupportedLocales($matches)) {
            return $locale;
        }

        // If any (i.e. "*") is acceptable, return the first supported locale
        if (isset($matches['*'])) {
            return $this->supportedLocales->first()->key();
        }

        return null;
    }
1320257
public function showSchemaDefinitionInTable()
    {
        //change connection if provide
        if ($this->option('c')) {
            $this->schema->setConnection($this->option('c'));
            $this->schema->switchWrapper();
        }

        $tables = $this->schema->databaseWrapper->getTables();

        if (!count($tables)) {
            $this->warn('Database does not contain any table');
            return false;
        }

        $tableName = $this->option('t');
        if (empty($tableName)) {
            $this->warn('Table name is required!');
            return false;
        }

        if ($this->isNamespaceModel($tableName)) {
            $tableName = $this->tableNameFromModel($tableName);
        }

        if (!in_array($tableName, $tables)) {
            $this->warn('Table name is not correct!');
            return false;
        }

        $page = (!empty($this->option('p'))) ? $this->option('p') : 1;
        $limit = (!empty($this->option('l'))) ? $this->option('l') : 15;
        $orderBy = (!empty($this->option('o'))) ? $this->option('o') : null;
        $select = (!empty($this->option('s'))) ? $this->option('s') : null;
        $columns = $this->schema->databaseWrapper->getColumns($tableName);
        if (str_contains($select, ',')) {
            $selectedColumns = explode(',', $select);
        } else {
            $selectedColumns[] = $select;
        }

        $headers = [];
        foreach ($columns as $column) {
            foreach ($selectedColumns as $selected) {
                if (!$select) {
                    $headers[] = $column['Field'];
                } else {
                    if (($selected == $column['Field']))
                        $headers[] = $column['Field'];
                }
            }
        }
        $attributeName = null;
        $order = null;
        if (null !== $orderBy) {
            if (strpos($orderBy, ':') !== false) {
                $orderBy = explode(':', $orderBy);
            }
            $attributeName = $orderBy[0];
            if (isset($orderBy[1])) {
                $order = ('desc' == strtolower($orderBy[1])) ? 'DESC' : 'ASC';
            }
            if (!in_array($attributeName, $headers)) {
                $this->warn("There is no column named '$attributeName'. Please provide a correct column name for ordering!");
                return false;
            }
        }

        $rows = $this->schema->getPaginatedData($tableName, $page, $limit, $attributeName, $order)['data'];
        $body = $this->makeTableBody($headers, $rows);
        $rowsCount = $this->schema->getTableRowCount($tableName);
        $this->info($tableName . ' (rows ' . $rowsCount . ')');

        $this->table($headers, $body);
        return false;
    }
1221277
public function getAvailableTill()
    {
        if ($this->AvailableTillDate) {
            return $this->dbObject('AvailableTillDate');
        } elseif ($startDate = $this->getEventStartDate()) {
            $till = strtotime(self::config()->get('sale_end_threshold'), strtotime($startDate->Nice()));
            $date = SS_Datetime::create();
            $date->setValue(date('Y-m-d H:i:s', $till));
            return $date;
        }

        return null;
    }
766546
public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) {
        global $CFG;
        $output = '';
        if (!$mod->is_visible_on_course_page()) {
            return $output;
        }
        if (!$mod->uservisible) {
            // this is a student who is not allowed to see the module but might be allowed
            // to see availability info (i.e. "Available from ...")
            if (!empty($mod->availableinfo)) {
                $formattedinfo = \core_availability\info::format_info(
                        $mod->availableinfo, $mod->get_course());
                $output = $this->availability_info($formattedinfo, 'isrestricted');
            }
            return $output;
        }
        // this is a teacher who is allowed to see module but still should see the
        // information that module is not available to all/some students
        $modcontext = context_module::instance($mod->id);
        $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
        if ($canviewhidden && !$mod->visible) {
            // This module is hidden but current user has capability to see it.
            // Do not display the availability info if the whole section is hidden.
            if ($mod->get_section_info()->visible) {
                $output .= $this->availability_info(get_string('hiddenfromstudents'), 'ishidden');
            }
        } else if ($mod->is_stealth()) {
            // This module is available but is normally not displayed on the course page
            // (this user can see it because they can manage it).
            $output .= $this->availability_info(get_string('hiddenoncoursepage'), 'isstealth');
        }
        if ($canviewhidden && !empty($CFG->enableavailability)) {
            // Display information about conditional availability.
            // Don't add availability information if user is not editing and activity is hidden.
            if ($mod->visible || $this->page->user_is_editing()) {
                $hidinfoclass = 'isrestricted isfullinfo';
                if (!$mod->visible) {
                    $hidinfoclass .= ' hide';
                }
                $ci = new \core_availability\info_module($mod);
                $fullinfo = $ci->get_full_information();
                if ($fullinfo) {
                    $formattedinfo = \core_availability\info::format_info(
                            $fullinfo, $mod->get_course());
                    $output .= $this->availability_info($formattedinfo, $hidinfoclass);
                }
            }
        }
        return $output;
    }
965174
public static function get_addable_lock_options() {
        $plugins = core_component::get_plugin_list_with_class('cachelock', '', 'lib.php');
        $options = array();
        $len = strlen('cachelock_');
        foreach ($plugins as $plugin => $class) {
            $method = "$class::can_add_instance";
            if (is_callable($method) && !call_user_func($method)) {
                // Can't add an instance of this plugin.
                continue;
            }
            $options[substr($plugin, $len)] = get_string('pluginname', $plugin);
        }
        return $options;
    }
949852
public function get_course() {
        global $DB;

        if ($this->course) {
            return $this->course;
        }

        if (!$this->context) {
            return null;
        }
        $params = array('id' => $this->get_course_context()->instanceid);
        $this->course = $DB->get_record('course', $params, '*', MUST_EXIST);

        return $this->course;
    }
103716
public static function get_site_categories() {
        global $DB;

        if (method_exists('\core_course_category', 'get_all')) {
            $categories = \core_course_category::get_all(['returnhidden' => true]);
        } else {
            // Fallback (to be removed once this gets integrated into master).
            $ids = $DB->get_fieldset_select('course_categories', 'id', '');
            $categories = \core_course_category::get_many($ids);
        }

        foreach ($categories as $key => $category) {
            if (!$category->is_uservisible()) {
                unset($categories[$key]);
            }
        }
        return $categories;
    }
1276309
public function get_course_module() {
        if ($this->coursemodule) {
            return $this->coursemodule;
        }
        if (!$this->context) {
            return null;
        }

        if ($this->context->contextlevel == CONTEXT_MODULE) {
            $modinfo = get_fast_modinfo($this->get_course());
            $this->coursemodule = $modinfo->get_cm($this->context->instanceid);
            return $this->coursemodule;
        }
        return null;
    }
470427
public function definition() {
        global $USER, $CFG, $DB;

        $courseconfig = get_config('moodlecourse');
        $mform = $this->_form;
        $course = $this->_customdata['course'];
        $completion = new completion_info($course);

        $params = array(
            'course'  => $course->id
        );

        // Check if there are existing criteria completions.
        if ($completion->is_course_locked()) {
            $mform->addElement('header', 'completionsettingslocked', get_string('completionsettingslocked', 'completion'));
            $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion'));
            $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion'));
        }

        // Get array of all available aggregation methods.
        $aggregation_methods = $completion->get_aggregation_methods();

        // Overall criteria aggregation.
        $mform->addElement('header', 'overallcriteria', get_string('general', 'core_form'));
        // Map aggregation methods to context-sensitive human readable dropdown menu.
        $overallaggregationmenu = array();
        foreach ($aggregation_methods as $methodcode => $methodname) {
            if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                $overallaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('overallaggregation_all', 'core_completion');
            } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                $overallaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('overallaggregation_any', 'core_completion');
            } else {
                $overallaggregationmenu[$methodcode] = $methodname;
            }
        }
        $mform->addElement('select', 'overall_aggregation', get_string('overallaggregation', 'core_completion'), $overallaggregationmenu);
        $mform->setDefault('overall_aggregation', $completion->get_aggregation_method());

        // Activity completion criteria
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('activitiescompleted', 'core_completion'));
        $mform->addElement('header', 'activitiescompleted', $label);
        // Get the list of currently specified conditions and expand the section if some are found.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY);
        if (!empty($current)) {
            $mform->setExpanded('activitiescompleted');
        }

        $activities = $completion->get_activities();
        if (!empty($activities)) {

            if (!$completion->is_course_locked()) {
                $this->add_checkbox_controller(1, null, null, 0);
            }
            foreach ($activities as $activity) {
                $params_a = array('moduleinstance' => $activity->id);
                $criteria = new completion_criteria_activity(array_merge($params, $params_a));
                $criteria->config_form_display($mform, $activity);
            }
            $mform->addElement('static', 'criteria_role_note', '', get_string('activitiescompletednote', 'core_completion'));

            if (count($activities) > 1) {
                // Map aggregation methods to context-sensitive human readable dropdown menu.
                $activityaggregationmenu = array();
                foreach ($aggregation_methods as $methodcode => $methodname) {
                    if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                        $activityaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('activityaggregation_all', 'core_completion');
                    } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                        $activityaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('activityaggregation_any', 'core_completion');
                    } else {
                        $activityaggregationmenu[$methodcode] = $methodname;
                    }
                }
                $mform->addElement('select', 'activity_aggregation', get_string('activityaggregation', 'core_completion'), $activityaggregationmenu);
                $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY));
            }

        } else {
            $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion'));
        }

        // Course prerequisite completion criteria.
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('dependenciescompleted', 'core_completion'));
        $mform->addElement('header', 'courseprerequisites', $label);
        // Get the list of currently specified conditions and expand the section if some are found.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE);
        if (!empty($current)) {
            $mform->setExpanded('courseprerequisites');
        }

        // Get applicable courses (prerequisites).
        $selectedcourses = $DB->get_fieldset_sql("SELECT cc.courseinstance
                  FROM {course_completion_criteria} cc WHERE cc.course = ?", [$course->id]);
        $hasselectablecourses = core_course_category::search_courses(['onlywithcompletion' => true], ['limit' => 2]);
        unset($hasselectablecourses[$course->id]);
        if ($hasselectablecourses) {
            // Show multiselect box.
            $mform->addElement('course', 'criteria_course', get_string('coursesavailable', 'completion'),
                array('multiple' => 'multiple', 'onlywithcompletion' => true, 'exclude' => $course->id));
            $mform->setDefault('criteria_course', $selectedcourses);

            // Map aggregation methods to context-sensitive human readable dropdown menu.
            $courseaggregationmenu = array();
            foreach ($aggregation_methods as $methodcode => $methodname) {
                if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                    $courseaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('courseaggregation_all', 'core_completion');
                } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                    $courseaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('courseaggregation_any', 'core_completion');
                } else {
                    $courseaggregationmenu[$methodcode] = $methodname;
                }
            }
            $mform->addElement('select', 'course_aggregation', get_string('courseaggregation', 'core_completion'), $courseaggregationmenu);
            $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE));
        } else {
            $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion'));
        }

        // Completion on date
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('completionondate', 'core_completion'));
        $mform->addElement('header', 'date', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DATE);
        if (!empty($current)) {
            $mform->setExpanded('date');
        }
        $criteria = new completion_criteria_date($params);
        $criteria->config_form_display($mform);

        // Completion after enrolment duration
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('enrolmentduration', 'core_completion'));
        $mform->addElement('header', 'duration', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DURATION);
        if (!empty($current)) {
            $mform->setExpanded('duration');
        }
        $criteria = new completion_criteria_duration($params);
        $criteria->config_form_display($mform);

        // Completion on unenrolment
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('unenrolment', 'core_completion'));
        $mform->addElement('header', 'unenrolment', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_UNENROL);
        if (!empty($current)) {
            $mform->setExpanded('unenrolment');
        }
        $criteria = new completion_criteria_unenrol($params);
        $criteria->config_form_display($mform);

        // Completion on course grade
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('coursegrade', 'core_completion'));
        $mform->addElement('header', 'grade', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_GRADE);
        if (!empty($current)) {
            $mform->setExpanded('grade');
        }
        $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
        if (!$course_grade) {
            $course_grade = '0.00000';
        }
        $criteria = new completion_criteria_grade($params);
        $criteria->config_form_display($mform, $course_grade);

        // Manual self completion
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualselfcompletion', 'core_completion'));
        $mform->addElement('header', 'manualselfcompletion', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_SELF);
        if (!empty($current)) {
            $mform->setExpanded('manualselfcompletion');
        }
        $criteria = new completion_criteria_self($params);
        $criteria->config_form_display($mform);
        $mform->addElement('static', 'criteria_self_note', '', get_string('manualselfcompletionnote', 'core_completion'));

        // Role completion criteria
        $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualcompletionby', 'core_completion'));
        $mform->addElement('header', 'roles', $label);
        // Expand the condition section if it is currently enabled.
        $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
        if (!empty($current)) {
            $mform->setExpanded('roles');
        }
        $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, context_course::instance($course->id, IGNORE_MISSING));

        if (!empty($roles)) {
            foreach ($roles as $role) {
                $params_a = array('role' => $role->id);
                $criteria = new completion_criteria_role(array_merge($params, $params_a));
                $criteria->config_form_display($mform, $role);
            }
            $mform->addElement('static', 'criteria_role_note', '', get_string('manualcompletionbynote', 'core_completion'));
            // Map aggregation methods to context-sensitive human readable dropdown menu.
            $roleaggregationmenu = array();
            foreach ($aggregation_methods as $methodcode => $methodname) {
                if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                    $roleaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('roleaggregation_all', 'core_completion');
                } else if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                    $roleaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('roleaggregation_any', 'core_completion');
                } else {
                    $roleaggregationmenu[$methodcode] = $methodname;
                }
            }
            $mform->addElement('select', 'role_aggregation', get_string('roleaggregation', 'core_completion'), $roleaggregationmenu);
            $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE));

        } else {
            $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion'));
        }

        // Add common action buttons.
        $this->add_action_buttons();

        // Add hidden fields.
        $mform->addElement('hidden', 'id', $course->id);
        $mform->setType('id', PARAM_INT);

        // If the criteria are locked, freeze values and submit button.
        if ($completion->is_course_locked()) {
            $except = array('settingsunlock');
            $mform->hardFreezeAllVisibleExcept($except);
            $mform->addElement('cancel');
        }
    }