Esempio n. 1
0
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    // Check we don't have a duplicate shortname.
    if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
            throw new moodle_exception('shortnametaken', '', '', $data->shortname);
        }
    }
    // Check we don't have a duplicate idnumber.
    if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
            throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
        }
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        $context->update_moved($newparent);
    }
    $fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
    if ($fixcoursesortorder) {
        fix_course_sortorder();
    }
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    // Trigger a course updated event.
    $event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
    $event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
    $event->trigger();
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
Esempio n. 2
0
 /**
  * Handle course_updated event.
  *
  * Does the following:
  *     - update associated sharepoint sites and associated groups.
  *
  * @param \core\event\course_updated $event The triggered event.
  * @return bool Success/Failure.
  */
 public static function handle_course_updated(\core\event\course_updated $event)
 {
     if (\local_o365\utils::is_configured() !== true) {
         return false;
     }
     $courseid = $event->objectid;
     $eventdata = $event->get_data();
     if (!empty($eventdata['other'])) {
         $sharepoint = static::construct_sharepoint_api_with_system_user();
         if (!empty($sharepoint)) {
             $sharepoint->update_course_site($courseid, $eventdata['other']['shortname'], $eventdata['other']['fullname']);
         }
     }
 }
Esempio n. 3
0
 /**
  * Observer for \core\event\course_updated event.
  *
  * @param \core\event\course_updated $event
  * @return void
  */
 public static function course_updated(\core\event\course_updated $event)
 {
     global $CFG;
     $course = $event->get_record_snapshot('course', $event->objectid);
     $format = course_get_format($course);
     if ($format->supports_news() && !empty($course->newsitems)) {
         require_once $CFG->dirroot . '/mod/forum/lib.php';
         // Auto create the announcements forum.
         forum_get_course_forum($event->objectid, 'news');
     }
 }
Esempio n. 4
0
/**
 * Update the Moodle course with the contents from the SIS course
 * Note: $course includes id, fullname, shortname and startdate
 *
 * @author Andrew Zoltay
 * date    2011-06-02
 * @param update course object $course
 * @return true for success, false for failure
 */
function accs_update_course($course)
{
    $course->timemodified = time();
    if (accs_dbupdate_course($course)) {
        // Trigger events.
        $context = context_course::instance($course->id);
        $event = \core\event\course_updated::create(array('context' => $context, 'objectid' => $course->id, 'other' => null));
        $event->trigger();
        return true;
    } else {
        return false;
    }
}
Esempio n. 5
0
 /**
  * Handle course_updated event.
  *
  * Does the following:
  *     - update associated sharepoint sites and associated groups.
  *
  * @param \core\event\course_updated $event The triggered event.
  * @return bool Success/Failure.
  */
 public static function handle_course_updated(\core\event\course_updated $event)
 {
     $courseid = $event->objectid;
     $eventdata = $event->get_data();
     if (!empty($eventdata['other'])) {
         $sharepoint = static::construct_sharepoint_api_with_system_user();
         if (!empty($sharepoint)) {
             $sharepoint->update_course_site($courseid, $eventdata['other']['shortname'], $eventdata['other']['fullname']);
         }
     }
 }
Esempio n. 6
0
 public static function course_updated(\core\event\course_updated $event)
 {
     $course = $event->get_record_snapshot('course', $event->objectid);
     $groups = get_config('auth/joomdle', 'jomsocial_groups');
     $autosell = get_config('auth/joomdle', 'auto_sell');
     $auth_joomdle = new auth_plugin_joomdle();
     if ($groups) {
         $auth_joomdle->call_method('updateSocialGroup', $course->fullname, get_string('auth_joomla_group_for_course', 'auth_joomdle') . ' ' . $course->fullname, (int) $course->id);
     }
     if ($autosell) {
         $cid = array($course->id);
         $auth_joomdle->call_method("updateCourseShop", array((int) $course->id));
     }
     return true;
 }
 /**
  * The course update event.
  *
  * process cover image.
  *
  * @param course_updated $event
  * @return void
  */
 public static function course_updated(course_updated $event)
 {
     $course = $event->get_record_snapshot('course', $event->objectid);
     $context = \context_course::instance($course->id);
     local::process_coverimage($context);
 }
 /**
  * Called when course_updated event happens.
  *
  * @param \core\event\course_updated $event Event data object
  */
 public static function course_updated(\core\event\course_updated $event)
 {
     year_tables::handle_updated_course($event->get_data()['objectid']);
 }