Creating template for exercise list - refs #2681

pull/3016/head
Alex Aragón 6 years ago
parent f777584044
commit 42f6987b74
  1. 2
      main/exercise/admin.php
  2. 8
      main/exercise/exercise.class.php
  3. 22
      main/exercise/exercise.php
  4. 2
      main/exercise/exercise_submit.php
  5. 12
      main/inc/lib/exercise.lib.php
  6. 47
      main/template/default/exercise/index.html.twig

@ -312,7 +312,7 @@ $htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js'
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
$template = new Template();
$templateName = $template->get_template('exercise/submit.js.tpl');
$templateName = $template->get_template('exercise/submit.js.html.twig');
$htmlHeadXtra[] = $template->fetch($templateName);
$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
$htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/css/hotspot.css">';

@ -7818,7 +7818,7 @@ class Exercise
/**
* @param string $class
* @param string $scoreLabel
* @param string $result
* @param array $result
* @param array
*
* @return string
@ -7832,7 +7832,7 @@ class Exercise
<h3>'.$scoreLabel.'</h3>
</div>';
if (!empty($result)) {
$label .= '<h4>'.get_lang('Score').': '.$result.'</h4>';
$label .= '<h4>'.get_lang('Score').': '.$result['html'].'</h4>';
}
if ($hideLabel === true) {
$answerUsed = (int) $array['used'];
@ -7847,7 +7847,7 @@ class Exercise
Display::return_icon('attempt-nocheck.png', null, null, ICON_SIZE_SMALL).
'</span>';
}
$label = '<div class="score-title">'.get_lang('CorrectAnswers').': '.$result.'</div>';
$label = '<div class="score-title">'.get_lang('CorrectAnswers').': '.$result['html'].'</div>';
$label .= '<div class="score-limits">';
$label .= $html;
$label .= '</div>';
@ -7863,7 +7863,7 @@ class Exercise
<h3>'.$scoreLabel.'</h3>
</div>';
if (!empty($result)) {
$html .= '<h4>'.get_lang('Score').': '.$result.'</h4>';
$html .= '<h4>'.get_lang('Score').': '.$result['html'].'</h4>';
}
$html .= '</div>';

@ -784,6 +784,7 @@ if (!empty($exerciseList)) {
$sessionId
);
$move = Display::return_icon(
'all_directions.png',
get_lang('Move'),
@ -805,6 +806,11 @@ if (!empty($exerciseList)) {
$listExercise['id'] = $row['id'];
$listExercise['title'] = $title;
$listExercise['url'] = "overview.php?".api_get_cidreq().$mylpid.$mylpitemid.'&exerciseId='.$row['id'];
$listExercise['lp_blocked'] = $lp_blocked;
$listExercise['visibility'] = $visibility;
$listExercise['active'] = $row['active'];
$item = Display::tag('td', $url.' '.$session_img.$lp_blocked);
@ -1087,6 +1093,8 @@ if (!empty($exerciseList)) {
} else {
$number_of_questions = $rowi;
}
$listExercise['number_questions'] = $number_of_questions;
$item .= Display::tag('td', $number_of_questions);
} else {
// Student only.
@ -1100,9 +1108,12 @@ if (!empty($exerciseList)) {
if ($visibility == 0) {
continue;
}
$score = null;
$url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.
$cut_title.'</a>';
$listExercise['id'] = $row['id'];
$listExercise['title'] = $cut_title;
$listExercise['url'] = 'overview.php?'.api_get_cidreq().$mylpid.$mylpitemid.'&exerciseId='.$row['id'];
// Link of the exercise.
$item = Display::tag('td', $url.' '.$session_img);
@ -1158,7 +1169,8 @@ if (!empty($exerciseList)) {
if ($num > 0) {
$row_track = Database :: fetch_array($qryres);
$attempt_text = get_lang('LatestAttempt').' : ';
$attempt_text .= ExerciseLib::show_score($row_track['score'], $row_track['max_score']);
$score = ExerciseLib::show_score($row_track['score'], $row_track['max_score']);
$attempt_text .= $score['html'];
} else {
//No attempts
$attempt_text = get_lang('NotAttempted');
@ -1248,6 +1260,9 @@ if (!empty($exerciseList)) {
$num = '<span class="tooltip" style="display: none;">'.$num.'</span>';
}
$listExercise['status'] = $attempt_text;
$listExercise['description'] = $row['description'];
$listExercise['score'] = $score;
$item .= Display::tag('td', $attempt_text);
}
@ -1511,7 +1526,8 @@ if (empty($exerciseList) && $hotpotatoes_exist == false) {
echo '</div>';
$tpl = new Template(null);
$tpl->assign('temp', $list);
$tpl->assign('data', $list);
$tpl->assign('is_teacher', $is_allowedToEdit);
$layout = $tpl->get_template('exercise/index.html.twig');
$content = $tpl->fetch($layout);
echo $content;

@ -181,7 +181,7 @@ if ($objExercise->review_answers) {
}
$template->assign('shuffle_answers', $objExercise->random_answers);
$templateName = $template->get_template('exercise/submit.js.tpl');
$templateName = $template->get_template('exercise/submit.js.html.twig');
$htmlHeadXtra[] = $template->fetch($templateName);
$current_timestamp = time();

@ -2789,7 +2789,7 @@ HOTSPOT;
* @param string $thousandSeparator
* @param bool $roundValues This option rounds the float values into a int using ceil()
*
* @return string an html with the score modified
* @return array an html with the score modified
*/
public static function show_score(
$score,
@ -2870,7 +2870,12 @@ HOTSPOT;
$html = Display::span($html, ['class' => 'score_exercise']);
return $html;
return [
'html' => $html,
'percentage' => $percentage,
'score_obtained' => $score,
'total_score' => $weight
];
}
/**
@ -5055,7 +5060,8 @@ EOT;
$ribbon .= '<div class="total">';
}
$ribbon .= '<h3>'.get_lang('YourTotalScore').":&nbsp;";
$ribbon .= self::show_score($score, $weight, false, true);
$score = self::show_score($score, $weight, false, true);
$ribbon .= $score['html'];
$ribbon .= '</h3>';
$ribbon .= '</div>';
if ($checkPassPercentage) {

@ -1 +1,46 @@
{{ dump(temp) }}
{% block content %}
{% autoescape false %}
<ul class="list-group list-group-flush">
{% for item in data %}
<li class="list-group-item">
<div class="row">
<div class="col-md-5">
<h5>
<img src="{{ 'quiz.png'|icon(22) }}">
<a href="{{ item.url }}">
{{ item.title }}
</a>
</h5>
{% if item.description %}
<div class="description">
{{ item.description }}
</div>
{% endif %}
</div>
<div class="col-md-5">
<p>{{ 'Percentage of completion'|trans }}</p>
{% if item.score %}
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ item.score.percentage }}%" aria-valuenow="{{ item.score.percentage }}" aria-valuemin="0" aria-valuemax="100">
{{ item.score.percentage }}%
</div>
</div>
{% endif %}
</div>
<div class="col-md-2">
{% if is_teacher %}
{{ item.actions }}
{% else %}
<p>{{ 'Latest Attempt'|trans }}</p>
<ul class="score-list">
<li>{{ 'Score obtained'|trans }} : {{ item.score.score_obtained }}</li>
<li>{{ 'Total score'|trans }} : {{ item.score.total_score }}</li>
</ul>
{% endif %}
</div>
</div>
</li>
{% endfor %}
</ul>
{% endautoescape %}
{% endblock %}
Loading…
Cancel
Save