From b2a9b8b087aa6ecd92a0363a5348295191321730 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Fri, 19 Aug 2011 01:44:23 +0200 Subject: [PATCH] Extend project and trial management --- application/config/form_validation.php | 23 +++++ application/controllers/projects.php | 95 +++++++++---------- application/controllers/trials.php | 61 ++++-------- application/models/trial.php | 14 ++- application/views/project/detail.php | 93 ------------------ application/views/project/list.php | 39 -------- application/views/projects/detail.php | 95 +++++++++++++++++++ .../views/{project => projects}/index.html | 0 application/views/projects/list.php | 39 ++++++++ .../views/{project => projects}/new.php | 0 application/views/trial/new.php | 1 + 11 files changed, 231 insertions(+), 229 deletions(-) delete mode 100644 application/views/project/detail.php delete mode 100644 application/views/project/list.php create mode 100644 application/views/projects/detail.php rename application/views/{project => projects}/index.html (100%) create mode 100644 application/views/projects/list.php rename application/views/{project => projects}/new.php (100%) diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 116dff5..c4509c9 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -201,6 +201,29 @@ $config['parameters/create'] = array( ), ); +/** + * Rules for creating trials. + * + * @var array + */ +$config['trials/create'] = array( + array( + 'field' => 'name', + 'label' => _('Trial name'), + 'rules' => 'required|min_length[3]|max_length[60]|trim', + ), + array( + 'field' => 'description', + 'label' => _('Description'), + 'rules' => 'required|trim', + ), + array( + 'field' => 'program_id', + 'label' => _('Program'), + 'rules' => 'required|alpha_numeric|trim', + ), +); + /* End of file form_validation.php */ /* Location: ./application/config/form_validation.php */ diff --git a/application/controllers/projects.php b/application/controllers/projects.php index cd8ef2d..1c7dff7 100644 --- a/application/controllers/projects.php +++ b/application/controllers/projects.php @@ -1,30 +1,31 @@ -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ /** + * * @author Karsten Heiken -*/ + * @author Eike Foken + */ class Projects extends CI_Controller { /** @@ -43,7 +44,7 @@ class Projects extends CI_Controller { $projects = $this->project->getAll(); $tpl['projects'] = $projects; - $this->load->view('project/list', $tpl); + $this->load->view('projects/list', $tpl); } /** @@ -100,7 +101,7 @@ class Projects extends CI_Controller { $data['model']['success'] = isset($modelUploaded) && $modelUploaded ? true : false; $data['config']['success'] = isset($configUploaded) && $configUploaded ? true: false; - $this->load->view('project/new', $data); + $this->load->view('projects/new', $data); } else { $data = array( 'name' => $this->input->post('name'), @@ -112,17 +113,9 @@ class Projects extends CI_Controller { $data['project_id'] = $this->project->create($data); if (isset($data['project_id'])) { - $userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/'; - $projectpath = $userpath . $data['project_id'] . '/'; - - if (!is_dir($projectpath)) { - if (!is_dir($userpath)) { - mkdir($userpath, 0777); - chmod($userpath, 0777); - } - mkdir($projectpath, 0777); - chmod($projectpath, 0777); - } + $this->load->helper('directory'); + $projectPath = FCPATH.'uploads/'.$this->session->userdata('user_id').'/'.$data['project_id'].'/'; + mkdirs($projectPath); if ($modelUploaded) { copy($modelData['full_path'], $projectpath . $modelData['file_name']); @@ -132,10 +125,10 @@ class Projects extends CI_Controller { } $this->messages->add($projectpath, 'notice'); - redirect('/projects/detail/' . $data['project_id'], 301); + redirect('/projects/detail/' . $data['project_id'], 303); } else { $this->messages->add(_('The project could not be created.'), 'error'); - $this->load->view('project/new'); + $this->load->view('projects/new'); } } } @@ -143,22 +136,22 @@ class Projects extends CI_Controller { /** * Shows the project details * - * @param integer $prj_id The ID of the project to show + * @param integer $id The ID of the project to show */ - public function detail($prj_id) { - $project = $this->project->getById($prj_id); + public function detail($id) { + $this->load->helper('typography'); + + $project = $this->project->getById($id); if (!$project) { $this->messages->add(_('The project could not be loaded.'), 'error'); - redirect('projects', 301); + redirect('projects', 303); } - $this->session->set_userdata('active_project', $prj_id); - $trials = $this->trial->getByProjectId($prj_id); + $data['project'] = $project; + $data['trials'] = $this->trial->getByProjectId($id); + $data['jobsDone'] = null; - $tpl['project'] = $project; - $tpl['trials'] = $trials; - $tpl['jobsDone'] = null; - $this->load->view('project/detail', $tpl); + $this->load->view('projects/detail', $data); } /** @@ -166,11 +159,11 @@ class Projects extends CI_Controller { * * @param integer $projectId */ - public function delete($projectId) { - $this->project->delete($projectId); - $this->session->unset_userdata('active_project'); - $this->messages->add(_('The project was deleted.'), 'success'); - redirect('projects'); + public function delete($id) { + if ($this->project->delete($id)) { + $this->messages->add(_('The project was deleted.'), 'success'); + } + redirect('projects', 303); } } diff --git a/application/controllers/trials.php b/application/controllers/trials.php index 0a65c45..e4e2f6d 100644 --- a/application/controllers/trials.php +++ b/application/controllers/trials.php @@ -42,9 +42,13 @@ class Trials extends CI_Controller { } /** - * Create a new project. + * Allows users to create new trials. + * + * @param string $projectId */ - public function create($projectId = '') { + public function create($projectId = '', $copyId = '') { + // TODO: Handle copying of trials + $project = $this->project->getByID($projectId); if (empty($projectId) || !isset($project['id'])){ @@ -58,22 +62,8 @@ class Trials extends CI_Controller { $parameters[$program['id']] = $this->parameter->getAll($program['id']); } - $config = array( - array( - 'field' => 'name', - 'label' => _('Trial name'), - 'rules' => 'required|min_length[3]|max_length[60]|trim', - ), - array( - 'field' => 'description', - 'label' => _('Description'), - 'rules' => 'required|trim', - ), - ); - $this->form_validation->set_rules($config); - - if ($this->form_validation->run() === true) { - // TODO: handle file upload + if ($this->form_validation->run('trials/create') === true) { + // TODO: Handle file upload $data = array( 'name' => $this->input->post('name'), @@ -83,43 +73,32 @@ class Trials extends CI_Controller { 'creator_id' => $this->session->userdata('user_id'), ); - $result = $this->trial->create($data); - if ($result) { + $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, $result); + $this->trial->addParameter($param, $trialId); } } - $userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/'; - $projectpath = $userpath . $projectId . '/'; - $trialpath = $projectpath . $result . '/'; - if(!is_dir($trialpath)) { - if (!is_dir($projectpath)) { - if(!is_dir($userpath)) { - mkdir($userpath); - chmod($userpath, 0777); - } - mkdir($projectpath); - chmod($projectpath, 0777); - } - mkdir($trialpath); - chmod($trialpath, 0777); - } + $this->load->helper('directory'); + $trialPath = FCPATH.'uploads/'.$this->session->userdata('user_id').'/'.$projectId.'/'. $trialId.'/'; + mkdirs($trialPath); - redirect('trials/detail/' . $result, 'refresh'); + redirect('trials/detail/' . $trialId, 'refresh'); } else { $this->messages->add(_('The trial could not be created.'), 'error'); } } - $tpl['parameters'] = $parameters; - $tpl['programs'] = $programs; - $tpl['project'] = $project; + $data = array(); // empty the data array + $data['parameters'] = $parameters; + $data['programs'] = $programs; + $data['project'] = $project; - $this->load->view('trial/new', $tpl); + $this->load->view('trial/new', $data); } } diff --git a/application/models/trial.php b/application/models/trial.php index fdf34b1..815b8bf 100644 --- a/application/models/trial.php +++ b/application/models/trial.php @@ -36,15 +36,19 @@ class Trial extends CI_Model { * @return bool was the insert successful */ public function create($data) { - do { + if (!isset($data['project_id'])) { + return false; + } + + do { // generate unique hash $data['id'] = random_hash(); } while ($this->db->where('id', $data['id'])->from('trials')->count_all_results() > 0); - - if ($this->db->insert('trials', $data)) + if ($this->db->insert('trials', $data)) { return $data['id']; - else - return FALSE; + } else { + return false; + } } /** diff --git a/application/views/project/detail.php b/application/views/project/detail.php deleted file mode 100644 index 8dc708d..0000000 --- a/application/views/project/detail.php +++ /dev/null @@ -1,93 +0,0 @@ -load->view('header'); ?> - -
- -
-

-
- -
-

-
-

- -

- - - - - - - - - - 0): - foreach($trials as $trial): -?> - - - - - - - - - - - -
- | - | -
- -

-

- -
-

-
- -
- - - - - - - - - - 0): - foreach($jobsDone as $job): -?> - - - - - - - - - - - -
VersuchsnameHeute, 09:32 - | -
-
- -
- -load->view('footer'); ?> diff --git a/application/views/project/list.php b/application/views/project/list.php deleted file mode 100644 index cf40bbe..0000000 --- a/application/views/project/list.php +++ /dev/null @@ -1,39 +0,0 @@ -load->view('header');?> - -
- -
-

-
- -
- - - - - - - - - - - - - - - - - - - -
| -
-
- -
- -load->view('footer');?> diff --git a/application/views/projects/detail.php b/application/views/projects/detail.php new file mode 100644 index 0000000..d405736 --- /dev/null +++ b/application/views/projects/detail.php @@ -0,0 +1,95 @@ +load->view('header');?> + +
+ +
+

+
+ +
+

+
+

+ +

+ + + + + + + + + + 0): + foreach ($trials as $trial): +?> + + + + + + + + + + + +
"> + | + | + | + +
+ +

+

+ +
+

+
+ +
+ + + + + + + + + + 0): + foreach ($jobsDone as $job): +?> + + + + + + + + + + + +
VersuchsnameHeute, 09:32 + | +
+
+ +
+ +load->view('footer');?> diff --git a/application/views/project/index.html b/application/views/projects/index.html similarity index 100% rename from application/views/project/index.html rename to application/views/projects/index.html diff --git a/application/views/projects/list.php b/application/views/projects/list.php new file mode 100644 index 0000000..3d92310 --- /dev/null +++ b/application/views/projects/list.php @@ -0,0 +1,39 @@ +load->view('header');?> + +
+ +
+

+
+ +
+ + + + + + + + + + + + + + + + + + + +
| +
+
+ +
+ +load->view('footer');?> diff --git a/application/views/project/new.php b/application/views/projects/new.php similarity index 100% rename from application/views/project/new.php rename to application/views/projects/new.php diff --git a/application/views/trial/new.php b/application/views/trial/new.php index 1ebd354..17749dd 100644 --- a/application/views/trial/new.php +++ b/application/views/trial/new.php @@ -66,6 +66,7 @@ ?>

+