Harjotsingh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374035 )
Change subject: Add ability for proposal positions to be shuffled on load
..
Add ability for proposal positions to be shuffled on load
Currently the quiz extension only shuffles the order of questions using Js.
This change adds shuffling feature for proposal for each questions by using
shuffle function of Php.It is achieved by using shuffleanswer parameter for
quiz.
Bug: T170799
Change-Id: I7bdeade1fb5359e0db2051a48a2e51831f673ba7
---
M Question.php
M Quiz.class.php
M tests/phpunit/QuestionTest.php
3 files changed, 60 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz
refs/changes/35/374035/1
diff --git a/Question.php b/Question.php
index 29fcd2f..a26a3ef 100644
--- a/Question.php
+++ b/Question.php
@@ -9,12 +9,13 @@
* @param $questionId Integer: the Identifier of the question used to
generate input names.
* @param $parser Parser the wikitext parser.
*/
- public function __construct( $beingCorrected, $caseSensitive,
$questionId, &$parser ) {
+ public function __construct( $beingCorrected, $caseSensitive,
$questionId, $shuffle, &$parser ) {
global $wgRequest;
$this->mRequest = &$wgRequest;
$this->mQuestionId = $questionId;
$this->mBeingCorrected = $beingCorrected;
$this->mCaseSensitive = $caseSensitive;
+ $this->shuffleAnswers = $shuffle;
$this->mParser = $parser;
$this->mState = ( $beingCorrected ) ? 'NA' : '';
$this->mType = 'multipleChoice';
@@ -161,12 +162,15 @@
// Parameters used in some special cases.
$expectOn = 0;
$attemptChecker = 0;
+ $lines = [];
+ $proposalCount = -1;
$checkedCount = 0;
foreach ( $raws as $proposalId => $raw ) {
$text = null;
$colSpan = '';
$signesOutput = '';
if ( preg_match( $this->mProposalPattern, $raw,
$matches ) ) {
+ $proposalCount++;
$rawClass = 'proposal';
// Insulate the proposal signes.
$text = array_pop( $matches );
@@ -274,18 +278,61 @@
$colSpan = ' colspan="13"';
}
if ( $text ) {
- $output .= '' .
"\n";
- $output .= $signesOutput;
- $output .= '';
- $output .= $this->mParser->recursiveTagParse(
$text );
- $output .= '';
- $output .= '' . "\n";
+ $lineOutput = '';
+ $lineOutput = ''
. "\n";
+ $lineOutput .= $signesOutput;
+ $lineOutput .= ' | ';
+ $lineOutput .=
$this->mParser->recursiveTagParse( $text );
+ $lineOutput .= '';
+ $lineOutput .= '' . "\n";
+ if ( $rawClass === 'correction selected' ||
$rawClass === 'correction unselected' ) {
+ if ( $proposalCount === -1 ) {
+ // Add to output directly
+ $output .= $lineOutput;
+ } else {
+ // Add feedback to previous
proposal
+ $lines[ $proposalCount ] .=
$lineOutput;
+ }
+ } else {
+ // Add lineOutput for proposal
+ $lines[ $proposalCount ] = $lineOutput;
+ }
}
}
// A single choice object with no correct proposal is a syntax
error.
if ( isset( $typeId ) && $typeId == 'sn' && $expectOn == 0 ) {
$this->setState( 'error' );
}
+ //Finding order
+ $order = '';
+ if ( $this->mBeingCorrected ) {
+ $order = $this->mRequest->getVal( $this->mQuestionId .
'|order' );
+ } else {
+ if ( $this->shuffleAnswers ) {
+ $order = '';
+ for( $i = 0; $i <= $proposalCount; ) {
+
Harjotsingh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/372130 )
Change subject: Add ability for proposal positions to be shuffled on load
..
Add ability for proposal positions to be shuffled on load
Currently the quiz extension only shuffles the order of questions using Js.
This change adds shuffling feature for proposal for each questions by using
shuffle function of Php.
Bug: T170799
Change-Id: I471984b7a9eb1faa0f5e4e4dae7c519312e495ea
---
M Question.php
1 file changed, 28 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz
refs/changes/30/372130/1
diff --git a/Question.php b/Question.php
index f2d544c..85e13a9 100644
--- a/Question.php
+++ b/Question.php
@@ -161,11 +161,14 @@
// Parameters used in some special cases.
$expectOn = 0;
$checkedCount = 0;
+ $lines = [];
+ $proposalCount = -1;
foreach ( $raws as $proposalId => $raw ) {
$text = null;
$colSpan = '';
$signesOutput = '';
if ( preg_match( $this->mProposalPattern, $raw,
$matches ) ) {
+ $proposalCount++;
$rawClass = 'proposal';
// Insulate the proposal signes.
$text = array_pop( $matches );
@@ -269,14 +272,33 @@
$colSpan = ' colspan="13"';
}
if ( $text ) {
- $output .= '' .
"\n";
- $output .= $signesOutput;
- $output .= '';
- $output .= $this->mParser->recursiveTagParse(
$text );
- $output .= '';
- $output .= '' . "\n";
+ $lineOutput = '';
+ $lineOutput = ''
. "\n";
+ $lineOutput .= $signesOutput;
+ $lineOutput .= ' | ';
+ $lineOutput .=
$this->mParser->recursiveTagParse( $text );
+ $lineOutput .= '';
+ $lineOutput .= '' . "\n";
+ if ( $rawClass === 'correction' ) {
+ if ( $proposalCount === -1 ) {
+ // Add to output directly
+ $output .= $lineOutput;
+ } else {
+ // Add feedback to previous
proposal
+ $lines[ $proposalCount ] .=
$lineOutput;
+
+ }
+ } else {
+ // Add lineOutput for proposal
+ $lines[ $proposalCount ] = $lineOutput;
+ }
}
}
+ // Shuffling the proposals
+ shuffle( $lines );
+ for( $i = 0; $i <= $proposalCount; ++$i ) {
+$output .= $lines[ $i ];
+}
// A single choice object with no correct proposal is a syntax
error.
if ( isset( $typeId ) && $typeId == 'sn' && $expectOn == 0 ) {
$this->setState( 'error' );
--
To view, visit https://gerrit.wikimedia.org/r/372130
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I471984b7a9eb1faa0f5e4e4dae7c519312e495ea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
|
|