From fcff639c9e7c4e8aea5a74fb6de8f92043c9683c Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Mon, 10 Jun 2024 14:22:59 -0500 Subject: [PATCH 1/2] Exercise: Fix ordering question shuffle issue in draggable questions - refs BT#21775 --- .../default/exercise/submit.js.html.twig | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/public/main/template/default/exercise/submit.js.html.twig b/public/main/template/default/exercise/submit.js.html.twig index 102ab3d5dc7..a9ca4df1c23 100644 --- a/public/main/template/default/exercise/submit.js.html.twig +++ b/public/main/template/default/exercise/submit.js.html.twig @@ -224,32 +224,38 @@ jsPlumb.ready(function () { }); $(function () { - DraggableAnswer.init( - $(".exercise-draggable-answer"), - $(".droppable") - ); - - // if shuffle answers - if ('{{ shuffle_answers }}' == '1') { - $('.exercise-draggable-answer').each(function(){ - // get current ul - var $ul = $(this); - // get array of list items in current ul - var $liArr = $ul.children('li'); - // sort array of list items in current ul randomly - $liArr.sort(function(a,b){ - // Get a random number between 0 and 10 - var temp = parseInt( Math.random()*100 ); - // Get 1 or 0, whether temp is odd or even - var isOddOrEven = temp%2; - // Get +1 or -1, whether temp greater or smaller than 5 - var isPosOrNeg = temp>5 ? 1 : -1; - // Return -1, 0, or +1 - return( isOddOrEven*isPosOrNeg ); - }) - // append list items to ul - .appendTo($ul); - }); - } + DraggableAnswer.init( + $(".exercise-draggable-answer"), + $(".droppable") + ); + + // if shuffle answers + if ('{{ shuffle_answers }}' == '1') { + $('.exercise-draggable-answer').each(function() { + var $ul = $(this); + var $liArr = $ul.children('li').toArray(); + + function shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; + } + + var previousOrder = $liArr.map(item => item.id).join(); + var newOrder; + + do { + shuffle($liArr); + newOrder = $liArr.map(item => item.id).join(); + } while (newOrder === previousOrder); + + // Detach and append list items to preserve event handlers + $.each($liArr, function(index, item) { + $ul.append($(item).detach()); + }); + }); + } }); From cf40a31095e3816a6fcbc7e18eb475f8524b8b95 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Mon, 10 Jun 2024 17:00:59 -0500 Subject: [PATCH 2/2] Learnpath: Validate items when parent titles is empty - refs BT#21786 --- public/main/lp/ScormApi.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/main/lp/ScormApi.php b/public/main/lp/ScormApi.php index f0a3ca21ad0..e148b53989d 100644 --- a/public/main/lp/ScormApi.php +++ b/public/main/lp/ScormApi.php @@ -829,7 +829,9 @@ public static function switchItem($lpId, $user_id, $view_id, $current_item, $nex // Encode JSON without escaping Unicode characters $titleItemParents = json_encode($escapedParents, JSON_UNESCAPED_UNICODE | JSON_HEX_APOS | JSON_HEX_QUOT); } - $return .= "olms.lms_lp_item_parents={$titleItemParents};"; + if (!empty($titleItemParents)) { + $return .= "olms.lms_lp_item_parents={$titleItemParents};"; + } //$return .= 'updateGamificationValues(); '; $mylp->set_error_msg('');