Beispiel #1
0
 /**
  * Triggered when the '\mod_workshop\event\course_module_viewed' event is triggered.
  *
  * This does the same job as {@link workshopallocation_scheduled_cron()} but for the
  * single workshop. The idea is that we do not need to wait for cron to execute.
  * Displaying the workshop main view.php can trigger the scheduled allocation, too.
  *
  * @param \mod_workshop\event\course_module_viewed $event
  * @return bool
  */
 public static function workshop_viewed($event)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/workshop/locallib.php';
     $workshop = $event->get_record_snapshot('workshop', $event->objectid);
     $course = $event->get_record_snapshot('course', $event->courseid);
     $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid);
     $workshop = new \workshop($workshop, $cm, $course);
     $now = time();
     // Non-expensive check to see if the scheduled allocation can even happen.
     if ($workshop->phase == \workshop::PHASE_SUBMISSION and $workshop->submissionend > 0 and $workshop->submissionend < $now) {
         // Make sure the scheduled allocation has been configured for this workshop, that it has not
         // been executed yet and that the passed workshop record is still valid.
         $sql = "SELECT a.id\n                      FROM {workshopallocation_scheduled} a\n                      JOIN {workshop} w ON a.workshopid = w.id\n                     WHERE w.id = :workshopid\n                           AND a.enabled = 1\n                           AND w.phase = :phase\n                           AND w.submissionend > 0\n                           AND w.submissionend < :now\n                           AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";
         $params = array('workshopid' => $workshop->id, 'phase' => \workshop::PHASE_SUBMISSION, 'now' => $now);
         if ($DB->record_exists_sql($sql, $params)) {
             // Allocate submissions for assessments.
             $allocator = $workshop->allocator_instance('scheduled');
             $result = $allocator->execute();
             // Todo inform the teachers about the results.
         }
     }
     return true;
 }
Beispiel #2
0
$cm         = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
$course     = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshop   = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
$workshop   = new workshop($workshop, $cm, $course);

$PAGE->set_url($workshop->allocation_url($method));

require_login($course, false, $cm);
$context = $PAGE->context;
require_capability('mod/workshop:allocate', $context);

$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('allocation', 'workshop'));

$allocator  = $workshop->allocator_instance($method);
$initresult = $allocator->init();

//
// Output starts here
//
$output = $PAGE->get_renderer('mod_workshop');
echo $output->header();

$allocators = workshop::installed_allocators();
if (!empty($allocators)) {
    $tabs       = array();
    $row        = array();
    $inactive   = array();
    $activated  = array();
    foreach ($allocators as $methodid => $methodname) {
function workshopallocation_live_assessable_uploaded($event)
{
    global $DB;
    $cm = get_coursemodule_from_id('workshop', $event->contextinstanceid, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $instance = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
    $workshop = new workshop($instance, $cm, $course);
    $record = $DB->get_record('workshopallocation_live', array('workshopid' => $workshop->id));
    if ($workshop->phase == workshop::PHASE_ASSESSMENT and $record and $record->enabled) {
        $randomallocator = $workshop->allocator_instance('random');
        $settings = workshop_random_allocator_setting::instance_from_text($record->settings);
        $result = new workshop_allocation_result($randomallocator);
        $randomallocator->execute($settings, $result);
    }
    return true;
}
Beispiel #4
0
/**
 * Regular jobs to execute via cron
 */
function workshopallocation_scheduled_cron() {
    global $CFG, $DB;

    $sql = "SELECT w.*
              FROM {workshopallocation_scheduled} a
              JOIN {workshop} w ON a.workshopid = w.id
             WHERE a.enabled = 1
                   AND w.phase = 20
                   AND w.submissionend > 0
                   AND w.submissionend < ?
                   AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";

    $workshops = $DB->get_records_sql($sql, array(time()));

    if (empty($workshops)) {
        mtrace('... no workshops awaiting scheduled allocation. ', '');
        return;
    }

    mtrace('... executing scheduled allocation in '.count($workshops).' workshop(s) ... ', '');

    // let's have some fun!
    require_once($CFG->dirroot.'/mod/workshop/locallib.php');

    foreach ($workshops as $workshop) {
        $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST);
        $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
        $workshop = new workshop($workshop, $cm, $course);
        $allocator = $workshop->allocator_instance('scheduled');
        $result = $allocator->execute();

        // todo inform the teachers about the results
    }
}