/**
  * Performs the task
  *
  * @throws moodle_exception on an error (the job will be retried)
  */
 public function execute()
 {
     global $DB;
     $subcourses = $DB->get_records("subcourse", null, "", "id, course, refcourse");
     if (empty($subcourses)) {
         return;
     }
     $updatedids = array();
     foreach ($subcourses as $subcourse) {
         if (empty($subcourse->refcourse)) {
             mtrace("Subcourse {$subcourse->id}: no referenced course configured ... skipped");
             continue;
         }
         mtrace("Subcourse {$subcourse->id}: fetching grades from course {$subcourse->refcourse} to course {$subcourse->course} ... ", "");
         $result = subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse);
         if ($result == GRADE_UPDATE_OK) {
             $updatedids[] = $subcourse->id;
             mtrace("ok");
         } else {
             mtrace("failed with error code " . $result);
         }
     }
     if (!empty($updatedids)) {
         subcourse_update_timefetched($updatedids);
     }
 }
 /**
  * Role assigned
  *
  * Every time new user is enrolled into course we should fetch all subcourses again,
  * because user can be previously enrolled into subcourse
  *
  * @param \core\event\role_assigned $event
  * @return void
  */
 public static function role_assigned(\core\event\role_assigned $event)
 {
     global $DB;
     $courseid = $event->courseid;
     $subcourses = $DB->get_records('subcourse', array('course' => $courseid));
     foreach ($subcourses as $subcourse) {
         $result = subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse);
         if ($result == GRADE_UPDATE_OK) {
             $updatedids[] = $subcourse->id;
         }
     }
     if (!empty($updatedids)) {
         subcourse_update_timefetched($updatedids);
     }
 }
Exemplo n.º 3
0
/**
 * Function to be run periodically according to the moodle cron
 * This function searches for things that need to be done, such
 * as sending out mail, toggling flags etc ...
 *
 * @uses $CFG
 * @return boolean
 * @todo Finish documenting this function
 */
function subcourse_cron()
{
    global $DB;
    $subcourse_instances = $DB->get_records('subcourse', null, '', 'id, course, refcourse');
    if (empty($subcourse_instances)) {
        return true;
    }
    $updatedids = array();
    echo "Fetching grades from remote gradebooks...\n";
    foreach ($subcourse_instances as $subcourse) {
        $message = "Subcourse {$subcourse->id}: fetching grades from course {$subcourse->refcourse} " . "to course {$subcourse->course} ... ";
        echo $message;
        try {
            subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse);
            $updatedids[] = $subcourse->id;
            echo "ok\n";
        } catch (subcourse_localremotescale_exception $e) {
            echo get_string($e->errorcode, 'subcourse') . "\n";
        }
    }
    subcourse_update_timefetched($updatedids);
    return true;
}
Exemplo n.º 4
0
    }
}
require_login($course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$course_context = get_context_instance(CONTEXT_COURSE, $course->id);
if (!($refcourse = $DB->get_record("course", array("id" => $subcourse->refcourse)))) {
    print_error("errinvalidrefcourse", "subcourse");
}
if ($fetchnow) {
    if (!confirm_sesskey()) {
        print_error('confirmsesskeybad');
    }
    require_capability('mod/subcourse:fetchgrades', $context);
    add_to_log($course->id, "subcourse", "fetch", "view.php?id={$cm->id}", "{$refcourse->id}");
    try {
        subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse);
        subcourse_update_timefetched($subcourse->id);
        redirect($CFG->wwwroot . '/mod/subcourse/view.php?id=' . $cm->id);
    } catch (subcourse_localremotescale_exception $e) {
        print_error($e->errorcode, 'subcourse', $CFG->wwwroot . '/mod/subcourse/view.php?id=' . $cm->id);
    }
}
add_to_log($course->id, "subcourse", "view", "view.php?id={$cm->id}", "{$subcourse->id}");
/// Print the page header
$strsubcourses = get_string("modulenameplural", "subcourse");
$strsubcourse = get_string("modulename", "subcourse");
$page_url = new moodle_url('/mod/subcourse/index.php', array('id' => $course->id));
$PAGE->set_url($page_url);
$PAGE->set_title(format_string($subcourse->name));
$PAGE->set_heading($course->shortname);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'subcourse'));
Exemplo n.º 5
0
/**
 * Given an object containing all the necessary data, (defined by the form)
 * this function will update an existing instance with new data.
 *
 * @param stdClass $subcourse
 * @return boolean success/failure
 */
function subcourse_update_instance(stdClass $subcourse)
{
    global $DB;
    $cmid = $subcourse->coursemodule;
    $subcourse->timemodified = time();
    $subcourse->id = $subcourse->instance;
    if (!empty($subcourse->refcoursecurrent)) {
        unset($subcourse->refcourse);
    }
    if (empty($subcourse->instantredirect)) {
        $subcourse->instantredirect = 0;
    }
    $DB->update_record('subcourse', $subcourse);
    $subcourse = $DB->get_record('subcourse', array('id' => $subcourse->id));
    if (!empty($subcourse->refcourse)) {
        if (has_capability('mod/subcourse:fetchgrades', context_module::instance($cmid))) {
            subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse, $subcourse->name);
            subcourse_update_timefetched($subcourse->id);
        }
    }
    return true;
}