if (!($submission = $DB->get_record('emarking_submission', array('id' => $submissionid)))) { $totaldocumentsignored++; continue; } if (!($student = $DB->get_record('user', array('id' => $submission->student)))) { $totaldocumentsignored++; continue; } if (emarking_multi_create_response_pdf($submission, $student, $context, $cmid)) { $totaldocumentsprocessed++; $pbar->update($totaldocumentsprocessed, $totalsubmissions, get_string('publishinggrade', 'mod_emarking') . $submission->id); emarking_multi_publish_grade($submission); } else { $totaldocumentsignored++; } } $pbar->update_full(100, get_string('publishinggradesfinished', 'mod_emarking')); $percentage = 0; if ($totaldocumentsprocessed > 0) { $percentage = round(($totaldocumentsprocessed - $totaldocumentsignored) / $totaldocumentsprocessed * 100, 2); } $table = new html_table(); $table->attributes['style'] = "width: 500px; margin-left:auto; margin-right:auto;"; $table->head = array(get_string('results', 'mod_emarking'), ' '); $table->data[] = array(get_string('publishedgrades', 'mod_emarking'), $totaldocumentsprocessed . " ({$percentage}%)"); $table->data[] = array(get_string('errors', 'mod_emarking'), $totaldocumentsignored); echo "<br/>"; echo html_writer::table($table); $continue_url = new moodle_url('/mod/emarking/view.php', array('id' => $cm->id)); echo $OUTPUT->continue_button($continue_url); echo $OUTPUT->footer();
/** * Finalyze (push to 100%) the progressbar, if any, showing a message. * @param progress_bar $progressbar Progress Bar instance to update; if null do nothing * @param string $msg */ function attendanceregister__finalize_progress_bar($progressbar, $msg = '') { if ($progressbar) { $progressbar->update_full(100, $msg); } }
$users = emarking_get_enroled_students($course->id); $pbar = new progress_bar(); $pbar->create(); if ($create) { quiz_delete_all_attempts($quiz); } $cur = 1; $total = count($users); // Insert answers or finish the attempt for each student foreach ($users as $user) { $pbar->update($cur, $total, get_string('processing', 'mod_emarking') . $user->lastname . $user->firstname); flush(); // Get the quiz instance for the specific student $quizobj = quiz::create($cm->instance, $user->id); // Get all the attempts $attempts = quiz_get_user_attempts($quizobj->get_quizid(), $user->id, 'all'); if ($create) { emarking_add_user_attempt($cm, $user); } else { // For each attempt insert the answers or finish foreach ($attempts as $attempt) { if ($finish) { emarking_finish_user_attempt($attempt->id); } } } $cur++; } $pbar->update_full(100, get_string('finished', 'mod_emarking')); echo $OUTPUT->single_button(new moodle_url('/mod/emarking/orm/quizzes.php', array('course' => $cm->course)), get_string('continue')); echo $OUTPUT->footer();
/** * Crea un archivo PDF a partir de un quiz, agregando una hoja de respuestas de opción múltiple * * @param unknown $cm * @param string $debug * @param string $context * @param string $course * @param string $logofilepath * @param boolean $answersheetsonly * @return void|NULL */ function emarking_create_quiz_pdf($cm, $debug = false, $context = null, $course = null, $answersheetsonly = false, $pbar = false) { global $DB, $CFG, $OUTPUT; // Inclusión de librerías require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi2tcpdf_bridge.php'; require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi.php'; require_once $CFG->libdir . '/pdflib.php'; require_once $CFG->dirroot . '/mod/quiz/locallib.php'; require_once $CFG->dirroot . '/mod/emarking/print/locallib.php'; $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}"; emarking_initialize_directory($filedir, true); $fileimg = $CFG->dataroot . "/temp/emarking/{$context->id}/qr"; emarking_initialize_directory($fileimg, true); $userimgdir = $CFG->dataroot . "/temp/emarking/{$context->id}/u"; emarking_initialize_directory($userimgdir, true); $logofile = emarking_get_logo_file(); $logofilepath = $logofile ? emarking_get_path_from_hash($filedir, $logofile->get_pathnamehash()) : null; $fullhtml = array(); $numanswers = array(); $attemptids = array(); $images = array(); $imageshtml = array(); $users = emarking_get_enroled_students($course->id); if ($pbar) { echo $OUTPUT->heading(get_string('loadingquestions', 'mod_emarking'), 3); $progressbar = new progress_bar(); $progressbar->create(); $progressbar->update(0, count($users), get_string('processing', 'mod_emarking')); } $current = 0; foreach ($users as $user) { $current++; if ($pbar) { $progressbar->update($current, count($users), "{$user->firstname}, {$user->lastname}"); } // Get the quiz object $quizobj = quiz::create($cm->instance, $user->id); // Create the new attempt and initialize the question sessions $attemptnumber = 1; $lastattempt = null; $timenow = time(); // Update time now, in case the server is running really slowly. $attempts = quiz_get_user_attempts($quizobj->get_quizid(), $user->id, 'all'); $numattempts = count($attempts); foreach ($attempts as $attempt) { $attemptobj = quiz_attempt::create($attempt->id); $slots = $attemptobj->get_slots(); foreach ($slots as $slot) { $qattempt = $attemptobj->get_question_attempt($slot); $question = $qattempt->get_question(); if ($question->get_type_name() === 'multianswer') { $q = $question->subquestions[1]; $numanswers[$user->id][] = count($q->answers); } else { if ($question->get_type_name() === 'multichoice') { $numanswers[$user->id][] = count($question->answers); } } $attemptids[$user->id] = $attempt->id; $qhtml = $attemptobj->render_question($slot, false); $qhtml = emarking_clean_question_html($qhtml); $currentimages = emarking_extract_images_url($qhtml); $idx = 0; foreach ($currentimages[1] as $imageurl) { if (!array_search($imageurl, $images)) { $images[] = $imageurl; $imageshtml[] = $currentimages[0][$idx]; } $idx++; } $fullhtml[$user->id][] = $qhtml; } // One attempt per user break; } } $save_to = $CFG->tempdir . '/emarking/printquiz/' . $cm->id . '/'; emarking_initialize_directory($save_to, true); // Bajar las imágenes del HTML a dibujar $search = array(); $replace = array(); $replaceweb = array(); $imagesize = array(); $idx = 0; if ($pbar) { $progressbar->update_full(100, get_string('finished', 'mod_emarking')); echo $OUTPUT->heading(get_string('downloadingimages', 'mod_emarking'), 3); $progressbar = new progress_bar(); $progressbar->create(); $progressbar->update(0, count($images), get_string('processing', 'mod_emarking')); } foreach ($images as $image) { if ($pbar) { $imagefilename = explode("/", $image); $progressbar->update($idx + 1, count($images), $imagefilename[count($imagefilename) - 1]); } // Si solamente incluiremos hojas de respuesta terminamos el ciclo if ($answersheetsonly) { break; } if (!(list($filename, $imageinfo) = emarking_get_file_from_url($image, $save_to))) { echo "Problem downloading file {$image} <hr>"; } else { // Buscamos el src de la imagen $search[] = 'src="' . $image . '"'; $replacehtml = ' src="' . $filename . '"'; $replacehtmlxweb = ' src="' . $image . '"'; // Si el html de la misma contiene ancho o alto, se deja tal cual $imghtml = $imageshtml[$idx]; if (substr_count($imghtml, "width") + substr_count($imghtml, "height") == 0) { $width = $imageinfo[0]; $height = $imageinfo[1]; $ratio = floatval(10) / floatval($height); $height = 10; $width = (int) ($ratio * floatval($width)); $sizehtml = 'width="' . $width . '" height="' . $height . '"'; $replacehtml = $sizehtml . ' ' . $replacehtml; $replacehtmlxweb = $sizehtml . ' ' . $replacehtmlxweb; } $replace[] = $replacehtml; $replaceweb[] = $replacehtmlxweb; $imagesize[] = $imageinfo; } $idx++; } if ($debug) { foreach ($fullhtml as $uid => $questions) { $index = 0; foreach ($questions as $question) { echo str_replace($search, $replaceweb, $fullhtml[$uid][$index]); $index++; } } return; } // Now we create the pdf file with the modified html $doc = new FPDI(); $doc->setPrintHeader(false); $doc->setPrintFooter(false); $doc->SetFont('times', '', 12); // set margins $doc->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $doc->SetHeaderMargin(250); $doc->SetFooterMargin(PDF_MARGIN_FOOTER); if ($pbar) { $progressbar->update_full(100, get_string('finished', 'mod_emarking')); echo $OUTPUT->heading(get_string('creatingpdffile', 'mod_emarking'), 3); $progressbar = new progress_bar(); $progressbar->create(); } $current = 0; foreach ($fullhtml as $uid => $questions) { $current++; $stinfo = $DB->get_record('user', array('id' => $uid)); $stinfo->name = $stinfo->firstname . ' ' . $stinfo->lastname; $stinfo->picture = emarking_get_student_picture($stinfo, $userimgdir); $stinfo->idnumber = $uid . '-' . $attemptids[$uid]; if ($pbar) { $progressbar->update($current, count($fullhtml), $stinfo->name); } $groups = groups_get_user_groups($course->id, $uid); if ($groups && isset($groups[0][0]) && ($group = $DB->get_record('groups', array('id' => $groups[0][0])))) { $stinfo->group = $group->name; } else { $stinfo->group = ''; } emarking_add_answer_sheet($doc, $filedir, $stinfo, $logofilepath, null, $fileimg, $course, $quizobj->get_quiz_name(), $numanswers[$uid], $attemptids[$uid]); // Una vez agregada la página de respuestas, si es todo lo que hay que hacer saltar al siguiente if ($answersheetsonly) { continue; } $doc->AddPage(); emarking_draw_header($doc, $stinfo, $quizobj->get_quiz_name(), 2, $fileimg, $logofilepath, $course, null, false, 0); $doc->SetFont('times', '', 12); $doc->SetAutoPageBreak(true); $doc->SetXY(PDF_MARGIN_LEFT, 40); $index = 0; foreach ($questions as $question) { $prevy = $doc->getY(); $fullhtml[$uid][$index] = str_replace($search, $replace, $fullhtml[$uid][$index]); $doc->writeHTML($fullhtml[$uid][$index]); $y = $doc->getY(); $fmargin = $doc->getFooterMargin(); $height = $doc->getPageHeight(); $spaceleft = $height - $fmargin - $y; $questionsize = $y - $prevy; if ($spaceleft < 70) { $doc->AddPage(); } $index++; } } if ($pbar) { $progressbar->update_full(100, get_string('finished', 'mod_emarking')); } $qid = $quizobj->get_quizid(); $pdfquizfilename = 'quiz-' . $qid . '-' . random_string() . '.pdf'; $fs = get_file_storage(); $filerecord = array('component' => 'mod_emarking', 'filearea' => 'pdfquiz', 'contextid' => $context->id, 'itemid' => $quizobj->get_quizid(), 'filepath' => '/', 'filename' => $pdfquizfilename); $doc->Output($filedir . '/' . $pdfquizfilename, 'F'); $file = $fs->create_file_from_pathname($filerecord, $filedir . '/' . $pdfquizfilename); $downloadurl = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$context->id}/mod_emarking/pdfquiz/{$qid}/{$pdfquizfilename}", null, true); return $downloadurl; }
$context = context_course::instance($course->id); require_capability('moodle/course:update', $context); require_capability('moodle/course:manageactivities', $context); require_sesskey(); $course = course_get_format($course)->get_course(); $modinfo = get_fast_modinfo($course); $sectioninfo = $modinfo->get_section_info($section); $context = context_course::instance($course->id); $num_newsection = null; $PAGE->set_pagelayout('course'); $PAGE->set_heading($course->fullname); $PAGE->set_title(get_string('coursetitle', 'moodle', array('course' => $course->fullname))); echo $OUTPUT->header(); if (!empty($sectioninfo)) { $pbar = new progress_bar('onetopic_duplicate_bar', 500, true); $pbar->update_full(1, get_string('duplicating', 'format_onetopic')); $course_format = course_get_format($course); $last_section_num = $DB->get_field('course_sections', 'MAX(section)', array('course' => $courseid), MUST_EXIST); //$courseformatoptions = $course_format->get_format_options(); //$courseformatoptions['numsections']++; $num_newsection = $last_section_num + 1; if (!$course_format->update_course_format_options(array('numsections' => $num_newsection))) { print_error('cantcreatesection', 'error', null, $course->fullname); return; } $pbar->update_full(5, get_string('creating_section', 'format_onetopic')); //Assign same section info $data = new stdClass(); $data->course = $sectioninfo->course; $data->section = $num_newsection; //The name is not duplicated