Files
monpas/application/models/monpas/Diversiteits_model.php
T
2021-07-10 16:25:16 +02:00

527 lines
21 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/** Diversiteits_model januari 2015 */
class Diversiteits_model extends MY_Model{
function __construct(){
parent::__construct();
$models = array('monpas/Aantalxondersteuningsvorm_model',
'monpas/Combifactoren_model',
'monpas/Dq_model',
'monpas/Groepen_model',
'monpas/Ondersteuningsvormen_model',
'shared/Organisaties_model');
$this->load->model($models);
}
function getnormaantallen($orgid, $schoolsoort){
$normaantallen = $this->getaantallenrecursief($orgid, $schoolsoort);
if (!$normaantallen) {
$normaantallen = $this->Dq_model->getaantallen(1, $schoolsoort);
}
return $normaantallen;
}
function getaantallenrecursief($orgid, $schoolsoort){
$org = $this->Organisaties_model->getorg($orgid);
$normaantallen = $this->Dq_model->getaantallen($orgid, $schoolsoort);
if (!$normaantallen && ($org->id !== $org->valtonder_id)){
$normaantallen = $this->getaantallenrecursief($org->valtonder_id, $schoolsoort);
};
return $normaantallen;
}
function getaantallenpercategorie($orgid, $schooljaarnr, $schooltype, $module ){
$this->sql = "SELECT sum(AO.aantal) as sum , OV.nivo
FROM tb_aantalxondersteuningsvorm AO
JOIN tb_ondersteuningsvormen OV ON OV.id = AO.ondersteuningsvorm_id
JOIN tb_groepen G ON G.id = AO.groep_id
WHERE AO.organisatie_id = {$orgid}
AND G.schooljaarnr ={$schooljaarnr}
AND G.schooltype = '{$schooltype}'
AND G.module = {$module}
GROUP BY nivo";
return $this->get_query_result();
}
function getallediversiteitsgegevens($schooljaarnr){
$orgid = $this->globorgid;
$bg = $this->getbgsenscholen($orgid);
$maxdq = new stdClass;
$maxdq->school = '';
$maxdq->dq = 0;
$mindq = new stdClass;
$mindq->school = '';
$mindq->dq = 100;
$maxoov = new stdClass;
$maxoov->school = '';
$maxoov->oov = 0;
$grandtotals = new stdClass;
$combifactoren = $this->Combifactoren_model->getfactoren($this->globorgid);
if ($bg){
$grandtotals->llng = 0;
$grandtotals->cat1 = 0;
$grandtotals->cat2 = 0;
$grandtotals->cat3 = 0;
$grandtotals->cat4 = 0;
$grandtotals->cat234 = 0;
foreach($bg as $bege){
if ($bege->scholen){
$bggem = new stdClass;
$bggem->brin = '';
$bggem->naam='Gemiddeld '.$bege->naamkort;
$bggem->aantallln = 0;
$bggem->aantalgroepen = 0;
$bggem->cat1=0;
$bggem->cat2=0;
$bggem->cat3=0;
$bggem->cat4=0;
$bggem->oov=0;
$bggem->tgd=0;
$bggem->dq=0;
$usedaantalscholen = 0;
$schoolsoort ='REGULIER';
foreach($bege->scholen as $school){
$school->groepen = $this->Groepen_model->getgroepen($school->id, $schooljaarnr);
// volgens mij is voor school het normaantal altijd 22 (groep 1/2 ) of 24 (groep 3/8) maar dat komt toch niet
//overeen met per groep. dus toch maar norm ophalen;
$normaantallen = $this->getnormaantallen($school->id, $schoolsoort);
if (!$normaantallen){
$normaantallen = new StdClass;
$normaantallen->groep12 = 22;
$normaantallen->groep38 = 24;
}
$tot = 0;
$normtot = 0;
if ($school->groepen){
foreach($school->groepen as $groep){
$groepasarray = explode(';',$groep->niveau);
$groep->combi = count($groepasarray);
if ($combifactoren && $combifactoren->addtoschool == "T"){
$combiwaarde = 0;
if ($groep->combi ==2) $combiwaarde = $combifactoren->combi2;
if ($groep->combi >= 3) $combiwaarde = $combifactoren->combi3;
} else{
$combiwaarde =0;
}
$tot = $tot + $groep->totaantal + $combiwaarde;
$bggem->aantallln = $bggem->aantallln + $groep->totaantal;
if ((strpos($groep->niveau, '1') !== false) || (strpos($groep->niveau, '2') !== false) ){
$normtot = $normtot + $normaantallen->groep12;
}
else {
$normtot = $normtot + $normaantallen->groep38;
};
}; // foreach
}
$school->aantallln = $tot;
$school->aantalgroepen =0 ;
if ($school->groepen){
$school->aantalgroepen = count($school->groepen);
};
$bggem->aantalgroepen = $bggem->aantalgroepen + $school->aantalgroepen;
$aantallenpercat = $this->getaantallenpercategorie($school->id,$schooljaarnr,"R");
$aantalmetvraag = 0;
$schooltgd =0;
if ($aantallenpercat){
foreach($aantallenpercat as $aantalpercat){
$aantalmetvraag = $aantalmetvraag + $aantalpercat->sum;
switch($aantalpercat->nivo){
case 2: $school->cat2 = $aantalpercat->sum;
$bggem->cat2 = $bggem->cat2 + $aantalpercat->sum;
$schooltgd =$schooltgd + ($aantalpercat->sum * 1.5);
break;
case 3: $school->cat3= $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 2);
$bggem->cat3 = $bggem->cat3+ $aantalpercat->sum ;
break;
case 4: $school->cat4 = $aantalpercat->sum;
$bggem->cat4 = $bggem->cat4 + $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 4);
break;
};
}; //foreach
}; // if aantallen
$school->oov = null;
if ($school->aantallln > 0) {
$school->oov = round(($aantalmetvraag / $school->aantallln) * 100);
$school->cat1 =$school->aantallln - $aantalmetvraag;
$school->tgd = round($schooltgd + $school->cat1);
$school->dq = round(($school->tgd / $normtot) * 100) / 100;
$bggem->cat1 = $bggem->cat1 + $school->cat1;
$bggem->oov = $bggem->oov + $school->oov;
$bggem->tgd = $bggem->tgd + $school->tgd ;
$bggem->dq= $bggem->dq + $school->dq;
$usedaantalscholen ++;
$grandtotals->llng =$grandtotals->llng + $school->aantallln;
$grandtotals->cat1 = $grandtotals->cat1 + $school->cat1;
if (isset($school->cat2)) $grandtotals->cat2 = $grandtotals->cat2 + $school->cat2;
if (isset($school->cat3)) $grandtotals->cat3 = $grandtotals->cat3 + $school->cat3;
if (isset($school->cat4)) $grandtotals->cat4 = $grandtotals->cat4 + $school->cat4;
};
if (isset($school->dq)){
if ($school->dq > $maxdq->dq) {
$maxdq->school = $school->brin ." - ".$school->naamkort;
$maxdq->dq = $school->dq;}
if ($school->dq < $mindq->dq) {
$mindq->school = $school->brin." - ".$school->naamkort;
$mindq->dq = $school->dq;}
}
if (isset($school->oov) && $school->oov > $maxoov->oov) {
$maxoov->school = $school->brin." - ".$school->naamkort;
$maxoov->oov = $school->oov;}
}; // foreach scholen
if ($usedaantalscholen > 0) {
$bgtot = new stdClass;
$bgtot->brin = '';
$bgtot->naam='Totaal '.$bege->naamkort;
$bgtot->aantallln = $bggem->aantallln;
$bgtot->aantalgroepen = $bggem->aantalgroepen;
$bgtot->cat1= $bggem->cat1;
$bgtot->cat2= $bggem->cat2;
$bgtot->cat3= $bggem->cat3;
$bgtot->cat4= $bggem->cat4;
$bgtot->oov= null;
$bgtot->tgd= round($bggem->tgd);
$bgtot->dq=null;
$bggem->aantallln = round($bggem->aantallln / $usedaantalscholen);
$bggem->groepen = round($bggem->aantalgroepen/$usedaantalscholen);
$bggem->cat1 =round($bggem->cat1/ $usedaantalscholen);
$bggem->cat2 =round($bggem->cat2/ $usedaantalscholen);
$bggem->cat3 =round($bggem->cat3/ $usedaantalscholen);
$bggem->cat4 =round($bggem->cat4/ $usedaantalscholen);
$bggem->oov = round($bggem->oov / $usedaantalscholen ) ;
$bggem->tgd = round($bggem->tgd / $usedaantalscholen);
$bggem->dq = round(($bggem->dq / $usedaantalscholen) * 100) / 100;
array_push($bege->scholen,$bgtot);
array_push($bege->scholen,$bggem);
}
} ; // if scholen
}; // foreach bg
$grandtotals->cat234 = $grandtotals->cat2 + $grandtotals->cat3 + $grandtotals->cat4;
}; // if bg
return array(array('bg'=>$bg,
"maxdq" =>$maxdq,
"mindq" =>$mindq,
"maxoov" => $maxoov,
"grandtotals" =>$grandtotals));
}
function getallediversiteitsgegevenssboso($schooljaarnr, $licentie){
$orgid = $this->globorgid;
$bg = $this->getbgsenscholenmetlicentie($orgid, $licentie);
$somschooldq = 0;
$maxdq = new stdClass;
$maxdq->school = '';
$maxdq->dq = 0;
$mindq = new stdClass;
$mindq->school = '';
$mindq->dq = 100;
$grandtotals = new stdClass;
$beschikbaar = 'F';
if ($bg){
$grandtotals->llng = 0;
$grandtotals->cat5 = 0;
$grandtotals->cat6 = 0;
$grandtotals->cat7 = 0;
$grandtotals->cat8 = 0;
$grandtotals->totaal = 0;
foreach($bg as $bege){
if ($bege->scholen){
$bggem = new stdClass;
$bggem->brin = '';
$bggem->naam='Gemiddeld '.$bege->naamkort;
$bggem->aantallln = 0;
$bggem->aantalgroepen = 0;
$bggem->cat5=0;
$bggem->cat6=0;
$bggem->cat7=0;
$bggem->cat8=0;
$bggem->tgd=0;
$bggem->dq=0;
$usedaantalscholen = 0;
foreach($bege->scholen as $school){
$school->groepen = $this->Groepen_model->getgroepenSboso($school->id, $schooljaarnr);
// volgens mij is voor school het normaantal altijd 22 (groep 1/2 ) of 24 (groep 3/8) maar dat komt toch niet
//overeen met per groep. dus toch maar norm ophalen;
$normaantallen = 0;
$normaantallenSBO = $this->getnormaantallen($school->id, 'SBO');
$normaantallenSO = $this->getnormaantallen($school->id, 'SO');
if (!$normaantallenSO) {
$normaantallenSO = new StdClass;
$normaantallenSO->groep12 = 22;
$normaantallenSO->groep38 = 24;
}
if (!$normaantallenSBO) {
$normaantallenSBO = new StdClass;
$normaantallenSBO->groep12 = 22;
$normaantallenSBO->groep38 = 24;
}
$tot = 0;
$normtot = 0;
if ($school->groepen){
foreach($school->groepen as $groep){
$tot = $tot + $groep->totaantal;
$bggem->aantallln = $bggem->aantallln + $groep->totaantal;
}; // foreach
}
$school->aantallln = $tot;
$school->aantalgroepen =0 ;
if ($school->groepen){
$school->aantalgroepen = count($school->groepen);
};
if($school->groepen) {
foreach($school->groepen as $groep) {
if ($groep->totaantal > 0) {
if ((strpos($groep->niveau, '1') !== false) || (strpos($groep->niveau, '2') !== false)) {
$groep->normaantal = (($groep->som5 / $groep->totaantal) * $normaantallenSBO->groep12)
+ ((($groep->totaantal - $groep->som5) / $groep->totaantal) *
$normaantallenSO->groep12);//== factor
} else {
$groep->normaantal = (($groep->som5 / $groep->totaantal) * $normaantallenSO->groep38)
+ ((($groep->totaantal - $groep->som5) / $groep->totaantal) *
$normaantallenSO->groep38); //== factor
};
$groep->diversiteit = ($groep->som5 * 2) + ($groep->som6 * 3) + ($groep->som7 * 4) +($groep ->som8 * 5);
$groep->groepdq = round($groep->diversiteit/$groep->normaantal);
$normtot = $normtot + $groep->normaantal;
$somschooldq = $somschooldq + $groep->groepdq;
}
}
}
$school->normaantal = $normtot;
$school->dq =0;
if($school->aantalgroepen > 0) {
$school->dq = round(($somschooldq / $school->aantalgroepen) * 100) / 100;
$bggem->aantalgroepen = $bggem->aantalgroepen + $school->aantalgroepen;
}
$aantallenpercat = $this->getaantallenpercategorie($school->id,$schooljaarnr,'SBO', $licentie);
$schooltgd =0;
if ($aantallenpercat){
foreach($aantallenpercat as $aantalpercat){
switch($aantalpercat->nivo){
case 5: $school->cat5 = $aantalpercat->sum;
$bggem->cat5 = $bggem->cat5 + $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 2);
break;
case 6: $school->cat6 = $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 3);
$bggem->cat6 = $bggem->cat6+ $aantalpercat->sum ;
break;
case 7: $school->cat7 = $aantalpercat->sum;
$bggem->cat7 = $bggem->cat7 + $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 4);
break;
case 8: $school->cat8 = $aantalpercat->sum;
$bggem->cat8 = $bggem->cat8 + $aantalpercat->sum;
$schooltgd = $schooltgd + ($aantalpercat->sum * 5);
break;
};
}; //foreach
}; // if aantallen
if ($school->aantallln > 0) {
$school->tgd = round($schooltgd);
$school->dq = round(($school->tgd / $school->normaantal) * 100) / 100;
$bggem->tgd = $bggem->tgd + $school->tgd ;
$bggem->dq= $bggem->dq + $school->dq;
$usedaantalscholen ++;
$grandtotals->llng =$grandtotals->llng + $school->aantallln;
if (isset($school->cat5)) $grandtotals->cat5 = $grandtotals->cat5+ $school->cat5;
if (isset($school->cat6)) $grandtotals->cat6 = $grandtotals->cat6 + $school->cat6;
if (isset($school->cat7)) $grandtotals->cat7 = $grandtotals->cat7 + $school->cat7;
if (isset($school->cat8)) $grandtotals->cat8 = $grandtotals->cat8 + $school->cat8;
};
if (isset($school->dq)){
if ($school->dq > $maxdq->dq) {
$maxdq->school = $school->brin ." - ".$school->naamkort;
$maxdq->dq = $school->dq;}
if ($school->dq < $mindq->dq) {
$mindq->school = $school->brin." - ".$school->naamkort;
$mindq->dq = $school->dq;}
}
}; // foreach scholen
if ($usedaantalscholen > 0) {
$bgtot = new stdClass;
$bgtot->brin = '';
$bgtot->naam='Totaal '.$bege->naamkort;
$bgtot->aantallln = $bggem->aantallln;
$bgtot->aantalgroepen = $bggem->aantalgroepen;
$bgtot->cat5= $bggem->cat5;
$bgtot->cat6= $bggem->cat6;
$bgtot->cat7= $bggem->cat7;
$bgtot->cat8= $bggem->cat8;
$bgtot->tgd= round($bggem->tgd);
$bgtot->dq=null;
//
$bggem->aantallln = round($bggem->aantallln / $usedaantalscholen);
$bggem->aantalgroepen = round($bggem->aantalgroepen/$usedaantalscholen);
$bggem->cat5 =round($bggem->cat5/ $usedaantalscholen);
$bggem->cat6 =round($bggem->cat6/ $usedaantalscholen);
$bggem->cat7 =round($bggem->cat7/ $usedaantalscholen);
$bggem->cat8 =round($bggem->cat8/ $usedaantalscholen);
$bggem->tgd = round($bggem->tgd / $usedaantalscholen);
$bggem->dq = round(($bggem->dq / $usedaantalscholen) * 100) / 100;
array_push($bege->scholen,$bgtot);
array_push($bege->scholen,$bggem);
}
} ; // if scholen
}; // foreach bg
$grandtotals->cat56789 = $grandtotals->cat5 + $grandtotals->cat6 + $grandtotals->cat7 + + $grandtotals->cat8;
if($grandtotals->cat56789 > 0){
$beschikbaar = 'T';
}
}; // if bg
return array(array('bg'=>$bg,
"maxdq" => $maxdq,
"mindq" => $mindq,
"grandtotals" => $grandtotals,
"beschikbaar" => $beschikbaar));
}
function getbgsenscholen($orgid){
$bg = null;
$bgs = array();
$organisatie = $this->Organisaties_model->get_record_by_id($orgid);
switch ($organisatie->soort){
case 0: $bgs = null; break;
case 1: $kamers = $this->Organisaties_model->getorgsvanaf($organisatie->id, false);
if ($kamers){
foreach($kamers as $kamer){
$bg = $this->Organisaties_model->getorgsvanaf($kamer->id, false);
if ($bg){
$bgs = array_merge($bgs, $bg);
}
}
}
break;
case 2 : $bgs = $this->Organisaties_model->getorgsvanaf($organisatie->id,false);
break;
case 3: $bgs[0] =$organisatie;
break;
}; // switch;
if ($bgs){
foreach($bgs as $bev){
$bev->scholen= $this->Organisaties_model->getorgsvanaf($bev->id, false);
}; // foreach
}; // if bgs
return $bgs;
}
function getbgsenscholenmetlicentie($orgid, $licentie){
$bg = null;
$bgs = array();
$organisatie = $this->Organisaties_model->get_record_by_id($orgid);
switch ($organisatie->soort){
case 0: $bgs = null; break;
case 1: $kamers = $this->Organisaties_model->getorgsvanaf($organisatie->id, false);
if ($kamers){
foreach($kamers as $kamer){
$bg = $this->Organisaties_model->getorgsvanaf($kamer->id, false);
if ($bg){
$bgs = array_merge($bgs, $bg);
}
}
}
break;
case 2: $bgs = $this->Organisaties_model->getorgsvanaf($organisatie->id,false);
break;
case 3: $bgs[0] =$organisatie;
break;
}; // switch;
$licentiebgs = [];
if ($bgs){
foreach($bgs as $bev){
$bev->scholen= $this->Organisaties_model->getorgsvanafmetlicentie($bev->id, $licentie);
if($bev->scholen){
$licentiebgs [] = $bev;
}
}; // foreach
}; // if bgs
return $licentiebgs;
}
function getosvormen($orgid, $schooljaarnr, $minnivo, $maxnivo, $module){
$groeparray = [];
$os = $this->Ondersteuningsvormen_model->getvormen($orgid, $minnivo, $maxnivo);
if($minnivo >= 5) {
// $groepen = $this->Aantalxondersteuningsvorm_model->getgroepenmetlln($orgid, $schooljaarnr, $minnivo, $maxnivo);
$groepen = $this->Groepen_model->getGroepenSboSo($orgid, $schooljaarnr);
}
else {
$groepen = $this->Groepen_model->getgroepen($orgid, $schooljaarnr, $module);
}
if(!$groepen){
return false;
}
foreach($groepen as $groep){
$groepsarray[]=$groep->id;
}
$groepids = implode(',', $groepsarray);
if ($os){
foreach($os as $vorm){
$vorm->groepsaantallen = $this->Aantalxondersteuningsvorm_model->getaantallen($vorm->id, $orgid,$schooljaarnr, $groepids);
$vorm->vormtotaal =0;
if ($vorm->groepsaantallen){
foreach($vorm->groepsaantallen as $aantallen){
$vorm->vormtotaal = $vorm->vormtotaal + $aantallen->aantal;
};
};
}
}
return $os;
}
}