From 06d9a0a1f6e00aace8140a2c1a3983d8b945eeff Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 12:45:30 +0100 Subject: [PATCH 01/35] Updated schema configuration file to actual database schema --- app/Config/Schema/schema.php | 140 +++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 65 deletions(-) diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index db52322..b36b1a0 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -228,19 +228,27 @@ public function after($event = array()) { array( array( 'id' => QuestionFormat::TRUE_FALSE, - 'name' => 'T/F' + 'name' => 'T/F', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-t-f.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-t-f.htm' ), array( 'id' => QuestionFormat::MULTIPLE_CHOICE, - 'name' => 'mc' + 'name' => 'mc', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-mcq.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-mcq.htm' ), array( 'id' => QuestionFormat::MULTIPLE_RESPONSE, - 'name' => 'mr' + 'name' => 'mr', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-mrq.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-mrq.htm' ), array( 'id' => QuestionFormat::OPEN_ANSWER, - 'name' => 'open' + 'name' => 'open', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/pro-con-general.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/pro-con-general.htm' ) ) ); @@ -268,14 +276,14 @@ public function after($event = array()) { } public $answer_options = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'index'), - 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'is_correct' => array('type' => 'boolean', 'null' => false, 'default' => null), - 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'given_answer_irc' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3'), - 'given_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1'), + 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) @@ -284,7 +292,7 @@ public function after($event = array()) { ); public $development_phases = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name_nld' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name_eng' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( @@ -294,7 +302,7 @@ public function after($event = array()) { ); public $exam_formats = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) @@ -303,7 +311,7 @@ public function after($event = array()) { ); public $exam_states = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name_eng' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name_nld' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( @@ -313,20 +321,19 @@ public function after($event = array()) { ); public $exams = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'exam_state_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'key' => 'index'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'index'), - 'exam_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'key' => 'index'), + 'exam_state_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'exam_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'data_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'mapping_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'average_score' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,3'), - 'standard_deviation' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,8'), - 'cronbachs_alpha' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3'), - 'report_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), + 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), + 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'uploaded' => array('type' => 'datetime', 'null' => true, 'default' => null), 'imported' => array('type' => 'datetime', 'null' => true, 'default' => null), 'duplicated' => array('type' => 'datetime', 'null' => true, 'default' => null), @@ -346,12 +353,12 @@ public function after($event = array()) { ); public $given_answers = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'index'), - 'subject_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'subject_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), 'content' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'score' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0), @@ -361,11 +368,11 @@ public function after($event = array()) { ); public $images = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'question_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'extension' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'filesize' => array('type' => 'integer', 'null' => true, 'default' => null), + 'filesize' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'file_type' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( @@ -375,9 +382,9 @@ public function after($event = array()) { ); public $instructions = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'key' => 'index'), - 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'content' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -391,17 +398,17 @@ public function after($event = array()) { ); public $items = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'index'), - 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10), - 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), + 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'correct_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'correct_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1'), - 'correct_answer_irc' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3'), - 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10), - 'missing_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1'), + 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'correct_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'correct_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0) @@ -410,12 +417,12 @@ public function after($event = array()) { ); public $question_answers = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'name' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'feedback' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'is_correct' => array('type' => 'boolean', 'null' => false, 'default' => null), - 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'question_id' => array('column' => 'question_id', 'unique' => 0) @@ -424,8 +431,10 @@ public function after($event = array()) { ); public $question_formats = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_info_diverge_url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_info_converge_url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) ), @@ -433,11 +442,12 @@ public function after($event = array()) { ); public $questions = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'code' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null), - 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'taxonomy_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'stimulus' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'comment' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'answer' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -445,7 +455,7 @@ public function after($event = array()) { 'feedback_when_correct' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'user_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'key' => 'index'), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'user_id' => array('column' => 'user_id', 'unique' => 0) @@ -454,9 +464,9 @@ public function after($event = array()) { ); public $questions_tags = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null), - 'tag_id' => array('type' => 'integer', 'null' => false, 'default' => null), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), + 'tag_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( @@ -466,7 +476,7 @@ public function after($event = array()) { ); public $queued_tasks = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'job_type' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'data' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'group' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -474,7 +484,7 @@ public function after($event = array()) { 'not_before' => array('type' => 'datetime', 'null' => true, 'default' => null), 'fetched' => array('type' => 'datetime', 'null' => true, 'default' => null), 'completed' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'failed' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10), + 'failed' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'failure_message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'worker_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => false, 'default' => null), @@ -485,7 +495,7 @@ public function after($event = array()) { ); public $roles = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) @@ -494,8 +504,8 @@ public function after($event = array()) { ); public $subjects = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), - 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'is_second_version' => array('type' => 'boolean', 'null' => false, 'default' => null), 'indexes' => array( @@ -506,9 +516,9 @@ public function after($event = array()) { ); public $tags = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'index'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( @@ -519,7 +529,7 @@ public function after($event = array()) { ); public $tips = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'content' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( @@ -529,11 +539,11 @@ public function after($event = array()) { ); public $users = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'username' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'password' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'role_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'role_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'surfconext_identifier' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'unique', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), From de1fe2863db09aaebe6992567151096c6180c352 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 14:19:59 +0100 Subject: [PATCH 02/35] Updated fixtures --- app/Test/Fixture/AnswerOptionFixture.php | 15 +++++----- app/Test/Fixture/ExamFixture.php | 24 +++++++--------- app/Test/Fixture/ExamFormatFixture.php | 5 ++-- app/Test/Fixture/ExamStateFixture.php | 5 ++-- app/Test/Fixture/GivenAnswerFixture.php | 15 +++++----- app/Test/Fixture/ImageFixture.php | 9 +++--- app/Test/Fixture/ItemFixture.php | 23 ++++++++------- app/Test/Fixture/QuestionFixture.php | 12 ++++---- app/Test/Fixture/QuestionFormatFixture.php | 33 +++++++++++++--------- app/Test/Fixture/QuestionsTagFixture.php | 9 +++--- app/Test/Fixture/SubjectFixture.php | 7 ++--- app/Test/Fixture/TagFixture.php | 7 ++--- app/Test/Fixture/UserFixture.php | 7 ++--- 13 files changed, 82 insertions(+), 89 deletions(-) diff --git a/app/Test/Fixture/AnswerOptionFixture.php b/app/Test/Fixture/AnswerOptionFixture.php index 8f026a2..cd5075c 100644 --- a/app/Test/Fixture/AnswerOptionFixture.php +++ b/app/Test/Fixture/AnswerOptionFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'), - 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), - 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'is_correct' => array('type' => 'boolean', 'null' => false, 'default' => null), - 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'given_answer_irc' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), - 'given_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => false), + 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) diff --git a/app/Test/Fixture/ExamFixture.php b/app/Test/Fixture/ExamFixture.php index d8b5653..a67880f 100644 --- a/app/Test/Fixture/ExamFixture.php +++ b/app/Test/Fixture/ExamFixture.php @@ -3,8 +3,7 @@ App::uses('ExamState', 'Model'); /** - * ExamFixture - * + * Exam Fixture */ class ExamFixture extends CakeTestFixture { @@ -14,20 +13,19 @@ class ExamFixture extends CakeTestFixture { * @var array */ public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'), - 'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'exam_state_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), + 'exam_state_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), - 'exam_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), + 'exam_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'data_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'mapping_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'average_score' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), - 'standard_deviation' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), - 'cronbachs_alpha' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), - 'report_filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), + 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), + 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'uploaded' => array('type' => 'datetime', 'null' => true, 'default' => null), 'imported' => array('type' => 'datetime', 'null' => true, 'default' => null), 'duplicated' => array('type' => 'datetime', 'null' => true, 'default' => null), @@ -66,7 +64,6 @@ class ExamFixture extends CakeTestFixture { 'average_score' => null, 'standard_deviation' => null, 'cronbachs_alpha' => null, - 'report_filename' => null, 'uploaded' => '2000-01-01 00:00:00', 'imported' => '2000-01-01 00:01:00', 'duplicated' => null, @@ -90,7 +87,6 @@ class ExamFixture extends CakeTestFixture { 'average_score' => null, 'standard_deviation' => null, 'cronbachs_alpha' => 0.737, - 'report_filename' => null, 'uploaded' => '2015-04-03 09:41:03', 'imported' => '2015-04-03 09:41:18', 'duplicated' => null, diff --git a/app/Test/Fixture/ExamFormatFixture.php b/app/Test/Fixture/ExamFormatFixture.php index e3c7fa0..2ce01e9 100644 --- a/app/Test/Fixture/ExamFormatFixture.php +++ b/app/Test/Fixture/ExamFormatFixture.php @@ -2,8 +2,7 @@ App::uses('ExamFormat', 'Model'); /** - * ExamFormatFixture - * + * ExamFormat Fixture */ class ExamFormatFixture extends CakeTestFixture { @@ -13,7 +12,7 @@ class ExamFormatFixture extends CakeTestFixture { * @var array */ public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) diff --git a/app/Test/Fixture/ExamStateFixture.php b/app/Test/Fixture/ExamStateFixture.php index 133e773..606d413 100644 --- a/app/Test/Fixture/ExamStateFixture.php +++ b/app/Test/Fixture/ExamStateFixture.php @@ -2,8 +2,7 @@ App::uses('ExamState', 'Model'); /** - * ExamStateFixture - * + * ExamState Fixture */ class ExamStateFixture extends CakeTestFixture { @@ -13,7 +12,7 @@ class ExamStateFixture extends CakeTestFixture { * @var array */ public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name_eng' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name_nld' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( diff --git a/app/Test/Fixture/GivenAnswerFixture.php b/app/Test/Fixture/GivenAnswerFixture.php index f9601d1..fefcd14 100644 --- a/app/Test/Fixture/GivenAnswerFixture.php +++ b/app/Test/Fixture/GivenAnswerFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'), - 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), - 'subject_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'item_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'subject_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), 'content' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'score' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0), @@ -36,8 +35,8 @@ class GivenAnswerFixture extends CakeTestFixture { 'item_id' => 21773, 'subject_id' => 100843, 'value' => null, - 'content' => null, - 'score' => 0.00000000 + 'score' => 0.00000000, + 'content' => null ), ); diff --git a/app/Test/Fixture/ImageFixture.php b/app/Test/Fixture/ImageFixture.php index 1343f31..3851a2e 100644 --- a/app/Test/Fixture/ImageFixture.php +++ b/app/Test/Fixture/ImageFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'question_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'filename' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'extension' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'filesize' => array('type' => 'integer', 'null' => true, 'default' => null), + 'filesize' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'file_type' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( diff --git a/app/Test/Fixture/ItemFixture.php b/app/Test/Fixture/ItemFixture.php index 5316586..320f031 100644 --- a/app/Test/Fixture/ItemFixture.php +++ b/app/Test/Fixture/ItemFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'), - 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), - 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false), - 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), + 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'correct_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'correct_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => false), - 'correct_answer_irc' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), - 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => false), - 'missing_answer_percentage' => array('type' => 'float', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => false), + 'answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'correct_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'correct_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), + 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0) diff --git a/app/Test/Fixture/QuestionFixture.php b/app/Test/Fixture/QuestionFixture.php index 01960c0..ca1c361 100644 --- a/app/Test/Fixture/QuestionFixture.php +++ b/app/Test/Fixture/QuestionFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'code' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null), - 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'taxonomy_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'stimulus' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'comment' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'answer' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -23,7 +23,7 @@ class QuestionFixture extends CakeTestFixture { 'feedback_when_correct' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'user_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'key' => 'index'), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'user_id' => array('column' => 'user_id', 'unique' => 0) diff --git a/app/Test/Fixture/QuestionFormatFixture.php b/app/Test/Fixture/QuestionFormatFixture.php index 8fc4b3b..33523c5 100644 --- a/app/Test/Fixture/QuestionFormatFixture.php +++ b/app/Test/Fixture/QuestionFormatFixture.php @@ -1,9 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_info_diverge_url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'question_info_converge_url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) ), @@ -28,20 +27,28 @@ class QuestionFormatFixture extends CakeTestFixture { */ public $records = array( array( - 'id' => '1', - 'name' => QuestionFormat::TRUE_FALSE + 'id' => QuestionFormat::TRUE_FALSE, + 'name' => 'T/F', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-t-f.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-t-f.htm' ), array( - 'id' => '2', - 'name' => QuestionFormat::MULTIPLE_CHOICE + 'id' => QuestionFormat::MULTIPLE_CHOICE, + 'name' => 'mc', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-mcq.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-mcq.htm' ), array( - 'id' => '3', - 'name' => QuestionFormat::MULTIPLE_RESPONSE + 'id' => QuestionFormat::MULTIPLE_RESPONSE, + 'name' => 'mr', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/dive-mrq.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/conv-mrq.htm' ), array( - 'id' => '4', - 'name' => QuestionFormat::OPEN_ANSWER + 'id' => QuestionFormat::OPEN_ANSWER, + 'name' => 'open', + 'question_info_diverge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/pro-con-general.htm', + 'question_info_converge_url' => 'http://testdevelopment.nl/qdst/qdst-nl/pro-con-q-formats/pro-con-general.htm' ), ); diff --git a/app/Test/Fixture/QuestionsTagFixture.php b/app/Test/Fixture/QuestionsTagFixture.php index b2be574..4706c2f 100644 --- a/app/Test/Fixture/QuestionsTagFixture.php +++ b/app/Test/Fixture/QuestionsTagFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null), - 'tag_id' => array('type' => 'integer', 'null' => false, 'default' => null), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), + 'tag_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( diff --git a/app/Test/Fixture/SubjectFixture.php b/app/Test/Fixture/SubjectFixture.php index c593157..43a257a 100644 --- a/app/Test/Fixture/SubjectFixture.php +++ b/app/Test/Fixture/SubjectFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'primary'), - 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => false, 'key' => 'index'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'is_second_version' => array('type' => 'boolean', 'null' => false, 'default' => null), 'indexes' => array( diff --git a/app/Test/Fixture/TagFixture.php b/app/Test/Fixture/TagFixture.php index 41f3c10..090793d 100644 --- a/app/Test/Fixture/TagFixture.php +++ b/app/Test/Fixture/TagFixture.php @@ -1,7 +1,6 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'index'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( diff --git a/app/Test/Fixture/UserFixture.php b/app/Test/Fixture/UserFixture.php index 37ee01d..281e7b7 100644 --- a/app/Test/Fixture/UserFixture.php +++ b/app/Test/Fixture/UserFixture.php @@ -3,8 +3,7 @@ App::uses('Security', 'Utility'); /** - * UserFixture - * + * User Fixture */ class UserFixture extends CakeTestFixture { @@ -14,11 +13,11 @@ class UserFixture extends CakeTestFixture { * @var array */ public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'username' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'password' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'role_id' => array('type' => 'integer', 'null' => true, 'default' => null), + 'role_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'surfconext_identifier' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'unique', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), From 0e5df77213f814f0c6d2f0d412faaa4a2da8f9b2 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 14:35:58 +0100 Subject: [PATCH 03/35] Added missing fixtures --- app/Test/Fixture/DevelopmentPhaseFixture.php | 42 ++++++++++++++++++++ app/Test/Fixture/InstructionFixture.php | 35 ++++++++++++++++ app/Test/Fixture/QuestionAnswerFixture.php | 33 +++++++++++++++ app/Test/Fixture/RoleFixture.php | 39 ++++++++++++++++++ app/Test/Fixture/TipFixture.php | 29 ++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 app/Test/Fixture/DevelopmentPhaseFixture.php create mode 100644 app/Test/Fixture/InstructionFixture.php create mode 100644 app/Test/Fixture/QuestionAnswerFixture.php create mode 100644 app/Test/Fixture/RoleFixture.php create mode 100644 app/Test/Fixture/TipFixture.php diff --git a/app/Test/Fixture/DevelopmentPhaseFixture.php b/app/Test/Fixture/DevelopmentPhaseFixture.php new file mode 100644 index 0000000..d8bac61 --- /dev/null +++ b/app/Test/Fixture/DevelopmentPhaseFixture.php @@ -0,0 +1,42 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'name_nld' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'name_eng' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => DevelopmentPhase::DIVERGE, + 'name_nld' => 'Divergeren', + 'name_eng' => 'Diverge' + ), + array( + 'id' => DevelopmentPhase::CONVERGE, + 'name_nld' => 'Convergeren', + 'name_eng' => 'Converge' + ), + ); + +} diff --git a/app/Test/Fixture/InstructionFixture.php b/app/Test/Fixture/InstructionFixture.php new file mode 100644 index 0000000..fafd3d4 --- /dev/null +++ b/app/Test/Fixture/InstructionFixture.php @@ -0,0 +1,35 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'development_phase_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'question_format_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'url' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'content' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'development_phase_id' => array('column' => 'development_phase_id', 'unique' => 0), + 'question_format_id' => array('column' => 'question_format_id', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array(); + +} diff --git a/app/Test/Fixture/QuestionAnswerFixture.php b/app/Test/Fixture/QuestionAnswerFixture.php new file mode 100644 index 0000000..da450d3 --- /dev/null +++ b/app/Test/Fixture/QuestionAnswerFixture.php @@ -0,0 +1,33 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'question_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'name' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'feedback' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'is_correct' => array('type' => 'boolean', 'null' => false, 'default' => null), + 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'question_id' => array('column' => 'question_id', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array(); + +} diff --git a/app/Test/Fixture/RoleFixture.php b/app/Test/Fixture/RoleFixture.php new file mode 100644 index 0000000..bbf2b3a --- /dev/null +++ b/app/Test/Fixture/RoleFixture.php @@ -0,0 +1,39 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => Role::USER, + 'name' => 'Ontwikkelaar' + ), + array( + 'id' => Role::ADMIN, + 'name' => 'Administrator' + ), + ); + +} diff --git a/app/Test/Fixture/TipFixture.php b/app/Test/Fixture/TipFixture.php new file mode 100644 index 0000000..d2be7bb --- /dev/null +++ b/app/Test/Fixture/TipFixture.php @@ -0,0 +1,29 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'content' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array(); + +} From ab5daec6e11f7408a930b8b34d21250bc0f85172 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 15:03:08 +0100 Subject: [PATCH 04/35] Removed default setting for validation rule: 'last' => true --- app/Model/Exam.php | 18 ++++++------------ app/Model/QuestionFormat.php | 1 - app/Model/Tag.php | 1 - app/Model/User.php | 5 ----- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 239ecef..435ac59 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -59,8 +59,7 @@ class Exam extends AppModel { 'notBlank' => array( 'rule' => 'notBlank', 'message' => 'This field cannot be left blank', - 'required' => 'create', - 'last' => true + 'required' => 'create' ), 'inList' => array( 'rule' => array('inList', array(ExamFormat::TELEFORM, ExamFormat::BLACKBOARD, ExamFormat::QMP), false), @@ -73,13 +72,11 @@ class Exam extends AppModel { 'extension', array('csv', 'txt') ), 'required' => 'create', - 'message' => 'Please supply a csv or txt file.', - 'last' => true + 'message' => 'Please supply a csv or txt file.' ), 'fileSize' => array( 'rule' => array('filesize', '<=', '8MB'), - 'message' => 'File must be less than 8 MB', - 'last' => true + 'message' => 'File must be less than 8 MB' ), 'uploadError' => array( 'rule' => 'uploadError', @@ -92,14 +89,12 @@ class Exam extends AppModel { 'extension', array('csv'), ), 'allowEmpty' => true, - 'message' => 'Please supply a csv file.', - 'last' => true + 'message' => 'Please supply a csv file.' ), 'fileSize' => array( 'rule' => array('filesize', '<=', '1MB'), 'allowEmpty' => true, - 'message' => 'File must be less than 1 MB', - 'last' => true + 'message' => 'File must be less than 1 MB' ), 'uploadError' => array( 'rule' => 'uploadError', @@ -110,8 +105,7 @@ class Exam extends AppModel { 'naturalNumber' => array( 'rule' => 'naturalNumber', 'required' => 'create', - 'message' => 'Please supply the default number of answer options.', - 'last' => true + 'message' => 'Please supply the default number of answer options.' ), 'comparison' => array( 'rule' => array('comparison', '<=', 8), diff --git a/app/Model/QuestionFormat.php b/app/Model/QuestionFormat.php index 32a8bc2..6b4cdec 100644 --- a/app/Model/QuestionFormat.php +++ b/app/Model/QuestionFormat.php @@ -24,7 +24,6 @@ class QuestionFormat extends AppModel { 'name' => array( 'notBlank' => array( 'rule' => 'notBlank', - 'last' => true, 'message' => 'This field cannot be left blank' ), 'required' => array( diff --git a/app/Model/Tag.php b/app/Model/Tag.php index fd2fd3d..a1e5a9e 100644 --- a/app/Model/Tag.php +++ b/app/Model/Tag.php @@ -24,7 +24,6 @@ class Tag extends AppModel { 'name' => array( 'notBlank' => array( 'rule' => 'notBlank', - 'last' => true, 'message' => 'This field cannot be left blank' ), 'required' => array( diff --git a/app/Model/User.php b/app/Model/User.php index 1e49631..1b366c9 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -17,12 +17,10 @@ class User extends AppModel { 'email' => array( 'rule' => 'email', 'allowEmpty' => false, - 'last' => true, 'message' => 'Please supply a valid email address.' ), 'isUnique' => array( 'rule' => 'isUnique', - 'last' => true, 'message' => 'This username has already been taken.' ), 'required' => array( @@ -34,7 +32,6 @@ class User extends AppModel { 'name' => array( 'notBlank' => array( 'rule' => 'notBlank', - 'last' => true, 'message' => 'This field cannot be left blank' ), 'required' => array( @@ -57,7 +54,6 @@ class User extends AppModel { 'minLength' => array( 'rule' => array('minLength', 6), 'allowEmpty' => false, - 'last' => true, 'message' => 'Passwords must be at least 8 characters long.' ), 'required' => array( @@ -68,7 +64,6 @@ class User extends AppModel { 'role_id' => array( 'notBlank' => array( 'rule' => 'notBlank', - 'last' => true, 'message' => 'This field cannot be left blank' ), 'required' => array( From ba4d24660cb08030c879fb9e520a9b1a5927e8ff Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 15:24:29 +0100 Subject: [PATCH 05/35] Fixed: PHP Fatal error: Class 'QuestionFormat' not found --- app/Test/Fixture/QuestionFormatFixture.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Test/Fixture/QuestionFormatFixture.php b/app/Test/Fixture/QuestionFormatFixture.php index 33523c5..4117463 100644 --- a/app/Test/Fixture/QuestionFormatFixture.php +++ b/app/Test/Fixture/QuestionFormatFixture.php @@ -1,4 +1,6 @@ Date: Thu, 10 Dec 2015 15:31:58 +0100 Subject: [PATCH 06/35] Added Domain model and associations --- app/Model/Domain.php | 75 ++++++++++++++++++++++++++++++++++++++++++++ app/Model/Exam.php | 14 ++++++--- app/Model/Item.php | 7 ++++- 3 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 app/Model/Domain.php diff --git a/app/Model/Domain.php b/app/Model/Domain.php new file mode 100644 index 0000000..25755aa --- /dev/null +++ b/app/Model/Domain.php @@ -0,0 +1,75 @@ + array( + 'notBlank' => array( + 'rule' => 'notBlank', + 'message' => 'This field cannot be left blank' + ), + 'required' => array( + 'rule' => 'notBlank', + 'required' => true, + 'on' => 'create' + ) + ), + 'name' => array( + 'notBlank' => array( + 'rule' => 'notBlank', + 'message' => 'This field cannot be left blank' + ), + 'maxLength' => array( + 'rule' => array('maxLength', 255), + 'allowEmpty' => false, + 'message' => 'Can not be longer than %d characters.' + ), + 'isUnique' => array( + 'rule' => array('isUnique', array('exam_id', 'name'), false), + 'message' => 'This name has already been taken for this exam.' + ), + 'required' => array( + 'rule' => 'notBlank', + 'required' => true, + 'on' => 'create' + ) + ) + ); + +/** + * belongsTo associations + * + * @var array + */ + public $belongsTo = array( + 'Exam' => array( + 'className' => 'Exam', + 'foreignKey' => 'exam_id' + ) + ); + +/** + * hasMany associations + * + * @var array + */ + public $hasMany = array( + 'Item' => array( + 'className' => 'Item', + 'foreignKey' => 'domain_id', + 'dependent' => false + ) + ); + +} diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 435ac59..583ca47 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -11,13 +11,14 @@ /** * Exam Model * - * @property User $User - * @property Item $Item - * @property Subject $Subject + * @property Exam $Child + * @property Domain $Domain * @property ExamFormat $ExamFormat * @property ExamState $ExamState + * @property Item $Item * @property Exam $Parent - * @property Exam $Child + * @property Subject $Subject + * @property User $User */ class Exam extends AppModel { @@ -169,6 +170,11 @@ class Exam extends AppModel { 'foreignKey' => 'parent_id', 'dependent' => false ), + 'Domain' => array( + 'className' => 'Domain', + 'foreignKey' => 'exam_id', + 'dependent' => true + ), 'Item' => array( 'className' => 'Item', 'foreignKey' => 'exam_id', diff --git a/app/Model/Item.php b/app/Model/Item.php index 16ff716..267518d 100644 --- a/app/Model/Item.php +++ b/app/Model/Item.php @@ -3,8 +3,9 @@ /** * Item Model * - * @property Exam $Exam * @property AnswerOption $AnswerOption + * @property Domain $Domain + * @property Exam $Exam */ class Item extends AppModel { @@ -21,6 +22,10 @@ class Item extends AppModel { * @var array */ public $belongsTo = array( + 'Domain' => array( + 'className' => 'Domain', + 'foreignKey' => 'exam_id' + ), 'Exam' => array( 'className' => 'Exam', 'foreignKey' => 'exam_id' From 15aac50082b35a5d368c655a6ea07fbcc5c95608 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 10 Dec 2015 17:18:09 +0100 Subject: [PATCH 07/35] Refactoring and adding test --- app/Model/Exam.php | 83 +++++++++++++++++++------------- app/Test/Case/Model/ExamTest.php | 32 ++++++++++++ 2 files changed, 81 insertions(+), 34 deletions(-) diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 583ca47..e70d7a3 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -1061,40 +1061,7 @@ public function importTeleform($exam) { $versionMappingFilename = Exam::UPLOADS . $exam['Exam']['mapping_filename']; } - if (!empty($versionMappingFilename)) { - ini_set('auto_detect_line_endings', true); - if (($handle = fopen($versionMappingFilename, "r")) !== false) { - $version1Index = false; - $version2Index = false; - $answerOptionCountIndex = false; - for ($i = 0; !feof($handle); $i++) { - $line = fgets($handle); - $line = $this->__decodeLine($line, $i == 0); - - if ($i == 0) { - $header = str_getcsv($line, ';', '"', '"'); - - $version1Index = $this->_getIndexOfVersionFromTeleformHeader($header, 1); - $version2Index = $this->_getIndexOfVersionFromTeleformHeader($header, 2); - $answerOptionCountIndex = array_search('Answer Option Count', $header); - } else { - $values = str_getcsv($line, ';', '"', '"'); - if (count($values) <= 1) { - continue; - } - if ($version1Index !== false && $version2Index !== false) { - $versionMapping[2][$values[$version1Index]] = intval($values[$version2Index]); - } - - if ($version1Index !== false && $answerOptionCountIndex !== false) { - $answerOptionCount[$values[$version1Index]] = intval($values[$answerOptionCountIndex]); - } - } - } - - fclose($handle); - } - } + list($versionMapping, $answerOptionCount) = $this->_extractMappingfile($versionMappingFilename); $result = true; ini_set('auto_detect_line_endings', true); @@ -1548,4 +1515,52 @@ protected function _executeAnalysis($questionCount, $studentCount, $maxAnswerOpt return Rserve::execute($script); } +/** + * Extract verion mapping and answer option count from Teleform mapping file + * + * @param string $filename Filename of a Teleform mapping file + * @return array List of verion mappings and answer option counts + */ + protected function _extractMappingfile($filename) { + $versionMapping = array(); + $answerOptionCount = array(); + + if (!empty($filename) && file_exists($filename)) { + ini_set('auto_detect_line_endings', true); + if (($handle = fopen($filename, "r")) !== false) { + $version1Index = false; + $version2Index = false; + $answerOptionCountIndex = false; + for ($i = 0; !feof($handle); $i++) { + $line = fgets($handle); + $line = $this->__decodeLine($line, $i == 0); + + if ($i == 0) { + $header = str_getcsv($line, ';', '"', '"'); + + $version1Index = $this->_getIndexOfVersionFromTeleformHeader($header, 1); + $version2Index = $this->_getIndexOfVersionFromTeleformHeader($header, 2); + $answerOptionCountIndex = array_search('Answer Option Count', $header); + } else { + $values = str_getcsv($line, ';', '"', '"'); + if (count($values) <= 1) { + continue; + } + if ($version1Index !== false && $version2Index !== false) { + $versionMapping[2][$values[$version1Index]] = intval($values[$version2Index]); + } + + if ($version1Index !== false && $answerOptionCountIndex !== false) { + $answerOptionCount[$values[$version1Index]] = intval($values[$answerOptionCountIndex]); + } + } + } + + fclose($handle); + } + } + + return array($versionMapping, $answerOptionCount); + } + } diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index a5e3a3f..997840d 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -45,6 +45,14 @@ public function duplicate($postData) { return parent::_duplicate($postData); } +/** + * Public test double of `parent::_extractMappingfile`. + * + */ + public function extractMappingfile($filename) { + return parent::_extractMappingfile($filename); + } + } /** @@ -399,4 +407,28 @@ public function testDuplicate() { $this->assertEquals($expected, $result); } +/** + * testExtractMappingfile method + * + * @return void + */ + public function testExtractMappingfile() { + $expectedVersionMapping = array( + 2 => array( + 1 => 2, + 2 => 1 + ) + ); + $expectedAnswerOptionCount = array( + 1 => 3, + 2 => 3 + ); + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform.mappingfile.csv'; + $result = $this->Exam->extractMappingfile($filename); + $this->assertTrue((bool)$result); + list($versionMapping, $answerOptionCount) = $result; + $this->assertEquals($expectedVersionMapping, $versionMapping); + $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); + } + } From 9094ae2449b8e2703e032f6bc405b24c2d63c331 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 14 Dec 2015 10:36:30 +0100 Subject: [PATCH 08/35] Added missing file --- app/Test/File/Exam/Teleform.mappingfile.csv | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/Test/File/Exam/Teleform.mappingfile.csv diff --git a/app/Test/File/Exam/Teleform.mappingfile.csv b/app/Test/File/Exam/Teleform.mappingfile.csv new file mode 100644 index 0000000..2007c36 --- /dev/null +++ b/app/Test/File/Exam/Teleform.mappingfile.csv @@ -0,0 +1,3 @@ +versie.1;versie.2;Answer Option Count +1;2;3 +2;1;3 From e97b650ed3860d5351b3ac510e5e8163045ddbe5 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 14 Dec 2015 11:15:06 +0100 Subject: [PATCH 09/35] Updated database schema --- app/Config/Schema/schema.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index b36b1a0..5c2288d 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -301,6 +301,20 @@ public function after($event = array()) { 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); + public $domains = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), + 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), + 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'exam_id' => array('column' => 'exam_id', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + public $exam_formats = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -400,6 +414,7 @@ public function after($event = array()) { public $items = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'domain_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -411,7 +426,8 @@ public function after($event = array()) { 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'exam_id' => array('column' => 'exam_id', 'unique' => 0) + 'exam_id' => array('column' => 'exam_id', 'unique' => 0), + 'domain_id' => array('column' => 'domain_id', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); From 287b2ab91de684e3b2e3ffd6cfccf109c2cf27f0 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 14 Dec 2015 11:31:28 +0100 Subject: [PATCH 10/35] Added Domain Fixture --- app/Test/Fixture/DomainFixture.php | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/Test/Fixture/DomainFixture.php diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/DomainFixture.php new file mode 100644 index 0000000..82267cc --- /dev/null +++ b/app/Test/Fixture/DomainFixture.php @@ -0,0 +1,33 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), + 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), + 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'exam_id' => array('column' => 'exam_id', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array(); + +} From 6d84d607c1b2d98cf4a29ca1e36eb00d46c24b98 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 14 Dec 2015 11:32:03 +0100 Subject: [PATCH 11/35] Added tests for other columns headers in Teleform mapping files --- app/Test/Case/Model/ExamTest.php | 21 +++++++++++++------ ...-with-spaces-in-version-column-headers.csv | 3 +++ ...d-lower-case-in-version-column-headers.csv | 3 +++ ...ppingfile.csv => Teleform-mappingfile.csv} | 0 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-spaces-in-version-column-headers.csv create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-upper-and-lower-case-in-version-column-headers.csv rename app/Test/File/Exam/{Teleform.mappingfile.csv => Teleform-mappingfile.csv} (100%) diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index 997840d..9dfa192 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -413,6 +413,12 @@ public function testDuplicate() { * @return void */ public function testExtractMappingfile() { + $files = array( + 'Teleform-mappingfile.csv', + 'Teleform-mappingfile-with-spaces-in-version-column-headers.csv', + 'Teleform-mappingfile-with-upper-and-lower-case-in-version-column-headers.csv' + ); + $expectedVersionMapping = array( 2 => array( 1 => 2, @@ -423,12 +429,15 @@ public function testExtractMappingfile() { 1 => 3, 2 => 3 ); - $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform.mappingfile.csv'; - $result = $this->Exam->extractMappingfile($filename); - $this->assertTrue((bool)$result); - list($versionMapping, $answerOptionCount) = $result; - $this->assertEquals($expectedVersionMapping, $versionMapping); - $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); + + foreach ($files as $file) { + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform.mappingfile.csv'; + $result = $this->Exam->extractMappingfile($filename); + $this->assertTrue((bool)$result); + list($versionMapping, $answerOptionCount) = $result; + $this->assertEquals($expectedVersionMapping, $versionMapping); + $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); + } } } diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-spaces-in-version-column-headers.csv b/app/Test/File/Exam/Teleform-mappingfile-with-spaces-in-version-column-headers.csv new file mode 100644 index 0000000..6b6e600 --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-spaces-in-version-column-headers.csv @@ -0,0 +1,3 @@ +versie 1;versie 2;Answer Option Count +1;2;3 +2;1;3 diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-upper-and-lower-case-in-version-column-headers.csv b/app/Test/File/Exam/Teleform-mappingfile-with-upper-and-lower-case-in-version-column-headers.csv new file mode 100644 index 0000000..0627fd7 --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-upper-and-lower-case-in-version-column-headers.csv @@ -0,0 +1,3 @@ +Versie.1;vErSiE.2;Answer Option Count +1;2;3 +2;1;3 diff --git a/app/Test/File/Exam/Teleform.mappingfile.csv b/app/Test/File/Exam/Teleform-mappingfile.csv similarity index 100% rename from app/Test/File/Exam/Teleform.mappingfile.csv rename to app/Test/File/Exam/Teleform-mappingfile.csv From 9ebb9d224ecca653b220649bbb945492670baebd Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 14 Dec 2015 17:26:08 +0100 Subject: [PATCH 12/35] Added support for import of domain in Teleform mapping file --- app/Model/Domain.php | 38 ++++++++++ app/Model/Exam.php | 28 ++++--- app/Test/Case/Model/ExamTest.php | 75 +++++++++++++++++-- ...ith-domain-without-answer-option-count.csv | 3 + .../Exam/Teleform-mappingfile-with-domain.csv | 3 + 5 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-domain.csv diff --git a/app/Model/Domain.php b/app/Model/Domain.php index 25755aa..5f98a61 100644 --- a/app/Model/Domain.php +++ b/app/Model/Domain.php @@ -72,4 +72,42 @@ class Domain extends AppModel { ) ); +/** + * Creates domains and returns ids + * + * @param int $examId An exam id + * @param array $names An array with names of domains + * @return array An array with domain ids + */ + public function createDomains($examId, $names) { + $domainIds = array(); + if (!empty($names)) { + $uniqueNames = array_values($names); + $uniqueNames = array_unique($uniqueNames); + + $data = array('Domain' => array()); + foreach ($uniqueNames as $name) { + $data['Domain'][] = array( + 'exam_id' => $examId, + 'name' => $name + ); + } + $this->create(); + $this->saveAll($data); + + $conditions = array('Domain.exam_id' => $examId); + $domains = $this->find('list', compact('conditions')); + + foreach ($names as $i => $name) { + foreach ($domains as $id => $domain) { + if ($name === $domain) { + $domainIds[$i] = $id; + break; + } + } + } + return $domainIds; + } + } + } diff --git a/app/Model/Exam.php b/app/Model/Exam.php index e70d7a3..b3c5129 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -1061,7 +1061,9 @@ public function importTeleform($exam) { $versionMappingFilename = Exam::UPLOADS . $exam['Exam']['mapping_filename']; } - list($versionMapping, $answerOptionCount) = $this->_extractMappingfile($versionMappingFilename); + list($versionMapping, $answerOptionCount, $domains) = $this->_extractTeleformMappingfile($versionMappingFilename); + + $domainIds = $this->Domain->createDomains($exam['Exam']['id'], $domains); $result = true; ini_set('auto_detect_line_endings', true); @@ -1089,6 +1091,7 @@ public function importTeleform($exam) { $item = array( 'exam_id' => $exam['Exam']['id'], + 'domain_id' => Hash::get($domainIds, $j - 1), 'order' => $j - 1, 'second_version_order' => $secondVersionOrder, 'value' => $j - 1 @@ -1516,14 +1519,15 @@ protected function _executeAnalysis($questionCount, $studentCount, $maxAnswerOpt } /** - * Extract verion mapping and answer option count from Teleform mapping file + * Extract version mappings, answer option counts and domains from Teleform mapping file * * @param string $filename Filename of a Teleform mapping file - * @return array List of verion mappings and answer option counts + * @return array List of verion mappings, answer option counts and domains */ - protected function _extractMappingfile($filename) { - $versionMapping = array(); - $answerOptionCount = array(); + protected function _extractTeleformMappingfile($filename) { + $versionMappings = array(); + $answerOptionCounts = array(); + $domains = array(); if (!empty($filename) && file_exists($filename)) { ini_set('auto_detect_line_endings', true); @@ -1531,6 +1535,7 @@ protected function _extractMappingfile($filename) { $version1Index = false; $version2Index = false; $answerOptionCountIndex = false; + $domainIndex = false; for ($i = 0; !feof($handle); $i++) { $line = fgets($handle); $line = $this->__decodeLine($line, $i == 0); @@ -1541,17 +1546,22 @@ protected function _extractMappingfile($filename) { $version1Index = $this->_getIndexOfVersionFromTeleformHeader($header, 1); $version2Index = $this->_getIndexOfVersionFromTeleformHeader($header, 2); $answerOptionCountIndex = array_search('Answer Option Count', $header); + $domainIndex = array_search('Domain', $header); } else { $values = str_getcsv($line, ';', '"', '"'); if (count($values) <= 1) { continue; } if ($version1Index !== false && $version2Index !== false) { - $versionMapping[2][$values[$version1Index]] = intval($values[$version2Index]); + $versionMappings[2][$values[$version1Index]] = intval($values[$version2Index]); } if ($version1Index !== false && $answerOptionCountIndex !== false) { - $answerOptionCount[$values[$version1Index]] = intval($values[$answerOptionCountIndex]); + $answerOptionCounts[$values[$version1Index]] = intval($values[$answerOptionCountIndex]); + } + + if ($version1Index !== false && $domainIndex !== false) { + $domains[$values[$version1Index]] = $values[$domainIndex]; } } } @@ -1560,7 +1570,7 @@ protected function _extractMappingfile($filename) { } } - return array($versionMapping, $answerOptionCount); + return array($versionMappings, $answerOptionCounts, $domains); } } diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index 9dfa192..37efd27 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -46,11 +46,11 @@ public function duplicate($postData) { } /** - * Public test double of `parent::_extractMappingfile`. + * Public test double of `parent::_extractTeleformMappingfile`. * */ - public function extractMappingfile($filename) { - return parent::_extractMappingfile($filename); + public function extractTeleformMappingfile($filename) { + return parent::_extractTeleformMappingfile($filename); } } @@ -408,11 +408,11 @@ public function testDuplicate() { } /** - * testExtractMappingfile method + * testExtractTeleformMappingfile method * * @return void */ - public function testExtractMappingfile() { + public function testExtractTeleformMappingfile() { $files = array( 'Teleform-mappingfile.csv', 'Teleform-mappingfile-with-spaces-in-version-column-headers.csv', @@ -431,13 +431,72 @@ public function testExtractMappingfile() { ); foreach ($files as $file) { - $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform.mappingfile.csv'; - $result = $this->Exam->extractMappingfile($filename); + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . $file; + $result = $this->Exam->extractTeleformMappingfile($filename); $this->assertTrue((bool)$result); - list($versionMapping, $answerOptionCount) = $result; + list($versionMapping, $answerOptionCount, $domains) = $result; $this->assertEquals($expectedVersionMapping, $versionMapping); $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); + $this->assertEmpty($domains); } } +/** + * testExtractTeleformMappingfileWithDomain method + * + * @return void + */ + public function testExtractTeleformMappingfileWithDomain() { + $expectedVersionMapping = array( + 2 => array( + 1 => 2, + 2 => 1 + ) + ); + $expectedAnswerOptionCount = array( + 1 => 3, + 2 => 3 + ); + + $expectedDomains = array( + 1 => 'M', + 2 => 'G' + ); + + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-domain.csv'; + $result = $this->Exam->extractTeleformMappingfile($filename); + $this->assertTrue((bool)$result); + list($versionMapping, $answerOptionCount, $domains) = $result; + $this->assertEquals($expectedVersionMapping, $versionMapping); + $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); + $this->assertEquals($expectedDomains, $domains); + } + +/** + * testExtractTeleformMappingfileWithDomainWithoutAnswerOptionCount method + * + * @return void + */ + public function testExtractTeleformMappingfileWithDomainWithoutAnswerOptionCount() { + $expectedVersionMapping = array( + 2 => array( + 1 => 2, + 2 => 1 + ) + ); + + $expectedDomains = array( + 1 => 'M', + 2 => 'G' + ); + + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-domain-without-answer-option-count.csv'; + $result = $this->Exam->extractTeleformMappingfile($filename); + $this->assertTrue((bool)$result); + list($versionMapping, $answerOptionCount, $domains) = $result; + $this->assertEquals($expectedVersionMapping, $versionMapping); + $this->assertEmpty($answerOptionCount); + $this->assertEquals($expectedDomains, $domains); + } + } diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv b/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv new file mode 100644 index 0000000..5036d5c --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv @@ -0,0 +1,3 @@ +versie.1;versie.2;Domain +1;2;M +2;1;G diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv b/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv new file mode 100644 index 0000000..b185ad3 --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv @@ -0,0 +1,3 @@ +versie.1;versie.2;Answer Option Count;Domain +1;2;3;M +2;1;3;G From 3c73d3285c04cffd3eb9be59705570aac8b05fb4 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 16 Dec 2015 15:18:04 +0100 Subject: [PATCH 13/35] Removed unused fields --- app/Config/Schema/schema.php | 2 -- app/Test/Fixture/DomainFixture.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index 6d1787e..7284002 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -305,8 +305,6 @@ public function after($event = array()) { 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), - 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/DomainFixture.php index 82267cc..44af888 100644 --- a/app/Test/Fixture/DomainFixture.php +++ b/app/Test/Fixture/DomainFixture.php @@ -13,8 +13,6 @@ class DomainFixture extends CakeTestFixture { 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'average_score' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,3', 'unsigned' => false), - 'standard_deviation' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '10,8', 'unsigned' => false), 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), From 8753a82e7392063f030f20416e3004d65eb08f5c Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 16 Dec 2015 17:10:45 +0100 Subject: [PATCH 14/35] Refactoring --- app/Model/Exam.php | 74 ++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 6df2f8c..e6db9d2 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -341,7 +341,7 @@ public function analyse($id) { $conditions = array('Exam.id' => $id); $exam = $this->find('first', compact('conditions')); if (!empty($exam)) { - return $this->__analyse($exam); + return $this->__analyse($id); } return false; } @@ -349,41 +349,14 @@ public function analyse($id) { /** * __analyse * - * @param array $exam Exam data + * @param int $id An exam id * @return bool */ - private function __analyse($exam) { - $this->id = $exam['Exam']['id']; + private function __analyse($id) { + $this->id = $id; $this->saveField('exam_state_id', ExamState::ANALYSING); - $conditions = array('Exam.id' => $exam['Exam']['id']); - $contain = array( - 'Item' => 'AnswerOption', - 'Subject' => 'GivenAnswer' - ); - $exam = $this->find('first', compact('conditions', 'contain')); - $fields = array('MAX(Item.answer_option_count) as answer_option_count'); - $conditions = array('Item.exam_id' => $exam['Exam']['id']); - $maxAnswerOptionCount = $this->Item->find('first', compact('fields', 'conditions')); - $maxAnswerOptionCount = $maxAnswerOptionCount[0]['answer_option_count']; - - $questionCount = count($exam['Item']); - $studentCount = count($exam['Subject']); - - $answerOptionCount = array(); - for ($i = 0; $i < $questionCount; $i++) { - $answerOptionCount[$i] = $exam['Item'][$i]['answer_option_count']; - } - - $givenAnswers = array(); - for ($i = 0; $i < $studentCount; $i++) { - $givenAnswerCount = count($exam['Subject'][$i]['GivenAnswer']); - for ($j = 0; $j < $givenAnswerCount; $j++) { - $givenAnswers[$i][$j] = $exam['Subject'][$i]['GivenAnswer'][$j]['value']; - } - } - - $result = $this->_executeAnalysis($questionCount, $studentCount, $maxAnswerOptionCount, $exam, $givenAnswers, $answerOptionCount); + $result = $this->executeAnalysis($id); if ($result) { $cronbachsAlpha = $result[0]; @@ -440,6 +413,43 @@ private function __analyse($exam) { return $result; } +/** + * Execute analysis + * + * @param int $id An exam id + * @return array + */ + public function executeAnalysis($id) { + $conditions = array('Exam.id' => $id); + $contain = array( + 'Item' => 'AnswerOption', + 'Subject' => 'GivenAnswer' + ); + $exam = $this->find('first', compact('conditions', 'contain')); + $fields = array('MAX(Item.answer_option_count) as answer_option_count'); + $conditions = array('Item.exam_id' => $exam['Exam']['id']); + $maxAnswerOptionCount = $this->Item->find('first', compact('fields', 'conditions')); + $maxAnswerOptionCount = $maxAnswerOptionCount[0]['answer_option_count']; + + $questionCount = count($exam['Item']); + $studentCount = count($exam['Subject']); + + $answerOptionCount = array(); + for ($i = 0; $i < $questionCount; $i++) { + $answerOptionCount[$i] = $exam['Item'][$i]['answer_option_count']; + } + + $givenAnswers = array(); + for ($i = 0; $i < $studentCount; $i++) { + $givenAnswerCount = count($exam['Subject'][$i]['GivenAnswer']); + for ($j = 0; $j < $givenAnswerCount; $j++) { + $givenAnswers[$i][$j] = $exam['Subject'][$i]['GivenAnswer'][$j]['value']; + } + } + + return $this->_executeAnalysis($questionCount, $studentCount, $maxAnswerOptionCount, $exam, $givenAnswers, $answerOptionCount); + } + /** * scheduleReport * From 658f3cd027280d645db3e571fb07b87693253637 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 16 Dec 2015 17:27:42 +0100 Subject: [PATCH 15/35] Added support to filter items by domain when analysing an exam --- app/Model/Domain.php | 19 +++++++++++++++++++ app/Model/Exam.php | 21 ++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/Model/Domain.php b/app/Model/Domain.php index 5f98a61..7e5ff4f 100644 --- a/app/Model/Domain.php +++ b/app/Model/Domain.php @@ -72,6 +72,25 @@ class Domain extends AppModel { ) ); +/** + * analyse + * + * @param int $id A domain id + * @param int $examId An exam id + * @return bool + */ + public function analyse($id, $examId) { + $result = $this->Exam->executeAnalysis($id, $examId); + + if ($result) { + $cronbachsAlpha = $result[0]; + + $this->id = $id; + $this->saveField('cronbachs_alpha', $cronbachsAlpha); + } + return $result; + } + /** * Creates domains and returns ids * diff --git a/app/Model/Exam.php b/app/Model/Exam.php index e6db9d2..6275d2a 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -417,17 +417,32 @@ private function __analyse($id) { * Execute analysis * * @param int $id An exam id + * @param int[optional] $domainId A domain id * @return array */ - public function executeAnalysis($id) { + public function executeAnalysis($id, $domainId = null) { $conditions = array('Exam.id' => $id); $contain = array( - 'Item' => 'AnswerOption', - 'Subject' => 'GivenAnswer' + 'Item' => array('AnswerOption'), + 'Subject' => array('GivenAnswer') ); + if ($domainId !== null) { + $fields = array('Item.id', 'Item.id'); + $conditions = array( + 'Item.exam_id' => $examId, + 'Item.domain_id' => $id + ); + $itemIds = $this->Item->find('list', compact('fields', 'conditions')); + + $contain['Item']['conditions'] = array('Item.domain_id' => $domainId); + $contain['Subject']['conditions'] = array('GivenAnswer.item_id' => $itemIds); + } $exam = $this->find('first', compact('conditions', 'contain')); $fields = array('MAX(Item.answer_option_count) as answer_option_count'); $conditions = array('Item.exam_id' => $exam['Exam']['id']); + if ($domainId !== null) { + $conditions['Item.domain_id'] = $domainId; + } $maxAnswerOptionCount = $this->Item->find('first', compact('fields', 'conditions')); $maxAnswerOptionCount = $maxAnswerOptionCount[0]['answer_option_count']; From 8042f43553296186b5d0cfeb981dd7b86d19185d Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Fri, 18 Dec 2015 13:33:02 +0100 Subject: [PATCH 16/35] Updated fixture --- app/Test/Fixture/ItemFixture.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Test/Fixture/ItemFixture.php b/app/Test/Fixture/ItemFixture.php index 320f031..7bb96ae 100644 --- a/app/Test/Fixture/ItemFixture.php +++ b/app/Test/Fixture/ItemFixture.php @@ -12,6 +12,7 @@ class ItemFixture extends CakeTestFixture { public $fields = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'domain_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -23,7 +24,8 @@ class ItemFixture extends CakeTestFixture { 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'exam_id' => array('column' => 'exam_id', 'unique' => 0) + 'exam_id' => array('column' => 'exam_id', 'unique' => 0), + 'domain_id' => array('column' => 'domain_id', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); @@ -37,6 +39,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1, 'exam_id' => 2, + 'domain_id' => null, 'order' => 1, 'second_version_order' => null, 'value' => '1B 05 individualisering 002', @@ -50,6 +53,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 21773, 'exam_id' => 747, + 'domain_id' => null, 'order' => 35, 'second_version_order' => null, 'value' => '35', From f57166566272cdd2f63265af4cabe1af4a5bd62d Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 6 Jan 2016 14:36:33 +0100 Subject: [PATCH 17/35] Add support for item domains --- app/Config/Schema/schema.php | 2 + app/Model/AppModel.php | 78 +++++++++++++++++++ app/Model/Domain.php | 33 ++++++-- app/Model/Exam.php | 63 +++------------- app/Model/Item.php | 23 +++++- app/Test/Case/Model/ItemTest.php | 96 ++++++++++++++++++++++++ app/Test/Case/View/Helper/empty | 0 app/Test/Fixture/AnswerOptionFixture.php | 1 + app/Test/Fixture/DomainFixture.php | 15 +++- app/Test/Fixture/ItemFixture.php | 29 +++++++ 10 files changed, 282 insertions(+), 58 deletions(-) create mode 100644 app/Test/Case/Model/ItemTest.php delete mode 100644 app/Test/Case/View/Helper/empty diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index 7284002..8a89a0e 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -284,6 +284,7 @@ public function after($event = array()) { 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'domain_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) @@ -420,6 +421,7 @@ public function after($event = array()) { 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'domain_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0), diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 9178f1d..b65c56f 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -113,4 +113,82 @@ public function removeFieldFromSchema($fieldname) { unset($this->_schema[$fieldname]); } +/** + * Save analysis to an ezam or a domain + * + * @param int $id An domain/exam id + * @param array $analysis An array with analysis data + * @return bool True on success, or false on failure. + * @throws NotImplementedException + */ + public function saveAnalysis($id, $analysis) { + if (!in_array($this->alias, array('Domain', 'Exam'))) { + throw new NotImplementedException(); + } + + $cronbachsAlpha = $result[0]; + $maxAnswerOptionCount = $result[1]; + $correctAnswerCount = $result[2]; + $correctAnswerPercentage = $result[3]; + $correctAnswerIrc = $result[4]; + $givenAnswerOptionCount = $result[5]; + $givenAnswerOptionPercentage = $result[6]; + $givenAnswerOptionIrc = $result[7]; + + $conditions = array(sprintf('%s.id', $this->alias) => $id); + $contain = array('Item' => array('AnswerOption')); + $object = $this->find('first', compact('conditions', 'contain')); + + if ($this->alias === 'Domain') { + $data = array( + 'Domain' =>array( + 'id' => $id, + 'cronbachs_alpha' => $cronbachsAlpha, + ) + ); + } elseif ($this->alias === 'Exam') { + $data = array( + 'Exam' => array( + 'id' => $id, + 'exam_state_id' => ExamState::ANALYSED, + 'cronbachs_alpha' => $cronbachsAlpha, + 'max_answer_option_count' => $maxAnswerOptionCount, + 'analysed' => date('Y-m-d H:i:s') + ) + ); + } + + foreach ($object['Item'] as $i => $item) { + $data['Item'][$i] = array('id' => $item['id']); + if ($this->alias === 'Domain') { + $data['Item'][$i]['domain_correct_answer_irc'] = $correctAnswerIrc[$i]; + } elseif ($this->alias === 'Exam') { + $data['Item'][$i]['correct_answer_count'] = $correctAnswerCount[$i]; + $data['Item'][$i]['correct_answer_percentage'] = $correctAnswerPercentage[$i]; + $data['Item'][$i]['correct_answer_irc'] = $correctAnswerIrc[$i]; + $data['Item'][$i]['missing_answer_count'] = $givenAnswerOptionCount[$i * ($maxAnswerOptionCount + 1)]; + $data['Item'][$i]['missing_answer_percentage'] = $givenAnswerOptionPercentage[$i * ($maxAnswerOptionCount + 1)]; + } + + for ($j = 0; !empty($item['answer_option_count']) && $j < $item['answer_option_count']; $j++) { + if (empty($item['AnswerOption'][$j]['id'])) { + $data['Item'][$i]['AnswerOption'][$j]['order'] = ($j + 1); + } else { + $data['Item'][$i]['AnswerOption'][$j]['id'] = $item['AnswerOption'][$j]['id']; + } + + if ($this->alias === 'Domain') { + $data['Item'][$i]['AnswerOption'][$j]['domain_given_answer_irc'] = (is_nan($givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1])?null:$givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1]); + } elseif ($this->alias === 'Exam') { + $data['Item'][$i]['AnswerOption'][$j]['given_answer_count'] = $givenAnswerOptionCount[$i * ($maxAnswerOptionCount + 1) + $j + 1]; + $data['Item'][$i]['AnswerOption'][$j]['given_answer_percentage'] = $givenAnswerOptionPercentage[$i * ($maxAnswerOptionCount + 1) + $j + 1]; + $data['Item'][$i]['AnswerOption'][$j]['given_answer_irc'] = (is_nan($givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1])?null:$givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1]); + } else { + } + } + } + $this->id = $id; + return $this->saveAll($data, array('deep' => true)); + } + } diff --git a/app/Model/Domain.php b/app/Model/Domain.php index 7e5ff4f..3f8d8df 100644 --- a/app/Model/Domain.php +++ b/app/Model/Domain.php @@ -80,13 +80,10 @@ class Domain extends AppModel { * @return bool */ public function analyse($id, $examId) { - $result = $this->Exam->executeAnalysis($id, $examId); + $result = $this->Exam->executeAnalysis($examId, $id); if ($result) { - $cronbachsAlpha = $result[0]; - - $this->id = $id; - $this->saveField('cronbachs_alpha', $cronbachsAlpha); + $result = $this->saveAnalysis($id, $result); } return $result; } @@ -129,4 +126,30 @@ public function createDomains($examId, $names) { } } +/** + * Duplicate all domains of given exam ids + * + * @param array $examIds A hash with original exam ids as key and corresponding duplicated exam ids as value + * @return array|bool A hash with original domain ids as key and corresponding duplicated domain ids as value, false on failure + */ + public function duplicate($examIds) { + $mapping = array(); + + $conditions = array('Domain.exam_id' => array_keys($examIds)); + $domains = $this->find('all', compact('conditions')); + + foreach ($domains as $domain) { + $oldId = $domain['Domain']['id']; + unset($domain['Domain']['id']); + $domain['Domain']['exam_id'] = $examIds[$domain['Domain']['exam_id']]; + + $this->create(); + if (!$this->save($domain)) { + return false; + } + $mapping[$oldId] = $this->getInsertID(); + } + return $mapping; + } + } diff --git a/app/Model/Exam.php b/app/Model/Exam.php index c8fcbf8..8ecefb5 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -359,54 +359,13 @@ private function __analyse($id) { $result = $this->executeAnalysis($id); if ($result) { - $cronbachsAlpha = $result[0]; - $maxAnswerOptionCount = $result[1]; - $correctAnswerCount = $result[2]; - $correctAnswerPercentage = $result[3]; - $correctAnswerIrc = $result[4]; - $givenAnswerOptionCount = $result[5]; - $givenAnswerOptionPercentage = $result[6]; - $givenAnswerOptionIrc = $result[7]; - - $data = array( - 'Exam' => array( - 'id' => $exam['Exam']['id'], - 'exam_state_id' => ExamState::ANALYSED, - 'cronbachs_alpha' => $cronbachsAlpha, - 'max_answer_option_count' => $maxAnswerOptionCount, - 'analysed' => date('Y-m-d H:i:s') - ) - ); - - foreach ($exam['Item'] as $i => $item) { - $data['Item'][$i] = array( - 'id' => $item['id'], - 'correct_answer_count' => $correctAnswerCount[$i], - 'correct_answer_percentage' => $correctAnswerPercentage[$i], - 'correct_answer_irc' => $correctAnswerIrc[$i] - ); - $data['Item'][$i]['missing_answer_count'] = $givenAnswerOptionCount[$i * ($maxAnswerOptionCount + 1)]; - $data['Item'][$i]['missing_answer_percentage'] = $givenAnswerOptionPercentage[$i * ($maxAnswerOptionCount + 1)]; - - for ($j = 0; !empty($item['answer_option_count']) && $j < $item['answer_option_count']; $j++) { - if (empty($item['AnswerOption'][$j]['id'])) { - $data['Item'][$i]['AnswerOption'][$j]['order'] = ($j + 1); - } else { - $data['Item'][$i]['AnswerOption'][$j]['id'] = $item['AnswerOption'][$j]['id']; - } - $data['Item'][$i]['AnswerOption'][$j]['given_answer_count'] = $givenAnswerOptionCount[$i * ($maxAnswerOptionCount + 1) + $j + 1]; - $data['Item'][$i]['AnswerOption'][$j]['given_answer_percentage'] = $givenAnswerOptionPercentage[$i * ($maxAnswerOptionCount + 1) + $j + 1]; - $data['Item'][$i]['AnswerOption'][$j]['given_answer_irc'] = (is_nan($givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1])?null:$givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1]); - } - } - $this->id = $exam['Exam']['id']; - $result = $this->saveAll($data, array('deep' => true)); + $result = $this->saveAnalysis($id, $result); } if ($result) { - $this->scheduleReport($exam['Exam']['id']); + $this->scheduleReport($id); } else { - $this->id = $exam['Exam']['id']; + $this->id = $id; $this->saveField('exam_state_id', ExamState::ANALYSE_FAILED); } @@ -427,12 +386,7 @@ public function executeAnalysis($id, $domainId = null) { 'Subject' => array('GivenAnswer') ); if ($domainId !== null) { - $fields = array('Item.id', 'Item.id'); - $conditions = array( - 'Item.exam_id' => $examId, - 'Item.domain_id' => $id - ); - $itemIds = $this->Item->find('list', compact('fields', 'conditions')); + $itemIds = $this->Item->getIds($examId, $domainId); $contain['Item']['conditions'] = array('Item.domain_id' => $domainId); $contain['Subject']['conditions'] = array('GivenAnswer.item_id' => $itemIds); @@ -1358,7 +1312,14 @@ protected function _duplicate($postData) { $examId = $this->id; if ($success) { - $itemMapping = $this->Item->duplicate(array($parentId => $examId), $filteredItemIds); + $domainMapping = $this->Domain->duplicate(array($parentId => $examId)); + if ($domainMapping === false) { + $success = false; + } + } + + if ($success) { + $itemMapping = $this->Item->duplicate(array($parentId => $examId), $domainMapping, $filteredItemIds); if ($itemMapping === false) { $success = false; } diff --git a/app/Model/Item.php b/app/Model/Item.php index a0dbde3..5638a26 100644 --- a/app/Model/Item.php +++ b/app/Model/Item.php @@ -213,14 +213,32 @@ public function stevie($item, $answerOptionCount = null) { return $item; } +/** + * Get items ids of an exam and optionally filter by a domain + * + * @param int $examId An exam id + * @param int[optional] $domainId A domain id + * @return array An array with items ids + */ + public function getIds($examId, $domainId = null) { + $fields = array('Item.id', 'Item.id'); + $conditions = array('Item.exam_id' => $examId); + if ($domainId !== null) { + $conditions[] = array('Item.domain_id' => $domainId); + } + $data = $this->find('list', compact('fields', 'conditions')); + return array_values($data); + } + /** * Duplicate all or optionally only filtered items of given exam ids * * @param array $examIds A hash with original exam ids as key and corresponding duplicated exam ids as value + * @param array $domainIds A hash with original domain ids as key and corresponding duplicated domain ids as value * @param array[optional] $filteredIds A list of item ids to filter * @return array|bool A hash with original item ids as key and corresponding duplicated item ids as value, false on failure */ - public function duplicate($examIds, $filteredIds = null) { + public function duplicate($examIds, $domainIds, $filteredIds = null) { $mapping = array(); $conditions = array('Item.exam_id' => array_keys($examIds)); @@ -233,6 +251,9 @@ public function duplicate($examIds, $filteredIds = null) { $oldId = $item['Item']['id']; unset($item['Item']['id']); $item['Item']['exam_id'] = $examIds[$item['Item']['exam_id']]; + if ($item['Item']['domain_id'] !== null) { + $item['Item']['domain_id'] = $domainIds[$item['Item']['domain_id']]; + } $this->create(); if (!$this->save($item)) { diff --git a/app/Test/Case/Model/ItemTest.php b/app/Test/Case/Model/ItemTest.php new file mode 100644 index 0000000..7942dbc --- /dev/null +++ b/app/Test/Case/Model/ItemTest.php @@ -0,0 +1,96 @@ +Item = ClassRegistry::init('Item'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->Item); + + parent::tearDown(); + } + +/** + * testAdd method + * + * @return void + */ + public function testAdd() { + $this->markTestIncomplete('testAdd not implemented.'); + } + +/** + * testStevie method + * + * @return void + */ + public function testStevie() { + $this->markTestIncomplete('testStevie not implemented.'); + } + +/** + * testGetIds method + * + * @return void + */ + public function testGetIds() { + $expected = array(); + $examId = 0; + $result = $this->Item->getIds($examId); + $this->assertEquals($expected, $result); + + $expected = array(1); + $examId = 2; + $result = $this->Item->getIds($examId); + $this->assertEquals($expected, $result); + + $expected = array(21773); + $examId = 747; + $result = $this->Item->getIds($examId); + $this->assertEquals($expected, $result); + + $expected = array(1000000, 1000001, 1000002, 1000003); + $examId = 1; + $result = $this->Item->getIds($examId); + $this->assertEquals($expected, $result); + + $expected = array(1000000, 1000001); + $examId = 1; + $domainId = 1; + $result = $this->Item->getIds($examId, $domainId); + $this->assertEquals($expected, $result); + + $expected = array(1000002); + $examId = 1; + $domainId = 2; + $result = $this->Item->getIds($examId, $domainId); + $this->assertEquals($expected, $result); + } + +} diff --git a/app/Test/Case/View/Helper/empty b/app/Test/Case/View/Helper/empty deleted file mode 100644 index e69de29..0000000 diff --git a/app/Test/Fixture/AnswerOptionFixture.php b/app/Test/Fixture/AnswerOptionFixture.php index 6ce19f7..196d37c 100644 --- a/app/Test/Fixture/AnswerOptionFixture.php +++ b/app/Test/Fixture/AnswerOptionFixture.php @@ -18,6 +18,7 @@ class AnswerOptionFixture extends CakeTestFixture { 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'domain_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/DomainFixture.php index 44af888..91667b9 100644 --- a/app/Test/Fixture/DomainFixture.php +++ b/app/Test/Fixture/DomainFixture.php @@ -26,6 +26,19 @@ class DomainFixture extends CakeTestFixture { * * @var array */ - public $records = array(); + public $records = array( + array( + 'id' => 1, + 'exam_id' => null, + 'name' => 'A', + 'cronbachs_alpha' => null + ), + array( + 'id' => 2, + 'exam_id' => null, + 'name' => 'B', + 'cronbachs_alpha' => null + ), + ); } diff --git a/app/Test/Fixture/ItemFixture.php b/app/Test/Fixture/ItemFixture.php index 7bb96ae..0ec4d87 100644 --- a/app/Test/Fixture/ItemFixture.php +++ b/app/Test/Fixture/ItemFixture.php @@ -22,6 +22,7 @@ class ItemFixture extends CakeTestFixture { 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), + 'domain_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0), @@ -64,6 +65,34 @@ class ItemFixture extends CakeTestFixture { 'missing_answer_count' => 1, 'missing_answer_percentage' => 1.1 ), + array( + 'id' => 1000000, + 'exam_id' => 1, + 'domain_id' => 1, + 'order' => 1, + 'value' => 'Item 1000000', + ), + array( + 'id' => 1000001, + 'exam_id' => 1, + 'domain_id' => 1, + 'order' => 2, + 'value' => 'Item 1000001', + ), + array( + 'id' => 1000002, + 'exam_id' => 1, + 'domain_id' => 2, + 'order' => 3, + 'value' => 'Item 1000002', + ), + array( + 'id' => 1000003, + 'exam_id' => 1, + 'domain_id' => 3, + 'order' => 4, + 'value' => 'Item 1000003', + ), ); } From 89a03bda50399598c20b6d3a6f080668af5132f7 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 6 Jan 2016 15:19:13 +0100 Subject: [PATCH 18/35] Fixed naming conflict in TestExam --- app/Model/Domain.php | 2 +- app/Model/Exam.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Model/Domain.php b/app/Model/Domain.php index 3f8d8df..53c6e13 100644 --- a/app/Model/Domain.php +++ b/app/Model/Domain.php @@ -80,7 +80,7 @@ class Domain extends AppModel { * @return bool */ public function analyse($id, $examId) { - $result = $this->Exam->executeAnalysis($examId, $id); + $result = $this->Exam->doAnalyse($examId, $id); if ($result) { $result = $this->saveAnalysis($id, $result); diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 8ecefb5..6f7d3df 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -347,7 +347,7 @@ public function analyse($id) { } /** - * __analyse + * Analyse an exam * * @param int $id An exam id * @return bool @@ -356,7 +356,7 @@ private function __analyse($id) { $this->id = $id; $this->saveField('exam_state_id', ExamState::ANALYSING); - $result = $this->executeAnalysis($id); + $result = $this->doAnalyse($id); if ($result) { $result = $this->saveAnalysis($id, $result); @@ -373,13 +373,13 @@ private function __analyse($id) { } /** - * Execute analysis + * Analyse an exam, optionally filter items by a domain * * @param int $id An exam id * @param int[optional] $domainId A domain id * @return array */ - public function executeAnalysis($id, $domainId = null) { + public function doAnalyse($id, $domainId = null) { $conditions = array('Exam.id' => $id); $contain = array( 'Item' => array('AnswerOption'), From 981d81a70fd0c565042b39fddb4f8d52f0d55837 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 6 Jan 2016 16:24:58 +0100 Subject: [PATCH 19/35] Fixed MissingTableException in Tests --- app/Test/Case/Controller/ExamsControllerTest.php | 4 ++-- app/Test/Case/Model/ExamTest.php | 6 +++--- app/Test/Fixture/DomainFixture.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Test/Case/Controller/ExamsControllerTest.php b/app/Test/Case/Controller/ExamsControllerTest.php index 53fb7bf..1e6f2c4 100644 --- a/app/Test/Case/Controller/ExamsControllerTest.php +++ b/app/Test/Case/Controller/ExamsControllerTest.php @@ -20,7 +20,7 @@ class ExamsControllerTest extends ControllerTestCase { * @var array */ public $fixtures = array( - 'app.exam', 'app.exam_format', 'app.exam_state', 'app.item', 'app.user' + 'app.answer_option', 'app.exam', 'app.exam_format', 'app.exam_state', 'app.item', 'app.user' ); /** @@ -76,7 +76,7 @@ public function testIndexGet() { * @return void */ public function testViewGet() { - $this->loadFixtures('Item', 'User'); + $this->loadFixtures('AnswerOption', 'Item', 'User'); $this->testAction('/exams/view/1', array('method' => 'get', 'return' => 'contents')); $this->assertInternalType('array', $this->vars['exam']); diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index ef21a6e..bb1ed52 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -73,7 +73,7 @@ class ExamTest extends CakeTestCase { * * @var array */ - public $fixtures = array('app.answer_option', 'app.exam', 'app.given_answer', 'app.item', 'app.subject'); + public $fixtures = array('app.answer_option', 'app.domain', 'app.exam', 'app.given_answer', 'app.item', 'app.subject'); /** * setUp method @@ -392,7 +392,7 @@ public function testDuplicate() { } protected function _testDuplicateExamWithSubjectsWithNonUniqueIdentifiers() { - $this->loadFixtures('AnswerOption', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $examId = 2; $postData = $this->_createPostDataForDuplicate($examId); @@ -417,7 +417,7 @@ protected function _testDuplicateExamWithSubjectsWithNonUniqueIdentifiers() { } protected function _testDuplicateExamWithMissingGivenAnswers() { - $this->loadFixtures('AnswerOption', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $expected = 748; diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/DomainFixture.php index 91667b9..9955a80 100644 --- a/app/Test/Fixture/DomainFixture.php +++ b/app/Test/Fixture/DomainFixture.php @@ -29,13 +29,13 @@ class DomainFixture extends CakeTestFixture { public $records = array( array( 'id' => 1, - 'exam_id' => null, + 'exam_id' => 1, 'name' => 'A', 'cronbachs_alpha' => null ), array( 'id' => 2, - 'exam_id' => null, + 'exam_id' => 1, 'name' => 'B', 'cronbachs_alpha' => null ), From 10ef36f518b9d49ba36bb58e3845799ffba35b14 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 6 Jan 2016 16:40:52 +0100 Subject: [PATCH 20/35] Fixed phpcs issue --- app/Model/AppModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index b65c56f..de090ab 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -141,7 +141,7 @@ public function saveAnalysis($id, $analysis) { if ($this->alias === 'Domain') { $data = array( - 'Domain' =>array( + 'Domain' => array( 'id' => $id, 'cronbachs_alpha' => $cronbachsAlpha, ) From 2f93534e007f8f4eef5a1b70071c8473fa3f242b Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 7 Jan 2016 16:28:12 +0100 Subject: [PATCH 21/35] Added tests and fixes --- app/Model/Domain.php | 30 +++--- app/Model/Exam.php | 4 +- app/Test/Case/Model/AnswerOptionTest.php | 14 +++ app/Test/Case/Model/DomainTest.php | 111 +++++++++++++++++++++++ app/Test/Case/Model/ItemTest.php | 52 ++++++++++- 5 files changed, 192 insertions(+), 19 deletions(-) create mode 100644 app/Test/Case/Model/DomainTest.php diff --git a/app/Model/Domain.php b/app/Model/Domain.php index 53c6e13..daf15f0 100644 --- a/app/Model/Domain.php +++ b/app/Model/Domain.php @@ -89,11 +89,11 @@ public function analyse($id, $examId) { } /** - * Creates domains and returns ids + * Creates domains for given domain names and exam and returns ids * * @param int $examId An exam id * @param array $names An array with names of domains - * @return array An array with domain ids + * @return bool|array An array with domain ids in the same order as corresponding given names, false on failure */ public function createDomains($examId, $names) { $domainIds = array(); @@ -101,29 +101,31 @@ public function createDomains($examId, $names) { $uniqueNames = array_values($names); $uniqueNames = array_unique($uniqueNames); - $data = array('Domain' => array()); + $data = array(); foreach ($uniqueNames as $name) { - $data['Domain'][] = array( + $data[] = array( 'exam_id' => $examId, 'name' => $name ); } $this->create(); - $this->saveAll($data); + if ($this->saveAll($data)) { + $conditions = array('Domain.exam_id' => $examId); + $domains = $this->find('list', compact('conditions')); - $conditions = array('Domain.exam_id' => $examId); - $domains = $this->find('list', compact('conditions')); - - foreach ($names as $i => $name) { - foreach ($domains as $id => $domain) { - if ($name === $domain) { - $domainIds[$i] = $id; - break; + foreach ($names as $i => $name) { + foreach ($domains as $id => $domain) { + if ($name === $domain) { + $domainIds[$i] = $id; + break; + } } } + } else { + $domainIds = false; } - return $domainIds; } + return $domainIds; } /** diff --git a/app/Model/Exam.php b/app/Model/Exam.php index 6f7d3df..1efd3fb 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -386,10 +386,10 @@ public function doAnalyse($id, $domainId = null) { 'Subject' => array('GivenAnswer') ); if ($domainId !== null) { - $itemIds = $this->Item->getIds($examId, $domainId); + $itemIds = $this->Item->getIds($id, $domainId); $contain['Item']['conditions'] = array('Item.domain_id' => $domainId); - $contain['Subject']['conditions'] = array('GivenAnswer.item_id' => $itemIds); + $contain['Subject']['GivenAnswer']['conditions'] = array('GivenAnswer.item_id' => $itemIds); } $exam = $this->find('first', compact('conditions', 'contain')); $fields = array('MAX(Item.answer_option_count) as answer_option_count'); diff --git a/app/Test/Case/Model/AnswerOptionTest.php b/app/Test/Case/Model/AnswerOptionTest.php index 88e8e4f..bcdb8cd 100644 --- a/app/Test/Case/Model/AnswerOptionTest.php +++ b/app/Test/Case/Model/AnswerOptionTest.php @@ -7,6 +7,13 @@ */ class AnswerOptionTest extends CakeTestCase { +/** + * Auto fixtures. + * + * @var bool + */ + public $autoFixtures = false; + /** * Fixtures * @@ -75,6 +82,13 @@ public function testPrintValue() { * @return void */ public function testDuplicate() { + $this->loadFixtures('AnswerOption'); + + $expected = array(); + $examIds = array(); + $result = $this->AnswerOption->duplicate($examIds); + $this->assertSame($expected, $result); + $itemIds = array(21773 => 100000); $conditions = array('AnswerOption.item_id' => array_keys($itemIds)); diff --git a/app/Test/Case/Model/DomainTest.php b/app/Test/Case/Model/DomainTest.php new file mode 100644 index 0000000..621057c --- /dev/null +++ b/app/Test/Case/Model/DomainTest.php @@ -0,0 +1,111 @@ +Domain = ClassRegistry::init('Domain'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->Domain); + + parent::tearDown(); + } + +/** + * testCreateDomains method + * + * @return void + */ + public function testCreateDomains() { + $this->loadFixtures('Domain'); + + $expected = array(); + $examId = 2; + $names = array(); + $result = $this->Domain->createDomains($examId, $names); + $this->assertSame($expected, $result); + + $expected = array(3); + $examId = 2; + $names = array('test'); + $result = $this->Domain->createDomains($examId, $names); + $this->assertEquals($expected, $result); + + $expected = array(4, 4); + $examId = 3; + $names = array('test', 'test'); + $result = $this->Domain->createDomains($examId, $names); + $this->assertEquals($expected, $result); + } + +/** + * testAnalyse method + * + * @return void + */ + public function testAnalyse() { + $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'Item', 'Subject'); + + $id = 1; + $examId = 1; + $result = $this->Domain->analyse($id, $examId); + $this->assertTrue($result); + } + +/** + * testDuplicate method + * + * @return void + */ + public function testDuplicate() { + $this->loadFixtures('Domain'); + + $expected = array(); + $examIds = array(); + $result = $this->Domain->duplicate($examIds); + $this->assertSame($expected, $result); + + $expected = array( + 1 => 3, + 2 => 4 + ); + $examIds = array(1 => 987); + $result = $this->Domain->duplicate($examIds); + $this->assertEquals($expected, $result); + + $examIds = array(1 => 1); + $result = $this->Domain->duplicate($examIds); + $this->assertFalse($result); + } + +} diff --git a/app/Test/Case/Model/ItemTest.php b/app/Test/Case/Model/ItemTest.php index 7942dbc..bb269d2 100644 --- a/app/Test/Case/Model/ItemTest.php +++ b/app/Test/Case/Model/ItemTest.php @@ -6,14 +6,19 @@ */ class ItemTest extends CakeTestCase { +/** + * Auto fixtures. + * + * @var bool + */ + public $autoFixtures = false; + /** * Fixtures * * @var array */ - public $fixtures = array( - 'app.item', - ); + public $fixtures = array('app.item'); /** * setUp method @@ -60,6 +65,8 @@ public function testStevie() { * @return void */ public function testGetIds() { + $this->loadFixtures('Item'); + $expected = array(); $examId = 0; $result = $this->Item->getIds($examId); @@ -93,4 +100,43 @@ public function testGetIds() { $this->assertEquals($expected, $result); } +/** + * testDuplicate method + * + * @return void + */ + public function testDuplicate() { + $this->loadFixtures('Item'); + + $expected = array(); + $examIds = array(); + $domainIds = array(); + $result = $this->Item->duplicate($examIds, $domainIds); + $this->assertSame($expected, $result); + + $expected = array(1 => 1000004); + $examIds = array(2 => 987); + $domainIds = array(); + $result = $this->Item->duplicate($examIds, $domainIds); + $this->assertEquals($expected, $result); + + $expected = array( + 1000000 => 1000005, + 1000001 => 1000006, + 1000002 => 1000007, + 1000003 => 1000008 + ); + $examIds = array(1 => 1001); + $domainIds = array(1 => 1001, 2 => 1002, 3 => 1003); + $result = $this->Item->duplicate($examIds, $domainIds); + $this->assertEquals($expected, $result); + + $expected = array(1000001 => 1000009); + $examIds = array(1 => 1001); + $domainIds = array(1 => 1001, 2 => 1002, 3 => 1003); + $filteredIds = array(1000001); + $result = $this->Item->duplicate($examIds, $domainIds, $filteredIds); + $this->assertEquals($expected, $result); + } + } From aa0211d550da6d55197f4f7aa73edfbfdaea1e46 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 11 Jan 2016 12:40:43 +0100 Subject: [PATCH 22/35] Added fixture data and tests --- app/Test/Case/Model/ExamTest.php | 8 ++- app/Test/Fixture/AnswerOptionFixture.php | 72 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index bb1ed52..01a7d76 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -254,9 +254,11 @@ public function testScheduleAnalyse() { * @return void */ public function testAnalyse() { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->loadFixtures('AnswerOption', 'Exam', 'Item', 'Subject'); + + $id = 1; + $result = $this->Exam->analyse($id); + $this->assertTrue((bool)$result); } /** diff --git a/app/Test/Fixture/AnswerOptionFixture.php b/app/Test/Fixture/AnswerOptionFixture.php index 196d37c..4fd3951 100644 --- a/app/Test/Fixture/AnswerOptionFixture.php +++ b/app/Test/Fixture/AnswerOptionFixture.php @@ -78,6 +78,78 @@ class AnswerOptionFixture extends CakeTestFixture { 'given_answer_irc' => 0.045, 'given_answer_percentage' => 29.9 ), + array( + 'id' => 1000000, + 'item_id' => 1000000, + 'order' => 1, + 'is_correct' => true, + ), + array( + 'id' => 1000001, + 'item_id' => 1000000, + 'order' => 2, + 'is_correct' => false, + ), + array( + 'id' => 1000002, + 'item_id' => 1000000, + 'order' => 3, + 'is_correct' => false, + ), + array( + 'id' => 1000003, + 'item_id' => 1000000, + 'order' => 4, + 'is_correct' => false, + ), + array( + 'id' => 1000004, + 'item_id' => 1000001, + 'order' => 1, + 'is_correct' => true, + ), + array( + 'id' => 1000005, + 'item_id' => 1000001, + 'order' => 2, + 'is_correct' => false, + ), + array( + 'id' => 1000006, + 'item_id' => 1000001, + 'order' => 3, + 'is_correct' => false, + ), + array( + 'id' => 1000007, + 'item_id' => 1000001, + 'order' => 4, + 'is_correct' => false, + ), + array( + 'id' => 1000008, + 'item_id' => 1000002, + 'order' => 1, + 'is_correct' => true, + ), + array( + 'id' => 1000009, + 'item_id' => 1000002, + 'order' => 2, + 'is_correct' => false, + ), + array( + 'id' => 1000010, + 'item_id' => 1000002, + 'order' => 3, + 'is_correct' => false, + ), + array( + 'id' => 1000011, + 'item_id' => 1000002, + 'order' => 4, + 'is_correct' => false, + ), ); } From 3b0756683fec1886ca96d7fc805c16cfded107be Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 11 Jan 2016 12:56:23 +0100 Subject: [PATCH 23/35] Fixed test --- app/Test/Case/Model/ExamTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index 01a7d76..f199789 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -254,7 +254,7 @@ public function testScheduleAnalyse() { * @return void */ public function testAnalyse() { - $this->loadFixtures('AnswerOption', 'Exam', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $id = 1; $result = $this->Exam->analyse($id); From f742b86fd58e775ae98fe593059b0ab2cf2ab263 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 11 Jan 2016 12:57:32 +0100 Subject: [PATCH 24/35] Fixed test --- app/Test/Case/Model/DomainTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Test/Case/Model/DomainTest.php b/app/Test/Case/Model/DomainTest.php index 621057c..8e88385 100644 --- a/app/Test/Case/Model/DomainTest.php +++ b/app/Test/Case/Model/DomainTest.php @@ -74,7 +74,7 @@ public function testCreateDomains() { * @return void */ public function testAnalyse() { - $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $id = 1; $examId = 1; From 938639c1d8cfa595d5c9dffd8187fec76c8c02ee Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 13 Jan 2016 13:47:04 +0100 Subject: [PATCH 25/35] Fixed typos --- app/Model/AppModel.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index de090ab..e64c258 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -126,14 +126,14 @@ public function saveAnalysis($id, $analysis) { throw new NotImplementedException(); } - $cronbachsAlpha = $result[0]; - $maxAnswerOptionCount = $result[1]; - $correctAnswerCount = $result[2]; - $correctAnswerPercentage = $result[3]; - $correctAnswerIrc = $result[4]; - $givenAnswerOptionCount = $result[5]; - $givenAnswerOptionPercentage = $result[6]; - $givenAnswerOptionIrc = $result[7]; + $cronbachsAlpha = $analysis[0]; + $maxAnswerOptionCount = $analysis[1]; + $correctAnswerCount = $analysis[2]; + $correctAnswerPercentage = $analysis[3]; + $correctAnswerIrc = $analysis[4]; + $givenAnswerOptionCount = $analysis[5]; + $givenAnswerOptionPercentage = $analysis[6]; + $givenAnswerOptionIrc = $analysis[7]; $conditions = array(sprintf('%s.id', $this->alias) => $id); $contain = array('Item' => array('AnswerOption')); From b2dc12958b91742020bd3a4767187f6fc2fb14a2 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 13 Jan 2016 13:59:40 +0100 Subject: [PATCH 26/35] Added data to fixtures --- app/Test/Fixture/AnswerOptionFixture.php | 24 ++++++++++ app/Test/Fixture/GivenAnswerFixture.php | 56 ++++++++++++++++++++++++ app/Test/Fixture/ItemFixture.php | 4 ++ app/Test/Fixture/SubjectFixture.php | 12 +++++ 4 files changed, 96 insertions(+) diff --git a/app/Test/Fixture/AnswerOptionFixture.php b/app/Test/Fixture/AnswerOptionFixture.php index 4fd3951..14709b5 100644 --- a/app/Test/Fixture/AnswerOptionFixture.php +++ b/app/Test/Fixture/AnswerOptionFixture.php @@ -150,6 +150,30 @@ class AnswerOptionFixture extends CakeTestFixture { 'order' => 4, 'is_correct' => false, ), + array( + 'id' => 1000012, + 'item_id' => 1000003, + 'order' => 1, + 'is_correct' => true, + ), + array( + 'id' => 1000013, + 'item_id' => 1000003, + 'order' => 2, + 'is_correct' => false, + ), + array( + 'id' => 1000014, + 'item_id' => 1000003, + 'order' => 3, + 'is_correct' => false, + ), + array( + 'id' => 1000015, + 'item_id' => 1000003, + 'order' => 4, + 'is_correct' => false, + ), ); } diff --git a/app/Test/Fixture/GivenAnswerFixture.php b/app/Test/Fixture/GivenAnswerFixture.php index cee475f..0d2f7d5 100644 --- a/app/Test/Fixture/GivenAnswerFixture.php +++ b/app/Test/Fixture/GivenAnswerFixture.php @@ -50,6 +50,62 @@ class GivenAnswerFixture extends CakeTestFixture { 'score' => 0.00000000, 'content' => null ), + array( + 'id' => 1000000, + 'item_id' => 1000000, + 'subject_id' => 1000000, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000001, + 'item_id' => 1000001, + 'subject_id' => 1000000, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000002, + 'item_id' => 1000002, + 'subject_id' => 1000000, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000003, + 'item_id' => 1000003, + 'subject_id' => 1000000, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000004, + 'item_id' => 1000000, + 'subject_id' => 1000001, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000005, + 'item_id' => 1000001, + 'subject_id' => 1000001, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000006, + 'item_id' => 1000002, + 'subject_id' => 1000001, + 'value' => 3, + 'score' => 0, + ), + array( + 'id' => 1000007, + 'item_id' => 1000003, + 'subject_id' => 1000001, + 'value' => 3, + 'score' => 0, + ), ); } diff --git a/app/Test/Fixture/ItemFixture.php b/app/Test/Fixture/ItemFixture.php index 0ec4d87..23ffbed 100644 --- a/app/Test/Fixture/ItemFixture.php +++ b/app/Test/Fixture/ItemFixture.php @@ -71,6 +71,7 @@ class ItemFixture extends CakeTestFixture { 'domain_id' => 1, 'order' => 1, 'value' => 'Item 1000000', + 'answer_option_count' => 4, ), array( 'id' => 1000001, @@ -78,6 +79,7 @@ class ItemFixture extends CakeTestFixture { 'domain_id' => 1, 'order' => 2, 'value' => 'Item 1000001', + 'answer_option_count' => 4, ), array( 'id' => 1000002, @@ -85,6 +87,7 @@ class ItemFixture extends CakeTestFixture { 'domain_id' => 2, 'order' => 3, 'value' => 'Item 1000002', + 'answer_option_count' => 4, ), array( 'id' => 1000003, @@ -92,6 +95,7 @@ class ItemFixture extends CakeTestFixture { 'domain_id' => 3, 'order' => 4, 'value' => 'Item 1000003', + 'answer_option_count' => 4, ), ); diff --git a/app/Test/Fixture/SubjectFixture.php b/app/Test/Fixture/SubjectFixture.php index c052f67..7afeb31 100644 --- a/app/Test/Fixture/SubjectFixture.php +++ b/app/Test/Fixture/SubjectFixture.php @@ -45,6 +45,18 @@ class SubjectFixture extends CakeTestFixture { 'value' => '10825363', 'is_second_version' => false ), + array( + 'id' => 1000000, + 'exam_id' => 1, + 'value' => '1000000', + 'is_second_version' => false + ), + array( + 'id' => 1000001, + 'exam_id' => 1, + 'value' => '1000001', + 'is_second_version' => false + ), ); } From 4d446f231d700b7410c64730c5fd5b66765a575b Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 15 Jun 2016 14:26:35 +0200 Subject: [PATCH 27/35] Added field max_answer_option_count to table domains --- app/Config/Schema/schema.php | 1 + app/Test/Fixture/DomainFixture.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index 8a89a0e..e891317 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -307,6 +307,7 @@ public function after($event = array()) { 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0) diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/DomainFixture.php index 9955a80..c961665 100644 --- a/app/Test/Fixture/DomainFixture.php +++ b/app/Test/Fixture/DomainFixture.php @@ -14,6 +14,7 @@ class DomainFixture extends CakeTestFixture { 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'cronbachs_alpha' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'max_answer_option_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0) @@ -31,13 +32,15 @@ class DomainFixture extends CakeTestFixture { 'id' => 1, 'exam_id' => 1, 'name' => 'A', - 'cronbachs_alpha' => null + 'cronbachs_alpha' => null, + 'max_answer_option_count' =>null ), array( 'id' => 2, 'exam_id' => 1, 'name' => 'B', - 'cronbachs_alpha' => null + 'cronbachs_alpha' => null, + 'max_answer_option_count' =>null ), ); From f87539f2c84b1bf949d444bb04c969d6e7f1d1e1 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 29 Jun 2016 15:28:10 +0200 Subject: [PATCH 28/35] Refactoring: renamed domain to category --- app/Config/Schema/schema.php | 10 ++-- app/Model/AppModel.php | 18 +++--- app/Model/{Domain.php => Category.php} | 50 ++++++++--------- app/Model/Exam.php | 56 +++++++++---------- app/Model/Item.php | 24 ++++---- .../{DomainTest.php => CategoryTest.php} | 36 ++++++------ app/Test/Case/Model/ExamTest.php | 34 +++++------ app/Test/Case/Model/ItemTest.php | 24 ++++---- ...h-category-without-answer-option-count.csv | 3 + .../Teleform-mappingfile-with-category.csv | 3 + ...ith-domain-without-answer-option-count.csv | 3 - .../Exam/Teleform-mappingfile-with-domain.csv | 3 - app/Test/Fixture/AnswerOptionFixture.php | 2 +- ...{DomainFixture.php => CategoryFixture.php} | 4 +- app/Test/Fixture/ItemFixture.php | 18 +++--- 15 files changed, 144 insertions(+), 144 deletions(-) rename app/Model/{Domain.php => Category.php} (64%) rename app/Test/Case/Model/{DomainTest.php => CategoryTest.php} (56%) create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-category-without-answer-option-count.csv create mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-category.csv delete mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv delete mode 100644 app/Test/File/Exam/Teleform-mappingfile-with-domain.csv rename app/Test/Fixture/{DomainFixture.php => CategoryFixture.php} (95%) diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index e891317..f0133d3 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -284,7 +284,7 @@ public function after($event = array()) { 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), - 'domain_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'category_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) @@ -302,7 +302,7 @@ public function after($event = array()) { 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); - public $domains = array( + public $categories = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -412,7 +412,7 @@ public function after($event = array()) { public $items = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), - 'domain_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -422,11 +422,11 @@ public function after($event = array()) { 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), - 'domain_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'category_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0), - 'domain_id' => array('column' => 'domain_id', 'unique' => 0) + 'category_id' => array('column' => 'category_id', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index e64c258..84f8975 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -114,15 +114,15 @@ public function removeFieldFromSchema($fieldname) { } /** - * Save analysis to an ezam or a domain + * Save analysis to an ezam or a category * - * @param int $id An domain/exam id + * @param int $id A category/exam id * @param array $analysis An array with analysis data * @return bool True on success, or false on failure. * @throws NotImplementedException */ public function saveAnalysis($id, $analysis) { - if (!in_array($this->alias, array('Domain', 'Exam'))) { + if (!in_array($this->alias, array('Category', 'Exam'))) { throw new NotImplementedException(); } @@ -139,9 +139,9 @@ public function saveAnalysis($id, $analysis) { $contain = array('Item' => array('AnswerOption')); $object = $this->find('first', compact('conditions', 'contain')); - if ($this->alias === 'Domain') { + if ($this->alias === 'Category') { $data = array( - 'Domain' => array( + 'Category' => array( 'id' => $id, 'cronbachs_alpha' => $cronbachsAlpha, ) @@ -160,8 +160,8 @@ public function saveAnalysis($id, $analysis) { foreach ($object['Item'] as $i => $item) { $data['Item'][$i] = array('id' => $item['id']); - if ($this->alias === 'Domain') { - $data['Item'][$i]['domain_correct_answer_irc'] = $correctAnswerIrc[$i]; + if ($this->alias === 'Category') { + $data['Item'][$i]['category_correct_answer_irc'] = $correctAnswerIrc[$i]; } elseif ($this->alias === 'Exam') { $data['Item'][$i]['correct_answer_count'] = $correctAnswerCount[$i]; $data['Item'][$i]['correct_answer_percentage'] = $correctAnswerPercentage[$i]; @@ -177,8 +177,8 @@ public function saveAnalysis($id, $analysis) { $data['Item'][$i]['AnswerOption'][$j]['id'] = $item['AnswerOption'][$j]['id']; } - if ($this->alias === 'Domain') { - $data['Item'][$i]['AnswerOption'][$j]['domain_given_answer_irc'] = (is_nan($givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1])?null:$givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1]); + if ($this->alias === 'Category') { + $data['Item'][$i]['AnswerOption'][$j]['category_given_answer_irc'] = (is_nan($givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1])?null:$givenAnswerOptionIrc[$i * ($maxAnswerOptionCount + 1) + $j + 1]); } elseif ($this->alias === 'Exam') { $data['Item'][$i]['AnswerOption'][$j]['given_answer_count'] = $givenAnswerOptionCount[$i * ($maxAnswerOptionCount + 1) + $j + 1]; $data['Item'][$i]['AnswerOption'][$j]['given_answer_percentage'] = $givenAnswerOptionPercentage[$i * ($maxAnswerOptionCount + 1) + $j + 1]; diff --git a/app/Model/Domain.php b/app/Model/Category.php similarity index 64% rename from app/Model/Domain.php rename to app/Model/Category.php index daf15f0..4faaebf 100644 --- a/app/Model/Domain.php +++ b/app/Model/Category.php @@ -1,12 +1,12 @@ array( 'className' => 'Item', - 'foreignKey' => 'domain_id', + 'foreignKey' => 'category_id', 'dependent' => false ) ); @@ -75,7 +75,7 @@ class Domain extends AppModel { /** * analyse * - * @param int $id A domain id + * @param int $id A category id * @param int $examId An exam id * @return bool */ @@ -89,14 +89,14 @@ public function analyse($id, $examId) { } /** - * Creates domains for given domain names and exam and returns ids + * Creates categories for given category names and exam and returns ids * * @param int $examId An exam id - * @param array $names An array with names of domains - * @return bool|array An array with domain ids in the same order as corresponding given names, false on failure + * @param array $names An array with names of categories + * @return bool|array An array with category ids in the same order as corresponding given names, false on failure */ - public function createDomains($examId, $names) { - $domainIds = array(); + public function createCategories($examId, $names) { + $categoryIds = array(); if (!empty($names)) { $uniqueNames = array_values($names); $uniqueNames = array_unique($uniqueNames); @@ -110,43 +110,43 @@ public function createDomains($examId, $names) { } $this->create(); if ($this->saveAll($data)) { - $conditions = array('Domain.exam_id' => $examId); - $domains = $this->find('list', compact('conditions')); + $conditions = array('Category.exam_id' => $examId); + $categories = $this->find('list', compact('conditions')); foreach ($names as $i => $name) { - foreach ($domains as $id => $domain) { - if ($name === $domain) { - $domainIds[$i] = $id; + foreach ($categories as $id => $category) { + if ($name === $category) { + $categoryIds[$i] = $id; break; } } } } else { - $domainIds = false; + $categoryIds = false; } } - return $domainIds; + return $categoryIds; } /** - * Duplicate all domains of given exam ids + * Duplicate all categories of given exam ids * * @param array $examIds A hash with original exam ids as key and corresponding duplicated exam ids as value - * @return array|bool A hash with original domain ids as key and corresponding duplicated domain ids as value, false on failure + * @return array|bool A hash with original category ids as key and corresponding duplicated category ids as value, false on failure */ public function duplicate($examIds) { $mapping = array(); - $conditions = array('Domain.exam_id' => array_keys($examIds)); - $domains = $this->find('all', compact('conditions')); + $conditions = array('Category.exam_id' => array_keys($examIds)); + $categories = $this->find('all', compact('conditions')); - foreach ($domains as $domain) { - $oldId = $domain['Domain']['id']; - unset($domain['Domain']['id']); - $domain['Domain']['exam_id'] = $examIds[$domain['Domain']['exam_id']]; + foreach ($categories as $category) { + $oldId = $category['Category']['id']; + unset($category['Category']['id']); + $category['Category']['exam_id'] = $examIds[$category['Category']['exam_id']]; $this->create(); - if (!$this->save($domain)) { + if (!$this->save($category)) { return false; } $mapping[$oldId] = $this->getInsertID(); diff --git a/app/Model/Exam.php b/app/Model/Exam.php index a446243..8bb10bf 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -11,8 +11,8 @@ /** * Exam Model * + * @property Category $Category * @property Exam $Child - * @property Domain $Domain * @property ExamFormat $ExamFormat * @property ExamState $ExamState * @property Item $Item @@ -165,16 +165,16 @@ class Exam extends AppModel { * @var array */ public $hasMany = array( + 'Category' => array( + 'className' => 'Category', + 'foreignKey' => 'exam_id', + 'dependent' => true + ), 'Child' => array( 'className' => 'Exam', 'foreignKey' => 'parent_id', 'dependent' => false ), - 'Domain' => array( - 'className' => 'Domain', - 'foreignKey' => 'exam_id', - 'dependent' => true - ), 'Item' => array( 'className' => 'Item', 'foreignKey' => 'exam_id', @@ -396,29 +396,29 @@ private function __analyse($id) { } /** - * Analyse an exam, optionally filter items by a domain + * Analyse an exam, optionally filter items by a category * * @param int $id An exam id - * @param int[optional] $domainId A domain id + * @param int[optional] $categoryId A category id * @return array */ - public function doAnalyse($id, $domainId = null) { + public function doAnalyse($id, $categoryId = null) { $conditions = array('Exam.id' => $id); $contain = array( 'Item' => array('AnswerOption'), 'Subject' => array('GivenAnswer') ); - if ($domainId !== null) { - $itemIds = $this->Item->getIds($id, $domainId); + if ($categoryId !== null) { + $itemIds = $this->Item->getIds($id, $categoryId); - $contain['Item']['conditions'] = array('Item.domain_id' => $domainId); + $contain['Item']['conditions'] = array('Item.category_id' => $categoryId); $contain['Subject']['GivenAnswer']['conditions'] = array('GivenAnswer.item_id' => $itemIds); } $exam = $this->find('first', compact('conditions', 'contain')); $fields = array('MAX(Item.answer_option_count) as answer_option_count'); $conditions = array('Item.exam_id' => $exam['Exam']['id']); - if ($domainId !== null) { - $conditions['Item.domain_id'] = $domainId; + if ($categoryId !== null) { + $conditions['Item.category_id'] = $categoryId; } $maxAnswerOptionCount = $this->Item->find('first', compact('fields', 'conditions')); $maxAnswerOptionCount = $maxAnswerOptionCount[0]['answer_option_count']; @@ -1059,9 +1059,9 @@ public function importTeleform($exam) { $versionMappingFilename = Exam::UPLOADS . $exam['Exam']['mapping_filename']; } - list($versionMapping, $answerOptionCount, $domains) = $this->_extractTeleformMappingfile($versionMappingFilename); + list($versionMapping, $answerOptionCount, $categories) = $this->_extractTeleformMappingfile($versionMappingFilename); - $domainIds = $this->Domain->createDomains($exam['Exam']['id'], $domains); + $categoryIds = $this->Category->createCategories($exam['Exam']['id'], $categories); $result = true; ini_set('auto_detect_line_endings', true); @@ -1089,7 +1089,7 @@ public function importTeleform($exam) { $item = array( 'exam_id' => $exam['Exam']['id'], - 'domain_id' => Hash::get($domainIds, $j - 1), + 'category_id' => Hash::get($categoryIds, $j - 1), 'order' => $j - 1, 'second_version_order' => $secondVersionOrder, 'value' => $j - 1 @@ -1335,14 +1335,14 @@ protected function _duplicate($postData) { $examId = $this->id; if ($success) { - $domainMapping = $this->Domain->duplicate(array($parentId => $examId)); - if ($domainMapping === false) { + $categoryMapping = $this->Category->duplicate(array($parentId => $examId)); + if ($categoryMapping === false) { $success = false; } } if ($success) { - $itemMapping = $this->Item->duplicate(array($parentId => $examId), $domainMapping, $filteredItemIds); + $itemMapping = $this->Item->duplicate(array($parentId => $examId), $categoryMapping, $filteredItemIds); if ($itemMapping === false) { $success = false; } @@ -1515,15 +1515,15 @@ protected function _executeAnalysis($questionCount, $studentCount, $maxAnswerOpt } /** - * Extract version mappings, answer option counts and domains from Teleform mapping file + * Extract version mappings, answer option counts and categories from Teleform mapping file * * @param string $filename Filename of a Teleform mapping file - * @return array List of verion mappings, answer option counts and domains + * @return array List of verion mappings, answer option counts and categories */ protected function _extractTeleformMappingfile($filename) { $versionMappings = array(); $answerOptionCounts = array(); - $domains = array(); + $categories = array(); if (!empty($filename) && file_exists($filename)) { ini_set('auto_detect_line_endings', true); @@ -1531,7 +1531,7 @@ protected function _extractTeleformMappingfile($filename) { $version1Index = false; $version2Index = false; $answerOptionCountIndex = false; - $domainIndex = false; + $categoryIndex = false; for ($i = 0; !feof($handle); $i++) { $line = fgets($handle); $line = $this->__decodeLine($line, $i == 0); @@ -1542,7 +1542,7 @@ protected function _extractTeleformMappingfile($filename) { $version1Index = $this->_getIndexOfVersionFromTeleformHeader($header, 1); $version2Index = $this->_getIndexOfVersionFromTeleformHeader($header, 2); $answerOptionCountIndex = array_search('Answer Option Count', $header); - $domainIndex = array_search('Domain', $header); + $categoryIndex = array_search('Category', $header); } else { $values = str_getcsv($line, ';', '"', '"'); if (count($values) <= 1) { @@ -1556,8 +1556,8 @@ protected function _extractTeleformMappingfile($filename) { $answerOptionCounts[$values[$version1Index]] = intval($values[$answerOptionCountIndex]); } - if ($version1Index !== false && $domainIndex !== false) { - $domains[$values[$version1Index]] = $values[$domainIndex]; + if ($version1Index !== false && $categoryIndex !== false) { + $categories[$values[$version1Index]] = $values[$categoryIndex]; } } } @@ -1566,7 +1566,7 @@ protected function _extractTeleformMappingfile($filename) { } } - return array($versionMappings, $answerOptionCounts, $domains); + return array($versionMappings, $answerOptionCounts, $categories); } } diff --git a/app/Model/Item.php b/app/Model/Item.php index 9974920..167db9e 100644 --- a/app/Model/Item.php +++ b/app/Model/Item.php @@ -5,7 +5,7 @@ * Item Model * * @property AnswerOption $AnswerOption - * @property Domain $Domain + * @property Category $Category * @property Exam $Exam */ class Item extends AppModel { @@ -23,8 +23,8 @@ class Item extends AppModel { * @var array */ public $belongsTo = array( - 'Domain' => array( - 'className' => 'Domain', + 'Category' => array( + 'className' => 'Category', 'foreignKey' => 'exam_id' ), 'Exam' => array( @@ -215,17 +215,17 @@ public function stevie($item, $answerOptionCount = null) { } /** - * Get items ids of an exam and optionally filter by a domain + * Get items ids of an exam and optionally filter by a category * * @param int $examId An exam id - * @param int[optional] $domainId A domain id + * @param int[optional] $categoryId A category id * @return array An array with items ids */ - public function getIds($examId, $domainId = null) { + public function getIds($examId, $categoryId = null) { $fields = array('Item.id', 'Item.id'); $conditions = array('Item.exam_id' => $examId); - if ($domainId !== null) { - $conditions[] = array('Item.domain_id' => $domainId); + if ($categoryId !== null) { + $conditions[] = array('Item.category_id' => $categoryId); } $data = $this->find('list', compact('fields', 'conditions')); return array_values($data); @@ -235,11 +235,11 @@ public function getIds($examId, $domainId = null) { * Duplicate all or optionally only filtered items of given exam ids * * @param array $examIds A hash with original exam ids as key and corresponding duplicated exam ids as value - * @param array $domainIds A hash with original domain ids as key and corresponding duplicated domain ids as value + * @param array $categoryIds A hash with original category ids as key and corresponding duplicated category ids as value * @param array[optional] $filteredIds A list of item ids to filter * @return array|bool A hash with original item ids as key and corresponding duplicated item ids as value, false on failure */ - public function duplicate($examIds, $domainIds, $filteredIds = null) { + public function duplicate($examIds, $categoryIds, $filteredIds = null) { $mapping = array(); $conditions = array('Item.exam_id' => array_keys($examIds)); @@ -252,8 +252,8 @@ public function duplicate($examIds, $domainIds, $filteredIds = null) { $oldId = $item['Item']['id']; unset($item['Item']['id']); $item['Item']['exam_id'] = $examIds[$item['Item']['exam_id']]; - if ($item['Item']['domain_id'] !== null) { - $item['Item']['domain_id'] = $domainIds[$item['Item']['domain_id']]; + if ($item['Item']['category_id'] !== null) { + $item['Item']['category_id'] = $categoryIds[$item['Item']['category_id']]; } $this->create(); diff --git a/app/Test/Case/Model/DomainTest.php b/app/Test/Case/Model/CategoryTest.php similarity index 56% rename from app/Test/Case/Model/DomainTest.php rename to app/Test/Case/Model/CategoryTest.php index 8e88385..fe01096 100644 --- a/app/Test/Case/Model/DomainTest.php +++ b/app/Test/Case/Model/CategoryTest.php @@ -1,10 +1,10 @@ Domain = ClassRegistry::init('Domain'); + $this->Category = ClassRegistry::init('Category'); } /** @@ -36,35 +36,35 @@ public function setUp() { * @return void */ public function tearDown() { - unset($this->Domain); + unset($this->Category); parent::tearDown(); } /** - * testCreateDomains method + * testCreateCategories method * * @return void */ - public function testCreateDomains() { - $this->loadFixtures('Domain'); + public function testCreateCategories() { + $this->loadFixtures('Category'); $expected = array(); $examId = 2; $names = array(); - $result = $this->Domain->createDomains($examId, $names); + $result = $this->Category->createCategories($examId, $names); $this->assertSame($expected, $result); $expected = array(3); $examId = 2; $names = array('test'); - $result = $this->Domain->createDomains($examId, $names); + $result = $this->Category->createCategories($examId, $names); $this->assertEquals($expected, $result); $expected = array(4, 4); $examId = 3; $names = array('test', 'test'); - $result = $this->Domain->createDomains($examId, $names); + $result = $this->Category->createCategories($examId, $names); $this->assertEquals($expected, $result); } @@ -74,11 +74,11 @@ public function testCreateDomains() { * @return void */ public function testAnalyse() { - $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Category', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $id = 1; $examId = 1; - $result = $this->Domain->analyse($id, $examId); + $result = $this->Category->analyse($id, $examId); $this->assertTrue($result); } @@ -88,11 +88,11 @@ public function testAnalyse() { * @return void */ public function testDuplicate() { - $this->loadFixtures('Domain'); + $this->loadFixtures('Category'); $expected = array(); $examIds = array(); - $result = $this->Domain->duplicate($examIds); + $result = $this->Category->duplicate($examIds); $this->assertSame($expected, $result); $expected = array( @@ -100,11 +100,11 @@ public function testDuplicate() { 2 => 4 ); $examIds = array(1 => 987); - $result = $this->Domain->duplicate($examIds); + $result = $this->Category->duplicate($examIds); $this->assertEquals($expected, $result); $examIds = array(1 => 1); - $result = $this->Domain->duplicate($examIds); + $result = $this->Category->duplicate($examIds); $this->assertFalse($result); } diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index dd88e90..e10b349 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -73,7 +73,7 @@ class ExamTest extends CakeTestCase { * * @var array */ - public $fixtures = array('app.answer_option', 'app.domain', 'app.exam', 'app.given_answer', 'app.item', 'app.subject'); + public $fixtures = array('app.answer_option', 'app.category', 'app.exam', 'app.given_answer', 'app.item', 'app.subject'); /** * setUp method @@ -397,7 +397,7 @@ public function testDuplicate() { } protected function _testDuplicateExamWithSubjectsWithNonUniqueIdentifiers() { - $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Category', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $examId = 2; $postData = $this->_createPostDataForDuplicate($examId); @@ -422,7 +422,7 @@ protected function _testDuplicateExamWithSubjectsWithNonUniqueIdentifiers() { } protected function _testDuplicateExamWithMissingGivenAnswers() { - $this->loadFixtures('AnswerOption', 'Domain', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Category', 'Exam', 'GivenAnswer', 'Item', 'Subject'); $expected = 748; @@ -486,19 +486,19 @@ public function testExtractTeleformMappingfile() { $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . $file; $result = $this->Exam->extractTeleformMappingfile($filename); $this->assertTrue((bool)$result); - list($versionMapping, $answerOptionCount, $domains) = $result; + list($versionMapping, $answerOptionCount, $categories) = $result; $this->assertEquals($expectedVersionMapping, $versionMapping); $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); - $this->assertEmpty($domains); + $this->assertEmpty($categories); } } /** - * testExtractTeleformMappingfileWithDomain method + * testExtractTeleformMappingfileWithCategory method * * @return void */ - public function testExtractTeleformMappingfileWithDomain() { + public function testExtractTeleformMappingfileWithCategory() { $expectedVersionMapping = array( 2 => array( 1 => 2, @@ -510,26 +510,26 @@ public function testExtractTeleformMappingfileWithDomain() { 2 => 3 ); - $expectedDomains = array( + $expectedCategories = array( 1 => 'M', 2 => 'G' ); - $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-domain.csv'; + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-category.csv'; $result = $this->Exam->extractTeleformMappingfile($filename); $this->assertTrue((bool)$result); - list($versionMapping, $answerOptionCount, $domains) = $result; + list($versionMapping, $answerOptionCount, $categories) = $result; $this->assertEquals($expectedVersionMapping, $versionMapping); $this->assertEquals($expectedAnswerOptionCount, $answerOptionCount); - $this->assertEquals($expectedDomains, $domains); + $this->assertEquals($expectedCategories, $categories); } /** - * testExtractTeleformMappingfileWithDomainWithoutAnswerOptionCount method + * testExtractTeleformMappingfileWithCategoryWithoutAnswerOptionCount method * * @return void */ - public function testExtractTeleformMappingfileWithDomainWithoutAnswerOptionCount() { + public function testExtractTeleformMappingfileWithCategoryWithoutAnswerOptionCount() { $expectedVersionMapping = array( 2 => array( 1 => 2, @@ -537,18 +537,18 @@ public function testExtractTeleformMappingfileWithDomainWithoutAnswerOptionCount ) ); - $expectedDomains = array( + $expectedCategories = array( 1 => 'M', 2 => 'G' ); - $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-domain-without-answer-option-count.csv'; + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-categories-without-answer-option-count.csv'; $result = $this->Exam->extractTeleformMappingfile($filename); $this->assertTrue((bool)$result); - list($versionMapping, $answerOptionCount, $domains) = $result; + list($versionMapping, $answerOptionCount, $categories) = $result; $this->assertEquals($expectedVersionMapping, $versionMapping); $this->assertEmpty($answerOptionCount); - $this->assertEquals($expectedDomains, $domains); + $this->assertEquals($expectedCategories, $categories); } } diff --git a/app/Test/Case/Model/ItemTest.php b/app/Test/Case/Model/ItemTest.php index bb269d2..3243a3e 100644 --- a/app/Test/Case/Model/ItemTest.php +++ b/app/Test/Case/Model/ItemTest.php @@ -89,14 +89,14 @@ public function testGetIds() { $expected = array(1000000, 1000001); $examId = 1; - $domainId = 1; - $result = $this->Item->getIds($examId, $domainId); + $categoryId = 1; + $result = $this->Item->getIds($examId, $categoryId); $this->assertEquals($expected, $result); $expected = array(1000002); $examId = 1; - $domainId = 2; - $result = $this->Item->getIds($examId, $domainId); + $categoryId = 2; + $result = $this->Item->getIds($examId, $categoryId); $this->assertEquals($expected, $result); } @@ -110,14 +110,14 @@ public function testDuplicate() { $expected = array(); $examIds = array(); - $domainIds = array(); - $result = $this->Item->duplicate($examIds, $domainIds); + $categoryIds = array(); + $result = $this->Item->duplicate($examIds, $categoryIds); $this->assertSame($expected, $result); $expected = array(1 => 1000004); $examIds = array(2 => 987); - $domainIds = array(); - $result = $this->Item->duplicate($examIds, $domainIds); + $categoryIds = array(); + $result = $this->Item->duplicate($examIds, $categoryIds); $this->assertEquals($expected, $result); $expected = array( @@ -127,15 +127,15 @@ public function testDuplicate() { 1000003 => 1000008 ); $examIds = array(1 => 1001); - $domainIds = array(1 => 1001, 2 => 1002, 3 => 1003); - $result = $this->Item->duplicate($examIds, $domainIds); + $categoryIds = array(1 => 1001, 2 => 1002, 3 => 1003); + $result = $this->Item->duplicate($examIds, $categoryIds); $this->assertEquals($expected, $result); $expected = array(1000001 => 1000009); $examIds = array(1 => 1001); - $domainIds = array(1 => 1001, 2 => 1002, 3 => 1003); + $categoryIds = array(1 => 1001, 2 => 1002, 3 => 1003); $filteredIds = array(1000001); - $result = $this->Item->duplicate($examIds, $domainIds, $filteredIds); + $result = $this->Item->duplicate($examIds, $categoryIds, $filteredIds); $this->assertEquals($expected, $result); } diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-category-without-answer-option-count.csv b/app/Test/File/Exam/Teleform-mappingfile-with-category-without-answer-option-count.csv new file mode 100644 index 0000000..6d0f505 --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-category-without-answer-option-count.csv @@ -0,0 +1,3 @@ +versie.1;versie.2;Category +1;2;M +2;1;G diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-category.csv b/app/Test/File/Exam/Teleform-mappingfile-with-category.csv new file mode 100644 index 0000000..876ae7b --- /dev/null +++ b/app/Test/File/Exam/Teleform-mappingfile-with-category.csv @@ -0,0 +1,3 @@ +versie.1;versie.2;Answer Option Count;Category +1;2;3;M +2;1;3;G diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv b/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv deleted file mode 100644 index 5036d5c..0000000 --- a/app/Test/File/Exam/Teleform-mappingfile-with-domain-without-answer-option-count.csv +++ /dev/null @@ -1,3 +0,0 @@ -versie.1;versie.2;Domain -1;2;M -2;1;G diff --git a/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv b/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv deleted file mode 100644 index b185ad3..0000000 --- a/app/Test/File/Exam/Teleform-mappingfile-with-domain.csv +++ /dev/null @@ -1,3 +0,0 @@ -versie.1;versie.2;Answer Option Count;Domain -1;2;3;M -2;1;3;G diff --git a/app/Test/Fixture/AnswerOptionFixture.php b/app/Test/Fixture/AnswerOptionFixture.php index 14709b5..493a045 100644 --- a/app/Test/Fixture/AnswerOptionFixture.php +++ b/app/Test/Fixture/AnswerOptionFixture.php @@ -18,7 +18,7 @@ class AnswerOptionFixture extends CakeTestFixture { 'given_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'given_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), - 'domain_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'category_given_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'item_id' => array('column' => 'item_id', 'unique' => 0) diff --git a/app/Test/Fixture/DomainFixture.php b/app/Test/Fixture/CategoryFixture.php similarity index 95% rename from app/Test/Fixture/DomainFixture.php rename to app/Test/Fixture/CategoryFixture.php index c961665..42c7502 100644 --- a/app/Test/Fixture/DomainFixture.php +++ b/app/Test/Fixture/CategoryFixture.php @@ -1,8 +1,8 @@ array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), 'exam_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), - 'domain_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'index'), 'order' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), 'second_version_order' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -22,11 +22,11 @@ class ItemFixture extends CakeTestFixture { 'correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'missing_answer_count' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10, 'unsigned' => true), 'missing_answer_percentage' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,1', 'unsigned' => true), - 'domain_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), + 'category_correct_answer_irc' => array('type' => 'decimal', 'null' => true, 'default' => null, 'length' => '4,3', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'exam_id' => array('column' => 'exam_id', 'unique' => 0), - 'domain_id' => array('column' => 'domain_id', 'unique' => 0) + 'category_id' => array('column' => 'category_id', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); @@ -40,7 +40,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1, 'exam_id' => 2, - 'domain_id' => null, + 'category_id' => null, 'order' => 1, 'second_version_order' => null, 'value' => '1B 05 individualisering 002', @@ -54,7 +54,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 21773, 'exam_id' => 747, - 'domain_id' => null, + 'category_id' => null, 'order' => 35, 'second_version_order' => null, 'value' => '35', @@ -68,7 +68,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1000000, 'exam_id' => 1, - 'domain_id' => 1, + 'category_id' => 1, 'order' => 1, 'value' => 'Item 1000000', 'answer_option_count' => 4, @@ -76,7 +76,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1000001, 'exam_id' => 1, - 'domain_id' => 1, + 'category_id' => 1, 'order' => 2, 'value' => 'Item 1000001', 'answer_option_count' => 4, @@ -84,7 +84,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1000002, 'exam_id' => 1, - 'domain_id' => 2, + 'category_id' => 2, 'order' => 3, 'value' => 'Item 1000002', 'answer_option_count' => 4, @@ -92,7 +92,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1000003, 'exam_id' => 1, - 'domain_id' => 3, + 'category_id' => 3, 'order' => 4, 'value' => 'Item 1000003', 'answer_option_count' => 4, From 9168960c7483b9c1b3d368ca908f66c70db5e786 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 11:39:37 +0200 Subject: [PATCH 29/35] Added QueuedTask Fixture --- app/Test/Case/Model/ExamTest.php | 6 ++-- app/Test/Fixture/QueuedTaskFixture.php | 38 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 app/Test/Fixture/QueuedTaskFixture.php diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index e10b349..1a9e0c0 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -73,7 +73,9 @@ class ExamTest extends CakeTestCase { * * @var array */ - public $fixtures = array('app.answer_option', 'app.category', 'app.exam', 'app.given_answer', 'app.item', 'app.subject'); + public $fixtures = array( + 'app.answer_option', 'app.category', 'app.exam', 'app.given_answer', 'app.item', 'app.queued_task', 'app.subject' + ); /** * setUp method @@ -257,7 +259,7 @@ public function testScheduleAnalyse() { * @return void */ public function testAnalyse() { - $this->loadFixtures('AnswerOption', 'Exam', 'GivenAnswer', 'Item', 'Subject'); + $this->loadFixtures('AnswerOption', 'Exam', 'GivenAnswer', 'Item', 'QueuedTask', 'Subject'); $id = 1; $result = $this->Exam->analyse($id); diff --git a/app/Test/Fixture/QueuedTaskFixture.php b/app/Test/Fixture/QueuedTaskFixture.php new file mode 100644 index 0000000..b44de5c --- /dev/null +++ b/app/Test/Fixture/QueuedTaskFixture.php @@ -0,0 +1,38 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'job_type' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'data' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'group' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'reference' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'not_before' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'fetched' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'completed' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'failed' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), + 'failure_message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'worker_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array(); + +} From 8491fdea4642e9a39e3483a02f34f039471626a3 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 11:45:49 +0200 Subject: [PATCH 30/35] Fixed typo --- app/Test/Case/Model/ExamTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Test/Case/Model/ExamTest.php b/app/Test/Case/Model/ExamTest.php index 1a9e0c0..f68553d 100644 --- a/app/Test/Case/Model/ExamTest.php +++ b/app/Test/Case/Model/ExamTest.php @@ -544,7 +544,7 @@ public function testExtractTeleformMappingfileWithCategoryWithoutAnswerOptionCou 2 => 'G' ); - $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-categories-without-answer-option-count.csv'; + $filename = APP . DS . 'Test' . DS . 'File' . DS . 'Exam' . DS . 'Teleform-mappingfile-with-category-without-answer-option-count.csv'; $result = $this->Exam->extractTeleformMappingfile($filename); $this->assertTrue((bool)$result); list($versionMapping, $answerOptionCount, $categories) = $result; From 6ece28b4301fd08ceaf30d6d5fb54004719d92ad Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 12:14:32 +0200 Subject: [PATCH 31/35] Added missing fixture --- app/Test/Case/Model/CategoryTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Test/Case/Model/CategoryTest.php b/app/Test/Case/Model/CategoryTest.php index fe01096..4ae1725 100644 --- a/app/Test/Case/Model/CategoryTest.php +++ b/app/Test/Case/Model/CategoryTest.php @@ -18,7 +18,9 @@ class CategoryTest extends CakeTestCase { * * @var array */ - public $fixtures = array('app.answer_option', 'app.category', 'app.exam', 'app.item', 'app.subject'); + public $fixtures = array( + 'app.answer_option', 'app.category', 'app.exam', 'app.given_answer', 'app.item', 'app.subject' + ); /** * setUp method From 87d10de2fc523679a0cf54d2a758a18fa42c68e7 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 12:20:05 +0200 Subject: [PATCH 32/35] Fixed: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'failed' doesn't have a default value --- app/Test/Fixture/QueuedTaskFixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Test/Fixture/QueuedTaskFixture.php b/app/Test/Fixture/QueuedTaskFixture.php index b44de5c..4844624 100644 --- a/app/Test/Fixture/QueuedTaskFixture.php +++ b/app/Test/Fixture/QueuedTaskFixture.php @@ -18,7 +18,7 @@ class QueuedTaskFixture extends CakeTestFixture { 'not_before' => array('type' => 'datetime', 'null' => true, 'default' => null), 'fetched' => array('type' => 'datetime', 'null' => true, 'default' => null), 'completed' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'failed' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'unsigned' => true), + 'failed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 10, 'unsigned' => true), 'failure_message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'worker_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => false, 'default' => null), From ce377e3e3061a89a1113ea1ad228aa7ac441857c Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 12:46:34 +0200 Subject: [PATCH 33/35] Fixed fixture and test --- app/Test/Case/Model/ItemTest.php | 2 +- app/Test/Fixture/ItemFixture.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Test/Case/Model/ItemTest.php b/app/Test/Case/Model/ItemTest.php index 3243a3e..ebd57b3 100644 --- a/app/Test/Case/Model/ItemTest.php +++ b/app/Test/Case/Model/ItemTest.php @@ -87,7 +87,7 @@ public function testGetIds() { $result = $this->Item->getIds($examId); $this->assertEquals($expected, $result); - $expected = array(1000000, 1000001); + $expected = array(1000000, 1000001, 1000003); $examId = 1; $categoryId = 1; $result = $this->Item->getIds($examId, $categoryId); diff --git a/app/Test/Fixture/ItemFixture.php b/app/Test/Fixture/ItemFixture.php index f2e8925..1bca069 100644 --- a/app/Test/Fixture/ItemFixture.php +++ b/app/Test/Fixture/ItemFixture.php @@ -92,7 +92,7 @@ class ItemFixture extends CakeTestFixture { array( 'id' => 1000003, 'exam_id' => 1, - 'category_id' => 3, + 'category_id' => 1, 'order' => 4, 'value' => 'Item 1000003', 'answer_option_count' => 4, From 02d57e2dc030853959a243421b1b536a2c084b0e Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 30 Jun 2016 12:57:43 +0200 Subject: [PATCH 34/35] Phpcs fixes --- app/Test/Fixture/CategoryFixture.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Test/Fixture/CategoryFixture.php b/app/Test/Fixture/CategoryFixture.php index 42c7502..3ffba77 100644 --- a/app/Test/Fixture/CategoryFixture.php +++ b/app/Test/Fixture/CategoryFixture.php @@ -33,14 +33,14 @@ class CategoryFixture extends CakeTestFixture { 'exam_id' => 1, 'name' => 'A', 'cronbachs_alpha' => null, - 'max_answer_option_count' =>null + 'max_answer_option_count' => null ), array( 'id' => 2, 'exam_id' => 1, 'name' => 'B', 'cronbachs_alpha' => null, - 'max_answer_option_count' =>null + 'max_answer_option_count' => null ), ); From 73de2813b3483849bcd235e6292e6fd7f67ea6d7 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Mon, 11 Jul 2016 15:52:41 +0200 Subject: [PATCH 35/35] Fixed tests --- app/Model/Exam.php | 6 +++--- app/Test/Case/Model/ItemTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Model/Exam.php b/app/Model/Exam.php index c0a456e..e37a976 100644 --- a/app/Model/Exam.php +++ b/app/Model/Exam.php @@ -365,7 +365,7 @@ public function analyse($id) { $conditions = array('Exam.id' => $id); $exam = $this->find('first', compact('conditions')); if (!empty($exam)) { - return $this->_analyse($exam); + return $this->_analyse($id); } return false; } @@ -376,7 +376,7 @@ public function analyse($id) { * @param int $id An exam id * @return bool */ - private function _analyse($id) { + protected function _analyse($id) { $this->id = $id; $this->saveField('exam_state_id', ExamState::ANALYSING); @@ -1535,7 +1535,7 @@ protected function _extractTeleformMappingfile($filename) { $categoryIndex = false; for ($i = 0; !feof($handle); $i++) { $line = fgets($handle); - $line = $this->__decodeLine($line, $i == 0); + $line = $this->_decodeLine($line, $i == 0); if ($i == 0) { $header = str_getcsv($line, ';', '"', '"'); diff --git a/app/Test/Case/Model/ItemTest.php b/app/Test/Case/Model/ItemTest.php index 1bfaa75..0d95119 100644 --- a/app/Test/Case/Model/ItemTest.php +++ b/app/Test/Case/Model/ItemTest.php @@ -19,7 +19,7 @@ class TestItem extends Item { * * @var mixed False or table name */ - public $useTable = 'Items'; + public $useTable = 'items'; /** * Public test double of `parent::_getMostGivenIncorrectAnswerOption`.