Fix trial creation
This commit is contained in:
@@ -206,6 +206,34 @@ $config['parameters/create'] = array(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rules for creating projects.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
$config['projects/create'] = array(
|
||||||
|
array(
|
||||||
|
'field' => 'name',
|
||||||
|
'label' => _('Project name'),
|
||||||
|
'rules' => 'required|min_length[3]|max_length[100]|trim',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'description',
|
||||||
|
'label' => _('Description'),
|
||||||
|
'rules' => 'required|trim',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'defaultmodel',
|
||||||
|
'label' => _('3D model'),
|
||||||
|
'rules' => 'file_allowed_type[obj]',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'defaultconfig',
|
||||||
|
'label' => _('Default configuration'),
|
||||||
|
'rules' => 'file_allowed_type[calc]',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rules for creating trials.
|
* Rules for creating trials.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Trials extends CI_Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
$this->load->library('upload');
|
||||||
$this->load->model('parameter');
|
$this->load->model('parameter');
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
$this->load->model('project');
|
$this->load->model('project');
|
||||||
@@ -64,35 +65,53 @@ class Trials extends CI_Controller {
|
|||||||
|
|
||||||
if ($this->form_validation->run('trials/create') === true) {
|
if ($this->form_validation->run('trials/create') === true) {
|
||||||
// TODO: Handle file upload
|
// TODO: Handle file upload
|
||||||
|
$config = array(
|
||||||
$data = array(
|
'upload_path' => '/tmp',
|
||||||
'name' => $this->input->post('name'),
|
'allowed_types' => '*',
|
||||||
'description' => $this->input->post('description'),
|
'max_size' => ini_get('upload_max_filesize'),
|
||||||
'program_id' => $this->input->post('program_id'),
|
'file_name' => 'default',
|
||||||
'project_id' => $projectId,
|
|
||||||
'creator_id' => $this->session->userdata('user_id'),
|
|
||||||
);
|
);
|
||||||
|
$this->upload->initialize($config);
|
||||||
|
|
||||||
$trialId = $this->trial->create($data);
|
if (!$this->upload->do_upload('3dmodel')) {
|
||||||
if ($trialId) {
|
$this->messages->add(_('There was an error while uploading the selected 3d model.'), 'error');
|
||||||
foreach ($_POST as $key => $value) {
|
|
||||||
if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) {
|
|
||||||
$param['parameter_id'] = substr($key, 6, 16);
|
|
||||||
$param['value'] = $this->input->post($key);
|
|
||||||
$this->trial->addParameter($param, $trialId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->load->helper('directory');
|
|
||||||
$trialPath = FCPATH . 'uploads/' . $projectId . '/' . $trialId . '/';
|
|
||||||
mkdirs($trialPath);
|
|
||||||
|
|
||||||
$this->load->library('job');
|
|
||||||
$this->job->createConfigs($trialId);
|
|
||||||
|
|
||||||
//redirect('trials/detail/' . $trialId, 'refresh');
|
|
||||||
} else {
|
} else {
|
||||||
$this->messages->add(_('The trial could not be created.'), 'error');
|
$data = array(
|
||||||
|
'name' => $this->input->post('name'),
|
||||||
|
'description' => $this->input->post('description'),
|
||||||
|
'program_id' => $this->input->post('program_id'),
|
||||||
|
'project_id' => $projectId,
|
||||||
|
'creator_id' => $this->session->userdata('user_id'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$trialId = $this->trial->create($data);
|
||||||
|
if ($trialId) {
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) {
|
||||||
|
$param['parameter_id'] = substr($key, 6, 16);
|
||||||
|
$param['value'] = $this->input->post($key);
|
||||||
|
$this->trial->addParameter($param, $trialId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->load->helper('directory');
|
||||||
|
$trialPath = FCPATH . 'uploads/' . $projectId . '/' . $trialId . '/';
|
||||||
|
mkdirs($trialPath);
|
||||||
|
|
||||||
|
$model = $this->upload->data();
|
||||||
|
if (!copy($model['full_path'], $trialPath . $model['file_name'])) {
|
||||||
|
$this->messages->add(_('The selected 3d model could not be copied to trial path.'), 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
$program = $this->program->getById($data['program_id']);
|
||||||
|
|
||||||
|
$this->load->library('program_runner', array('program_driver' => $program['driver']));
|
||||||
|
$this->program_runner->createJob($trialId);
|
||||||
|
|
||||||
|
redirect('trials/detail/' . $trialId, 'refresh');
|
||||||
|
} else {
|
||||||
|
$this->messages->add(_('The trial could not be created.'), 'error');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<h2><?=_('Create a new trial');?></h2>
|
<h2><?=_('Create a new trial');?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form name="newTrial" method="post" action="<?=site_url('trials/create/' . $project['id']);?>">
|
<form name="newTrial" method="post" action="<?=site_url('trials/create/' . $project['id']);?>" enctype="multipart/form-data">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
||||||
<h3><?=_('Required information');?></h3>
|
<h3><?=_('Required information');?></h3>
|
||||||
@@ -31,8 +31,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<h4><?=_('3D model');?></h4>
|
<h4><?=_('3D model');?></h4>
|
||||||
<?
|
<?
|
||||||
$defaultmodel = 'foo';
|
if (file_exists(FCPATH.'uploads/'.$project['id'].'/default.txt')):
|
||||||
if (isset($defaultmodel)):
|
|
||||||
?>
|
?>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
<strong><?=_('There is a default model set for this project.');?></strong><br />
|
<strong><?=_('There is a default model set for this project.');?></strong><br />
|
||||||
@@ -42,8 +41,9 @@
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" class="file" name="defaultmodel" value="<?=set_value('defaultmodel');?>" />
|
<input type="file" class="file" name="3dmodel" value="<?=set_value('3dmodel');?>" />
|
||||||
<?=form_error('defaultmodel');?>
|
<?=form_error('3dmodel');?>
|
||||||
|
<?=$this->upload->display_errors('<span class="error">', '</span>');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -53,7 +53,6 @@
|
|||||||
|
|
||||||
<h3><?=_('Application-specific parameters');?></h3>
|
<h3><?=_('Application-specific parameters');?></h3>
|
||||||
<?
|
<?
|
||||||
$defaultconfig = 'foo';
|
|
||||||
if (isset($defaultconfig)):
|
if (isset($defaultconfig)):
|
||||||
?>
|
?>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
|
|||||||
Reference in New Issue
Block a user