Add ability to create new trials

This commit is contained in:
Eike Foken
2011-08-18 20:48:44 +02:00
parent 04c8301d6f
commit 20d0d2b9f5
4 changed files with 118 additions and 74 deletions

View File

@@ -24,7 +24,7 @@
/**
* Trials are used to store different variations of the same project.
*
*
* @author Karsten Heiken <karsten@disposed.de>
*/
class Trial extends CI_Model {
@@ -56,6 +56,28 @@ class Trial extends CI_Model {
return $this->db->delete('trials', array('id' => $trial_id));
}
/**
* Adds a parameter for a specific trial.
*
* @param array $data
* @param string $trialId
* @return boolean Returns TRUE if the parameter was added successfully.
*/
public function addParameter($data, $trialId) {
if (!isset($data['parameter_id'])) {
return false;
}
$trial = $this->get($trialId);
$parameter = $this->db->get_where('parameters', array('id' => $data['parameter_id']))->row_array();
if (isset($trial['id']) && $trial['program_id'] == $parameter['program_id']) {
$data['trial_id'] = $trialId;
$this->db->insert('trials_parameters', $data);
}
return $this->db->affected_rows() == 1 ? $trialId : false;
}
/**
* Get a trial by id.
*