Skip to content

Commit

Permalink
Re-implementig some parts of quiz plugin in order to generalize solut…
Browse files Browse the repository at this point in the history
…ion for future enhancements.

Now all question types must inherit the Question model using the inheritable behavior.
  • Loading branch information
lorenzo committed Mar 30, 2009
1 parent 4e629bc commit 160cf10
Show file tree
Hide file tree
Showing 31 changed files with 649 additions and 743 deletions.
242 changes: 115 additions & 127 deletions plugins/quiz/config/sql/schema.php
@@ -1,140 +1,128 @@
<?php
class QuizSchema extends CakeSchema {
var $name = 'Quiz';

var $quiz_quizzes = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'name' => array('type'=>'string', 'null' => false),
'course_id' => array('type'=>'integer', 'null' => false),
'member_id' => array('type'=>'integer', 'null' => false),
'published' => array('type'=>'boolean', 'null' => false, 'default' => '0'),
'created' => array('type'=>'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);

var $quiz_choice_choices = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'choice_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'choice_question_id' => array('type' => 'integer', 'null' => false),
'text' => array('type'=>'text', 'null' => false),
'position' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 3),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'position' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 3,'null' => true, 'default' => NULL,),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_choice_choices_answers = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'choice_questions_answer_id' => array('type' => 'integer', 'null' => false),
'choice_choice_id' => array('type' => 'integer', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_choice_questions = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'body' => array('type'=>'text', 'null' => false),
'shuffle' => array('type'=>'boolean', 'null' => false),
'max_choices' => array('type'=>'integer', 'null' => false),
'min_choices' => array('type'=>'integer', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'body' => array('type' => 'text', 'null' => false),
'shuffle' => array('type' => 'boolean', 'null' => false),
'max_choices' => array('type' => 'integer', 'null' => true, 'default' => NULL),
'min_choices' => array('type' => 'integer', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_choice_questions_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'member_id' => array('type'=>'integer', 'null' => false),
'choice_questions_quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'created' => array('type'=>'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_choice_choices_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'choice_questions_answer_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'choice_choice_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'member_id' => array('type' => 'integer', 'null' => false),
'questions_quiz_id' => array('type' => 'integer', 'null' => false),
'created' => array('type' => 'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_choices = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'text' => array('type' => 'text', 'null' => false),
'matching_question_id' => array('type' => 'integer', 'null' => false),
'target_id' => array('type' => 'integer', 'null' => true, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_choices_answers = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'matching_questions_answer_id' => array('type' => 'integer', 'null' => false),
'source_id' => array('type' => 'integer', 'null' => false),
'target_id' => array('type' => 'integer', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_questions = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'body' => array('type'=>'text', 'null' => false),
'shuffle' => array('type'=>'boolean', 'null' => false),
'max_associations' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 3),
'min_associations' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 3),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'body' => array('type' => 'text', 'null' => false),
'shuffle' => array('type' => 'boolean', 'null' => false),
'max_associations' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 3),
'min_associations' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 3),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_questions_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'member_id' => array('type'=>'integer', 'null' => false),
'matching_questions_quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'created' => array('type'=>'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_choices_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'quiz_matching_choices_answers' => array('type'=>'string', 'null' => false, 'length' => 36),
'source_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'target_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_questions = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'body' => array('type'=>'text', 'null' => false),
'shuffle' => array('type'=>'boolean', 'null' => false),
'max_choices' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 4),
'min_choices' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_questions_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'member_id' => array('type'=>'integer', 'null' => false),
'ordering_questions_quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'created' => array('type'=>'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'member_id' => array('type' => 'integer', 'null' => false),
'questions_quiz_id' => array('type' => 'integer', 'null' => false),
'created' => array('type' => 'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_choices = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'ordering_question_id' => array('type' => 'integer', 'null' => false),
'text' => array('type' => 'text', 'null' => false),
'position' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 3),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_choices_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'ordering_questions_answer_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'ordering_choice_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'position' => array('type'=>'integer', 'null' => false, 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_text_questions = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'title' => array('type'=>'string', 'null' => false),
'body' => array('type'=>'text', 'null' => false),
'format' => array('type'=>'string', 'null' => false, 'length' => 5),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'ordering_questions_answer_id' => array('type' => 'integer', 'null' => false),
'ordering_choice_id' => array('type' => 'integer', 'null' => false),
'position' => array('type' => 'integer', 'null' => false, 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_questions = array(
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'body' => array('type' => 'text', 'null' => false),
'shuffle' => array('type' => 'boolean', 'null' => false),
'max_choices' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 4),
'min_choices' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_questions_answers = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'member_id' => array('type' => 'integer', 'null' => false),
'questions_quiz_id' => array('type' => 'integer', 'null' => false),
'created' => array('type' => 'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_questions = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'type' => array('type' => 'string', 'null' => false, 'length' => 20),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_questions_quizzes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'question_id' => array('type' => 'integer', 'null' => false),
'quiz_id' => array('type' => 'string', 'null' => false, 'length' => 36),
'position' => array('type' => 'integer', 'null' => false, 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_quizzes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
'course_id' => array('type' => 'integer', 'null' => false),
'member_id' => array('type' => 'integer', 'null' => false),
'published' => array('type' => 'boolean', 'null' => false, 'default' => '0'),
'created' => array('type' => 'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_text_questions = array(
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => false),
'format' => array('type' => 'string', 'null' => false, 'length' => 5),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_text_questions_answers = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'member_id' => array('type'=>'integer', 'null' => false),
'text_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'answer' => array('type'=>'text', 'null' => false),
'created' => array('type'=>'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_matching_questions_quizzes = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'matching_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_questions_quizzes = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'ordering_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_choice_questions_quizzes = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'choice_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_text_questions_quizzes = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'text_question_id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'index'),
'quiz_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'text_question_id' => array('column' => array('text_question_id', 'quiz_id'), 'unique' => 1))
);
var $quiz_matching_choices = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'text' => array('type'=>'text', 'null' => false),
'matching_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'target_id' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 36),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $quiz_ordering_choices = array(
'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'),
'ordering_question_id' => array('type'=>'string', 'null' => false, 'length' => 36),
'text' => array('type'=>'text', 'null' => false),
'position' => array('type'=>'integer', 'null' => false, 'default' => '0', 'length' => 3),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'member_id' => array('type' => 'integer', 'null' => false),
'questions_quiz_id' => array('type' => 'integer', 'null' => false),
'answer' => array('type' => 'text', 'null' => false),
'created' => array('type' => 'datetime', 'null' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
}
?>
6 changes: 3 additions & 3 deletions plugins/quiz/controllers/choice_questions_controller.php
Expand Up @@ -29,7 +29,7 @@
* @lastmodified $Date$
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
*/
class ChoiceQuestionsController extends AppController {
class ChoiceQuestionsController extends QuizAppController {

var $name = 'ChoiceQuestions';
var $helpers = array('Html', 'Form' );
Expand Down Expand Up @@ -69,10 +69,10 @@ function add() {
$this->ChoiceQuestion->set($this->data);
if ($this->ChoiceQuestion->validates() && $this->ChoiceQuestion->saveAll($this->data, array('validate' => false))) {
$habtm_data = array(
'choice_question_id' => $this->ChoiceQuestion->getLastInsertID(),
'question_id' => $this->ChoiceQuestion->getLastInsertID(),
'quiz_id' => $this->data['Quiz'][0]['id']
);
if ($this->ChoiceQuestion->QuizChoice->save($habtm_data)) {
if ($this->ChoiceQuestion->QuizQuestion->save($habtm_data)) {
$this->Session->setFlash(__('The Choice Question has been saved',true), 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'quizzes', 'action'=>'edit', $this->data['Quiz'][0]['id']));
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/quiz/controllers/matching_questions_controller.php
Expand Up @@ -29,10 +29,10 @@
* @lastmodified $Date$
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
*/
class MatchingQuestionsController extends AppController {
class MatchingQuestionsController extends QuizAppController {

var $name = 'MatchingQuestions';
var $helpers = array('Html', 'Form' );
var $helpers = array('Html', 'Form');

function _setActiveCourse() {
parent::_setActiveCourse();
Expand Down Expand Up @@ -80,11 +80,11 @@ function add() {

if ($this->MatchingQuestion->saveAll($newData,array('validate' => false))) {
$habtm_data = array(
'matching_question_id' => $this->MatchingQuestion->getLastInsertID(),
'question_id' => $this->MatchingQuestion->getLastInsertID(),
'quiz_id' => $this->data['Quiz'][0]['id']
);

if ($this->MatchingQuestion->QuizMatching->save($habtm_data)) {
if ($this->MatchingQuestion->QuizQuestion->save($habtm_data)) {
$this->Session->setFlash(__('The Choice Question has been saved',true), 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'quizzes', 'action'=>'edit', $this->data['Quiz'][0]['id']));
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/quiz/controllers/ordering_questions_controller.php
Expand Up @@ -67,12 +67,12 @@ function add() {
$this->_cleanupEmpty();
$this->OrderingQuestion->create();
$this->OrderingQuestion->set($this->data);
if ($this->OrderingQuestion->validates() && $this->OrderingQuestion->saveAll($this->data, array('validate' => false))) {
if ($this->OrderingQuestion->validates() && $this->OrderingQuestion->saveAll($this->data, array('validate' => false)) === true) {
$habtm_data = array(
'ordering_question_id' => $this->OrderingQuestion->getLastInsertID(),
'question_id' => $this->OrderingQuestion->getLastInsertID(),
'quiz_id' => $this->data['Quiz'][0]['id']
);
if ($this->OrderingQuestion->QuizOrdering->save($habtm_data)) {
if ($this->OrderingQuestion->QuizQuestion->save($habtm_data)) {
$this->Session->setFlash(__('The Ordering Question has been saved',true), 'default', array('class' => 'success'));
$this->redirect(
array('controller' => 'quizzes', 'action'=>'edit', $this->data['Quiz'][0]['id'])
Expand Down
3 changes: 1 addition & 2 deletions plugins/quiz/controllers/quizzes_controller.php
Expand Up @@ -33,7 +33,6 @@ class QuizzesController extends QuizAppController {

var $name = 'Quizzes';
var $helpers = array('Html', 'Form' );

/**
* question_types: used on the list of available question types
*/
Expand Down Expand Up @@ -178,7 +177,7 @@ function answer($id = null) {
if (!empty($this->data)) {
if ($this->Quiz->saveAnswers($id,$this->data,$this->Auth->user('id'))) {
$this->Session->setFlash(__('You have completed the Quiz.', true), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
$this->redirect(array('action' => 'index','course_id' => $this->activeCourse));
}
}

Expand Down

0 comments on commit 160cf10

Please sign in to comment.