From 78cd0a2c1441acdcaeb28f108a6b8148f3e94018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Arag=C3=B3n?= Date: Mon, 25 Mar 2019 17:27:56 -0500 Subject: [PATCH] WP - Create tpl for list of exercises - refs #2681 --- assets/css/scss/_base.scss | 23 +++- main/exercise/exercise.php | 119 ++++++++++++------ .../template/default/exercise/index.html.twig | 23 ++-- 3 files changed, 115 insertions(+), 50 deletions(-) diff --git a/assets/css/scss/_base.scss b/assets/css/scss/_base.scss index aaeb1392d9..83b6491091 100755 --- a/assets/css/scss/_base.scss +++ b/assets/css/scss/_base.scss @@ -1316,14 +1316,25 @@ hr { .list-exercise{ .list-group{ .list-group-item{ + .toolbar{ + margin-top: 10px; + a{ + img{ + border: 1px solid #cdcdcd; + background-color: #ffffff; + padding: 2px; + border-radius: 4px; + } + } + } + .score-list{ + padding: 0; + margin: 0; + list-style: none; + font-size: 12px; + } .description{ width:100%; - height:20px; - padding:0; - text-overflow:ellipsis; - overflow:hidden; - transition: all 1s; - box-sizing: border-box; } } } diff --git a/main/exercise/exercise.php b/main/exercise/exercise.php index cdbf72edff..8047c01f47 100644 --- a/main/exercise/exercise.php +++ b/main/exercise/exercise.php @@ -663,6 +663,7 @@ if (!empty($exerciseList)) { $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id='.$learnpath_id); $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id='.$learnpath_item_id); $i = 1; + foreach ($exerciseList as $row) { $my_exercise_id = $row['id']; @@ -734,6 +735,12 @@ if (!empty($exerciseList)) { } // Teacher only + // Count number exercise - teacher + $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION + WHERE c_id = $courseId AND exercice_id = $my_exercise_id"; + $sqlresult = Database::query($sql); + $rowi = intval(Database :: result($sqlresult, 0, 0)); + if ($is_allowedToEdit) { $lp_blocked = null; if ($exercise->exercise_was_added_in_lp == true) { @@ -805,19 +812,13 @@ if (!empty($exerciseList)) { $listExercise['id'] = $row['id']; $listExercise['title'] = $title; - $listExercise['description'] = $row['description']; + $listExercise['description'] = cut($row['description'],150, false); $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); - - // Count number exercise - teacher - $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION - WHERE c_id = $courseId AND exercice_id = $my_exercise_id"; - $sqlresult = Database::query($sql); - $rowi = intval(Database :: result($sqlresult, 0, 0)); + //$item = Display::tag('td', $url.' '.$session_img.$lp_blocked); if ($sessionId == $row['session_id']) { // Questions list @@ -1065,6 +1066,7 @@ if (!empty($exerciseList)) { $actions .= $delete; // Number of questions + $random_label = null; if ($row['random'] > 0 || $row['random'] == -1) { // if random == -1 means use random questions with all questions @@ -1093,7 +1095,7 @@ if (!empty($exerciseList)) { $number_of_questions = $rowi; } $listExercise['number_questions'] = $number_of_questions; - $item .= Display::tag('td', $number_of_questions); + //$item .= Display::tag('td', $number_of_questions); } else { // Student only. $visibility = api_get_item_visibility( @@ -1114,7 +1116,7 @@ if (!empty($exerciseList)) { $listExercise['url'] = 'overview.php?'.api_get_cidreq().$mylpid.$mylpitemid.'&exerciseId='.$row['id']; // Link of the exercise. - $item = Display::tag('td', $url.' '.$session_img); + //$item = Display::tag('td', $url.' '.$session_img); // Count number exercise questions. /*$sql = "SELECT count(*) FROM $TBL_EXERCISE_QUESTION @@ -1231,10 +1233,12 @@ if (!empty($exerciseList)) { if ($num > 0) { $row_track = Database :: fetch_array($qryres); $attempt_text = get_lang('LatestAttempt').' : '; - $attempt_text .= ExerciseLib::show_score( + $score = ExerciseLib::show_score( $row_track['score'], $row_track['max_score'] ); + $attempt_text .= $score['html']; + } else { $attempt_text = get_lang('NotAttempted'); } @@ -1259,9 +1263,10 @@ if (!empty($exerciseList)) { } $listExercise['status'] = $attempt_text; - $listExercise['description'] = $row['description']; + $listExercise['description'] = cut($row['description'], 150, false); $listExercise['score'] = $score; - $item .= Display::tag('td', $attempt_text); + $listExercise['number_questions'] = $rowi; + //$item .= Display::tag('td', $attempt_text); } if ($is_allowedToEdit) { @@ -1270,8 +1275,8 @@ if (!empty($exerciseList)) { if (!empty($additionalActions)) { $actions .= $additionalActions.PHP_EOL; } - $listExercise['actions'] = $actions; - $item .= Display::tag('td', $actions, ['class' => 'td_actions']); + $listExercise['actions'] = $actions; + //$item .= Display::tag('td', $actions, ['class' => 'td_actions']); } else { if ($isDrhOfCourse) { @@ -1279,18 +1284,18 @@ if (!empty($exerciseList)) { Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).''; $listExercise['actions'] = $actions; - $item .= Display::tag('td', $actions, ['class' => 'td_actions']); + // .= Display::tag('td', $actions, ['class' => 'td_actions']); } } - $tableRows[] = Display::tag( + /*$tableRows[] = Display::tag( 'tr', $item, [ 'id' => 'exercise_list_'.$my_exercise_id, ] - ); + );*/ $list[] = $listExercise; } @@ -1332,11 +1337,16 @@ while ($row = Database :: fetch_array($result, 'ASSOC')) { } $nbrActiveTests = 0; +$itemHotpotatoes = []; +$listHotpotatoes = []; + if (isset($attribute['path']) && is_array($attribute['path'])) { $hotpotatoes_exist = true; foreach ($attribute['path'] as $key => $path) { - $item = ''; + + //$item = ''; $title = GetQuizName($path, $documentPath); + if ($title == '') { $title = basename($path); } @@ -1363,7 +1373,11 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { ); } - $item = Display::tag( + $url = 'showinframes.php?'.api_get_cidreq().'&'.http_build_query(['file' => $path, 'uid' => $userId]); + $itemHotpotatoes['url'] = $url; + $itemHotpotatoes['visibility'] = $visibility; + + /*$item = Display::tag( 'td', implode(PHP_EOL, [ Display::return_icon('hotpotatoes_s.png', "HotPotatoes"), @@ -1376,9 +1390,11 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { ['class' => $visibility == 0 ? 'text-muted' : null] ), ]) - ); + );*/ + + $itemHotpotatoes['title'] = $title; - $item .= Display::tag('td', '-'); + //$item .= Display::tag('td', '-'); $actions = Display::url( Display::return_icon( @@ -1404,8 +1420,13 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { } $actions .= ''. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).''; - $item .= Display::tag('td', $actions); - $tableRows[] = Display::tag('tr', $item); + + $itemHotpotatoes['actions'] = $actions; + + $listHotpotatoes[] = $itemHotpotatoes; + //$item .= Display::tag('td', $actions); + //$tableRows[] = Display::tag('tr', $item); + } else { $visibility = api_get_item_visibility( ['real_id' => $courseId], @@ -1413,6 +1434,7 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { $attribute['id'][$key], $sessionId ); + $itemHotpotatoes['visibility'] = $visibility; if (0 == $visibility) { continue; @@ -1426,8 +1448,14 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { api_get_session_id() ); + + $url = 'showinframes.php?'.api_get_cidreq().'&'.http_build_query(['file' => $path, 'cid' => api_get_course_id(), 'uid' => $userId]); + $itemHotpotatoes['url'] = $url; + $itemHotpotatoes['title'] = $title; + $itemHotpotatoes['attempt'] = $attempt; + $nbrActiveTests = $nbrActiveTests + 1; - $item .= Display::tag( + /*$item .= Display::tag( 'td', Display::url( $title, @@ -1437,34 +1465,50 @@ if (isset($attribute['path']) && is_array($attribute['path'])) { 'uid' => $userId, ]) ) - ); + );*/ if (!empty($attempt)) { - $actions = ''.Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).''; - $attemptText = get_lang('LatestAttempt').' : '; - $attemptText .= ExerciseLib::show_score( + $urlResults = 'hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'&filter_by_user='.$userId; + $itemHotpotatoes['results'] = $url; + + /*$actions = '' + .Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL). + '';*/ + + $attemptText = get_lang('LatestAttempt'); + + $score = ExerciseLib::show_score( $attempt['score'], $attempt['max_score'] - ).' '; - $attemptText .= $actions; + ); + + $itemHotpotatoes['score'] = $score; + + } else { // No attempts. $attemptText = get_lang('NotAttempted').' '; } - $item .= Display::tag('td', $attemptText); + $itemHotpotatoes['status'] = $attemptText; + + //$item .= Display::tag('td', $attemptText); if ($isDrhOfCourse) { - $actions = ''. + $urlResults = 'hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path; + $itemHotpotatoes['results'] = $urlResults; + /*$actions = ''. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).''; $item .= Display::tag( 'td', $actions, ['class' => 'td_actions'] - ); + );*/ } - $tableRows[] = Display::tag('tr', $item); + + $listHotpotatoes[] = $itemHotpotatoes; + //$tableRows[] = Display::tag('tr', $item); } } @@ -1485,7 +1529,7 @@ if (empty($exerciseList) && $hotpotatoes_exist == false) { echo ''; } } else { - if ($is_allowedToEdit) { + /*if ($is_allowedToEdit) { $headers = [ get_lang('ExerciseName'), get_lang('QuantityQuestions'), @@ -1521,10 +1565,11 @@ if (empty($exerciseList) && $hotpotatoes_exist == false) { echo ''; echo ''; - echo ''; + echo ''*/; $tpl = new Template(null); $tpl->assign('data', $list); + $tpl->assign('hotpotatoes', $listHotpotatoes); $tpl->assign('is_teacher', $is_allowedToEdit); $layout = $tpl->get_template('exercise/index.html.twig'); $content = $tpl->fetch($layout); diff --git a/main/template/default/exercise/index.html.twig b/main/template/default/exercise/index.html.twig index f5fbf30c50..cb187b1015 100644 --- a/main/template/default/exercise/index.html.twig +++ b/main/template/default/exercise/index.html.twig @@ -18,25 +18,34 @@ {% endif %} -
+
+ {{ 'Quantity Questions'|trans }}: {{ item.number_questions }} -

{{ 'Percentage of completion'|trans }}

+ {% if item.score %}
{{ item.score.percentage }}%
+ {% else %} +
+
+ 0% +
+
{% endif %}
-
+
{% if is_teacher %} - {{ item.actions }} +
+ {{ item.actions }} +
{% else %} -

{{ 'Latest Attempt'|trans }}

+ {{ 'Latest Attempt'|trans }}
    -
  • {{ 'Score obtained'|trans }} : {{ item.score.score_obtained }}
  • -
  • {{ 'Total score'|trans }} : {{ item.score.total_score }}
  • +
  • {{ 'Score obtained'|trans }} : {{ item.score.score_obtained }}
  • +
  • {{ 'Total score'|trans }} : {{ item.score.total_score }}
{% endif %}