Implement program parameter management
This commit is contained in:
133
application/controllers/admin/parameters.php
Normal file
133
application/controllers/admin/parameters.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2011 Eike Foken <kontakt@eikefoken.de>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
require_once APPPATH . 'core/Admin_Controller.php';
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Eike Foken <kontakt@eikefoken.de>
|
||||
*/
|
||||
class Parameters extends Admin_Controller {
|
||||
|
||||
/**
|
||||
* Calls the parent constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->model('parameter');
|
||||
$this->load->model('program');
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows admins to create a new parameter.
|
||||
*
|
||||
* @param string $programId
|
||||
*/
|
||||
public function create($programId = '') {
|
||||
$program = $this->program->getByID($programId);
|
||||
|
||||
if (empty($programId) || !isset($program['id'])) {
|
||||
show_404();
|
||||
}
|
||||
|
||||
if ($this->form_validation->run('parameters/create') === true) {
|
||||
$paramName = $this->input->post('name');
|
||||
|
||||
$data = array(
|
||||
'program_id' => $program['id'],
|
||||
'name' => $paramName,
|
||||
'readable' => $this->input->post('readable'),
|
||||
'unit' => $this->input->post('unit'),
|
||||
'description' => $this->input->post('description'),
|
||||
'type' => $this->input->post('type'),
|
||||
'default_value' => $this->input->post('default_value'),
|
||||
);
|
||||
|
||||
if ($this->parameter->create($data)) {
|
||||
$this->messages->add(sprintf(_("The parameter '%s' has been successfully created."), $paramName), 'success');
|
||||
redirect('admin/programs/edit/' . $program['id'], 303);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array(); // empty the data array
|
||||
$data['types'] = $this->parameter->getTypes();
|
||||
$data['program'] = $program;
|
||||
|
||||
$this->load->view('admin/parameters/create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows admins to edit a parameter.
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function edit($id = '') {
|
||||
$parameter = $this->parameter->getByID($id);
|
||||
|
||||
if (empty($id) || !isset($parameter['id'])){
|
||||
show_404();
|
||||
}
|
||||
|
||||
if ($this->form_validation->run('parameters/create') === true) {
|
||||
$data = array(
|
||||
'name' => $this->input->post('name'),
|
||||
'readable' => $this->input->post('readable'),
|
||||
'unit' => $this->input->post('unit'),
|
||||
'description' => $this->input->post('description'),
|
||||
'type' => $this->input->post('type'),
|
||||
'default_value' => $this->input->post('default_value'),
|
||||
);
|
||||
|
||||
if ($this->parameter->update($data, $id)) {
|
||||
$this->messages->add(sprintf(_("The parameter '%s' has been successfully updated."), $parameter['name']), 'success');
|
||||
redirect('admin/programs/edit/' . $parameter['program_id'], 303);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array(); // empty the data array
|
||||
$data['types'] = $this->parameter->getTypes();
|
||||
$data['parameter'] = $parameter;
|
||||
|
||||
$this->load->view('admin/parameters/edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows admins to delete a parameter.
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function delete($id = '') {
|
||||
$parameter = $this->parameter->getByID($id);
|
||||
|
||||
if (empty($id) || !isset($parameter['id'])) {
|
||||
show_404();
|
||||
} else {
|
||||
if ($this->parameter->delete($parameter['id'])) {
|
||||
$this->messages->add(_('The selected parameter has been successfully deleted.'), 'success');
|
||||
}
|
||||
redirect('admin/programs/edit/' . $parameter['program_id'], 303);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file parameters.php */
|
||||
/* Location: ./application/controllers/admin/parameters.php */
|
||||
@@ -13,6 +13,7 @@ class Programs extends CI_Controller {
|
||||
parent::__construct();
|
||||
$this->load->library('form_validation');
|
||||
$this->load->model('program');
|
||||
$this->load->model('parameter');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,8 +44,9 @@ class Programs extends CI_Controller {
|
||||
}
|
||||
|
||||
$data['program'] = $program;
|
||||
$data['parameters'] = $this->program->getParameters($program['id']);
|
||||
$data['parameters'] = $this->parameter->getAll($program['id']);
|
||||
|
||||
$this->load->view('admin/programs/edit', $data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user