Пример #1
0
 /**
  * Processing functions go here
  *
  * @global moodledatabase $DB
  * @param stdClass $data
  */
 public function process_course($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $fullname = $this->get_setting_value('course_fullname');
     $shortname = $this->get_setting_value('course_shortname');
     $startdate = $this->get_setting_value('course_startdate');
     // Calculate final course names, to avoid dupes
     list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname);
     // Need to change some fields before updating the course record
     $data->id = $this->get_courseid();
     $data->fullname = $fullname;
     $data->shortname = $shortname;
     // Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by
     // another course on this site.
     $context = context::instance_by_id($this->task->get_contextid());
     if (!empty($data->idnumber) && has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid()) && $this->task->is_samesite() && !$DB->record_exists('course', array('idnumber' => $data->idnumber))) {
         // Do not reset idnumber.
     } else {
         $data->idnumber = '';
     }
     // Any empty value for course->hiddensections will lead to 0 (default, show collapsed).
     // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532
     if (empty($data->hiddensections)) {
         $data->hiddensections = 0;
     }
     // Set legacyrestrictmodules to true if the course was resticting modules. If so
     // then we will need to process restricted modules after execution.
     $this->legacyrestrictmodules = !empty($data->restrictmodules);
     $data->startdate = $this->apply_date_offset($data->startdate);
     if ($data->defaultgroupingid) {
         $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
     }
     if (empty($CFG->enablecompletion)) {
         $data->enablecompletion = 0;
         $data->completionstartonenrol = 0;
         $data->completionnotify = 0;
     }
     $languages = get_string_manager()->get_list_of_translations();
     // Get languages for quick search
     if (!array_key_exists($data->lang, $languages)) {
         $data->lang = '';
     }
     $themes = get_list_of_themes();
     // Get themes for quick search later
     if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
         $data->theme = '';
     }
     // Check if this is an old SCORM course format.
     if ($data->format == 'scorm') {
         $data->format = 'singleactivity';
         $data->activitytype = 'scorm';
     }
     // Course record ready, update it
     $DB->update_record('course', $data);
     course_get_format($data)->update_course_format_options($data);
     // Role name aliases
     restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
 }
 /**
  * Processing functions go here
  *
  * @global moodledatabase $DB
  * @param stdClass $data
  */
 public function process_course($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $fullname = $this->get_setting_value('course_fullname');
     $shortname = $this->get_setting_value('course_shortname');
     $startdate = $this->get_setting_value('course_startdate');
     // Calculate final course names, to avoid dupes
     list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname);
     // Need to change some fields before updating the course record
     $data->id = $this->get_courseid();
     $data->fullname = $fullname;
     $data->shortname = $shortname;
     $context = get_context_instance_by_id($this->task->get_contextid());
     if (has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) {
         $data->idnumber = '';
     } else {
         unset($data->idnumber);
     }
     // Any empty value for course->hiddensections will lead to 0 (default, show collapsed).
     // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532
     if (empty($data->hiddensections)) {
         $data->hiddensections = 0;
     }
     // Only restrict modules if original course was and target site too for new courses
     $data->restrictmodules = $data->restrictmodules && !empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor == 'all';
     $data->startdate = $this->apply_date_offset($data->startdate);
     if ($data->defaultgroupingid) {
         $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
     }
     if (empty($CFG->enablecompletion)) {
         $data->enablecompletion = 0;
         $data->completionstartonenrol = 0;
         $data->completionnotify = 0;
     }
     $languages = get_string_manager()->get_list_of_translations();
     // Get languages for quick search
     if (!array_key_exists($data->lang, $languages)) {
         $data->lang = '';
     }
     $themes = get_list_of_themes();
     // Get themes for quick search later
     if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
         $data->theme = '';
     }
     // Course record ready, update it
     $DB->update_record('course', $data);
     // Role name aliases
     restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
 }
Пример #3
0
    /**
     * Processing functions go here
     *
     * @global moodledatabase $DB
     * @param stdClass $data
     */
    public function process_course($data) {
        global $CFG, $DB;

        $data = (object)$data;
        $oldid = $data->id; // We'll need this later

        $fullname  = $this->get_setting_value('course_fullname');
        $shortname = $this->get_setting_value('course_shortname');
        $startdate = $this->get_setting_value('course_startdate');

        // Calculate final course names, to avoid dupes
        list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname);

        // Need to change some fields before updating the course record
        $data->id = $this->get_courseid();
        $data->fullname = $fullname;
        $data->shortname= $shortname;
        $data->idnumber = '';

        // Only restrict modules if original course was and target site too for new courses
        $data->restrictmodules = $data->restrictmodules && !empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor == 'all';

        $data->startdate= $this->apply_date_offset($data->startdate);
        if ($data->defaultgroupingid) {
            $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
        }
        if (empty($CFG->enablecompletion)) {
            $data->enablecompletion = 0;
            $data->completionstartonenrol = 0;
            $data->completionnotify = 0;
        }
        $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search
        if (!array_key_exists($data->lang, $languages)) {
            $data->lang = '';
        }

        $themes = get_list_of_themes(); // Get themes for quick search later
        if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
            $data->theme = '';
        }

        // Course record ready, update it
        $DB->update_record('course', $data);

        // Role name aliases
        restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
    }
Пример #4
0
 /**
  * Processing functions go here
  *
  * @global moodledatabase $DB
  * @param stdClass $data
  */
 public function process_course($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $coursetags = isset($data->tags['tag']) ? $data->tags['tag'] : array();
     $coursemodules = isset($data->allowed_modules['module']) ? $data->allowed_modules['module'] : array();
     $oldid = $data->id;
     // We'll need this later
     $fullname = $this->get_setting_value('course_fullname');
     $shortname = $this->get_setting_value('course_shortname');
     $startdate = $this->get_setting_value('course_startdate');
     // Calculate final course names, to avoid dupes
     list($fullname, $shortname) = restore_dbops::calculate_course_names($this->get_courseid(), $fullname, $shortname);
     // Need to change some fields before updating the course record
     $data->id = $this->get_courseid();
     $data->fullname = $fullname;
     $data->shortname = $shortname;
     $data->idnumber = '';
     // Category is set by UI when choosing the destination
     unset($data->category);
     $data->startdate = $this->apply_date_offset($data->startdate);
     if ($data->defaultgroupingid) {
         $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
     }
     if (empty($CFG->enablecompletion)) {
         $data->enablecompletion = 0;
         $data->completionstartonenrol = 0;
         $data->completionnotify = 0;
     }
     $languages = get_string_manager()->get_list_of_translations();
     // Get languages for quick search
     if (!array_key_exists($data->lang, $languages)) {
         $data->lang = '';
     }
     $themes = get_list_of_themes();
     // Get themes for quick search later
     if (!in_array($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
         $data->theme = '';
     }
     // Course record ready, update it
     $DB->update_record('course', $data);
     // Course tags
     if (!empty($CFG->usetags) && isset($coursetags)) {
         // if enabled in server and present in backup
         $tags = array();
         foreach ($coursetags as $coursetag) {
             $coursetag = (object) $coursetag;
             $tags[] = $coursetag->rawname;
         }
         tag_set('course', $this->get_courseid(), $tags);
     }
     // Course allowed modules
     if (!empty($data->restrictmodules) && !empty($coursemodules)) {
         $available = get_plugin_list('mod');
         foreach ($coursemodules as $coursemodule) {
             $mname = $coursemodule['modulename'];
             if (array_key_exists($mname, $available)) {
                 if ($module = $DB->get_record('modules', array('name' => $mname, 'visible' => 1))) {
                     $rec = new stdclass();
                     $rec->course = $this->get_courseid();
                     $rec->module = $module->id;
                     if (!$DB->record_exists('course_allowed_modules', (array) $rec)) {
                         $DB->insert_record('course_allowed_modules', $rec);
                     }
                 }
             }
         }
     }
     // Role name aliases
     restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
 }