/** * Add a competency to this course. * * @param int $courseid The id of the course * @param int $competencyid The id of the competency * @return bool */ public static function add_competency_to_course($courseid, $competencyid) { static::require_enabled(); // Check the user have access to the course. self::validate_course($courseid); // First we do a permissions check. $context = context_course::instance($courseid); require_capability('moodle/competency:coursecompetencymanage', $context); $record = new stdClass(); $record->courseid = $courseid; $record->competencyid = $competencyid; $competency = new competency($competencyid); // Can not add a competency that belong to a hidden framework. if ($competency->get_framework()->get_visible() == false) { throw new coding_exception('A competency belonging to hidden framework can not be linked to course'); } $coursecompetency = new course_competency(); $exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid)); if (!$exists) { $coursecompetency->from_record($record); if ($coursecompetency->create()) { return true; } } return false; }
/** * Create a new course competency. * * @param array|stdClass $record * @return user_competency */ public function create_course_competency($record = null) { $record = (object) $record; if (!isset($record->courseid)) { throw new coding_exception('The courseid value is required.'); } if (!isset($record->competencyid)) { throw new coding_exception('The competencyid value is required.'); } $cc = new course_competency(0, $record); $cc->create(); return $cc; }