diff --git a/application/controllers/Uitslag.php b/application/controllers/Uitslag.php index ddc34c3..18f0f0d 100644 --- a/application/controllers/Uitslag.php +++ b/application/controllers/Uitslag.php @@ -26,13 +26,20 @@ class Uitslag extends CI_Controller $this->load->model('Uitslag_model'); $subgroepen = $this->Uitslag_model->get_subgroep_list(); $spelgebieden = $this->Uitslag_model->get_spelgebieden_list(); - + $maxpuntenraw = $this->Uitslag_model->get_max_punten(); + + foreach ($maxpuntenraw as $max) { + $maxpunten[$max['spelgebiedid']]['maxscore'] = $max['maxscore']; + $maxpunten[$max['spelgebiedid']]['naam'] = $max['naam']; + $maxpunten[$max['spelgebiedid']]['gewicht'] = $max['gewicht']; + } + foreach ($subgroepen as $subgroep) { $data['uitslag'][$subgroep['id']]['total'] = 0; $scores = $this->Uitslag_model->get_subgroep_punten($subgroep['id']); foreach ($scores as $score) { - $scoreitem = (($score['score']/$score['maxscore'])*100)*$score['gewicht']; + $scoreitem = (($score['score']/$maxpunten[$score['spelgebiedid']]['maxscore'])*100)*$maxpunten[$score['spelgebiedid']]['gewicht']; $data['uitslag'][$subgroep['id']][$score['spelgebiedid']] = $scoreitem; $data['uitslag'][$subgroep['id']]['total'] = $data['uitslag'][$subgroep['id']]['total'] + $scoreitem; } diff --git a/application/models/Uitslag_model.php b/application/models/Uitslag_model.php index 6779369..2750483 100644 --- a/application/models/Uitslag_model.php +++ b/application/models/Uitslag_model.php @@ -46,9 +46,7 @@ class Uitslag_model extends CI_Model public function get_subgroep_punten($subgroepid) { $this->db->select('SUM('.$this->db->dbprefix('resultaat').'.score/'.$this->db->dbprefix('lijst').'.ronde) AS score, - SUM('.$this->db->dbprefix('vragen').'.score) AS maxscore, spelgebied.id AS spelgebiedid, - spelgebied.gewicht AS gewicht, '); $this->db->from('resultaat'); @@ -70,4 +68,27 @@ class Uitslag_model extends CI_Model return $query->result_array(); } + public function get_max_punten() + { + $this->db->select('SUM('.$this->db->dbprefix('vragen').'.score) AS maxscore, + spelgebied.naam AS naam, + spelgebied.id AS spelgebiedid, + spelgebied.gewicht AS gewicht'); + $this->db->from('vragen'); + + $this->db->where('vragen.regioid', $this->session->regio); + $this->db->where('vragen.jaar', date('Y')); + + $this->db->join('onderdeel', 'vragen.onderdeelid=onderdeel.id', 'left'); + $this->db->join('spelgebied', 'onderdeel.spelgebiedid=spelgebied.id', 'left'); + + $this->db->group_by('spelgebied.naam'); + + $this->db->order_by('spelgebied.id', 'ASC'); + + $query = $this->db->get(); + + return $query->result_array(); + } + } \ No newline at end of file