protected function display_content($question, $rowclasses) { $contains = $this->qbank->offlinequiz_contains($question->id); if ($contains) { echo '<span class="greyed">'; } echo print_question_icon($question); if ($contains) { echo '</span>'; } }
/** * Creates a textual representation of a question for display. * * @param object $question A question object from the database questions table * @param bool $showicon If true, show the question's icon with the question. False by default. * @param bool $showquestiontext If true (default), show question text after question name. * If false, show only question name. * @param bool $return If true (default), return the output. If false, print it. */ function quiz_question_tostring($question, $showicon = false, $showquestiontext = true, $return = true) { global $COURSE; $result = ''; $result .= '<span class="questionname">'; if ($showicon) { $result .= print_question_icon($question, true); echo ' '; } $result .= shorten_text(format_string($question->name), 200) . '</span>'; if ($showquestiontext) { $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; $questiontext = strip_tags(format_text($question->questiontext, $question->questiontextformat, $formatoptions, $COURSE->id)); $questiontext = shorten_text($questiontext, 200); $result .= '<span class="questiontext">'; if (!empty($questiontext)) { $result .= $questiontext; } else { $result .= '<span class="error">'; $result .= get_string('questiontextisempty', 'quiz'); $result .= '</span>'; } $result .= '</span>'; } if ($return) { return $result; } else { echo $result; } }
function display($quiz, $cm, $course) { /// This function just displays the report global $CFG, $SESSION, $db, $QTYPES; $strnoquiz = get_string('noquiz', 'quiz'); $strnoattempts = get_string('noattempts', 'quiz'); /// Only print headers if not asked to download data $download = optional_param('download', NULL); if (!$download) { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode = "analysis"); } /// Construct the table for this particular report if (!$quiz->questions) { print_heading($strnoattempts); return true; } /// Check to see if groups are being used in this quiz if ($groupmode = groupmode($course, $cm)) { // Groups are being used if (!$download) { $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=analysis"); } else { $currentgroup = get_and_set_current_group($course, $groupmode); } } else { $currentgroup = get_and_set_current_group($course, $groupmode); } // set Table and Analysis stats options if (!isset($SESSION->quiz_analysis_table)) { $SESSION->quiz_analysis_table = array('attemptselection' => 0, 'lowmarklimit' => 0, 'pagesize' => 10); } foreach ($SESSION->quiz_analysis_table as $option => $value) { $urlparam = optional_param($option, NULL); if ($urlparam === NULL) { ${$option} = $value; } else { ${$option} = $SESSION->quiz_analysis_table[$option] = $urlparam; } } $scorelimit = $quiz->sumgrades * $lowmarklimit / 100; // ULPGC ecastro DEBUG this is here to allow for different SQL to select attempts switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $limit = ''; $group = ''; break; case QUIZ_HIGHESTATTEMPT: $limit = ', max(qa.sumgrades) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_FIRSTATTEMPT: $limit = ', min(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_LASTATTEMPT: $limit = ', max(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; } if ($attemptselection != QUIZ_ALLATTEMPTS) { $sql = 'SELECT qa.userid ' . $limit . 'FROM ' . $CFG->prefix . 'user u LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON u.id = qa.userid ' . 'WHERE qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 ' . $group; $usermax = get_records_sql_menu($sql); } $groupmembers = ''; $groupwhere = ''; //Add this to the SQL to show only group users if ($currentgroup) { $groupmembers = ', ' . groups_members_from_sql(); $groupwhere = ' AND ' . groups_members_where_sql($currentgroup, 'u.id'); } $sql = 'SELECT qa.* FROM ' . $CFG->prefix . 'quiz_attempts qa, ' . $CFG->prefix . 'user u ' . $groupmembers . 'WHERE u.id = qa.userid AND qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 AND ( qa.sumgrades >= ' . $scorelimit . ' ) ' . $groupwhere; // ^^^^^^ es posible seleccionar aqu TODOS los quizzes, como quiere Jussi, // pero habra que llevar la cuenta ed cada quiz para restaura las preguntas (quizquestions, states) /// Fetch the attempts $attempts = get_records_sql($sql); if (empty($attempts)) { print_heading(get_string('nothingtodisplay')); $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; } /// Here we rewiew all attempts and record data to construct the table $questions = array(); $statstable = array(); $questionarray = array(); foreach ($attempts as $attempt) { $questionarray[] = quiz_questions_in_quiz($attempt->layout); } $questionlist = quiz_questions_in_quiz(implode(",", $questionarray)); $questionarray = array_unique(explode(",", $questionlist)); $questionlist = implode(",", $questionarray); unset($questionarray); foreach ($attempts as $attempt) { switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $userscore = 0; // can be anything, not used break; case QUIZ_HIGHESTATTEMPT: $userscore = $attempt->sumgrades; break; case QUIZ_FIRSTATTEMPT: $userscore = $attempt->timemodified; break; case QUIZ_LASTATTEMPT: $userscore = $attempt->timemodified; break; } if ($attemptselection == QUIZ_ALLATTEMPTS || $userscore == $usermax[$attempt->userid]) { $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance" . " FROM {$CFG->prefix}question q," . " {$CFG->prefix}quiz_question_instances i" . " WHERE i.quiz = '{$quiz->id}' AND q.id = i.question" . " AND q.id IN ({$questionlist})"; if (!($quizquestions = get_records_sql($sql))) { error('No questions found'); } // Load the question type specific information if (!get_question_options($quizquestions)) { error('Could not load question options'); } // Restore the question sessions to their most recent states // creating new sessions where required if (!($states = get_question_states($quizquestions, $quiz, $attempt))) { error('Could not restore question sessions'); } $numbers = explode(',', $questionlist); $statsrow = array(); foreach ($numbers as $i) { if (!isset($quizquestions[$i]) or !isset($states[$i])) { continue; } $qtype = $quizquestions[$i]->qtype == 'random' ? $states[$i]->options->question->qtype : $quizquestions[$i]->qtype; $q = get_question_responses($quizquestions[$i], $states[$i]); if (empty($q)) { continue; } $qid = $q->id; if (!isset($questions[$qid])) { $questions[$qid]['id'] = $qid; $questions[$qid]['qname'] = $quizquestions[$i]->name; foreach ($q->responses as $answer => $r) { $r->count = 0; $questions[$qid]['responses'][$answer] = $r->answer; $questions[$qid]['rcounts'][$answer] = 0; $questions[$qid]['credits'][$answer] = $r->credit; $statsrow[$qid] = 0; } } $responses = get_question_actual_response($quizquestions[$i], $states[$i]); foreach ($responses as $resp) { if ($resp) { if ($key = array_search($resp, $questions[$qid]['responses'])) { $questions[$qid]['rcounts'][$key]++; } else { $test = new stdClass(); $test->responses = $QTYPES[$quizquestions[$i]->qtype]->get_correct_responses($quizquestions[$i], $states[$i]); if ($key = $QTYPES[$quizquestions[$i]->qtype]->check_response($quizquestions[$i], $states[$i], $test)) { $questions[$qid]['rcounts'][$key]++; } else { $questions[$qid]['responses'][] = $resp; $questions[$qid]['rcounts'][] = 1; $questions[$qid]['credits'][] = 0; } } } } $statsrow[$qid] = get_question_fraction_grade($quizquestions[$i], $states[$i]); } $attemptscores[$attempt->id] = $attempt->sumgrades; $statstable[$attempt->id] = $statsrow; } } // Statistics Data table built unset($attempts); unset($quizquestions); unset($states); // now calculate statistics and set the values in the $questions array $top = max($attemptscores); $bottom = min($attemptscores); $gap = ($top - $bottom) / 3; $top -= $gap; $bottom += $gap; foreach ($questions as $qid => $q) { $questions[$qid] = $this->report_question_stats($q, $attemptscores, $statstable, $top, $bottom); } unset($attemptscores); unset($statstable); /// Now check if asked download of data if ($download = optional_param('download', NULL)) { $filename = clean_filename("{$course->shortname} " . format_string($quiz->name, true)); switch ($download) { case "Excel": $this->Export_Excel($questions, $filename); break; case "ODS": $this->Export_ODS($questions, $filename); break; case "CSV": $this->Export_CSV($questions, $filename); break; } } /// Construct the table for this particular report $tablecolumns = array('id', 'qname', 'responses', 'credits', 'rcounts', 'rpercent', 'facility', 'qsd', 'disc_index', 'disc_coeff'); $tableheaders = array(get_string('qidtitle', 'quiz_analysis'), get_string('qtexttitle', 'quiz_analysis'), get_string('responsestitle', 'quiz_analysis'), get_string('rfractiontitle', 'quiz_analysis'), get_string('rcounttitle', 'quiz_analysis'), get_string('rpercenttitle', 'quiz_analysis'), get_string('facilitytitle', 'quiz_analysis'), get_string('stddevtitle', 'quiz_analysis'), get_string('dicsindextitle', 'quiz_analysis'), get_string('disccoefftitle', 'quiz_analysis')); $table = new flexible_table('mod-quiz-report-itemanalysis'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id . '&mode=analysis'); $table->sortable(true); $table->no_sorting('rpercent'); $table->collapsible(true); $table->initialbars(false); $table->column_class('id', 'numcol'); $table->column_class('credits', 'numcol'); $table->column_class('rcounts', 'numcol'); $table->column_class('rpercent', 'numcol'); $table->column_class('facility', 'numcol'); $table->column_class('qsd', 'numcol'); $table->column_class('disc_index', 'numcol'); $table->column_class('disc_coeff', 'numcol'); $table->column_suppress('id'); $table->column_suppress('qname'); $table->column_suppress('facility'); $table->column_suppress('qsd'); $table->column_suppress('disc_index'); $table->column_suppress('disc_coeff'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'itemanalysis'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); $tablesort = $table->get_sql_sort(); $sorts = explode(",", trim($tablesort)); if ($tablesort and is_array($sorts)) { $sortindex = array(); $sortorder = array(); foreach ($sorts as $sort) { $data = explode(" ", trim($sort)); $sortindex[] = trim($data[0]); $s = trim($data[1]); if ($s == "ASC") { $sortorder[] = SORT_ASC; } else { $sortorder[] = SORT_DESC; } } if (count($sortindex) > 0) { $sortindex[] = "id"; $sortorder[] = SORT_ASC; foreach ($questions as $qid => $row) { $index1[$qid] = $row[$sortindex[0]]; $index2[$qid] = $row[$sortindex[1]]; } array_multisort($index1, $sortorder[0], $index2, $sortorder[1], $questions); } } $format_options = new stdClass(); $format_options->para = false; $format_options->noclean = true; $format_options->newlines = false; // Now it is time to page the data, simply slice the keys in the array if (!isset($pagesize) || (int) $pagesize < 1) { $pagesize = 10; } $table->pagesize($pagesize, count($questions)); $start = $table->get_page_start(); $pagequestions = array_slice(array_keys($questions), $start, $pagesize); foreach ($pagequestions as $qnum) { $q = $questions[$qnum]; $qid = $q['id']; $question = get_record('question', 'id', $qid); if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $course->id))) { $qnumber = " (" . link_to_popup_window('/question/question.php?id=' . $qid, '&cmid=' . $cm->id . 'editquestion', $qid, 450, 550, get_string('edit'), 'none', true) . ") "; } else { $qnumber = $qid; } $qname = '<div class="qname">' . format_text($question->name . " : ", $question->questiontextformat, $format_options, $quiz->course) . '</div>'; $qicon = print_question_icon($question, true); $qreview = quiz_question_preview_button($quiz, $question); $qtext = format_text($question->questiontext, $question->questiontextformat, $format_options, $quiz->course); $qquestion = $qname . "\n" . $qtext . "\n"; $responses = array(); foreach ($q['responses'] as $aid => $resp) { $response = new stdClass(); if ($q['credits'][$aid] <= 0) { $qclass = 'uncorrect'; } elseif ($q['credits'][$aid] == 1) { $qclass = 'correct'; } else { $qclass = 'partialcorrect'; } $response->credit = '<span class="' . $qclass . '">(' . format_float($q['credits'][$aid], 2) . ') </span>'; $response->text = '<span class="' . $qclass . '">' . format_text($resp, FORMAT_MOODLE, $format_options, $quiz->course) . ' </span>'; $count = $q['rcounts'][$aid] . '/' . $q['count']; $response->rcount = $count; $response->rpercent = '(' . format_float($q['rcounts'][$aid] / $q['count'] * 100, 0) . '%)'; $responses[] = $response; } $facility = format_float($q['facility'] * 100, 0) . "%"; $qsd = format_float($q['qsd'], 3); $di = format_float($q['disc_index'], 2); $dc = format_float($q['disc_coeff'], 2); $response = array_shift($responses); $table->add_data(array($qnumber . "\n<br />" . $qicon . "\n " . $qreview, $qquestion, $response->text, $response->credit, $response->rcount, $response->rpercent, $facility, $qsd, $di, $dc)); foreach ($responses as $response) { $table->add_data(array('', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '')); } } print_heading_with_help(get_string("analysistitle", "quiz_analysis"), "itemanalysis", "quiz"); echo '<div id="tablecontainer">'; $table->print_html(); echo '</div>'; $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; }
/** * Prints the table of questions in a category with interactions * * @param object $course The course object * @param int $categoryid The id of the question category to be displayed * @param int $quizid The quiz id if we are in the context of a particular quiz, 0 otherwise * @param int $recurse This is 1 if subcategories should be included, 0 otherwise * @param int $page The number of the page to be displayed * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($course, $categoryid, $quizid = 0, $recurse = 1, $page = 0, $perpage = 100, $showhidden = false, $sortorder = 'qtype, name ASC', $showquestiontext = false) { global $USER, $CFG, $THEME; $qtypemenu = question_type_menu(); if ($rqp_types = get_records('question_rqp_types')) { foreach ($rqp_types as $type) { $qtypemenu['rqp_' . $type->id] = $type->name; } } $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $straddquestions = get_string("addquestions", "quiz"); $strimportquestions = get_string("importquestions", "quiz"); $strexportquestions = get_string("exportquestions", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); $strselectall = get_string("selectall", "quiz"); $strselectnone = get_string("selectnone", "quiz"); $strcreatenewquestion = get_string("createnewquestion", "quiz"); $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); $straction = get_string("action"); $strrestore = get_string('restore'); $straddtoquiz = get_string("addtoquiz", "quiz"); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview", "quiz"); if (!$categoryid) { echo "<p style=\"text-align:center;\"><b>"; print_string("selectcategoryabove", "quiz"); echo "</b></p>"; if ($quizid) { echo "<p>"; print_string("addingquestions", "quiz"); echo "</p>"; } return; } if (!($category = get_record('question_categories', 'id', $categoryid))) { notify('Category not found!'); return; } $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course)); $editingquiz = false; if ($quizid) { $cm = get_coursemodule_from_instance('quiz', $quizid); $editingquiz = has_capability('mod/quiz:manage', get_context_instance(CONTEXT_MODULE, $cm->id)); } echo '<div class="boxaligncenter">'; $formatoptions = new stdClass(); $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $course->id); echo '<table><tr>'; // check if editing questions in this category is allowed if ($canedit) { echo "<td valign=\"top\"><b>{$strcreatenewquestion}:</b></td>"; echo '<td valign="top" align="right">'; popup_form("{$CFG->wwwroot}/question/question.php?category={$category->id}&qtype=", $qtypemenu, "addquestion", "", "choose", "", "", false, "self"); echo '</td><td valign="top" align="right">'; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '</td>'; } else { echo '<td>'; print_string("publishedit", "quiz"); echo '</td>'; } echo '</tr></table>'; echo '</div>'; $categorylist = $recurse ? question_categorylist($category->id) : $category->id; // hide-feature $showhidden = $showhidden ? '' : " AND hidden = '0'"; if (!($totalnumber = count_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}"))) { echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorder, '*', $page * $perpage, $perpage))) { // There are no questions on the requested page. $page = 0; if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorder, '*', 0, $perpage))) { // There are no questions at all echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } } print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage={$perpage}&"); echo '<form method="post" action="edit.php?courseid=' . $course->id . '">'; echo '<fieldset class="invisiblefieldset" style="display: block;">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo '<table id="categoryquestions" style="width: 100%"><tr>'; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>"; $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"), 'qtype, name ASC' => get_string("sorttypealpha", "quiz"), 'id ASC' => get_string("sortage", "quiz")); $orderselect = choose_from_menu($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true); $orderselect .= '<noscript><div><input type="submit" value="' . get_string("sortsubmit", "quiz") . '" /></div></noscript>'; echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">{$strquestionname} {$orderselect}</th>\n <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">{$strtype}</th>"; echo "</tr>\n"; foreach ($questions as $question) { $nameclass = ''; $textclass = ''; if ($question->hidden) { $nameclass = 'dimmed_text'; $textclass = 'dimmed_text'; } if ($showquestiontext) { $nameclass .= ' header'; } if ($nameclass) { $nameclass = 'class="' . $nameclass . '"'; } if ($textclass) { $textclass = 'class="' . $textclass . '"'; } echo "<tr>\n<td style=\"white-space:nowrap;\" {$nameclass}>\n"; // add to quiz if ($editingquiz) { echo "<a title=\"{$straddtoquiz}\" href=\"edit.php?addquestion={$question->id}&quizid={$quizid}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/moveleft.gif\" alt=\"{$straddtoquiz}\" /></a> "; } // preview link_to_popup_window('/question/preview.php?id=' . $question->id . '&quizid=' . $quizid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS); // edit, hide, delete question, using question capabilities, not quiz capabilieies if ($canedit) { echo "<a title=\"{$stredit}\" href=\"{$CFG->wwwroot}/question/question.php?id={$question->id}\"><img\n src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a> "; // hide-feature if ($question->hidden) { echo "<a title=\"{$strrestore}\" href=\"edit.php?courseid={$course->id}&unhide={$question->id}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/restore.gif\" alt=\"{$strrestore}\" /></a>"; } else { echo "<a title=\"{$strdelete}\" href=\"edit.php?courseid={$course->id}&deleteselected={$question->id}&q{$question->id}=1\"><img\n src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>"; } } echo " <input title=\"{$strselect}\" type=\"checkbox\" name=\"q{$question->id}\" value=\"1\" />"; echo "</td>\n"; echo "<td {$nameclass}>" . format_string($question->name) . "</td>\n"; echo "<td {$nameclass} style='text-align: right'>\n"; print_question_icon($question); echo "</td>\n"; echo "</tr>\n"; if ($showquestiontext) { echo '<tr><td colspan="3" ' . $textclass . '>'; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; echo format_text($question->questiontext, $question->questiontextformat, $formatoptions, $course->id); echo "</td></tr>\n"; } } echo "</table>\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage={$perpage}&", 'page', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { $showall = '<a href="edit.php?courseid=' . $course->id . '&perpage=1000">' . get_string('showall', 'moodle', $totalnumber) . '</a>'; } else { $showall = '<a href="edit.php?courseid=' . $course->id . '&perpage=' . DEFAULT_QUESTIONS_PER_PAGE . '">' . get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE) . '</a>'; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '</div>')); $paging .= "<br />{$showall}</div>"; } else { $paging = "<div class='paging'>{$showall}</div>"; } } echo $paging; echo '<table class="quiz-edit-selected"><tr><td colspan="2">'; echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectall . '</a> /' . ' <a href="javascript:deselect_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectnone . '</a>' . '</td><td align="right"><b> ' . get_string('withselected', 'quiz') . ':</b></td></tr><tr><td>'; if ($editingquiz) { echo "<input type=\"submit\" name=\"add\" value=\"{$THEME->larrow} {$straddtoquiz}\" />\n"; echo '</td><td>'; } // print delete and move selected question if ($canedit) { echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" /></td><td>\n"; echo '<input type="submit" name="move" value="' . get_string('moveto', 'quiz') . "\" />\n"; question_category_select_menu($course->id, false, true, $category->id); } echo "</td></tr></table>"; // add random question if ($editingquiz) { for ($i = 1; $i <= min(10, $totalnumber); $i++) { $randomcount[$i] = $i; } for ($i = 20; $i <= min(100, $totalnumber); $i += 10) { $randomcount[$i] = $i; } echo '<br />'; print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true)); echo '<input type="hidden" name="recurse" value="' . $recurse . '" />'; echo "<input type=\"hidden\" name=\"categoryid\" value=\"{$category->id}\" />"; echo ' <input type="submit" name="addrandom" value="' . get_string('add') . '" />'; helpbutton('random', get_string('random', 'quiz'), 'quiz'); } echo '</fieldset>'; echo "</form>\n"; }
$table = new flexible_table('qtypeadmintable'); $table->define_baseurl($thispageurl); $table->define_columns(array('questiontype', 'numquestions', 'version', 'requires', 'availableto', 'delete', 'settings')); $table->define_headers(array(get_string('questiontype', 'question'), get_string('numquestions', 'question'), get_string('version'), get_string('requires', 'admin'), get_string('availableq', 'question'), get_string('delete'), get_string('settings'))); $table->set_attribute('id', 'qtypes'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); // Add a row for each question type. $createabletypes = question_bank::get_creatable_qtypes(); foreach ($sortedqtypes as $qtypename => $localname) { $qtype = $qtypes[$qtypename]; $row = array(); // Question icon and name. $fakequestion = new stdClass(); $fakequestion->qtype = $qtypename; $icon = print_question_icon($fakequestion, true); $row[] = $icon . ' ' . $localname; // Number of questions of this type. if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden > 0) { if ($counts[$qtypename]->numhidden > 0) { $strcount = get_string('numquestionsandhidden', 'question', $counts[$qtypename]); } else { $strcount = $counts[$qtypename]->numquestions; } if ($canviewreports) { $row[] = html_writer::link(new moodle_url('/report/questioninstances/index.php', array('qtype' => $qtypename)), $strcount, array('title' => get_string('showdetails', 'admin'))); } else { $strcount; } } else { $row[] = 0;
/** * Prints the table of questions in a category with interactions * * @param object $course The course object * @param int $categoryid The id of the question category to be displayed * @param int $cm The course module record if we are in the context of a particular module, 0 otherwise * @param int $recurse This is 1 if subcategories should be included, 0 otherwise * @param int $page The number of the page to be displayed * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($contexts, $pageurl, $categoryandcontext, $cm = null, $recurse = 1, $page = 0, $perpage = 100, $showhidden = false, $sortorder = 'typename', $sortorderdecoded = 'qtype, name ASC', $showquestiontext = false, $addcontexts = array()) { global $USER, $CFG, $THEME, $COURSE; $lastchangedid = optional_param('lastchanged', 0, PARAM_INT); list($categoryid, $contextid) = explode(',', $categoryandcontext); $qtypemenu = question_type_menu(); $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $straddquestions = get_string("addquestions", "quiz"); $strimportquestions = get_string("importquestions", "quiz"); $strexportquestions = get_string("exportquestions", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); $strselectall = get_string("selectall", "quiz"); $strselectnone = get_string("selectnone", "quiz"); $strcreatenewquestion = get_string("createnewquestion", "quiz"); $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); $strmove = get_string('moveqtoanothercontext', 'question'); $strview = get_string("view"); $straction = get_string("action"); $strrestore = get_string('restore'); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview", "quiz"); if (!$categoryid) { echo "<p style=\"text-align:center;\"><b>"; print_string("selectcategoryabove", "quiz"); echo "</b></p>"; return; } if (!($category = get_record('question_categories', 'id', $categoryid, 'contextid', $contextid))) { notify('Category not found!'); return; } $catcontext = get_context_instance_by_id($contextid); $canadd = has_capability('moodle/question:add', $catcontext); //check for capabilities on all questions in category, will also apply to sub cats. $caneditall = has_capability('moodle/question:editall', $catcontext); $canuseall = has_capability('moodle/question:useall', $catcontext); $canmoveall = has_capability('moodle/question:moveall', $catcontext); if ($cm and $cm->modname == 'quiz') { $quizid = $cm->instance; } else { $quizid = 0; } $returnurl = $pageurl->out(); $questionurl = new moodle_url("{$CFG->wwwroot}/question/question.php", array('returnurl' => $returnurl)); if ($cm !== null) { $questionurl->param('cmid', $cm->id); } else { $questionurl->param('courseid', $COURSE->id); } $questionmoveurl = new moodle_url("{$CFG->wwwroot}/question/contextmoveq.php", array('returnurl' => $returnurl)); if ($cm !== null) { $questionmoveurl->param('cmid', $cm->id); } else { $questionmoveurl->param('courseid', $COURSE->id); } echo '<div class="boxaligncenter">'; $formatoptions = new stdClass(); $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $COURSE->id); echo '<table><tr>'; if ($canadd) { echo '<td valign="top" align="right">'; popup_form($questionurl->out(false, array('category' => $category->id)) . '&qtype=', $qtypemenu, "addquestion", "", "choose", "", "", false, "self", "<strong>{$strcreatenewquestion}</strong>"); echo '</td><td valign="top" align="right">'; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '</td>'; } else { echo '<td>'; print_string('nopermissionadd', 'question'); echo '</td>'; } echo '</tr></table>'; echo '</div>'; $categorylist = $recurse ? question_categorylist($category->id) : $category->id; // hide-feature $showhidden = $showhidden ? '' : " AND hidden = '0'"; if (!($totalnumber = count_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}"))) { echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorderdecoded, '*', $page * $perpage, $perpage))) { // There are no questions on the requested page. $page = 0; if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorderdecoded, '*', 0, $perpage))) { // There are no questions at all echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } } print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage'); echo question_sort_options($pageurl, $sortorder); echo '<form method="post" action="edit.php">'; echo '<fieldset class="invisiblefieldset" style="display: block;">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo $pageurl->hidden_params_out(); echo '<table id="categoryquestions" style="width: 100%"><tr>'; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>"; echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">{$strquestionname}</th>\n <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">{$strtype}</th>"; echo "</tr>\n"; foreach ($questions as $question) { $nameclass = ''; $textclass = ''; if ($question->hidden) { $nameclass = 'dimmed_text'; $textclass = 'dimmed_text'; } if ($showquestiontext) { $nameclass .= ' header'; } if ($question->id == $lastchangedid) { $nameclass = 'highlight'; } if ($nameclass) { $nameclass = 'class="' . $nameclass . '"'; } if ($textclass) { $textclass = 'class="' . $textclass . '"'; } echo "<tr>\n<td style=\"white-space:nowrap;\" {$nameclass}>\n"; $canuseq = question_has_capability_on($question, 'use', $question->category); if (function_exists('module_specific_actions')) { echo module_specific_actions($pageurl, $question->id, $cm->id, $canuseq); } // preview if ($canuseq) { $quizorcourseid = $quizid ? '&quizid=' . $quizid : '&courseid=' . $COURSE->id; link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS); } // edit, hide, delete question, using question capabilities, not quiz capabilieies if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) { echo "<a title=\"{$stredit}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a> "; } elseif (question_has_capability_on($question, 'view', $question->category)) { echo "<a title=\"{$strview}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/i/info.gif\" alt=\"{$strview}\" /></a> "; } if (question_has_capability_on($question, 'move', $question->category) && question_has_capability_on($question, 'view', $question->category)) { echo "<a title=\"{$strmove}\" href=\"" . $questionurl->out(false, array('id' => $question->id, 'movecontext' => 1)) . "\"><img\n src=\"{$CFG->pixpath}/t/move.gif\" alt=\"{$strmove}\" /></a> "; } if (question_has_capability_on($question, 'edit', $question->category)) { // hide-feature if ($question->hidden) { echo "<a title=\"{$strrestore}\" href=\"edit.php?" . $pageurl->get_query_string() . "&unhide={$question->id}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/restore.gif\" alt=\"{$strrestore}\" /></a>"; } else { echo "<a title=\"{$strdelete}\" href=\"edit.php?" . $pageurl->get_query_string() . "&deleteselected={$question->id}&q{$question->id}=1\"><img\n src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>"; } } if ($caneditall || $canmoveall || $canuseall) { echo " <input title=\"{$strselect}\" type=\"checkbox\" name=\"q{$question->id}\" value=\"1\" />"; } echo "</td>\n"; echo "<td {$nameclass}>" . format_string($question->name) . "</td>\n"; echo "<td {$nameclass} style='text-align: right'>\n"; print_question_icon($question); echo "</td>\n"; echo "</tr>\n"; if ($showquestiontext) { echo '<tr><td colspan="3" ' . $textclass . '>'; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; echo format_text($question->questiontext, $question->questiontextformat, $formatoptions, $COURSE->id); echo "</td></tr>\n"; } } echo "</table>\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { $showall = '<a href="edit.php?' . $pageurl->get_query_string(array('qperpage' => 1000)) . '">' . get_string('showall', 'moodle', $totalnumber) . '</a>'; } else { $showall = '<a href="edit.php?' . $pageurl->get_query_string(array('qperpage' => DEFAULT_QUESTIONS_PER_PAGE)) . '">' . get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE) . '</a>'; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '</div>')); $paging .= "<br />{$showall}</div>"; } else { $paging = "<div class='paging'>{$showall}</div>"; } } echo $paging; if ($caneditall || $canmoveall || $canuseall) { echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectall . '</a> /' . ' <a href="javascript:deselect_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectnone . '</a>'; echo '<br />'; echo '<strong> ' . get_string('withselected', 'quiz') . ':</strong><br />'; if (function_exists('module_specific_buttons')) { echo module_specific_buttons($cm->id); } // print delete and move selected question if ($caneditall) { echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" />\n"; } if ($canmoveall && count($addcontexts)) { echo '<input type="submit" name="move" value="' . get_string('moveto', 'quiz') . "\" />\n"; question_category_select_menu($addcontexts, false, 0, "{$category->id},{$category->contextid}"); } if (function_exists('module_specific_controls') && $canuseall) { echo module_specific_controls($totalnumber, $recurse, $category, $cm->id); } } echo '</fieldset>'; echo "</form>\n"; }
function col_icon($question){ return print_question_icon($question, true); }
/** * The question type icon. * @param object $question containst the data to display. * @return string contents of this table cell. */ protected function col_icon($question) { if (property_exists($question, 'qtype') && $question->qtype) { return print_question_icon($question, true); } else { return ''; } }
/** * The question type icon. * @param \core_question\statistics\questions\calculated $questionstat stats for the question. * @return string contents of this table cell. */ protected function col_icon($questionstat) { return print_question_icon($questionstat->question, true); }
/** * Prints a list of quiz questions in a small layout form with knobs * * @return int sum of maximum grades * @param object $quiz This is not the standard quiz object used elsewhere but * it contains the quiz layout in $quiz->questions and the grades in * $quiz->grades * @param boolean $allowdelete Indicates whether the delete icons should be displayed * @param boolean $showbreaks Indicates whether the page breaks should be displayed * @param boolean $showbreaks Indicates whether the reorder tool should be displayed */ function quiz_print_question_list($quiz, $pageurl, $allowdelete = true, $showbreaks = true, $reordertool = false) { global $USER, $CFG, $QTYPES; $strorder = get_string("order"); $strquestionname = get_string("questionname", "quiz"); $strgrade = get_string("grade"); $strremove = get_string('remove', 'quiz'); $stredit = get_string("edit"); $strview = get_string("view"); $straction = get_string("action"); $strmoveup = get_string("moveup"); $strmovedown = get_string("movedown"); $strsavegrades = get_string("savegrades", "quiz"); $strtype = get_string("type", "quiz"); $strpreview = get_string("preview", "quiz"); if (!$quiz->questions) { echo "<p class=\"quizquestionlistcontrols\">"; print_string("noquestions", "quiz"); echo "</p>"; return 0; } if (!($questions = get_records_sql("SELECT q.*,c.contextid\n FROM {$CFG->prefix}question q,\n {$CFG->prefix}question_categories c\n WHERE q.id in ({$quiz->questions})\n AND q.category = c.id"))) { echo "<p class=\"quizquestionlistcontrols\">"; print_string("noquestions", "quiz"); echo "</p>"; return 0; } $count = 0; $qno = 1; $sumgrade = 0; $order = explode(',', $quiz->questions); $lastindex = count($order) - 1; // If the list does not end with a pagebreak then add it on. if ($order[$lastindex] != 0) { $order[] = 0; $lastindex++; } echo "<form method=\"post\" action=\"edit.php\">"; echo '<fieldset class="invisiblefieldset" style="display: block;">'; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; echo $pageurl->hidden_params_out(); echo "<table style=\"width:100%;\">\n"; echo "<tr><th colspan=\"3\" style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$strorder}</th>"; echo "<th class=\"header\" scope=\"col\">#</th>"; echo "<th align=\"left\" style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$strquestionname}</th>"; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$strtype}</th>"; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$strgrade}</th>"; echo "<th align=\"center\" style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>"; echo "</tr>\n"; foreach ($order as $i => $qnum) { if ($qnum and empty($questions[$qnum])) { continue; } // If the questiontype is missing change the question type if ($qnum and !array_key_exists($questions[$qnum]->qtype, $QTYPES)) { $questions[$qnum]->qtype = 'missingtype'; } // Show the re-ordering field if the tool is turned on. // But don't show it in front of pagebreaks if they are hidden. if ($reordertool) { if ($qnum or $showbreaks) { echo '<tr><td><input type="text" name="o' . $i . '" size="2" value="' . (10 * $count + 10) . '" /></td>'; } else { echo '<tr><td><input type="hidden" name="o' . $i . '" size="2" value="' . (10 * $count + 10) . '" /></td>'; } } else { echo '<tr><td></td>'; } if ($qnum == 0) { // This is a page break if ($showbreaks) { echo '<td colspan ="3"> </td>'; echo '<td><table style="width:100%; line-height:11px; font-size:9px; margin: -5px -5px;"><tr>'; echo '<td><hr /></td>'; echo '<td style="width:50px;">Page break</td>'; echo '<td><hr /></td>'; echo '<td style="width:45px;">'; if ($count > 1) { echo "<a title=\"{$strmoveup}\" href=\"" . $pageurl->out_action(array('up' => $count)) . "\"><img\n src=\"{$CFG->pixpath}/t/up.gif\" class=\"iconsmall\" alt=\"{$strmoveup}\" /></a>"; } echo ' '; if ($count < $lastindex) { echo "<a title=\"{$strmovedown}\" href=\"" . $pageurl->out_action(array('down' => $count)) . "\"><img\n src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strmovedown}\" /></a>"; echo "<a title=\"{$strremove}\" href=\"" . $pageurl->out_action(array('delete' => $count)) . "\">\n <img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strremove}\" /></a>"; } echo '</td></tr></table></td>'; echo '<td colspan="2"> </td>'; } $count++; // missing </tr> here, if loop is broken, need to close the </tr> echo "</tr>"; continue; } $question = $questions[$qnum]; echo "<td>"; if ($count != 0) { echo "<a title=\"{$strmoveup}\" href=\"" . $pageurl->out_action(array('up' => $count)) . "\"><img\n src=\"{$CFG->pixpath}/t/up.gif\" class=\"iconsmall\" alt=\"{$strmoveup}\" /></a>"; } echo "</td>"; echo "<td>"; if ($count < $lastindex - 1) { echo "<a title=\"{$strmovedown}\" href=\"" . $pageurl->out_action(array('down' => $count)) . "\"><img\n src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strmovedown}\" /></a>"; } echo "</td>"; if (!$quiz->shufflequestions) { // Print and increment question number echo '<td>' . ($question->length ? $qno : ' ') . '</td>'; $qno += $question->length; } else { echo '<td> </td>'; } echo '<td>' . format_string($question->name) . '</td>'; echo "<td align=\"center\">"; print_question_icon($question); echo "</td>"; echo '<td align="left">'; if ($question->qtype == 'description') { echo "<input type=\"hidden\" name=\"q{$qnum}\" value=\"0\" /> \n"; } else { echo '<input type="text" name="q' . $qnum . '" size="2" value="' . $quiz->grades[$qnum] . '" tabindex="' . ($lastindex + $qno) . '" />'; } echo '</td><td align="center">'; if ($question->qtype != 'random') { echo quiz_question_preview_button($quiz, $question); } $returnurl = $pageurl->out(); $questionparams = array('returnurl' => $returnurl, 'cmid' => $quiz->cmid, 'id' => $question->id); $questionurl = new moodle_url("{$CFG->wwwroot}/question/question.php", $questionparams); if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) { echo "<a title=\"{$stredit}\" href=\"" . $questionurl->out() . "\">\n <img src=\"{$CFG->pixpath}/t/edit.gif\" class=\"iconsmall\" alt=\"{$stredit}\" /></a>"; } elseif (question_has_capability_on($question, 'view', $question->category)) { echo "<a title=\"{$strview}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/i/info.gif\" alt=\"{$strview}\" /></a> "; } if ($allowdelete && question_has_capability_on($question, 'use', $question->category)) { // remove from quiz, not question delete. echo "<a title=\"{$strremove}\" href=\"" . $pageurl->out_action(array('delete' => $count)) . "\">\n <img src=\"{$CFG->pixpath}/t/removeright.gif\" class=\"iconsmall\" alt=\"{$strremove}\" /></a>"; } echo "</td></tr>"; $count++; $sumgrade += $quiz->grades[$qnum]; } echo "<tr><td colspan=\"6\" align=\"right\">\n"; print_string('total'); echo ": </td>"; echo "<td align=\"left\">\n"; echo "<strong>{$sumgrade}</strong>"; echo "</td><td> \n</td></tr>\n"; echo "<tr><td colspan=\"6\" align=\"right\">\n"; print_string('maximumgrade'); echo ": </td>"; echo "<td align=\"left\">\n"; echo '<input type="text" name="maxgrade" size="2" tabindex="' . ($qno + 1) . '" value="' . $quiz->grade . '" />'; echo '</td><td align="left">'; helpbutton("maxgrade", get_string("maximumgrade"), "quiz"); echo "</td></tr></table>\n"; echo '<div class="quizquestionlistcontrols"><input type="submit" value="' . get_string('savechanges') . '" />'; echo '<input type="hidden" name="savechanges" value="save" /></div>'; echo '</fieldset>'; echo "</form>\n"; /// Form to choose to show pagebreaks and to repaginate quiz echo '<form method="post" action="edit.php" id="showbreaks">'; echo '<fieldset class="invisiblefieldset">'; echo $pageurl->hidden_params_out(array('showbreaks', 'reordertool')); echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo '<input type="hidden" name="showbreaks" value="0" />'; echo '<input type="checkbox" name="showbreaks" value="1"'; if ($showbreaks) { echo ' checked="checked"'; } echo ' onchange="getElementById(\'showbreaks\').submit(); return true;" />'; print_string('showbreaks', 'quiz'); if ($showbreaks) { $perpage = array(); for ($i = 0; $i <= 50; ++$i) { $perpage[$i] = $i; } $perpage[0] = get_string('allinone', 'quiz'); echo '<br /> '; print_string('repaginate', 'quiz', choose_from_menu($perpage, 'questionsperpage', $quiz->questionsperpage, '', '', '', true)); } echo '<br /><input type="hidden" name="reordertool" value="0" />'; echo '<input type="checkbox" name="reordertool" value="1"'; if ($reordertool) { echo ' checked="checked"'; } echo ' onchange="getElementById(\'showbreaks\').submit(); return true;" />'; print_string('reordertool', 'quiz'); echo ' '; helpbutton('reorderingtool', get_string('reordertool', 'quiz'), 'quiz'); echo '<div class="quizquestionlistcontrols"><input type="submit" name="repaginate" value="' . get_string('go') . '" /></div>'; echo '</fieldset>'; echo '</form>'; return $sumgrade; }
protected function display_content($question, $rowclasses) { echo print_question_icon($question); }
/** * sets up what is displayed for each question on the edit quiz question listing * * @param \mod_activequiz\activequiz_question $question * @param int $qnum The question number we're currently on * @param int $qcount The total number of questions * * @return string */ protected function display_question_block($question, $qnum, $qcount) { $return = ''; $dragicon = new pix_icon('i/dragdrop', 'dragdrop'); $return .= html_writer::div($this->output->render($dragicon), 'dragquestion'); $return .= html_writer::div(print_question_icon($question->getQuestion()), 'icon'); $namehtml = html_writer::start_tag('p'); $namehtml .= $question->getQuestion()->name . '<br />'; $namehtml .= get_string('points', 'activequiz') . ': ' . $question->getPoints(); $namehtml .= html_writer::end_tag('p'); $return .= html_writer::div($namehtml, 'name'); $controlHTML = ''; $spacericon = new pix_icon('spacer', 'space', null, array('class' => 'smallicon space')); $controlHTML .= html_writer::start_tag('noscript'); if ($qnum > 1) { // if we're on a later question than the first one add the move up control $moveupurl = clone $this->pageurl; $moveupurl->param('action', 'moveup'); $moveupurl->param('questionid', $question->getId()); // add the rtqqid so that the question manager handles the translation $alt = get_string('questionmoveup', 'mod_activequiz', $qnum); $upicon = new pix_icon('t/up', $alt); $controlHTML .= html_writer::link($moveupurl, $this->output->render($upicon)); } else { $controlHTML .= $this->output->render($spacericon); } if ($qnum < $qcount) { // if we're not on the last question add the move down control $movedownurl = clone $this->pageurl; $movedownurl->param('action', 'movedown'); $movedownurl->param('questionid', $question->getId()); $alt = get_string('questionmovedown', 'mod_activequiz', $qnum); $downicon = new pix_icon('t/down', $alt); $controlHTML .= html_writer::link($movedownurl, $this->output->render($downicon)); } else { $controlHTML .= $this->output->render($spacericon); } $controlHTML .= html_writer::end_tag('noscript'); // always add edit and delete icons $editurl = clone $this->pageurl; $editurl->param('action', 'editquestion'); $editurl->param('rtqquestionid', $question->getId()); $alt = get_string('questionedit', 'activequiz', $qnum); $deleteicon = new pix_icon('t/edit', $alt); $controlHTML .= html_writer::link($editurl, $this->output->render($deleteicon)); $deleteurl = clone $this->pageurl; $deleteurl->param('action', 'deletequestion'); $deleteurl->param('questionid', $question->getId()); $alt = get_string('questiondelete', 'mod_activequiz', $qnum); $deleteicon = new pix_icon('t/delete', $alt); $controlHTML .= html_writer::link($deleteurl, $this->output->render($deleteicon)); $return .= html_writer::div($controlHTML, 'controls'); return $return; }
/** * Creates a textual representation of a question for display. * * @param object $question A question object from the database questions table * @param bool $showicon If true, show the question's icon with the question. False by default. * @param bool $showquestiontext If true (default), show question text after question name. * If false, show only question name. * @return string */ function quiz_question_tostring($question, $showicon = false, $showquestiontext = true) { $result = ''; $name = shorten_text(format_string($question->name), 200); if ($showicon) { $name .= print_question_icon($question) . ' ' . $name; } $result .= html_writer::span($name, 'questionname'); if ($showquestiontext) { $questiontext = question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false)); $questiontext = shorten_text($questiontext, 200); if ($questiontext) { $result .= ' ' . html_writer::span(s($questiontext), 'questiontext'); } } return $result; }
/** * Creates a textual representation of a question for display. * * @param object $question A question object from the database questions table * @param bool $showicon If true, show the question's icon with the question. False by default. * @param bool $showquestiontext If true (default), show question text after question name. * If false, show only question name. * @param bool $return If true (default), return the output. If false, print it. */ function quiz_question_tostring($question, $showicon = false, $showquestiontext = true, $return = true) { global $COURSE; $result = ''; $result .= '<span class="questionname">'; if ($showicon) { $result .= print_question_icon($question, true); echo ' '; } $result .= shorten_text(format_string($question->name), 200) . '</span>'; if ($showquestiontext) { $questiontext = question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false)); $questiontext = shorten_text($questiontext, 200); $result .= '<span class="questiontext">'; if (!empty($questiontext)) { $result .= s($questiontext); } else { $result .= '<span class="error">'; $result .= get_string('questiontextisempty', 'quiz'); $result .= '</span>'; } $result .= '</span>'; } if ($return) { return $result; } else { echo $result; } }
/** * Creates a textual representation of a question for display. * * @param object $question A question object from the database questions table * @param bool $showicon If true, show the question's icon with the question. False by default. * @param bool $showquestiontext If true (default), show question text after question name. * If false, show only question name. * @param bool $return If true (default), return the output. If false, print it. */ function offlinequiz_question_tostring($question, $showicon = false, $showquestiontext = true, $return = true, $shorttitle = false) { global $COURSE; $result = ''; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; $questiontext = strip_tags(question_utils::to_plain_text($question->questiontext, $question->questiontextformat, array('noclean' => true, 'para' => false))); $questiontitle = strip_tags(format_text($question->name, $question->questiontextformat, $formatoptions, $COURSE->id)); $result .= '<span class="questionname" title="' . $questiontitle . '">'; if ($shorttitle && strlen($questiontitle) > 25) { $questiontitle = shorten_text($questiontitle, 25, false, '...'); } if ($showicon) { $result .= print_question_icon($question, true); echo ' '; } if ($shorttitle) { $result .= $questiontitle; } else { $result .= shorten_text(format_string($question->name), 200) . '</span>'; } if ($showquestiontext) { $result .= '<span class="questiontext" title="' . $questiontext . '">'; $questiontext = shorten_text($questiontext, 200); if (!empty($questiontext)) { $result .= $questiontext; } else { $result .= '<span class="error">'; $result .= get_string('questiontextisempty', 'offlinequiz'); $result .= '</span>'; } $result .= '</span>'; } if ($return) { return $result; } else { echo $result; } }