Merge branch 'MDL-33653' of git://github.com/timhunt/moodle
This commit is contained in:
@@ -230,6 +230,7 @@ $string['novirtualquestiontype'] = 'No virtual question type for question type {
|
||||
$string['numqas'] = 'No. question attempts';
|
||||
$string['numquestions'] = 'No. questions';
|
||||
$string['numquestionsandhidden'] = '{$a->numquestions} (+{$a->numhidden} hidden)';
|
||||
$string['openpreviewfromform'] = '{$a} Preview';
|
||||
$string['orphanedquestionscategory'] = 'Questions saved from deleted categories';
|
||||
$string['orphanedquestionscategoryinfo'] = 'Occasionally, typically due to old software bugs, questions can remain in the database even though the corresponding question category has been deleted. Of course, this should not happen, it has happened in the past on this site. This category has been created automatically, and the orphaned questions moved here so that you can manage them. Note that any images or media files used by these questions have probably been lost.';
|
||||
$string['page-question-x'] = 'Any question page';
|
||||
@@ -270,6 +271,7 @@ $string['questionuse'] = 'Use question in this activity';
|
||||
$string['questionvariant'] = 'Question variant';
|
||||
$string['reviewresponse'] = 'Review response';
|
||||
$string['save'] = 'Save';
|
||||
$string['savechangesandcontinueediting'] = 'Save changes and continue editing';
|
||||
$string['saveflags'] = 'Save the state of the flags';
|
||||
$string['selectacategory'] = 'Select a category:';
|
||||
$string['selectaqtypefordescription'] = 'Select a question type to see its description.';
|
||||
|
||||
+1
-1
@@ -660,7 +660,7 @@ function question_move_category_to_context($categoryid, $oldcontextid, $newconte
|
||||
* be picked randomly.
|
||||
* @param object $context context to run the preview in (affects things like
|
||||
* filter settings, theme, lang, etc.) Defaults to $PAGE->context.
|
||||
* @return string the URL.
|
||||
* @return moodle_url the URL.
|
||||
*/
|
||||
function question_preview_url($questionid, $preferredbehaviour = null,
|
||||
$maxmark = null, $displayoptions = null, $variant = null, $context = null) {
|
||||
|
||||
+19
-15
@@ -728,11 +728,8 @@ class question_bank_copy_action_column extends question_bank_action_column_base
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_bank_preview_action_column extends question_bank_action_column_base {
|
||||
protected $strpreview;
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
$this->strpreview = get_string('preview');
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
@@ -740,16 +737,10 @@ class question_bank_preview_action_column extends question_bank_action_column_ba
|
||||
}
|
||||
|
||||
protected function display_content($question, $rowclasses) {
|
||||
global $OUTPUT;
|
||||
global $PAGE;
|
||||
if (question_has_capability_on($question, 'use')) {
|
||||
// Build the icon.
|
||||
$image = $OUTPUT->pix_icon('t/preview', $this->strpreview, '', array('class' => 'iconsmall'));
|
||||
|
||||
$link = $this->qbank->preview_question_url($question);
|
||||
$action = new popup_action('click', $link, 'questionpreview',
|
||||
question_preview_popup_params());
|
||||
|
||||
echo $OUTPUT->action_link($link, $image, $action, array('title' => $this->strpreview));
|
||||
echo $PAGE->get_renderer('core_question')->question_preview_link(
|
||||
$question->id, $this->qbank->get_most_specific_context(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1264,9 +1255,22 @@ class question_bank_view {
|
||||
return $this->editquestionurl->out(true, array('id' => $questionid, 'makecopy' => 1));
|
||||
}
|
||||
|
||||
public function preview_question_url($question) {
|
||||
return question_preview_url($question->id, null, null, null, null,
|
||||
$this->contexts->lowest());
|
||||
/**
|
||||
* Get the context we are displaying the question bank for.
|
||||
* @return context context object.
|
||||
*/
|
||||
public function get_most_specific_context() {
|
||||
return $this->contexts->lowest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to preview a question.
|
||||
* @param stdClass $questiondata the data defining the question.
|
||||
* @return moodle_url the URL.
|
||||
*/
|
||||
public function preview_question_url($questiondata) {
|
||||
return question_preview_url($questiondata->id, null, null, null, null,
|
||||
$this->get_most_specific_context());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,34 @@ class core_question_renderer extends plugin_renderer_base {
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an icon, optionally with the word 'Preview' beside it, to preview
|
||||
* a given question.
|
||||
* @param int $questionid the id of the question to be previewed.
|
||||
* @param context $context the context in which the preview is happening.
|
||||
* Must be a course or category context.
|
||||
* @param bool $showlabel if true, show the word 'Preview' after the icon.
|
||||
* If false, just show the icon.
|
||||
*/
|
||||
public function question_preview_link($questionid, context $context, $showlabel) {
|
||||
if ($showlabel) {
|
||||
$alt = '';
|
||||
$label = ' ' . get_string('preview');
|
||||
$attributes = array();
|
||||
} else {
|
||||
$alt = get_string('preview');
|
||||
$label = '';
|
||||
$attributes = array('title' => $alt);
|
||||
}
|
||||
|
||||
$image = $this->pix_icon('t/preview', $alt, '', array('class' => 'iconsmall'));
|
||||
$link = question_preview_url($questionid, null, null, null, null, $context);
|
||||
$action = new popup_action('click', $link, 'questionpreview',
|
||||
question_preview_popup_params());
|
||||
|
||||
return $this->action_link($link, $image . $label, $action, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the display of a question in a particular state, and with certain
|
||||
* display options. Normally you do not call this method directly. Intsead
|
||||
|
||||
+10
-2
@@ -31,7 +31,7 @@ require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
// Read URL parameters telling us which question to edit.
|
||||
$id = optional_param('id', 0, PARAM_INT); // question id
|
||||
$makecopy = optional_param('makecopy', 0, PARAM_INT);
|
||||
$makecopy = optional_param('makecopy', 0, PARAM_BOOL);
|
||||
$qtype = optional_param('qtype', '', PARAM_FILE);
|
||||
$categoryid = optional_param('category', 0, PARAM_INT);
|
||||
$cmid = optional_param('cmid', 0, PARAM_INT);
|
||||
@@ -46,7 +46,7 @@ $url = new moodle_url('/question/question.php');
|
||||
if ($id !== 0) {
|
||||
$url->param('id', $id);
|
||||
}
|
||||
if ($makecopy !== 0) {
|
||||
if ($makecopy) {
|
||||
$url->param('makecopy', $makecopy);
|
||||
}
|
||||
if ($qtype !== '') {
|
||||
@@ -165,6 +165,7 @@ if ($id) {
|
||||
if ($makecopy) {
|
||||
// If we are duplicating a question, add some indication to the question name.
|
||||
$question->name = get_string('questionnamecopy', 'question', $question->name);
|
||||
$question->beingcopied = true;
|
||||
}
|
||||
|
||||
} else { // creating a new question
|
||||
@@ -263,6 +264,13 @@ if ($mform->is_cancelled()) {
|
||||
// Purge this question from the cache.
|
||||
question_bank::notify_question_edited($question->id);
|
||||
|
||||
// If we are saving and continuing to edit the question.
|
||||
if (!empty($fromform->updatebutton)) {
|
||||
$url->param('id', $question->id);
|
||||
$url->remove_params('makecopy');
|
||||
redirect($url);
|
||||
}
|
||||
|
||||
if ($qtypeobj->finished_edit_wizard($fromform)) {
|
||||
if ($inpopup) {
|
||||
echo $OUTPUT->notification(get_string('changessaved'), '');
|
||||
|
||||
@@ -51,6 +51,12 @@ class question_dataset_dependent_items_form extends question_wizard_form {
|
||||
*/
|
||||
public $qtypeobj;
|
||||
|
||||
/** @var stdClass the question category. */
|
||||
protected $category;
|
||||
|
||||
/** @var context the context of the question category. */
|
||||
protected $categorycontext;
|
||||
|
||||
public $datasetdefs;
|
||||
|
||||
public $maxnumber = -1;
|
||||
@@ -108,8 +114,10 @@ class question_dataset_dependent_items_form extends question_wizard_form {
|
||||
}
|
||||
|
||||
protected function definition() {
|
||||
global $PAGE;
|
||||
|
||||
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
$mform->setDisableShortforms();
|
||||
|
||||
$strquestionlabel = $this->qtypeobj->comment_header($this->question);
|
||||
@@ -325,11 +333,19 @@ class question_dataset_dependent_items_form extends question_wizard_form {
|
||||
|
||||
}
|
||||
$mform->addElement('static', 'outsidelimit', '', '');
|
||||
// ...----------------------------------------------------------------------
|
||||
// Non standard name for button element needed so not using add_action_buttons.
|
||||
if (!($this->noofitems==0) ) {
|
||||
$mform->addElement('submit', 'savechanges', get_string('savechanges'));
|
||||
$mform->closeHeaderBefore('savechanges');
|
||||
|
||||
// Submit buttons.
|
||||
if ($this->noofitems > 0) {
|
||||
$buttonarray = array();
|
||||
$buttonarray[] = $mform->createElement(
|
||||
'submit', 'savechanges', get_string('savechanges'));
|
||||
|
||||
$previewlink = $PAGE->get_renderer('core_question')->question_preview_link(
|
||||
$this->question->id, $this->categorycontext, true);
|
||||
$buttonarray[] = $mform->createElement('static', 'previewlink', '', $previewlink);
|
||||
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
}
|
||||
|
||||
$this->add_hidden_fields();
|
||||
|
||||
@@ -172,6 +172,10 @@ class qtype_calculated_edit_form extends qtype_numerical_edit_form {
|
||||
$mform->setType('wizard', PARAM_ALPHA);
|
||||
}
|
||||
|
||||
protected function can_preview() {
|
||||
return false; // Generally not possible for calculated questions on this page.
|
||||
}
|
||||
|
||||
public function data_preprocessing($question) {
|
||||
$question = parent::data_preprocessing($question);
|
||||
$question = $this->data_preprocessing_answers($question);
|
||||
|
||||
@@ -63,6 +63,10 @@ class qtype_calculatedmulti_edit_form extends question_edit_form {
|
||||
parent::__construct($submiturl, $question, $category, $contexts, $formeditable);
|
||||
}
|
||||
|
||||
protected function can_preview() {
|
||||
return false; // Generally not possible for calculated multi-choice questions on this page.
|
||||
}
|
||||
|
||||
public function get_per_answer_fields($mform, $label, $gradeoptions,
|
||||
&$repeatedoptions, &$answersoption) {
|
||||
$repeated = array();
|
||||
|
||||
@@ -566,6 +566,11 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form {
|
||||
}
|
||||
}
|
||||
|
||||
protected function can_preview() {
|
||||
return empty($this->question->beingcopied) && !empty($this->question->id) &&
|
||||
$this->question->formoptions->canedit && $this->noofitems > 0;
|
||||
}
|
||||
|
||||
public function data_preprocessing($question) {
|
||||
$question = parent::data_preprocessing($question);
|
||||
$question = $this->data_preprocessing_answers($question);
|
||||
|
||||
@@ -121,7 +121,7 @@ abstract class question_edit_form extends question_wizard_form {
|
||||
* override this method and remove the ones you don't want with $mform->removeElement().
|
||||
*/
|
||||
protected function definition() {
|
||||
global $COURSE, $CFG, $DB;
|
||||
global $COURSE, $CFG, $DB, $PAGE;
|
||||
|
||||
$qtype = $this->qtype();
|
||||
$langfile = "qtype_$qtype";
|
||||
@@ -236,21 +236,18 @@ abstract class question_edit_form extends question_wizard_form {
|
||||
$mform->setType('makecopy', PARAM_INT);
|
||||
|
||||
$buttonarray = array();
|
||||
if (!empty($this->question->id)) {
|
||||
// Editing question.
|
||||
if ($this->question->formoptions->canedit) {
|
||||
$buttonarray[] = $mform->createElement('submit', 'submitbutton',
|
||||
get_string('savechanges'));
|
||||
}
|
||||
$buttonarray[] = $mform->createElement('cancel');
|
||||
} else {
|
||||
// Adding new question.
|
||||
$buttonarray[] = $mform->createElement('submit', 'submitbutton',
|
||||
get_string('savechanges'));
|
||||
$buttonarray[] = $mform->createElement('cancel');
|
||||
$buttonarray[] = $mform->createElement('submit', 'updatebutton',
|
||||
get_string('savechangesandcontinueediting', 'question'));
|
||||
if ($this->can_preview()) {
|
||||
$previewlink = $PAGE->get_renderer('core_question')->question_preview_link(
|
||||
$this->question->id, $this->context, true);
|
||||
$buttonarray[] = $mform->createElement('static', 'previewlink', '', $previewlink);
|
||||
}
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
|
||||
$mform->addGroup($buttonarray, 'updatebuttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('updatebuttonar');
|
||||
|
||||
$this->add_action_buttons(true, get_string('savechanges'));
|
||||
|
||||
if ((!empty($this->question->id)) && (!($this->question->formoptions->canedit ||
|
||||
$this->question->formoptions->cansaveasnew))) {
|
||||
@@ -267,6 +264,15 @@ abstract class question_edit_form extends question_wizard_form {
|
||||
// By default, do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the question being edited in a state where it can be previewed?
|
||||
* @return bool whether to show the preview link.
|
||||
*/
|
||||
protected function can_preview() {
|
||||
return empty($this->question->beingcopied) && !empty($this->question->id) &&
|
||||
$this->question->formoptions->canedit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of form elements to repeat, one for each answer.
|
||||
* @param object $mform the form being built.
|
||||
|
||||
@@ -158,3 +158,8 @@ body.path-question-type .fitem_fgroup .accesshide {font: inherit;left: 0;positio
|
||||
.dir-rtl #qtypechoicecontainer #chooseqtype .instruction,
|
||||
.dir-rtl #qtypechoicecontainer #chooseqtype .qtypesummary {right: 60%;left: 0%; border-left:0;border-right: 1px solid grey;}
|
||||
#qtypechoicecontainer #chooseqtype .qtypeoption {padding-right: 0.3em;}
|
||||
|
||||
body.path-question-type .mform fieldset.hidden {
|
||||
padding: 0;
|
||||
margin: 0.7em 0 0;
|
||||
}
|
||||
|
||||
@@ -460,3 +460,8 @@ a#hidebankcmd {
|
||||
.que label {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
body.path-question-type .mform fieldset.hidden {
|
||||
padding: 0;
|
||||
margin: 0.7em 0 0;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user