Improved MVC layout of code
这个提交包含在:
父节点
8ac7fbd70f
当前提交
eaddb5220c
共有 5 个文件被更改,包括 149 次插入 和 92 次删除
|
|
@ -5,8 +5,8 @@ class Notes extends CI_Controller {
|
||||||
/* Displays all notes in a list */
|
/* Displays all notes in a list */
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
$this->load->model('note');
|
||||||
$data['notes'] = $this->db->get('notes');
|
$data['notes'] = $this->note->list_all();
|
||||||
|
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('notes/main', $data);
|
$this->load->view('notes/main', $data);
|
||||||
|
|
@ -16,6 +16,8 @@ class Notes extends CI_Controller {
|
||||||
/* Provides function for adding notes to the system. */
|
/* Provides function for adding notes to the system. */
|
||||||
function add() {
|
function add() {
|
||||||
|
|
||||||
|
$this->load->model('note');
|
||||||
|
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
$this->form_validation->set_rules('title', 'Note Title', 'required');
|
$this->form_validation->set_rules('title', 'Note Title', 'required');
|
||||||
|
|
@ -29,14 +31,8 @@ class Notes extends CI_Controller {
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$data = array(
|
$this->note->add();
|
||||||
'cat' => $this->input->post('category'),
|
|
||||||
'title' => $this->input->post('title'),
|
|
||||||
'note' => $this->input->post('content')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->db->insert('notes', $data);
|
|
||||||
|
|
||||||
redirect('notes');
|
redirect('notes');
|
||||||
}
|
}
|
||||||
|
|
@ -44,9 +40,9 @@ class Notes extends CI_Controller {
|
||||||
|
|
||||||
/* View Notes */
|
/* View Notes */
|
||||||
function view($id) {
|
function view($id) {
|
||||||
// Get Note
|
$this->load->model('note');
|
||||||
$this->db->where('id', $id);
|
|
||||||
$data['note'] = $this->db->get('notes');
|
$data['note'] = $this->note->view($id);
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
|
|
@ -56,10 +52,10 @@ class Notes extends CI_Controller {
|
||||||
|
|
||||||
/* Edit Notes */
|
/* Edit Notes */
|
||||||
function edit($id) {
|
function edit($id) {
|
||||||
|
$this->load->model('note');
|
||||||
$data['id'] = $id;
|
$data['id'] = $id;
|
||||||
$this->db->where('id', $id);
|
|
||||||
$data['note'] = $this->db->get('notes');
|
$data['note'] = $this->note->view($id);
|
||||||
|
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
|
|
@ -75,22 +71,17 @@ class Notes extends CI_Controller {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$data = array(
|
$this->note->edit();
|
||||||
'cat' => $this->input->post('category'),
|
|
||||||
'title' => $this->input->post('title'),
|
|
||||||
'note' => $this->input->post('content')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->db->where('id', $this->input->post('id'));
|
|
||||||
$this->db->update('notes', $data);
|
|
||||||
|
|
||||||
redirect('notes');
|
redirect('notes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete Note */
|
/* Delete Note */
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$this->db->delete('notes', array('id' => $id));
|
$this->load->model('note');
|
||||||
|
$this->note->delete($id);
|
||||||
|
|
||||||
redirect('notes');
|
redirect('notes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,12 +12,11 @@ class QSO extends CI_Controller {
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
$this->load->model('logbook_model');
|
||||||
|
|
||||||
$data['notice'] = false;
|
$data['notice'] = false;
|
||||||
|
|
||||||
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY');
|
$data['query'] = $this->logbook_model->last_ten();
|
||||||
$this->db->order_by("COL_TIME_ON", "desc");
|
|
||||||
$this->db->limit(10);
|
|
||||||
$data['query'] = $this->db->get($this->config->item('table_name'));
|
|
||||||
|
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
|
|
@ -33,41 +32,23 @@ class QSO extends CI_Controller {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Join date+time
|
|
||||||
$datetime = date('Y-m-d') ." ". $this->input->post('start_time');
|
|
||||||
|
|
||||||
// Create array with QSO Data
|
// Add QSO
|
||||||
$data = array(
|
$this->logbook_model->add();
|
||||||
'COL_TIME_ON' => $datetime,
|
|
||||||
'COL_TIME_OFF' => $datetime,
|
// Store Basic QSO Info for reuse
|
||||||
'COL_CALL' => strtoupper($this->input->post('callsign')),
|
|
||||||
'COL_BAND' => $this->input->post('band'),
|
|
||||||
'COL_FREQ' => $this->input->post('freq'),
|
|
||||||
'COL_MODE' => $this->input->post('mode'),
|
|
||||||
'COL_RST_RCVD' => $this->input->post('rst_recv'),
|
|
||||||
'COL_RST_SENT' => $this->input->post('rst_sent'),
|
|
||||||
'COL_COMMENT' => $this->input->post('comment'),
|
|
||||||
'COL_SAT_NAME' => $this->input->post('sat_name'),
|
|
||||||
'COL_SAT_MODE' => $this->input->post('sat_mode'),
|
|
||||||
'COL_GRIDSQUARE' => $this->input->post('locator'),
|
|
||||||
'COL_COUNTRY' => $this->input->post('country'),
|
|
||||||
'COL_MY_RIG' => $this->input->post('equipment'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add QSO to database
|
|
||||||
$this->db->insert($this->config->item('table_name'), $data);
|
|
||||||
$this->session->set_userdata('band', $this->input->post('band'));
|
$this->session->set_userdata('band', $this->input->post('band'));
|
||||||
$this->session->set_userdata('freq', $this->input->post('freq'));
|
$this->session->set_userdata('freq', $this->input->post('freq'));
|
||||||
$this->session->set_userdata('mode', $this->input->post('mode'));
|
$this->session->set_userdata('mode', $this->input->post('mode'));
|
||||||
$this->session->set_userdata('sat_name', $this->input->post('sat_name'));
|
$this->session->set_userdata('sat_name', $this->input->post('sat_name'));
|
||||||
$this->session->set_userdata('sat_mode', $this->input->post('sat_mode'));
|
$this->session->set_userdata('sat_mode', $this->input->post('sat_mode'));
|
||||||
|
|
||||||
|
// Get last Ten QSOs
|
||||||
|
$data['query'] = $this->logbook_model->last_ten();
|
||||||
|
|
||||||
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY');
|
// Set Any Notice Messages
|
||||||
$this->db->order_by("COL_TIME_ON", "desc");
|
|
||||||
$this->db->limit(10);
|
|
||||||
$data['query'] = $this->db->get($this->config->item('table_name'));
|
|
||||||
|
|
||||||
$data['notice'] = "QSO Added";
|
$data['notice'] = "QSO Added";
|
||||||
|
|
||||||
// Load view to create another contact
|
// Load view to create another contact
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('qso/index', $data);
|
$this->load->view('qso/index', $data);
|
||||||
|
|
@ -76,8 +57,9 @@ class QSO extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit() {
|
function edit() {
|
||||||
$this->db->where('COL_PRIMARY_KEY', $this->uri->segment(3));
|
|
||||||
$query = $this->db->get($this->config->item('table_name'));
|
$this->load->model('logbook_model');
|
||||||
|
$query = $this->logbook_model->qso_info($this->uri->segment(3));
|
||||||
|
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
|
|
@ -86,6 +68,7 @@ class QSO extends CI_Controller {
|
||||||
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
|
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
|
||||||
|
|
||||||
$data = $query->row();
|
$data = $query->row();
|
||||||
|
|
||||||
if ($this->form_validation->run() == FALSE)
|
if ($this->form_validation->run() == FALSE)
|
||||||
{
|
{
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
|
|
@ -94,24 +77,7 @@ class QSO extends CI_Controller {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$this->logbook_model->edit();
|
||||||
$data = array(
|
|
||||||
'COL_TIME_ON' => $this->input->post('time_on'),
|
|
||||||
'COL_TIME_OFF' => $this->input->post('time_off'),
|
|
||||||
'COL_CALL' => strtoupper($this->input->post('callsign')),
|
|
||||||
'COL_BAND' => $this->input->post('band'),
|
|
||||||
'COL_FREQ' => $this->input->post('freq'),
|
|
||||||
'COL_MODE' => $this->input->post('mode'),
|
|
||||||
'COL_RST_RCVD' => $this->input->post('rst_recv'),
|
|
||||||
'COL_RST_SENT' => $this->input->post('rst_sent'),
|
|
||||||
'COL_COMMENT' => $this->input->post('comment'),
|
|
||||||
'COL_NAME' => $this->input->post('name'),
|
|
||||||
'COL_SAT_NAME' => $this->input->post('sat_name'),
|
|
||||||
'COL_SAT_MODE' => $this->input->post('sat_mode'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->db->where('COL_PRIMARY_KEY', $this->input->post('id'));
|
|
||||||
$this->db->update($this->config->item('table_name'), $data);
|
|
||||||
$this->session->set_flashdata('notice', 'Record Updated');
|
$this->session->set_flashdata('notice', 'Record Updated');
|
||||||
redirect('logbook');
|
redirect('logbook');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,6 @@
|
||||||
|
|
||||||
class Search extends CI_Controller {
|
class Search extends CI_Controller {
|
||||||
|
|
||||||
/**
|
|
||||||
* Index Page for this controller.
|
|
||||||
*
|
|
||||||
* Maps to the following URL
|
|
||||||
* http://example.com/index.php/welcome
|
|
||||||
* - or -
|
|
||||||
* http://example.com/index.php/welcome/index
|
|
||||||
* - or -
|
|
||||||
* Since this controller is set as the default controller in
|
|
||||||
* config/routes.php, it's displayed at http://example.com/
|
|
||||||
*
|
|
||||||
* So any other public methods not prefixed with an underscore will
|
|
||||||
* map to /index.php/welcome/<method_name>
|
|
||||||
* @see http://codeigniter.com/user_guide/general/urls.html
|
|
||||||
*/
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,73 @@ class Logbook_model extends CI_Model {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add QSO to Logbook */
|
||||||
|
function add() {
|
||||||
|
// Join date+time
|
||||||
|
$datetime = date('Y-m-d') ." ". $this->input->post('start_time');
|
||||||
|
|
||||||
|
// Create array with QSO Data
|
||||||
|
$data = array(
|
||||||
|
'COL_TIME_ON' => $datetime,
|
||||||
|
'COL_TIME_OFF' => $datetime,
|
||||||
|
'COL_CALL' => strtoupper($this->input->post('callsign')),
|
||||||
|
'COL_BAND' => $this->input->post('band'),
|
||||||
|
'COL_FREQ' => $this->input->post('freq'),
|
||||||
|
'COL_MODE' => $this->input->post('mode'),
|
||||||
|
'COL_RST_RCVD' => $this->input->post('rst_recv'),
|
||||||
|
'COL_RST_SENT' => $this->input->post('rst_sent'),
|
||||||
|
'COL_COMMENT' => $this->input->post('comment'),
|
||||||
|
'COL_SAT_NAME' => $this->input->post('sat_name'),
|
||||||
|
'COL_SAT_MODE' => $this->input->post('sat_mode'),
|
||||||
|
'COL_GRIDSQUARE' => $this->input->post('locator'),
|
||||||
|
'COL_COUNTRY' => $this->input->post('country'),
|
||||||
|
'COL_MY_RIG' => $this->input->post('equipment'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add QSO to database
|
||||||
|
$this->db->insert($this->config->item('table_name'), $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Edit QSO */
|
||||||
|
function edit() {
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'COL_TIME_ON' => $this->input->post('time_on'),
|
||||||
|
'COL_TIME_OFF' => $this->input->post('time_off'),
|
||||||
|
'COL_CALL' => strtoupper($this->input->post('callsign')),
|
||||||
|
'COL_BAND' => $this->input->post('band'),
|
||||||
|
'COL_FREQ' => $this->input->post('freq'),
|
||||||
|
'COL_MODE' => $this->input->post('mode'),
|
||||||
|
'COL_RST_RCVD' => $this->input->post('rst_recv'),
|
||||||
|
'COL_RST_SENT' => $this->input->post('rst_sent'),
|
||||||
|
'COL_COMMENT' => $this->input->post('comment'),
|
||||||
|
'COL_NAME' => $this->input->post('name'),
|
||||||
|
'COL_SAT_NAME' => $this->input->post('sat_name'),
|
||||||
|
'COL_SAT_MODE' => $this->input->post('sat_mode'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->db->where('COL_PRIMARY_KEY', $this->input->post('id'));
|
||||||
|
$this->db->update($this->config->item('table_name'), $data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return last 10 QSOs */
|
||||||
|
function last_ten() {
|
||||||
|
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY');
|
||||||
|
$this->db->order_by("COL_TIME_ON", "desc");
|
||||||
|
$this->db->limit(10);
|
||||||
|
|
||||||
|
return $this->db->get($this->config->item('table_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return QSO Info */
|
||||||
|
function qso_info($id) {
|
||||||
|
$this->db->where('COL_PRIMARY_KEY', $id);
|
||||||
|
|
||||||
|
return $this->db->get($this->config->item('table_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_qsos($num, $offset) {
|
function get_qsos($num, $offset) {
|
||||||
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY');
|
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY');
|
||||||
$this->db->order_by("COL_TIME_ON", "desc");
|
$this->db->order_by("COL_TIME_ON", "desc");
|
||||||
|
|
|
||||||
48
application/models/note.php
普通文件
48
application/models/note.php
普通文件
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Note extends CI_Model {
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
// Call the Model constructor
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
function list_all() {
|
||||||
|
return $this->db->get('notes');
|
||||||
|
}
|
||||||
|
|
||||||
|
function add() {
|
||||||
|
$data = array(
|
||||||
|
'cat' => $this->input->post('category'),
|
||||||
|
'title' => $this->input->post('title'),
|
||||||
|
'note' => $this->input->post('content')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->db->insert('notes', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function edit() {
|
||||||
|
$data = array(
|
||||||
|
'cat' => $this->input->post('category'),
|
||||||
|
'title' => $this->input->post('title'),
|
||||||
|
'note' => $this->input->post('content')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->db->where('id', $this->input->post('id'));
|
||||||
|
$this->db->update('notes', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($id) {
|
||||||
|
$this->db->delete('notes', array('id' => $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
function view($id) {
|
||||||
|
// Get Note
|
||||||
|
$this->db->where('id', $id);
|
||||||
|
return $this->db->get('notes');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
正在加载…
在新工单中引用