From 561aa6333631243693d9ac85c07878e75c845a56 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Thu, 25 Aug 2011 20:56:19 +0200 Subject: [PATCH] Implement generating of simple config files --- application/controllers/trials.php | 9 +++-- application/libraries/Job.php | 48 +++++++++++++++++++++++ application/models/trial.php | 28 ++++++++++++- application/views/admin/programs/edit.php | 14 +++++++ 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 application/libraries/Job.php diff --git a/application/controllers/trials.php b/application/controllers/trials.php index e4e2f6d..f9bd280 100644 --- a/application/controllers/trials.php +++ b/application/controllers/trials.php @@ -25,7 +25,7 @@ * Trials are used to store different variations of the same project. * * @author Karsten Heiken - * @author Eike Foken + * @author Eike Foken */ class Trials extends CI_Controller { @@ -84,10 +84,13 @@ class Trials extends CI_Controller { } $this->load->helper('directory'); - $trialPath = FCPATH.'uploads/'.$this->session->userdata('user_id').'/'.$projectId.'/'. $trialId.'/'; + $trialPath = FCPATH . 'uploads/' . $projectId . '/' . $trialId . '/'; mkdirs($trialPath); - redirect('trials/detail/' . $trialId, 'refresh'); + $this->load->library('job'); + $this->job->createConfigs($trialId); + + //redirect('trials/detail/' . $trialId, 'refresh'); } else { $this->messages->add(_('The trial could not be created.'), 'error'); } diff --git a/application/libraries/Job.php b/application/libraries/Job.php new file mode 100644 index 0000000..9971a36 --- /dev/null +++ b/application/libraries/Job.php @@ -0,0 +1,48 @@ + + */ +class Job { + + private $CI; + + /** + * Constructor. + */ + public function __construct() { + $this->CI =& get_instance(); + + // load models + $this->CI->load->model('program'); + $this->CI->load->model('trial'); + + log_message('debug', "Trial Class Initialized"); + } + + /** + * + * @param string $trialId + * @return boolean Returns TRUE on success. + */ + public function createConfigs($trialId) { + $trial = $this->CI->trial->getById($trialId); + $path = FCPATH . 'uploads/' . $trial['project_id'] . '/' . $trial['id'] . '/'; + + $program = $this->CI->program->getById($trial['program_id']); + + $handler = fopen($path . 'trial.conf', "w"); + + $parameters = $this->CI->trial->getParameters($trialId); + foreach ($parameters as $param) { + $line = str_replace("{type}", $param['type'], $program['input_line']); + $line = str_replace("{param}", $param['name'], $line); + $line = str_replace("{value}", $param['value'], $line); + fwrite($handler, $line); + } + fclose($handler); + + return true; + } +} \ No newline at end of file diff --git a/application/models/trial.php b/application/models/trial.php index 815b8bf..e34e3b5 100644 --- a/application/models/trial.php +++ b/application/models/trial.php @@ -82,10 +82,26 @@ class Trial extends CI_Model { return $this->db->affected_rows() == 1 ? $trialId : false; } + /** + * Gets all parameters for the specified trial. + * + * @param string $trialId + * @return array + */ + public function getParameters($trialId) { + $this->db->select('trials_parameters.*, parameters.name AS `name`, parameters.type AS `type`'); + $this->db->join('parameters', 'trials_parameters.parameter_id = parameters.id', 'left'); + $this->db->where('trial_id', $trialId); + + $query = $this->db->get('trials_parameters'); + + return $query->num_rows() > 0 ? $query->result_array() : false; + } + /** * Get a trial by id. * - * @param type $trial_id The trial to get. + * @param string $trial_id The trial to get. * @return array The trial */ public function get($trial_id) { @@ -94,6 +110,16 @@ class Trial extends CI_Model { return $query->row_array(); } + /** + * Gets a trial by ID. + * + * @param string $trialId The trial to get + * @return array The trial + */ + public function getById($trialId) { + return $this->db->get_where('trials', array('id' => $trialId))->row_array(); + } + /** * Get a trial by its project id. * diff --git a/application/views/admin/programs/edit.php b/application/views/admin/programs/edit.php index ddf9f4e..2c58427 100644 --- a/application/views/admin/programs/edit.php +++ b/application/views/admin/programs/edit.php @@ -31,6 +31,20 @@ $(document).ready(function() { +
  • + + * +
    + + +
    + +