} // for numberpaperquiz } if ($cron == 1) { mtrace("<p>Su cuestionario sera generado mas tarde</a></p>"); $continue = "{$CFG->wwwroot}/mod/blended/edit_paperquiz.php?a={$a}"; print_continue($continue); // Finish the page print_footer($course); } else { // Generate every job matching this data. (This makes a grouping of attempts) $job->quiz = $quiz->id; $job->userid = $USER->id; $job->blended = $blended->id; $job->timestamp = $timestamp; list($numattempts, $pdfFile) = generateJobs($job); if ($numattempts > 0) { $tex = new object(); $tex->href = "{$CFG->wwwroot}/files/index.php?id={$course->id}&wdir=%2F{$pdfFile->inCourseFolderRelativePath}"; $tex->hrefText = $pdfFile->inCourseFolderRelativePath; $tex->directLinkhref = "{$CFG->wwwroot}/file.php/{$pdfFile->RelativePath}?forcedownload=1"; $tex->directLinkText = $pdfFile->Name; echo get_string("PDFgeneratedMessage", "blended", $tex); } else { echo "<p>No PDF file generated.</p>"; } $continue = "{$CFG->wwwroot}/mod/blended/edit_paperquiz.php?a={$a}"; print_continue($continue); // Finish the page echo "<center>"; helpbutton($page = 'generateQuizesPDF', get_string('pagehelp', 'blended'), $module = 'blended', $image = true, $linktext = true, $text = '', $return = false, $imagetext = '');
/** * 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 ... * * @global $CFG * @return boolean * @todo Finish documenting this function **/ function blended_cron() { global $CFG; global $COURSE; global $USER; global $DB; $course->id = $COURSE->id; mtrace("\n======================="); mtrace("Blended module."); mtrace("======================="); $query = 'SELECT timestamp, quiz, userid, count(*) FROM ' . "{$CFG->prefix}blended_jobs WHERE status = '" . JOB_STATE_WAITING . "' group by quiz, timestamp, userid"; mtrace("Querying with: {$query}"); if (!($jobs = $DB->get_records_sql($query))) { mtrace("There are no waiting PDF jobs."); } else { mtrace(" Found:" . count($jobs) . " questionnaire sets."); /** * $jobs contain jobs generated simultaneouly from the same quiz, in the same timestamp and from the same userid */ foreach ($jobs as $job) { generateJobs($job); } } //blended_check_scans_status(); /** * Consider it hung if delayed more than 30 minutes. */ $expiration_time = time() - 30 * 60; // TODO implement a locking mechanism //$scans = get_records($table="blended_scans",$field="status",$value="Espera") $condition = "status = '" . JOB_STATE_WAITING . "' OR (status='" . JOB_STATE_BUSY . "' AND timestatus < {$expiration_time})"; mtrace($condition); if (!($scans = $DB->get_records_select('blended_scans', $condition))) { mtrace("There are no ready scan jobs"); } else { mtrace(" Found:" . count($scans) . " scanned sets."); foreach ($scans as $scan) { omrprocess($scan); } } if ($scans = $DB->get_records_select('blended_scans', "status='" . JOB_STATE_BUSY . "'")) { mtrace("There are " . count($scans) . " scanned sets waiting for retrying in less than 5 minutes."); } mtrace("======================="); mtrace("======================="); return true; }