Skip to content

Commit

Permalink
Fixed possible issues when cloning a course containing a quiz built w…
Browse files Browse the repository at this point in the history
…ith the Advanced Quizzes addon, after disabling it
  • Loading branch information
eri-trabiccolo committed Oct 6, 2023
1 parent bfedbf1 commit 3be7246
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .changelogs/fix-clone-advanced-quizzes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
significance: patch
type: fixed
entry: Fixed possible issues when cloning a course containing a quiz built with
the Advanced Quizzes addon, after disabling it.
25 changes: 14 additions & 11 deletions includes/models/model.llms.question.choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package LifterLMS/Models/Classes
*
* @since 3.16.0
* @version 3.16.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -216,13 +216,14 @@ public function save() {
}

/**
* Set a piece of data by key
* Set a piece of data by key.
*
* @param string $key name of the key to set
* @param mixed $val value to set
* @return self
* @since 3.16.0
* @version 3.16.0
* @since 3.16.0
* @since [version] Check `$type['choices']` is an array before trying to access it as such.
*
* @param string $key Name of the key to set.
* @param mixed $val Value to set.
* @return self
*/
public function set( $key, $val ) {

Expand All @@ -244,10 +245,12 @@ public function set( $key, $val ) {
break;

case 'marker':
$type = $this->get_question()->get_question_type();
$markers = $type['choices']['markers'];
if ( ! in_array( $val, $markers ) ) {
$val = $markers[0];
$type = $this->get_question()->get_question_type();
if ( is_array( $type['choices'] ?? false ) ) {
$markers = $type['choices']['markers'];
if ( ! in_array( $val, $markers ) ) {
$val = $markers[0];
}
}
break;

Expand Down
10 changes: 7 additions & 3 deletions includes/models/model.llms.question.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package LifterLMS/Models/Classes
*
* @since 1.0.0
* @version 4.4.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -407,17 +407,21 @@ public function get_image( $size = 'full', $unused = null ) {
}

/**
* Retrieve the next marker for question choices
* Retrieve the next marker for question choices.
*
* @since 3.16.0
* @since 3.30.1 Fixed bug which caused the next marker to be 1 index too high.
* @since [version] Check `$type['choices']` is an array before trying to access it as such.
*
* @return string
*/
protected function get_next_choice_marker() {
$next_index = count( $this->get_choices( 'ids', false ) );
$type = $this->get_question_type();
$markers = $type['choices']['markers'];
if ( ! is_array( $type['choices'] ?? false ) ) {
return false;
}
$markers = $type['choices']['markers'];
return $next_index > count( $markers ) ? false : $markers[ $next_index ];
}

Expand Down

0 comments on commit 3be7246

Please sign in to comment.