Esempio n. 1
0
 /**
  * Update the competency settings for a course.
  *
  * Requires moodle/competency:coursecompetencyconfigure capability at the course context.
  *
  * @param int $courseid The course id
  * @param stdClass $settings List of settings. The only valid setting ATM is pushratginstouserplans (boolean).
  * @return bool
  */
 public static function update_course_competency_settings($courseid, $settings)
 {
     static::require_enabled();
     $settings = (object) $settings;
     // Get all the valid settings.
     $pushratingstouserplans = isset($settings->pushratingstouserplans) ? $settings->pushratingstouserplans : false;
     // First we do a permissions check.
     if (!course_competency_settings::can_manage_course($courseid)) {
         $context = context_course::instance($courseid);
         throw new required_capability_exception($context, 'moodle/competency:coursecompetencyconfigure', 'nopermissions', '');
     }
     $exists = course_competency_settings::get_record(array('courseid' => $courseid));
     // Now update or insert.
     if ($exists) {
         $settings = $exists;
         $settings->set_pushratingstouserplans($pushratingstouserplans);
         return $settings->update();
     } else {
         $data = (object) array('courseid' => $courseid, 'pushratingstouserplans' => $pushratingstouserplans);
         $settings = new course_competency_settings(0, $data);
         $result = $settings->create();
         return !empty($result);
     }
 }