本文整理汇总了PHP中question_usage_by_activity::get_slots方法的典型用法代码示例。如果您正苦于以下问题:PHP question_usage_by_activity::get_slots方法的具体用法?PHP question_usage_by_activity::get_slots怎么用?PHP question_usage_by_activity::get_slots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_usage_by_activity
的用法示例。
在下文中一共展示了question_usage_by_activity::get_slots方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: offlinequiz_create_pdf_question
//.........这里部分代码省略.........
$pdf->AddPage();
$pdf->Ln(14);
$pdf->writeHTMLCell(165, round($offlinequiz->fontsize / 2), $pdf->GetX(), $pdf->GetY(), $sentence);
$pdf->Ln();
}
}
}
}
}
}
$pdf->AddPage();
$pdf->Ln(2);
}
$pdf->SetMargins(15, 15, 15);
// Load all the questions needed for this offline quiz group.
$sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark \n FROM {offlinequiz_group_questions} ogq,\n {question} q,\n {question_categories} c\n WHERE ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid\n AND q.id = ogq.questionid\n AND q.category = c.id\n ORDER BY ogq.slot ASC ";
$params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
// Load the questions.
$questions = $DB->get_records_sql($sql, $params);
if (!$questions) {
echo $OUTPUT->box_start();
echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
echo $OUTPUT->box_end();
return;
}
// Load the question type specific information.
if (!get_question_options($questions)) {
print_error('Could not load question options');
}
// Restore the question sessions to their most recent states.
// Creating new sessions where required.
$number = 1;
// We need a mapping from question IDs to slots, assuming that each question occurs only once.
$slots = $templateusage->get_slots();
$texfilter = new filter_tex($context, array());
// If shufflequestions has been activated we go through the questions in the order determined by
// the template question usage.
if ($offlinequiz->shufflequestions) {
foreach ($slots as $slot) {
$slotquestion = $templateusage->get_question($slot);
$currentquestionid = $slotquestion->id;
// Add page break if necessary because of overflow.
if ($pdf->GetY() > 230) {
$pdf->AddPage();
$pdf->Ln(14);
}
set_time_limit(120);
$question = $questions[$currentquestionid];
/*****************************************************/
/* Either we print the question HTML */
/*****************************************************/
$pdf->checkpoint();
$questiontext = $question->questiontext;
// Filter only for tex formulas.
if (!empty($texfilter)) {
$questiontext = $texfilter->filter($questiontext);
}
// Remove all HTML comments (typically from MS Office).
$questiontext = preg_replace("/<!--.*?--\\s*>/ms", "", $questiontext);
// Remove <font> tags.
$questiontext = preg_replace("/<font[^>]*>[^<]*<\\/font>/ms", "", $questiontext);
// Remove <script> tags that are created by mathjax preview.
$questiontext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $questiontext);
// Remove all class info from paragraphs because TCPDF won't use CSS.
$questiontext = preg_replace('/<p[^>]+class="[^"]*"[^>]*>/i', "<p>", $questiontext);
$questiontext = $trans->fix_image_paths($questiontext, $question->contextid, 'questiontext', $question->id, 1, 300);
示例2: __construct
/**
* To create an instance of this class, use
* {@link question_usage_by_activity::get_attempt_iterator()}.
* @param $quba the usage to iterate over.
*/
public function __construct(question_usage_by_activity $quba) {
$this->quba = $quba;
$this->slots = $quba->get_slots();
$this->rewind();
}
示例3: offlinequiz_count_multichoice_questions
/**
* Counts the multichoice question in a questionusage.
*
* @param question_usage_by_activity $questionusage
* @return number
*/
function offlinequiz_count_multichoice_questions(question_usage_by_activity $questionusage)
{
$count = 0;
$slots = $questionusage->get_slots();
foreach ($slots as $slot) {
$question = $questionusage->get_question($slot);
if ($question->qtype->name() == 'multichoice' || $question->qtype->name() == 'multichoiceset') {
$count++;
}
}
return $count;
}
示例4: offlinequiz_create_latex_question
/**
* Generates the LaTeX question form for an offlinequiz group.
*
* @param question_usage_by_activity $templateusage the template question usage for this offline group
* @param object $offlinequiz The offlinequiz object
* @param object $group the offline group object
* @param int $courseid the ID of the Moodle course
* @param object $context the context of the offline quiz.
* @param boolean correction if true the correction form is generated.
* @return stored_file instance, the generated PDF file.
*/
function offlinequiz_create_latex_question(question_usage_by_activity $templateusage, $offlinequiz, $group, $courseid, $context, $correction = false)
{
global $CFG, $DB, $OUTPUT;
$letterstr = 'abcdefghijklmnopqrstuvwxyz';
$groupletter = strtoupper($letterstr[$group->number - 1]);
$coursecontext = context_course::instance($courseid);
$course = $DB->get_record('course', array('id' => $courseid));
$title = format_text($offlinequiz->name, FORMAT_HTML);
$title .= ", " . get_string('group') . $groupletter;
// Load all the questions needed for this offline quiz group.
$sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark\n FROM {offlinequiz_group_questions} ogq,\n {question} q,\n {question_categories} c\n WHERE ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid\n AND q.id = ogq.questionid\n AND q.category = c.id\n ORDER BY ogq.slot ASC ";
$params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
// Load the questions.
$questions = $DB->get_records_sql($sql, $params);
if (!$questions) {
echo $OUTPUT->box_start();
echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
echo $OUTPUT->box_end();
return;
}
// Load the question type specific information.
if (!get_question_options($questions)) {
print_error('Could not load question options');
}
$number = 1;
// We need a mapping from question IDs to slots, assuming that each question occurs only once.
$slots = $templateusage->get_slots();
$latexforquestions = '\\begin{enumerate}' . "\n";
// If shufflequestions has been activated we go through the questions in the order determined by
// the template question usage.
if ($offlinequiz->shufflequestions) {
foreach ($slots as $slot) {
$slotquestion = $templateusage->get_question($slot);
$currentquestionid = $slotquestion->id;
$question = $questions[$currentquestionid];
$questiontext = offlinequiz_convert_html_to_latex($question->questiontext);
$latexforquestions .= '\\item ' . $questiontext . "\n";
if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') {
// There is only a slot for multichoice questions.
$attempt = $templateusage->get_question_attempt($slot);
$order = $slotquestion->get_order($attempt);
// Order of the answers.
$latexforquestions .= '\\begin{enumerate}' . " \n";
foreach ($order as $key => $answer) {
$latexforquestions .= offlinequiz_get_answer_latex($question, $answer);
}
$latexforquestions .= '\\end{enumerate}' . "\n";
$infostr = offlinequiz_get_question_infostring($offlinequiz, $question);
if ($infostr) {
$latexforquestions .= $infostr . "\n";
}
}
}
$latexforquestions .= '\\end{enumerate}' . "\n";
} else {
// No shufflequestions, so go through the questions as they have been added to the offlinequiz group.
// We also have to show description questions that are not in the template.
// First, compute mapping questionid -> slotnumber.
$questionslots = array();
foreach ($slots as $slot) {
$questionslots[$templateusage->get_question($slot)->id] = $slot;
}
foreach ($questions as $question) {
$currentquestionid = $question->id;
$questiontext = $question->questiontext;
$questiontext = offlinequiz_convert_html_to_latex($question->questiontext);
if ($question->qtype == 'description') {
$latexforquestions .= "\n" . '\\ ' . $questiontext . "\n";
} else {
$latexforquestions .= '\\item ' . $questiontext . "\n";
}
if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') {
$slot = $questionslots[$currentquestionid];
// There is only a slot for multichoice questions.
$slotquestion = $templateusage->get_question($slot);
$attempt = $templateusage->get_question_attempt($slot);
$order = $slotquestion->get_order($attempt);
// Order of the answers.
$latexforquestions .= '\\begin{enumerate}' . " \n";
foreach ($order as $key => $answer) {
$latexforquestions .= offlinequiz_get_answer_latex($question, $answer);
}
$latexforquestions .= '\\end{enumerate}' . "\n";
$infostr = offlinequiz_get_question_infostring($offlinequiz, $question);
if ($infostr) {
$latexforquestions .= $infostr . "\n";
}
}
}
//.........这里部分代码省略.........
示例5: offlinequiz_create_docx_question
//.........这里部分代码省略.........
$table->addRow();
$cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('idnumber', 'offlinequiz')) . ': ', 'brStyle');
$table->addRow();
$cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('studycode', 'offlinequiz')) . ': ', 'brStyle');
$table->addRow();
$cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('signature', 'offlinequiz')) . ': ', 'brStyle');
$section->addTextBreak(2);
// The DOCX intro text can be arbitrarily long so we have to catch page overflows.
if (!empty($offlinequiz->pdfintro)) {
$blocks = offlinequiz_convert_image_docx($offlinequiz->pdfintro);
offlinequiz_print_blocks_docx($section, $blocks);
}
$section->addPageBreak();
}
// Load all the questions needed for this offline quiz group.
$sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark \n FROM {offlinequiz_group_questions} ogq,\n {question} q,\n {question_categories} c\n WHERE ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid\n AND q.id = ogq.questionid\n AND q.category = c.id\n ORDER BY ogq.slot ASC ";
$params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
// Load the questions.
$questions = $DB->get_records_sql($sql, $params);
if (!$questions) {
echo $OUTPUT->box_start();
echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
echo $OUTPUT->box_end();
return;
}
// Load the question type specific information.
if (!get_question_options($questions)) {
print_error('Could not load question options');
}
// Restore the question sessions to their most recent states.
// Creating new sessions where required.
$number = 1;
// We need a mapping from question IDs to slots, assuming that each question occurs only once.
$slots = $templateusage->get_slots();
$texfilter = new filter_tex($context, array());
// Create the docx question numbering. This is only created once since we number all questions from 1...n.
$questionnumbering = new PHPWord_Numbering_AbstractNumbering("Question-level", array(new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_DECIMAL, "%1)", "left", $level1, $boldfont), new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_LOWER_LETTER, "%2)", "left", $level2, $normalfont)));
$docx->addNumbering($questionnumbering);
// If shufflequestions has been activated we go through the questions in the order determined by
// the template question usage.
if ($offlinequiz->shufflequestions) {
foreach ($slots as $slot) {
$slotquestion = $templateusage->get_question($slot);
$myquestion = $slotquestion->id;
set_time_limit(120);
$question = $questions[$myquestion];
// Either we print the question HTML.
$questiontext = $question->questiontext;
// Filter only for tex formulas.
if (!empty($texfilter)) {
$questiontext = $texfilter->filter($questiontext);
}
// Remove all HTML comments (typically from MS Office).
$questiontext = preg_replace("/<!--.*?--\\s*>/ms", "", $questiontext);
// Remove <font> tags.
$questiontext = preg_replace("/<font[^>]*>[^<]*<\\/font>/ms", "", $questiontext);
// Remove <script> tags that are created by mathjax preview.
$questiontext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $questiontext);
// Remove all class info from paragraphs because TCDOCX won't use CSS.
$questiontext = preg_replace('/<p[^>]+class="[^"]*"[^>]*>/i', "<p>", $questiontext);
$questiontext = $trans->fix_image_paths($questiontext, $question->contextid, 'questiontext', $question->id, 0.6, 300, 'docx');
$blocks = offlinequiz_convert_image_docx($questiontext);
offlinequiz_print_blocks_docx($section, $blocks, $questionnumbering, 0);
$answernumbering = new PHPWord_Numbering_AbstractNumbering("Adv Multi-level", array(new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_DECIMAL, "%1.", "left", $level1, $boldfont), new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_LOWER_LETTER, "%2)", "left", $level2, $normalfont)));
$docx->addNumbering($answernumbering);
if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') {