コード例 #1
0
ファイル: api.php プロジェクト: gabrielrosset/moodle
 /**
  * Add a competency to this course module.
  *
  * @param mixed $cmorid The course module, or id of the course module
  * @param int $competencyid The id of the competency
  * @return bool
  */
 public static function add_competency_to_course_module($cmorid, $competencyid)
 {
     static::require_enabled();
     $cm = $cmorid;
     if (!is_object($cmorid)) {
         $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
     }
     // Check the user have access to the course module.
     self::validate_course_module($cm);
     // First we do a permissions check.
     $context = context_module::instance($cm->id);
     require_capability('moodle/competency:coursecompetencymanage', $context);
     // Check that the competency belongs to the course.
     $exists = course_competency::get_records(array('courseid' => $cm->course, 'competencyid' => $competencyid));
     if (!$exists) {
         throw new coding_exception('Cannot add a competency to a module if it does not belong to the course');
     }
     $record = new stdClass();
     $record->cmid = $cm->id;
     $record->competencyid = $competencyid;
     $coursemodulecompetency = new course_module_competency();
     $exists = $coursemodulecompetency->get_records(array('cmid' => $cm->id, 'competencyid' => $competencyid));
     if (!$exists) {
         $coursemodulecompetency->from_record($record);
         if ($coursemodulecompetency->create()) {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: lib.php プロジェクト: evltuma/moodle
 /**
  * Create a new course module competency.
  *
  * @param array|stdClass $record
  * @return course_module_competency
  */
 public function create_course_module_competency($record = null)
 {
     $record = (object) $record;
     if (!isset($record->cmid)) {
         throw new coding_exception('The cmid value is required.');
     }
     if (!isset($record->competencyid)) {
         throw new coding_exception('The competencyid value is required.');
     }
     $cc = new course_module_competency(0, $record);
     $cc->create();
     return $cc;
 }