Skip to content

Exercise: Implement Page Break question type and AJAX navigation - refs #2939 #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,12 @@ img.course-tool__icon {
}
}

.media-group { border:2px solid #337ab7; background:#f5fafd; padding:1rem; margin:2rem 0; border-radius:4px; }
.media-content { margin-bottom:1rem; }
.media-description { font-style:italic; margin-bottom:1rem; }
.media-children { margin-left:1rem; }
.media-group h4 { margin-top:0; color:#23527c; }

@import "~@fancyapps/fancybox/dist/jquery.fancybox.css";
@import "~timepicker/jquery.timepicker.min.css";
@import "~qtip2/dist/jquery.qtip.min.css";
Binary file added public/img/icons/22/media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/22/page_break.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/64/media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/64/page_break.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions public/main/exercise/MediaQuestion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/* For licensing terms, see /license.txt */

class MediaQuestion extends Question
{
/**
* Icon shown in the question-type menu.
*/
public $typePicture = 'media.png';
public $explanationLangVar = 'MediaQuestion';

public function __construct()
{
parent::__construct();
$this->type = MEDIA_QUESTION;
// Mark as content so it’s not counted towards score
$this->isContent = 1;
}

/**
* Form to create / edit a Media item.
*/
public function createForm(&$form, $exercise)
{
// Title for the media block
$form->addText(
'questionName',
get_lang('Media Title'),
false,
['maxlength' => 255]
);

// WYSIWYG for the media content (could be text, embed code, etc.)
$editorConfig = [
'ToolbarSet' => 'TestQuestionDescription',
'Height' => '150'
];
$form->addHtmlEditor(
'questionDescription',
get_lang('Media Content'),
false,
false,
$editorConfig
);

global $text;
$form->addButtonSave($text, 'submitQuestion');

// Populate defaults if editing
$defaults = [
'questionName' => $this->question,
'questionDescription' => $this->description
];
$form->setDefaults($defaults);
}

/**
* No answers to configure for media.
*/
public function createAnswersForm($form) {}

public function processAnswersCreation($form, $exercise) {}

/**
* On save, treat like any other question: persist and attach to the exercise.
*/
public function processCreation(FormValidator $form, Exercise $exercise)
{
$this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription'));
$this->save($exercise);
$exercise->addToList($this->id);
}
}
57 changes: 57 additions & 0 deletions public/main/exercise/PageBreakQuestion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/* For licensing terms, see /license.txt */

class PageBreakQuestion extends Question
{
public $typePicture = 'page_break.png';
public $explanationLangVar = 'PageBreak';

public function __construct()
{
parent::__construct();
$this->type = PAGE_BREAK;
$this->isContent = 1;
}

public function createForm(&$form, $exercise)
{
$form->addText(
'questionName',
get_lang('Page Title'),
false,
['maxlength' => 255]
);
$editorConfig = [
'ToolbarSet' => 'TestQuestionDescription',
'Height' => '100'
];
$form->addHtmlEditor(
'questionDescription',
get_lang('Page Introduction'),
false,
false,
$editorConfig
);

global $text;
$form->addButtonSave($text, 'submitQuestion');

$defaults = [
'questionName' => $this->question,
'questionDescription' => $this->description
];
$form->setDefaults($defaults);
}

public function createAnswersForm($form) {}

public function processAnswersCreation($form, $exercise) {}

public function processCreation(FormValidator $form, Exercise $exercise)
{
$this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription'));
$this->save($exercise);
$exercise->addToList($this->id);
}
}
20 changes: 20 additions & 0 deletions public/main/exercise/exercise.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,19 @@ public function save_stat_track_exercise_info(
$clock_expired_time = null;
}

$questionList = array_filter(
$questionList,
function (int $qid) {
$q = Question::read($qid);
return $q
&& !in_array(
$q->type,
[PAGE_BREAK, MEDIA_QUESTION],
true
);
}
);

$questionList = array_map('intval', $questionList);
$em = Database::getManager();

Expand Down Expand Up @@ -5885,6 +5898,13 @@ public function manage_answer(
// Store results directly in the database
// For all in one page exercises, the results will be
// stored by exercise_results.php (using the session)
if (in_array(
$objQuestionTmp->type,
[PAGE_BREAK, MEDIA_QUESTION],
true
)) {
$save_results = false;
}
if ($save_results) {
if ($debug) {
error_log("Save question results $save_results");
Expand Down
50 changes: 48 additions & 2 deletions public/main/exercise/exercise_show.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ function getFCK(vals, marksid) {
$marksid = '';

$countPendingQuestions = 0;
$panelsByParent = [];
foreach ($questionList as $questionId) {
$choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : '';
// destruction of the Question object
Expand All @@ -419,6 +420,11 @@ function getFCK(vals, marksid) {
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();

$objQ = Question::read($questionId, $objExercise->course);
if (!$objQ || $objQ->type === MEDIA_QUESTION) {
continue;
}

// Start buffer
ob_start();
if (MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE == $answerType) {
Expand Down Expand Up @@ -882,7 +888,10 @@ class="exercise_mark_select"
$counter++;
$questionContent .= $contents;
$questionContent .= '</div>';
$exercise_content .= Display::panel($questionContent);
//$exercise_content .= Display::panel($questionContent);
$panelHtml = Display::panel($questionContent);
$parentId = (int) $objQ->parent_id;
$panelsByParent[$parentId][] = $panelHtml;
} // end of large foreach on questions

// Display the text when finished message if we are on a LP #4227
Expand Down Expand Up @@ -966,7 +975,44 @@ class="exercise_mark_select"
}

echo $totalScoreText;
echo $exercise_content;
//echo $exercise_content;
foreach ($panelsByParent as $pid => $panels) {
if ($pid !== 0) {
$mediaQ = Question::read($pid, $objExercise->course);
echo '<div class="media-group">';
echo '<div class="media-content">';
ob_start();
$objExercise->manage_answer(
$id,
$pid,
null,
'exercise_show',
[],
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
);
echo ob_get_clean();
echo '</div>';

if (!empty($mediaQ->question)) {
echo '<div class="media-description">';
echo $mediaQ->description;
echo '</div>';
}

echo '<div class="media-children">';
}

foreach ($panels as $panelHtml) {
echo $panelHtml;
}

if ($pid !== 0) {
echo '</div></div>';
}
}

// only show "score" in bottom of page if there's exercise content
if ($show_results) {
Expand Down
Loading
Loading