Create directory structure when creating a project or trial

This commit is contained in:
Karsten Heiken
2011-08-01 16:31:54 +02:00
parent 40406456cb
commit 4ce4e8c9e0
2 changed files with 56 additions and 41 deletions

View File

@@ -27,17 +27,17 @@
*/
class Projects extends CI_Controller {
/**
* Constructor.
*/
public function __construct() {
parent::__construct();
$this->load->model('project');
$this->load->model('trial');
/**
* Constructor.
*/
public function __construct() {
parent::__construct();
$this->load->model('project');
$this->load->model('trial');
// load language file
$this->lang->load(strtolower($this->router->class));
}
// load language file
$this->lang->load(strtolower($this->router->class));
}
/**
* Create a new project.
@@ -66,16 +66,13 @@ class Projects extends CI_Controller {
'label' => 'Standard-Konfiguration',
),
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$this->load->view('project/new');
}
else
{
} else {
// TODO: handle file upload
$data = array(
@@ -85,37 +82,46 @@ class Projects extends CI_Controller {
'defaultconfig' => "todo",
);
$result = $this->project->create($data);
if($result)
redirect('/projects/detail/' . $result, 301);
else {
$data['project_id'] = $this->project->create($data);
if ($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);
mkdir($projectpath, 0777);
chmod($userpath, 0777);
chmod($projectpath, 0777);
$this->messages->add($projectpath, 'notice');
redirect('/projects/detail/' . $data['project_id'], 301);
} else {
$this->messages->add('Das Projekt konnte nicht gespeichert werden.', 'error');
$this->load->view('project/new');
}
}
}
public function index() {
$projects = $this->project->getAll();
$tpl['projects'] = $projects;
$this->load->view('project/list', $tpl);
}
public function detail($prj_id) {
$project = $this->project->getById($prj_id);
if(!$project) {
if (!$project) {
$this->messages->add('Das Projekt konnte nicht geladen werden.', 'error');
redirect('/projects/', 301);
}
$this->session->set_userdata('active_project', $prj_id);
$trials = $this->trial->getByProjectId($prj_id);
$tpl['project'] = $project;
$tpl['trials'] = $trials;
$tpl['jobsDone'] = null;
$this->load->view('project/detail', $tpl);
}
}

View File

@@ -30,17 +30,17 @@
class Trials extends CI_Controller {
/**
* Constructor.
*/
public function __construct() {
parent::__construct();
$this->load->model('trial');
* Constructor.
*/
public function __construct() {
parent::__construct();
$this->load->model('trial');
$this->load->model('program');
$this->load->model('project');
// load language file
// $this->lang->load(strtolower($this->router->class));
}
// load language file
// $this->lang->load(strtolower($this->router->class));
}
/**
* Create a new project.
@@ -52,7 +52,7 @@ class Trials extends CI_Controller {
$programs = $this->program->getAll();
// Get the parameters for a specific program
foreach($programs as $program)
foreach ($programs as $program)
$parameters[$program['id']] = $this->program->getParameters($program['id']);
$config = array(
@@ -71,14 +71,11 @@ class Trials extends CI_Controller {
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$tpl['parameters'] = $parameters;
$tpl['programs'] = $programs;
$this->load->view('trial/new', $tpl);
}
else
{
} else {
// TODO: handle file upload
$data = array(
@@ -89,13 +86,25 @@ class Trials extends CI_Controller {
);
$result = $this->trial->create($data);
if($result)
if ($result) {
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
$projectpath = $userpath . $data['project_id'] . '/';
$trialpath = $projectpath . $data['trial_id'] . '/';
if(!is_dir($trialpath))
if (!is_dir($projectpath))
if(!is_dir($userpath))
mkdir($userpath);
mkdir($projectpath);
mkdir($trialpath);
chmod($userpath, 0777);
chmod($projectpath, 0777);
chmod($trialpath, 0777);
redirect('/trial/detail/' . $result, 'refresh');
else {
} else {
$tpl['error'][] = "Der Versuch konnte nicht gespeichert werden.";
$this->load->view('trial/new', $tpl);
}
}
}
}