From c1975f6c7ec7e602435600955d93fc32c981ea92 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Thu, 7 Apr 2016 17:58:27 +0200 Subject: [PATCH] Mogelijkheid editen van lijsten. --- application/controllers/Edit.php | 76 ++++++++++++++++++++++++++ application/controllers/Uitslag.php | 12 ++++- application/models/Edit_model.php | 83 ++++++++++++++++++++++++++++- application/views/edit_lijst.php | 10 +++- application/views/edit_score.php | 81 ++++++++++++++++++++++++++++ application/views/user_score.php | 2 +- 6 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 application/views/edit_score.php diff --git a/application/controllers/Edit.php b/application/controllers/Edit.php index 842c58b..4671f07 100644 --- a/application/controllers/Edit.php +++ b/application/controllers/Edit.php @@ -55,4 +55,80 @@ class Edit extends CI_Controller redirect(base_url('edit/')); } + public function lijst($lijstid, $ronde) + { + $data['page'] = 'edit'; + $score = array(); + + // Get data + $this->load->model('Edit_model'); + $subgroepen = $this->Edit_model->get_subgroepen(); + $vragen = $this->Edit_model->get_vragen($lijstid); + $lijstnaam = $this->Edit_model->get_lijstnaam($lijstid); + + foreach ($vragen as $vraag) { + $scorepv = $this->Edit_model->get_score($vraag['id'], $ronde); + foreach ($scorepv as $item) { + $score[$item['subgroepid']][$vraag['id']]['resultaatid'] = $item['id']; + $score[$item['subgroepid']][$vraag['id']]['score'] = $item['score']; + } + } + + // Prepare data + $data['subgroepen'] = $subgroepen; + $data['vragen'] = $vragen; + $data['scores'] = $score; + $data['lijstid'] = $lijstid; + $data['lijstnaam'] = $lijstnaam; + $data['ronde'] = $ronde; + + // Header + $this->load->view('header', $data); + + // lijst list page + $this->load->view('edit_score', $data); + + // Footer + $this->load->view('footer'); + } + + public function save() + { + if (!$this->input->post('save')) { + redirect(base_url('edit/')); + } + + // Get data + $lijstid = $this->input->post('lijstid'); + + $this->load->model('Edit_model'); + $subgroepen = $this->Edit_model->get_subgroepen(); + $vragen = $this->Edit_model->get_vragen($lijstid); + + $i=0; + foreach ($subgroepen as $subgroep) { + foreach ($vragen as $vraag) { + if (!empty($this->input->post($vraag['id'].'-'.$subgroep['id']))) { + $score=$this->input->post($vraag['id'].'-'.$subgroep['id']); + } else { + $score="0.00"; + } + $store[$i] = array( + 'regioid' => $this->session->regio, + 'vraagid' => $vraag['id'], + 'ronde' => $this->input->post('ronde'), + 'subgroepid' => $subgroep['id'], + 'timestamp' => date("Y-m-d H:i:s"), + 'score' => $score, + 'userid' => $this->session->id, + ); + $i++; + } + } + + $this->Edit_model->save_score($store); + + redirect(base_url('edit/')); + } + } \ No newline at end of file diff --git a/application/controllers/Uitslag.php b/application/controllers/Uitslag.php index 05287a8..d14a60c 100644 --- a/application/controllers/Uitslag.php +++ b/application/controllers/Uitslag.php @@ -44,7 +44,10 @@ class Uitslag extends CI_Controller $maxpunten[$max['spelgebiedid']]['naam'] = $max['naam']; $maxpunten[$max['spelgebiedid']]['gewicht'] = $max['gewicht']; } - + + $uitslagr = array(); + $uitslag = array(); + foreach ($subgroepen as $subgroep) { $data['uitslag'][$subgroep['id']]['total'] = 0; $scores = $this->Uitslag_model->get_subgroep_punten($subgroep['id']); @@ -69,6 +72,13 @@ class Uitslag extends CI_Controller $uitslag[$key]['rang'] = $i; $i++; } + + foreach ($subgroepen as $subgroep) { + if (!isset($uitslag[$subgroep['id']]['rang'])) { + $uitslag[$subgroep['id']]['rang'] = 999; + $uitslag[$subgroep['id']] = 0; + } + } // Prepare data $data['subgroepen'] = $subgroepen; diff --git a/application/models/Edit_model.php b/application/models/Edit_model.php index 1fc4c7d..bd67be9 100644 --- a/application/models/Edit_model.php +++ b/application/models/Edit_model.php @@ -14,7 +14,7 @@ class Edit_model extends CI_Model public function get_lijst() { - $this->db->select('id, naam, actief'); + $this->db->select('id, naam, ronde, actief'); $this->db->from('lijst'); $this->db->where('jaar', date('Y')); $this->db->where('regioid', $this->session->regio); @@ -25,6 +25,20 @@ class Edit_model extends CI_Model return $query->result_array(); } + public function get_lijstnaam($id) + { + $this->db->select('naam'); + $this->db->from('lijst'); + $this->db->where('jaar', date('Y')); + $this->db->where('regioid', $this->session->regio); + $this->db->where('id', $id); + $this->db->order_by('naam', 'ASC'); + + $query = $this->db->get(); + + return $query->row()->naam; + } + public function change_lijst($id, $val) { $data = array( @@ -36,4 +50,71 @@ class Edit_model extends CI_Model $this->db->update('lijst', $data); } + public function get_subgroepen() + { + $this->db->select('id, naam, themanaam'); + $this->db->from('subgroep'); + $this->db->where('subgroep.regioid', $this->session->regio); + $this->db->where('subgroep.jaar', date('Y')); + + $query = $this->db->get(); + + return $query->result_array(); + } + + public function get_vragen($lijstid) + { + $this->db->select('vragen.id AS id, vraag, antwoord, score'); + $this->db->from('vragen'); + $this->db->where('vragen.regioid', $this->session->regio); + $this->db->where('vragen.jaar', date('Y')); + $this->db->where('lijst.id', $lijstid); + + $this->db->join('lijst', 'vragen.lijstid=lijst.id', 'left'); + + $query = $this->db->get(); + + return $query->result_array(); + } + + public function get_score($vraagid, $ronde) + { + $this->db->select('id, subgroepid, score'); + $this->db->from('resultaat'); + $this->db->where('regioid', $this->session->regio); + $this->db->where('vraagid', $vraagid); + $this->db->where('ronde', $ronde); + + $query = $this->db->get(); + + return $query->result_array(); + } + + public function save_score($data) + { + foreach ($data as $row) { + // Check for insert or update + $this->db->select('COUNT(*) AS aantal'); + $this->db->from('resultaat'); + $this->db->where('regioid', $this->session->regio); + $this->db->where('vraagid', $row['vraagid']); + $this->db->where('subgroepid', $row['subgroepid']); + $this->db->where('ronde', $row['ronde']); + $query = $this->db->get(); + $rows = $query->row()->aantal; + + if ($rows==1) { + $this->db->where('regioid', $this->session->regio); + $this->db->where('vraagid', $row['vraagid']); + $this->db->where('subgroepid', $row['subgroepid']); + $this->db->where('ronde', $row['ronde']); + $this->db->update('resultaat', $row); + } elseif ($rows==0) { + $this->db->insert('resultaat', $row); + } else { + echo "Duplicate result!"; + } + } + } + } \ No newline at end of file diff --git a/application/views/edit_lijst.php b/application/views/edit_lijst.php index 7881b48..5d89b82 100644 --- a/application/views/edit_lijst.php +++ b/application/views/edit_lijst.php @@ -2,6 +2,10 @@
+

+ Met deze pagina kun je lijsten actief of inactief maken tbv. de beoordeling. + Tevens kunnen de ingevulde scores aangepast worden. +

@@ -14,7 +18,11 @@ - + diff --git a/application/views/edit_score.php b/application/views/edit_score.php new file mode 100644 index 0000000..5fae83e --- /dev/null +++ b/application/views/edit_score.php @@ -0,0 +1,81 @@ +
+
+
+
+

Lijst:
Ronde:

+ + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + +
Naam
+ + $vraag['id'].'-'.$subgroep['id'], + 'value' => $vraag['score'] + ); + if (isset($scores[$subgroep['id']][$vraag['id']]['score']) && $scores[$subgroep['id']][$vraag['id']]['score'] == $vraag['score']) { + $checkbox['checked'] = TRUE; + } else { + $checkbox['checked'] = FALSE; + } + echo form_checkbox($checkbox); + } elseif ($vraag['antwoord'] == 1) { + $dropdown = array(); + for ($i=0; $i <= $vraag['score']; $i++) { + $dropdown[$i] = $i; + } + if (isset($scores[$subgroep['id']][$vraag['id']]['score'])) { + $select=$scores[$subgroep['id']][$vraag['id']]['score']; + } else { + $select=0; + } + echo form_dropdown($vraag['id'].'-'.$subgroep['id'], $dropdown, $select); + } elseif ($vraag['antwoord'] == 2) { + if (isset($scores[$subgroep['id']][$vraag['id']]['score'])) { + $select=$scores[$subgroep['id']][$vraag['id']]['score']; + } else { + $select="0.00"; + } + + $inputsetting = array( + 'name' => $vraag['id'].'-'.$subgroep['id'], + 'value' => $select, + 'maxlength' => '4', + 'size' => '4' + ); + echo form_input($inputsetting); + } + ?> + +
+
+ +
+ +
+
\ No newline at end of file diff --git a/application/views/user_score.php b/application/views/user_score.php index d5a9bef..760af97 100644 --- a/application/views/user_score.php +++ b/application/views/user_score.php @@ -27,7 +27,7 @@