Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
06d9a0a
Updated schema configuration file to actual database schema
mvdriel Dec 10, 2015
de1fe28
Updated fixtures
mvdriel Dec 10, 2015
0e5df77
Added missing fixtures
mvdriel Dec 10, 2015
ab5daec
Removed default setting for validation rule: 'last' => true
mvdriel Dec 10, 2015
ba4d246
Fixed: PHP Fatal error: Class 'QuestionFormat' not found
mvdriel Dec 10, 2015
a4fa42b
Added Domain model and associations
mvdriel Dec 10, 2015
15aac50
Refactoring and adding test
mvdriel Dec 10, 2015
9094ae2
Added missing file
mvdriel Dec 14, 2015
e97b650
Updated database schema
mvdriel Dec 14, 2015
287b2ab
Added Domain Fixture
mvdriel Dec 14, 2015
6d84d60
Added tests for other columns headers in Teleform mapping files
mvdriel Dec 14, 2015
9ebb9d2
Added support for import of domain in Teleform mapping file
mvdriel Dec 14, 2015
d73fca6
Merge branch 'master' into support-for-item-domains
mvdriel Dec 16, 2015
3c73d32
Removed unused fields
mvdriel Dec 16, 2015
8753a82
Refactoring
mvdriel Dec 16, 2015
658f3cd
Added support to filter items by domain when analysing an exam
mvdriel Dec 16, 2015
8042f43
Updated fixture
mvdriel Dec 18, 2015
60d040b
Merge branch 'master' into support-for-item-domains
mvdriel Jan 6, 2016
f571665
Add support for item domains
mvdriel Jan 6, 2016
89a03bd
Fixed naming conflict in TestExam
mvdriel Jan 6, 2016
981d81a
Fixed MissingTableException in Tests
mvdriel Jan 6, 2016
10ef36f
Fixed phpcs issue
mvdriel Jan 6, 2016
2f93534
Added tests and fixes
mvdriel Jan 7, 2016
aa0211d
Added fixture data and tests
mvdriel Jan 11, 2016
3b07566
Fixed test
mvdriel Jan 11, 2016
f742b86
Fixed test
mvdriel Jan 11, 2016
938639c
Fixed typos
mvdriel Jan 13, 2016
b2dc129
Added data to fixtures
mvdriel Jan 13, 2016
5ea0ef7
Merge branch 'master' into support-for-item-domains
mvdriel Jan 14, 2016
ecca5e4
Merge branch 'master' into support-for-item-domains
mvdriel May 30, 2016
4d446f2
Added field max_answer_option_count to table domains
mvdriel Jun 15, 2016
451a397
Merge branch 'master' into support-for-item-domains
mvdriel Jun 15, 2016
9e70e4a
Merge branch 'master' into support-for-item-domains
mvdriel Jun 16, 2016
f87539f
Refactoring: renamed domain to category
mvdriel Jun 29, 2016
9168960
Added QueuedTask Fixture
mvdriel Jun 30, 2016
8491fde
Fixed typo
mvdriel Jun 30, 2016
6ece28b
Added missing fixture
mvdriel Jun 30, 2016
87d10de
Fixed: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'fail…
mvdriel Jun 30, 2016
ce377e3
Fixed fixture and test
mvdriel Jun 30, 2016
02d57e2
Phpcs fixes
mvdriel Jun 30, 2016
fa1e03a
Merge branch 'master' into support-for-item-domains
mvdriel Jun 30, 2016
40df923
Merge branch 'master' into support-for-item-domains
mvdriel Jul 11, 2016
73de281
Fixed tests
mvdriel Jul 11, 2016
2782988
Merge branch 'master' into support-for-item-domains
mvdriel Jul 14, 2016
574db31
Merge branch 'master' into support-for-item-domains
mvdriel Jul 21, 2016
a6010c7
Merge branch 'master' into support-for-item-domains
mvdriel Aug 11, 2016
0c0a28c
Merge branch 'master' into support-for-item-domains
mvdriel Aug 11, 2016
ac3aae8
Merge branch 'master' into support-for-item-domains
mvdriel Sep 21, 2016
0bce6cc
Merge branch 'master' into support-for-item-domains
mvdriel Oct 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 91 additions & 64 deletions app/Config/Schema/schema.php

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions app/Model/AppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,82 @@ public function removeFieldFromSchema($fieldname) {
unset($this->_schema[$fieldname]);
}

/**
* Save analysis to an ezam or a category
*
* @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('Category', 'Exam'))) {
throw new NotImplementedException();
}

$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'));
$object = $this->find('first', compact('conditions', 'contain'));

if ($this->alias === 'Category') {
$data = array(
'Category' => 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 === '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];
$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 === '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];
$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));
}

}
157 changes: 157 additions & 0 deletions app/Model/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php
App::uses('AppModel', 'Model');
/**
* Category Model
*
* @property Exam $Exam
* @property Item $Item
*/
class Category extends AppModel {

/**
* Validation rules
*
* @var array
*/
public $validate = array(
'exam_id' => 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' => 'category_id',
'dependent' => false
)
);

/**
* analyse
*
* @param int $id A category id
* @param int $examId An exam id
* @return bool
*/
public function analyse($id, $examId) {
$result = $this->Exam->doAnalyse($examId, $id);

if ($result) {
$result = $this->saveAnalysis($id, $result);
}
return $result;
}

/**
* 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 categories
* @return bool|array An array with category ids in the same order as corresponding given names, false on failure
*/
public function createCategories($examId, $names) {
$categoryIds = array();
if (!empty($names)) {
$uniqueNames = array_values($names);
$uniqueNames = array_unique($uniqueNames);

$data = array();
foreach ($uniqueNames as $name) {
$data[] = array(
'exam_id' => $examId,
'name' => $name
);
}
$this->create();
if ($this->saveAll($data)) {
$conditions = array('Category.exam_id' => $examId);
$categories = $this->find('list', compact('conditions'));

foreach ($names as $i => $name) {
foreach ($categories as $id => $category) {
if ($name === $category) {
$categoryIds[$i] = $id;
break;
}
}
}
} else {
$categoryIds = false;
}
}
return $categoryIds;
}

/**
* 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 category ids as key and corresponding duplicated category ids as value, false on failure
*/
public function duplicate($examIds) {
$mapping = array();

$conditions = array('Category.exam_id' => array_keys($examIds));
$categories = $this->find('all', compact('conditions'));

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($category)) {
return false;
}
$mapping[$oldId] = $this->getInsertID();
}
return $mapping;
}

}
Loading