352 lines
11 KiB
PHP
352 lines
11 KiB
PHP
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Scores
|
|
{
|
|
private $CI;
|
|
private $ijkpunten;
|
|
private $aantalY = 0;
|
|
private $scores;
|
|
private $score;
|
|
private $somscore;
|
|
private $org;
|
|
private $ambities;
|
|
private $resultaten;
|
|
private $wensen;
|
|
private $adviezen= [];
|
|
private $aantaldisablenvt = 0;
|
|
private $aantalscores = 0;
|
|
private $ijkpuntenok = 0;
|
|
private $welkelaagste;
|
|
private $welkehoogste;
|
|
private $laagstescore = 110;
|
|
private $hoogstescore = 0;
|
|
private $gemiddelde;
|
|
|
|
|
|
public function __construct( $orgversieid, $orgid, $scoretype, $isVergelijking)
|
|
{
|
|
$this->CI =& get_instance();
|
|
$this->orgversieid = $orgversieid;
|
|
$this->orgid = $orgid;
|
|
$this->scoretype= $scoretype;
|
|
$this->isVergelijking = $isVergelijking;
|
|
$this->handle();
|
|
}
|
|
|
|
public function getScores(){
|
|
return $this->scores;
|
|
}
|
|
|
|
public function getAmbities(){
|
|
return $this->ambities;
|
|
}
|
|
|
|
public function getWensen(){
|
|
return $this->wensen;
|
|
}
|
|
|
|
public function getIJkpunten(){
|
|
return $this->ijkpunten;
|
|
}
|
|
|
|
public function getResults(){
|
|
return $this->results;
|
|
}
|
|
|
|
private function handle()
|
|
{ $this->setIJkpunten();
|
|
$this->telIJkpunten();
|
|
$this->setOrglist();
|
|
$this->setOrg();
|
|
$this->setScores();
|
|
$this->setMetingen();
|
|
$this->setAmbities();
|
|
$this->setWensen();
|
|
$this->setKleuren();
|
|
$this->loopScores1();
|
|
$this->loopScores2();
|
|
$this->setGemiddeldeScore();
|
|
$this->addGemiddeldeScore();
|
|
|
|
$this->setResults();
|
|
}
|
|
|
|
|
|
private function setIJkpunten(){
|
|
$this->ijkpunten = $this->CI->Ijkpunten_model->getijkpuntenMetIndicatoren($this->orgversieid);
|
|
}
|
|
|
|
private function telIJkpunten(){
|
|
if($this->ijkpunten){
|
|
foreach($this->ijkpunten as $ijkpunt){
|
|
if($ijkpunt->disabled == 'F'){
|
|
$this->aantalY++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private function setOrglist(){
|
|
$orglist = $this->CI->Organisaties_model->getlistrecursief($this->orgid, []);
|
|
if($orglist) {
|
|
$this->orgstring = implode(',', $orglist);
|
|
}
|
|
}
|
|
private function setOrg(){
|
|
$this->org = $this->CI->Organisaties_model->get_record_by_id($this->orgid);
|
|
$this->orgnaam = $this->org->brin? $this->org->brin . ' ' . $this->org->naamkort : $this->org->naamkort;
|
|
}
|
|
|
|
private function setScores(){
|
|
$this->scores = $this->CI->Scores_model->getgemscores($this->orgversieid, $this->orgstring);
|
|
}
|
|
|
|
private function setMetingen(){
|
|
$this->metingen = new stdClass();
|
|
if(count($this->scores)==0)
|
|
$this->metingen->aantal= 0;
|
|
$this->metingen->aantalorgs = 0;
|
|
|
|
if($this->org->soort == 4) {
|
|
$this->metingen->aantal = 1;
|
|
$this->metingen->aantalorgs = 1;
|
|
}
|
|
else {
|
|
$this->metingen = $this->CI->Scores_model->fCountGevuldeVersiesNieuw($this->orgversieid, $this->orgstring);
|
|
}
|
|
}
|
|
|
|
|
|
private function setAmbities(){
|
|
$ambitieorgs = '';
|
|
|
|
$ambitieorgs = $this->getAmbitieOrgs($this->orgid, $ambitieorgs);
|
|
$ambitieorgs = rtrim($ambitieorgs, ',');
|
|
|
|
$toporgsarray = explode(',', $ambitieorgs);
|
|
$toporgs = '';
|
|
$index = 0;
|
|
for($i = count($toporgsarray)-1; $i >= 0 ; $i--) {
|
|
if($index < 2) {
|
|
$toporgs .= $toporgsarray[$i] . ',';
|
|
$index++;
|
|
}
|
|
}
|
|
$toporgs = rtrim($toporgs, ',' );
|
|
|
|
$this->ambities = $this->CI->Ambities_model->mh_get_ambitie_orgversie($this->orgversieid, $ambitieorgs, $toporgs);
|
|
}
|
|
|
|
|
|
private function setWensen(){
|
|
if($this->isVergelijking =='T' ) {$this->wensen = false;
|
|
return;
|
|
}
|
|
$this->wensen = $this->CI->Wenssituaties_model->getgewenst( $this->orgversieid, $this->orgid);
|
|
}
|
|
|
|
private function setKleuren(){
|
|
|
|
$this->kleuren = new stdClass();
|
|
$this->kleuren->grens1 = '60';
|
|
$this->kleuren->grens2 = '80';
|
|
$this->kleuren->grens3 = '90';
|
|
$this->kleuren->grens4 = '100';
|
|
if($this->scoretype ==7){
|
|
$this->kleuren->grens1 = '33';
|
|
$this->kleuren->grens2 = '66';
|
|
$this->kleuren->grens3 = '100';
|
|
}
|
|
$this->kleuren->kleur1 = '#e08885';
|
|
$this->kleuren->kleur2 = '#ffcc80';
|
|
$this->kleuren->kleur3 = '#9fdf9f';
|
|
$this->kleuren->kleur4 = '#99d6ff';
|
|
$this->kleuren->organisatie_id = '0';
|
|
// }
|
|
}
|
|
|
|
private function loopScores1(){
|
|
if(!$this->scores) return;
|
|
foreach ($this->scores as $index => $this->score) {
|
|
if($this->score->disabled == 'F' && $this->score->disablenvt == 'F') {
|
|
$this->somscore = $this->somscore + $this->score->gem;
|
|
$this->aantalscores++;
|
|
}
|
|
if($this->score->disabled == 'F' && $this->score->disablenvt == 'T'){
|
|
$this->aantaldisablenvt++;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private function loopScores2(){
|
|
if (!$this->scores) return;
|
|
foreach ($this->scores as $index => $this->score) {
|
|
$this->setScoreNummer();
|
|
$this->rondScoresAf();
|
|
$this->setScoreKleuren();
|
|
$this->telIJkpuntenok();
|
|
$this->setResultaten();
|
|
$this->addGewensteScores($index);
|
|
$this->setWenskleuren();
|
|
$this->setAdviezen();
|
|
|
|
}
|
|
}
|
|
|
|
private function setScoreNummer(){
|
|
if($this->isVergelijking =='T' ) return;
|
|
$this->score->huidig = 1;
|
|
if ($this->score->gem >= $this->kleuren->grens1) $this->score->huidig =2;
|
|
if ($this->score->gem >= $this->kleuren->grens2) $this->score->huidig =3;
|
|
if ($this->score->gem >= $this->kleuren->grens3) $this->score->huidig =4;
|
|
|
|
if($this->scoretype == 7){
|
|
if ($this->score->gem == $this->kleuren->grens3) $this->score->huidig = 4;
|
|
if ($this->score->gem < $this->kleuren->grens3) $this->score->huidig = 3;
|
|
if ($this->score->gem <= $this->kleuren->grens2) $this->score->huidig = 2;
|
|
if ($this->score->gem <= $this->kleuren->grens1) $this->score->huidig = 1;
|
|
|
|
}
|
|
}
|
|
|
|
private function rondScoresAf(){
|
|
$this->score->gem = round($this->score->gem);
|
|
|
|
}
|
|
|
|
private function setScoreKleuren(){
|
|
$kleur = $this->CI->Scorekleuren_model->getGemiddeldeKleur($this->scoretype, $this->score->gem);
|
|
$kleur = $kleur->kleurcode;
|
|
if(!$kleur) $kleur = '#ffffff';
|
|
$this->score->kleur = $kleur;
|
|
|
|
}
|
|
|
|
private function telIJkpuntenok(){
|
|
if($this->score->disabled == 'F' && $this->score->disablenvt == 'F') {
|
|
$zprocent = 60;
|
|
if(isset($this->ambities) && $this->ambities ) $zprocent = $this->ambities->zprocent;
|
|
if ($this->score->gem >= $zprocent ) {
|
|
$this->ijkpuntenok++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function setResultaten(){
|
|
if($this->score->disabled == 'F' && $this->score->disablenvt == 'F') {
|
|
|
|
if ($this->score->gem > $this->hoogstescore) {
|
|
$this->hoogstescore = $this->score->gem;
|
|
$this->welkehoogste = $this->score->nummer;
|
|
}
|
|
if ($this->score->gem <= $this->laagstescore) {
|
|
$this->laagstescore = $this->score->gem;
|
|
$this->welkelaagste = $this->score->nummer;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addGewensteScores($index){
|
|
if($this->isVergelijking =='T' ) return;
|
|
|
|
$this->score->wens = 3;
|
|
if ($this->wensen && $index < $this->aantalscores) {
|
|
$this->score->wens = $this->wensen[$index]->wens;
|
|
}
|
|
}
|
|
|
|
private function setWensKleuren(){
|
|
if($this->isVergelijking =='T' ) return;
|
|
|
|
if(! isset($this->wensen)) return;
|
|
if(!isset($this->score->wens)) return;
|
|
$kleur = $this->CI->Scorekleuren_model->getWensKleur($this->scoretype, $this->score->wens);
|
|
if(!$kleur) $kleur = '#ffffff';
|
|
$this->score->wenskleur = $kleur;
|
|
|
|
}
|
|
|
|
private function setAdviezen(){
|
|
if($this->isVergelijking =='T' ) {
|
|
$this->adviezen = false;
|
|
return;
|
|
}
|
|
if(isset($this->score->wens) &&
|
|
$this->score->huidig < $this->score->wens &&
|
|
$this->score->wens!= 0 &&
|
|
$this->score->disabled == 'F' &&
|
|
$this->score->disablenvt == 'F'){
|
|
$omschrijving = "";
|
|
if(isset($this->score->omschrijving)){
|
|
$omschrijving = $this->score->omschrijving;
|
|
}
|
|
$this->adviezen[] = ["nummer"=> $this->score->nummer, "omschrijving" =>$omschrijving];
|
|
}
|
|
}
|
|
|
|
private function setGemiddeldeScore(){
|
|
if(!$this->scores || $this->aantalscores == 0) return;
|
|
$this->gemiddelde = new stdClass();
|
|
$this->gemiddelde->gem = 0;
|
|
$this->gemiddelde->score = 0;
|
|
$deler = $this->aantalY - $this->aantaldisablenvt;
|
|
if($deler > 0) $this->gemiddelde->gem = round($this->somscore / $deler);
|
|
|
|
$this->gemiddelde->disabled = 'F';
|
|
$this->gemiddelde->disablenvt = 'F';
|
|
$this->gemiddelde->nummer = 'gem';
|
|
|
|
$kleur = $this->CI->Scorekleuren_model->getGemiddeldeKleur($this->scoretype, $this->gemiddelde->gem);
|
|
$kleur = $kleur->kleurcode;
|
|
if(!$kleur) $kleur = '#ffffff';
|
|
$this->gemiddelde->kleur = $kleur;
|
|
|
|
}
|
|
|
|
private function addGemiddeldeScore(){
|
|
if(!$this->scores || ! $this->gemiddelde) return;
|
|
array_push($this->scores, $this->gemiddelde);
|
|
}
|
|
|
|
|
|
private function setResults(){
|
|
|
|
$this->resultaten = [
|
|
'totgem' => $this->gemiddelde->gem,
|
|
'ijkpuntenok' => $this->ijkpuntenok,
|
|
'welkehoogste' => $this->welkehoogste,
|
|
'hoogstescore' => round($this->hoogstescore, 1),
|
|
'welkelaagste' => $this->welkelaagste,
|
|
'laagstescore' => round($this->laagstescore, 1),
|
|
];
|
|
|
|
$this->results= [
|
|
'orgnaam' => $this->orgnaam,
|
|
'ijkpunten' => $this->ijkpunten,
|
|
'scores' => $this->scores,
|
|
'metingen' => $this->metingen,
|
|
'ambities' => $this->ambities,
|
|
'kleuren' => $this->kleuren,
|
|
'wensen' => $this->wensen,
|
|
'resultaten' => $this->resultaten,
|
|
'adviezen' => $this->adviezen,
|
|
'aantalY' => $this->aantalY
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
private function getAmbitieOrgs($orgid, $ambitieorgs){
|
|
$ambitieorgs .= $orgid . ',';
|
|
$valtonder = $this->CI->Organisaties_model->get_fieldvalue(['id' => $orgid], 'valtonder_id');
|
|
if($valtonder != $orgid){
|
|
return $this->getAmbitieOrgs($valtonder, $ambitieorgs);
|
|
}
|
|
|
|
return $ambitieorgs;
|
|
|
|
}
|
|
|
|
} |