Index: trunk/extensions/QPoll/qp_results.php |
— | — | @@ -345,10 +345,10 @@ |
346 | 346 | if ( $userName === false ) { |
347 | 347 | return ''; |
348 | 348 | } |
349 | | - $pollStore->loadRandomQuestions( $userName ); |
350 | 349 | $userTitle = Title::makeTitleSafe( NS_USER, $userName ); |
351 | 350 | $user_link = $this->qpLink( $userTitle, $userName ); |
352 | 351 | $pollStore->setLastUser( $userName, false ); |
| 352 | + $pollStore->loadRandomQuestions(); |
353 | 353 | if ( !$pollStore->loadUserVote() ) { |
354 | 354 | return ''; |
355 | 355 | } |
Index: trunk/extensions/QPoll/README |
— | — | @@ -1,5 +1,7 @@ |
2 | | -MediaWiki extension QPoll, version 0.8.0a |
| 2 | +== MediaWiki extension QPoll, version 0.8.0a == |
3 | 3 | |
| 4 | +=== v0.7.0 === |
| 5 | + |
4 | 6 | This extension allows to create polls embedded into the wikipages. Every poll |
5 | 7 | may contain a set of the questions of various types. The polls can be "chained" |
6 | 8 | (when the dependent poll would be available for voting only after a successful |
— | — | @@ -8,7 +10,7 @@ |
9 | 11 | the groups (metacategories also known as category spans) to make a |
10 | 12 | "subquestions" inside a question. Optional dependence of the question's |
11 | 13 | proposal text on the user's choice of category in another previously voted |
12 | | -poll. |
| 14 | +poll. Categories can be checkboxes, radiobuttons or text fields. |
13 | 15 | |
14 | 16 | === v0.8.0a === |
15 | 17 | Now it is possible to: |
— | — | @@ -17,7 +19,11 @@ |
18 | 20 | * Generate and store interpretations / marks / scores |
19 | 21 | * Highlight wrong answers to question proposals |
20 | 22 | * Log and limit number of answer attempts |
| 23 | +* Select number of random questions for every user of the particular poll |
| 24 | + (similar to Russian EGE test) |
21 | 25 | |
22 | 26 | which allows to use the extension as education tool. |
23 | 27 | |
24 | | -See http://mediawiki.org/wiki/Extension:QPoll for further details. |
\ No newline at end of file |
| 28 | +Documentation will be updated when the extension will become stable enough. |
| 29 | + |
| 30 | +See http://mediawiki.org/wiki/Extension:QPoll for further details. |
Index: trunk/extensions/QPoll/ctrl/qp_poll.php |
— | — | @@ -174,7 +174,8 @@ |
175 | 175 | |
176 | 176 | function setUsedQuestions() { |
177 | 177 | # load random questions from DB (when available) |
178 | | - $this->pollStore->loadRandomQuestions( $this->username ); |
| 178 | + $this->pollStore->setLastUser( $this->username ); |
| 179 | + $this->pollStore->loadRandomQuestions(); |
179 | 180 | if ( $this->randomQuestionCount > 0 ) { |
180 | 181 | if ( $this->randomQuestionCount > $this->questions->totalCount() ) { |
181 | 182 | $this->randomQuestionCount = $this->questions->totalCount(); |
Index: trunk/extensions/QPoll/qp_pollstore.php |
— | — | @@ -184,7 +184,9 @@ |
185 | 185 | /// DB keys |
186 | 186 | var $pid = null; |
187 | 187 | var $last_uid = null; |
188 | | - # username is used for caching of setLastUser() method (which now may be called multiple times) |
| 188 | + |
| 189 | + # username is used for caching of setLastUser() method (which now may be called multiple times); |
| 190 | + # also used by randomizer |
189 | 191 | var $username = ''; |
190 | 192 | /// common properties |
191 | 193 | var $mArticleId = null; |
— | — | @@ -678,16 +680,28 @@ |
679 | 681 | } |
680 | 682 | } |
681 | 683 | |
| 684 | + /** |
| 685 | + * Checks, whether particular question belongs to user's random seed |
| 686 | + * @param $question_id question_id from DB |
| 687 | + * @return true: question belongs to the seed; |
| 688 | + * false: question does not belong to the seed; |
| 689 | + */ |
682 | 690 | function isUsedQuestion( $question_id ) { |
683 | 691 | return !is_array( $this->randomQuestions ) || |
684 | 692 | in_array( $question_id, $this->randomQuestions, true ); |
685 | 693 | } |
686 | 694 | |
687 | | - function loadRandomQuestions( $username ) { |
| 695 | + /** |
| 696 | + * Loads $this->randomQuestions from DB for current user |
| 697 | + * Will be overriden in memory when number of random questions was changed |
| 698 | + */ |
| 699 | + function loadRandomQuestions() { |
| 700 | + if ( is_null( $this->last_uid ) ) { |
| 701 | + throw new Exception( 'User was not set, cannot load random questions in ' . __METHOD__ ); |
| 702 | + } |
688 | 703 | if ( is_null( $this->pid ) ) { |
689 | 704 | $this->setPid(); |
690 | 705 | } |
691 | | - $this->setLastUser( $username ); |
692 | 706 | $res = self::$db->select( 'qp_random_questions', 'question_id', array( 'uid' => $this->last_uid, 'pid' => $this->pid ), __METHOD__ ); |
693 | 707 | $this->randomQuestions = array(); |
694 | 708 | while ( $row = self::$db->fetchObject( $res ) ) { |
— | — | @@ -698,6 +712,12 @@ |
699 | 713 | } |
700 | 714 | } |
701 | 715 | |
| 716 | + /** |
| 717 | + * Stores $this->randomQuestions into DB |
| 718 | + * Should be called: |
| 719 | + * when user views the page with the poll first time |
| 720 | + * when number of random questions for poll was changed |
| 721 | + */ |
702 | 722 | function setRandomQuestions() { |
703 | 723 | if ( is_null( $this->pid ) || is_null( $this->last_uid ) ) { |
704 | 724 | throw new MWException( __METHOD__ . ' cannot be called when pid/uid was not set' ); |
— | — | @@ -707,12 +727,17 @@ |
708 | 728 | foreach( $this->randomQuestions as $qidx ) { |
709 | 729 | $data[] = array( 'pid' => $this->pid, 'uid' => $this->last_uid, 'question_id' => $qidx ); |
710 | 730 | } |
711 | | - $res = self::$db->replace( 'qp_random_questions', |
712 | | - 'user_poll_question', |
| 731 | + self::$db->begin(); |
| 732 | + self::$db->delete( 'qp_random_questions', |
| 733 | + array( 'pid' => $this->pid, 'uid' => $this->last_uid ), |
| 734 | + __METHOD__ ); |
| 735 | + $res = self::$db->insert( 'qp_random_questions', |
713 | 736 | $data, |
714 | | - __METHOD__ . ':random questions seed update' ); |
| 737 | + __METHOD__ . ':set random questions seed' ); |
| 738 | + self::$db->commit(); |
715 | 739 | return; |
716 | 740 | } |
| 741 | + # this->randomQuestions === false; this poll is not randomized anymore |
717 | 742 | self::$db->delete( 'qp_random_questions', |
718 | 743 | array( 'pid'=>$this->pid ), |
719 | 744 | __METHOD__ . ':remove question random seed' |