Skip to content

Commit

Permalink
Improved MathJax integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Jul 8, 2021
1 parent aae85e3 commit 1969f72
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 20 deletions.
27 changes: 25 additions & 2 deletions classes/MoodleMatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ private function record_to_player_answer($record) {
'question_data' => is_array($record['data']) ? $record['data'] : unserialize($record['data']),
'question_id' => $record['question_id'],
'created' => $record['timecreated'],

];
}

Expand Down Expand Up @@ -1062,20 +1061,40 @@ public function get_question_summary_formated($question, $coursestudents) {
return $data;
}

public function ivs_prepare_latex_for_rendering($text,$only_inline = FALSE){
if($only_inline){
$text = str_replace('$$','$',$text);
$text = str_replace('$','$$',$text);
$text = str_replace('\[','$$',$text);
$text = str_replace('\]','$$',$text);
$text = str_replace('\(', '$$', $text);
$text = str_replace('\)', '$$', $text);
}
else {
$text = str_replace('\[', '$$', $text);
$text = str_replace('\]', '$$', $text);
$text = str_replace('\(', '$', $text);
$text = str_replace('\)', '$', $text);
}
$text = format_text($text,FORMAT_MARKDOWN);
return $text;
}

public function get_question_answers_data($detailarray, $questions, $cmid, $videoid, $courseusers, $totalcount, $output) {
$data = new \stdClass;

$controller = $this;

$data->id = $detailarray[0]['question']['nid'];
$data->label = $controller->get_match_question_title($detailarray[0]['question']);
$data->label = $this->ivs_prepare_latex_for_rendering($data->label,TRUE);
$data->question = $detailarray[0]['question']['question_body'];
if (strlen($detailarray[0]['question']['title']) > 0) {
$data->question = $detailarray[0]['question']['title'] . ': ' . $data->question;
} else {
$data->question = $data->question;
}

$data->question = $this->ivs_prepare_latex_for_rendering($data->question,TRUE);
$data->answers = [];

// Pager.
Expand Down Expand Up @@ -1145,6 +1164,8 @@ public function get_question_answers_data($detailarray, $questions, $cmid, $vide
$questionurl = new moodle_url('/mod/ivs/question_answers.php?id=' . $cmid . '&vid=' . $videoid . '&qid=' .
$question['nid'] . '&perpage=10');
$selected = required_param('qid', PARAM_INT) == $question['nid'] ? 'selected' : '';
# $label = $this->ivs_prepare_latex_for_rendering($label);
# $label = format_text("$$ f(x)$$",FORMAT_MARKDOWN);
$data->dropdown_options[] = '<option value="' . $questionurl . '" ' . $selected . '>' . $label . '</option>';
}

Expand Down Expand Up @@ -1267,6 +1288,8 @@ public function get_question_answers_data_text_question($answer, $courseuser) {
}
}

$data->first = $this->ivs_prepare_latex_for_rendering($data->first);
$data->last = $this->ivs_prepare_latex_for_rendering($data->last);
return $data;
}

Expand Down
4 changes: 4 additions & 0 deletions classes/annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ function get_body() {
*/
public
function get_rendered_body() {
$this->body = str_replace('\[','$$',$this->body);
$this->body = str_replace('\]','$$',$this->body);
$this->body = str_replace('\(','$',$this->body);
$this->body = str_replace('\)','$',$this->body);
return format_text($this->body, FORMAT_MARKDOWN);
}

Expand Down
2 changes: 2 additions & 0 deletions classes/output/match/question_answers_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function export_for_template(renderer_base $output) {
'question_answers_download.php', 'download',
array('question_id' => $qid, 'cmid' => $this->cmid, 'instance_id' => $instance,
'total_count' => $this->totalcount));


return $data;
}
}
18 changes: 16 additions & 2 deletions classes/output/match/question_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,25 @@ public function __construct($question, $module) {

public function export_for_template(renderer_base $output) {
$data = new stdClass();

$data->id = $this->question['nid'];
$this->question['question_body'] = str_replace('\[','$$',$this->question['question_body']);
$this->question['question_body'] = str_replace('\]','$$',$this->question['question_body']);
$this->question['question_body'] = str_replace('\(','$',$this->question['question_body']);
$this->question['question_body'] = str_replace('\)','$',$this->question['question_body']);
$this->question['title'] = str_replace('\[','$$',$this->question['title']);
$this->question['title'] = str_replace('\]','$$',$this->question['title']);
$this->question['title'] = str_replace('\(','$',$this->question['title']);
$this->question['title'] = str_replace('\)','$',$this->question['title']);
// We need this, because he dont apply mathjax when no $$ exists.
if(!strpos($this->question['question_body'],'$$')){
$this->question['question_body'] .= ' $$ $$';
}
if(!strpos($this->question['title'],'$$')){
$this->question['title'] .= ' $$ $$';
}
$data->question = format_text($this->question['question_body'], FORMAT_MARKDOWN);
if (strlen($this->question['title']) > 0) {
$data->question = format_text($this->question['title'] . ': ' . $this->question['question_body'], FORMAT_MARKDOWN);
$data->question = '<div style="display:flex; align-items: baseline;">'.format_text($this->question['title'], FORMAT_MARKDOWN) . ': &nbsp;&nbsp;' . format_text($this->question['question_body'], FORMAT_MARKDOWN) . '</div>';
}

$data->link = new \moodle_url('/mod/ivs/question_answers.php',
Expand Down
17 changes: 17 additions & 0 deletions classes/output/match/question_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ public function export_for_template(renderer_base $output) {
break;
}
$renderable = new question_summary_view($this->questions[$i], $this->course_students);
$renderable->question['question_body'] = str_replace('\[','$$',$renderable->question['question_body']);
$renderable->question['question_body'] = str_replace('\]','$$',$renderable->question['question_body']);
$renderable->question['question_body'] = str_replace('\(','$',$renderable->question['question_body']);
$renderable->question['question_body'] = str_replace('\)','$',$renderable->question['question_body']);
$renderable->question['title'] = str_replace('$$','$',$renderable->question['title']);
$renderable->question['title'] = str_replace('$','$$',$renderable->question['title']);
$renderable->question['title'] = str_replace('\[','$$',$renderable->question['title']);
$renderable->question['title'] = str_replace('\]','$$',$renderable->question['title']);
$renderable->question['title'] = str_replace('\(','$$',$renderable->question['title']);
$renderable->question['title'] = str_replace('\)','$$',$renderable->question['title']);
// We need this, because he dont apply mathjax when no $$ exists.
if(!strpos($renderable->question['question_body'],'$$')){
$renderable->question['question_body'] .= ' $$ $$';
}
if(!strpos($renderable->question['title'],'$$')){
$renderable->question['title'] .= ' $$ $$';
}
$renderable->question['question_body'] = format_text($renderable->question['question_body'], FORMAT_MARKDOWN);
$renderable->question['title'] = format_text($renderable->question['title'], FORMAT_MARKDOWN);
$data->questions[] = $output->render($renderable);
Expand Down
4 changes: 1 addition & 3 deletions templates/annotation_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@
}
}

.ivs-annotations .MathJax_Display{
display: inline !important;
}



12 changes: 12 additions & 0 deletions templates/question_answers_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ table th.text-center, table td.text-center {
justify-content: space-between;
flex-wrap: wrap;
}

.answers-header-details .MathJax_Display{
display: inline !important;
}

.answers-header-details .filter_mathjaxloader_equation p{
display: inline !important;
}

.answers-header-details p{
display: inline !important;
}
12 changes: 6 additions & 6 deletions templates/question_answers_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<tr>
<th scope="col" colspan="2">{{id_label}}<span class="answers-header-details">{{id}}</span></th>
<th scope="col" colspan="1">{{type_label}}<span class="answers-header-details">{{question_type}}</span></th>
<th scope="col" colspan="1">{{title_label}}<span class="answers-header-details">{{label}}</span></th>
<th scope="col" colspan="1">{{title_label}}<span class="answers-header-details">{{{label}}}</span></th>
</tr>
<tr>
<th scope="col" colspan="4">{{question_label}}<span class="answers-header-details">{{question}}</span></th>
<th scope="col" colspan="4">{{question_label}}<span class="answers-header-details">{{{question}}}</span></th>
</tr>
<tr>
<th scope="col" class="centeralign">{{name}}</th>
Expand Down Expand Up @@ -52,10 +52,10 @@
<tr>
<th scope="col" colspan="2">{{id_label}}<span class="answers-header-details">{{id}}</span></th>
<th scope="col" colspan="1">{{type_label}}<span class="answers-header-details">{{question_type}}</span></th>
<th scope="col" colspan="2">{{title_label}}<span class="answers-header-details">{{label}}</span></th>
<th scope="col" colspan="2">{{title_label}}<span class="answers-header-details">{{{label}}}</span></th>
</tr>
<tr>
<th scope="col" colspan="5">{{question_label}}<span class="answers-header-details">{{question}}</span></th>
<th scope="col" colspan="5">{{question_label}}<span class="answers-header-details">{{{question}}}</span></th>
</tr>
<tr>
<th scope="col">{{name}}</th>
Expand All @@ -82,10 +82,10 @@
<tr>
<th scope="col" colspan="2">{{id_label}}<span class="answers-header-details">{{id}}</span></th>
<th scope="col" colspan="2">{{type_label}}<span class="answers-header-details">{{question_type}}</span></th>
<th scope="col" colspan="2">{{title_label}}<span class="answers-header-details">{{label}}</span></th>
<th scope="col" colspan="2">{{title_label}}<span class="answers-header-details">{{{label}}}</span></th>
</tr>
<tr>
<th scope="col" colspan="7">{{question_label}}<span class="answers-header-details">{{question}}</span></th>
<th scope="col" colspan="7">{{question_label}}<span class="answers-header-details">{{{question}}}</span></th>
</tr>
<tr>
<th scope="col">{{name}}</th>
Expand Down
4 changes: 2 additions & 2 deletions templates/question_text_answer_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<tr>
<td>{{fullname}}</td>
<td>{{id}}</td>
<td class="text-answer">{{first}}</td>
<td class="text-answer">{{last}}</td>
<td class="text-answer">{{{first}}}</td>
<td class="text-answer">{{{last}}}</td>
</tr>
{{/fullname}}
3 changes: 0 additions & 3 deletions templates/question_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@
float: right;
}

.ivs-questions .MathJax_Display{
display: inline !important;
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_ivs';
$plugin->release = 'v1.6.443';
$plugin->version = 2021060700;
$plugin->release = 'v1.6.469';
$plugin->version = 2021080601;
$plugin->requires = 2014051200;
$plugin->maturity = MATURITY_BETA;
$plugin->cron = 0;
Expand Down

0 comments on commit 1969f72

Please sign in to comment.