910 lines
41 KiB
PHP
910 lines
41 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**Scores_model maart 2015 */
|
|
|
|
class Scores_model extends MY_Model{
|
|
|
|
protected $tablename = 'tb_scores';
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array('');
|
|
$this->load->model($models);
|
|
}
|
|
|
|
function getscores($ijkpuntid, $filledversionid, $vorm){
|
|
$this->sql="SELECT SC.id, score , scoretype,
|
|
IF ({$vorm}=1, I.omschrijving1, I.omschrijving2) AS omschrijving,
|
|
I.nummer, I.inspectie
|
|
FROM tb_scores SC
|
|
JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
WHERE filledversion_id = {$filledversionid}
|
|
AND SC.ijkpunt_id = {$ijkpuntid}
|
|
|
|
GROUP BY SC.id ";
|
|
|
|
return $this->get_query_result();
|
|
}
|
|
function calculateindividualscores($orgversieid, $orgid, $userid){
|
|
$this->sql="SELECT SC.id, filledversion_id, SC.ijkpunt_id, scoretype, score, Y.disabled,
|
|
SUM(CASE WHEN Y.disabled = 'T' THEN 0
|
|
WHEN Y.disabled = 'F' THEN
|
|
CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 2 THEN 60 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
ELSE 0
|
|
END
|
|
ELSE 0
|
|
END) AS somscore,
|
|
|
|
SUM( Indi.gewicht ) AS num,
|
|
SUM(CASE WHEN SC.scoretype = 4 AND SC.score = 3 THEN 1
|
|
ELSE 0
|
|
END) AS aantalnvt,
|
|
SUM(CASE WHEN SC.scoretype = 4 THEN 1
|
|
ELSE 0
|
|
END) AS aantalvier,
|
|
Y.nummer, Y.omschrijving, 0 AS aantalscholen, Y.toelichting
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id = {$orgid}
|
|
AND FV.user_id ={$userid}
|
|
AND FV.meetellen = 1
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer ";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
|
|
function calculateindividualscoresoud($orgversieid, $orgid, $userid){
|
|
$this->sql="SELECT SC.id, filledversion_id, SC.ijkpunt_id, scoretype, score,
|
|
SUM(CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 2 THEN 60 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END) AS somscore,
|
|
|
|
SUM( IF ((SC.scoretype=4 && score=3), 0, Indi.gewicht) ) AS num,
|
|
|
|
Y.nummer, Y.omschrijving, 0 AS aantalscholen, Y.toelichting
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id = {$orgid}
|
|
AND FV.user_id ={$userid}
|
|
AND FV.meetellen = 1
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer ";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
|
|
function calculateindividualMonPon($filledversionid){
|
|
$this->sql = "SELECT SC.id, SC.ijkpunt_id , scoretype, score,
|
|
sum( (IF(SC.scoretype =1,(SC.score * 10),
|
|
IF(SC.scoretype =2, SC.score,
|
|
IF ((SC.scoretype = 3 OR SC.scoretype=5), IF(SC.score=1 , 100, IF((SC.score =2 or SC.score= 0), 0 , 50)),
|
|
IF (SC.scoretype = 4 , IF(SC.score=1, 100, IF((SC.score=2 or SC.score =0), 0 , 0)) , 0)
|
|
) )) * Indi.gewicht)) AS somscore,
|
|
|
|
sum( IF ((SC.scoretype=4 && score=3), 0, Indi.gewicht) ) AS num,
|
|
|
|
Y.nummer, Y.omschrijving, 0 AS aantalscholen, Y.toelichting
|
|
FROM (SELECT COUNT(*) AS aantal, S.filledversion_id as filledid
|
|
FROM tb_scores S
|
|
WHERE S.score > 0
|
|
GROUP BY S.filledversion_id)
|
|
AS Q
|
|
JOIN tb_filledversions FV ON FV.id = Q.filledid
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE FV.id = {$filledversionid}
|
|
AND Q.aantal >= 5
|
|
AND FV.meetellen = 1
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer ";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function calculateschool($orgversieid, $orgid)
|
|
{
|
|
$gevuldeversies = $this->fGetGevuldeVersies($orgversieid, $orgid);
|
|
if ($gevuldeversies) {
|
|
$this->sql = "SELECT SC.id as scoreid, filledversion_id,SC.ijkpunt_id , SC.score, scoretype,
|
|
SUM(CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 50 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 70 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END) AS somscore,
|
|
|
|
sum( IF ((SC.scoretype=4 && score=3), 0, Indi.gewicht) ) AS num,
|
|
|
|
Y.nummer, Y.omschrijving, 1 AS aantalscholen, Y.toelichting
|
|
|
|
FROM tb_scores SC
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE SC.filledversion_id IN ({$gevuldeversies})
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
function calculateBG($orgversieid, $bgid){
|
|
$gevuldeversies = $this->fGetGevuldeBestuurVersie($orgversieid, $bgid);
|
|
if ($gevuldeversies) {
|
|
$this->sql = "SELECT SC.id,filledversion_id,SC.ijkpunt_id, scoretype,
|
|
SUM(CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 2 THEN 60 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END)AS somscore,
|
|
|
|
sum( IF ((SC.scoretype=4 && SC.score=3), 0, Indi.gewicht) ) AS num,
|
|
Y.nummer, Y.omschrijving,count(DISTINCT O.id) AS aantalscholen, Y.toelichting
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_organisaties O ON O.id = FV.organisatie_id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE O.valtonder_id = {$bgid}
|
|
AND FV.id IN ({$gevuldeversies})
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
function calculateBGs($orgversieid, $bgids){
|
|
$gevuldeversies = $this->fGetGevuldeBestuurVersies($orgversieid, $bgids);
|
|
|
|
$this->sql="SELECT SC.id,filledversion_id,SC.ijkpunt_id , scoretype,
|
|
SUM(CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 50 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 70 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 4 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END)AS somscore,
|
|
|
|
sum( IF ((SC.scoretype=4 && SC.score=3), 0, Indi.gewicht) ) AS num,
|
|
Y.nummer, Y.omschrijving,count(DISTINCT O.id) AS aantalscholen,Y.toelichting
|
|
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_organisaties O ON O.id = FV.organisatie_id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE O.valtonder_id IN ( {$bgids})
|
|
AND FV.id = {$gevuldeversies}
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
|
|
function calculateOverScholen($orgversieid, $orgstring)
|
|
{
|
|
$gevuldeversies = $this->fGetGevuldeSWVVersies($orgversieid, $orgstring);
|
|
|
|
if ($gevuldeversies) {
|
|
$this->sql = "SELECT SC.id,filledversion_id,SC.ijkpunt_id , scoretype,
|
|
SUM(CASE
|
|
WHEN SC.scoretype = 1 THEN SC.score * 10 * Indi.gewicht
|
|
WHEN SC.scoretype = 2 THEN SC.score * Indi.gewicht
|
|
WHEN (SC.scoretype = 3 OR SC.scoretype = 5) THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (SC.score = 2 OR SC.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN SC.scoretype = 4 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 6 THEN
|
|
CASE
|
|
WHEN SC.score = 2 THEN 60 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7 THEN
|
|
CASE
|
|
WHEN SC.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN SC.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN SC.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END)AS somscore,
|
|
|
|
sum( IF ((SC.scoretype=4 && SC.score=3), 0, Indi.gewicht) ) AS num,
|
|
Y.nummer, Y.omschrijving,count(DISTINCT O.id) AS aantalscholen, count(DISTINCT FV.id) AS aantallijsten, Y.toelichting
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_organisaties O ON O.id = FV.organisatie_id
|
|
JOIN tb_indicatoren Indi ON Indi.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE FV.id IN ({$gevuldeversies})
|
|
AND FV.orgversie_id = {$orgversieid}
|
|
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
function calculateOverScholenNieuw($orgversieid, $orgstring){
|
|
$gevuldeversies = $this->fGetGevuldeSWVVersies($orgversieid, $orgstring);
|
|
|
|
$m = "SC.scoretype= 4";
|
|
$n = "IF (SC.score = 1, (100 * I.gewicht), 0)";
|
|
$o = "0";
|
|
$l = "IF ($m, $n, $o)";
|
|
|
|
|
|
$j = "SC.scoretype = 6";
|
|
$k = "IF (SC.score =1 , (50 * I.gewicht) , IF (SC.score = 2 , (70 * I.gewicht), IF (SC.score = 3, (100 * I.gewicht),0) ))";
|
|
$i = "IF ($j, $k ,$l)";
|
|
|
|
$g = "(SC.scoretype=3 or SC.scoretype=5)";
|
|
$h = "IF (SC.score = 1, (100 * I.gewicht),
|
|
IF ((SC.score = 2 or SC.score = 0), (0 * I.gewicht), (50 * I.gewicht) ) ) ";
|
|
$f = "if ($g, $h, $i)";
|
|
|
|
$d = "SC.scoretype = 2";
|
|
$e = "(SC.score * I.gewicht)";
|
|
$c = "if($d, $e, $f)";
|
|
|
|
$a = "SC.scoretype = 1";
|
|
$b = "(SC.score * I.gewicht * 10)";
|
|
|
|
|
|
if ($gevuldeversies) {
|
|
$this->sql = "SELECT SC.id, filledversion_id, SC.ijkpunt_id , scoretype,
|
|
sum(IF ({$a}, {$b} ,{$c}) )/ sum(IF ((SC.scoretype=4 && SC.score=3), 0, I.gewicht)) AS gem,
|
|
Y.nummer, Y.omschrijving, count(DISTINCT O.id) AS aantalscholen, count(DISTINCT FV.id) AS aantallijsten, Y.toelichting
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores SC ON SC.filledversion_id = FV.id
|
|
JOIN tb_organisaties O ON O.id = FV.organisatie_id
|
|
JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE FV.id IN ({$gevuldeversies})
|
|
AND FV.orgversie_id = {$orgversieid}
|
|
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getlkscores($filledversionid){
|
|
$this->sql="SELECT
|
|
SUM(CASE
|
|
WHEN OV.scoretype = 1 THEN S.score * 10 * Indi.gewicht
|
|
WHEN OV.scoretype = 2 THEN S.score * Indi.gewicht
|
|
WHEN (OV.scoretype = 3 OR OV.scoretype = 5) THEN
|
|
CASE
|
|
WHEN S.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN (S.score = 2 OR S.score = 0) THEN 0
|
|
ELSE 50 * Indi.gewicht
|
|
END
|
|
WHEN OV.scoretype = 4 THEN
|
|
CASE
|
|
WHEN S.score = 1 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN OV.scoretype = 6 THEN
|
|
CASE
|
|
WHEN S.score = 2 THEN 60 * Indi.gewicht
|
|
WHEN S.score = 3 THEN 100 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
WHEN OV.scoretype = 7 THEN
|
|
CASE
|
|
WHEN S.score = 1 THEN 100 * Indi.gewicht
|
|
WHEN S.score = 2 THEN 66.6 * Indi.gewicht
|
|
WHEN S.score = 3 THEN 33.3 * Indi.gewicht
|
|
ELSE 0
|
|
END
|
|
END) AS somscore,
|
|
|
|
SUM( IF((OV.scoretype=4 && S.score=3), 0, Indi.gewicht) ) AS num,
|
|
|
|
Y.nummer
|
|
|
|
FROM tb_filledversions FV
|
|
JOIN tb_scores S ON FV.id = S.filledversion_id
|
|
JOIN tb_indicatoren Indi ON Indi.id = S.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = S.ijkpunt_id
|
|
JOIN tb_orgversies OV ON FV.orgversie_id = OV.id
|
|
WHERE filledversion_id = {$filledversionid}
|
|
AND FV.meetellen = 1
|
|
GROUP BY S.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function fCountGevuldeVersies($orgversieid, $orgid){
|
|
$this->sql =" SELECT COUNT(DISTINCT filledversion_id) as aantal
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id = {$orgid}
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
HAVING COUNT(S.id) >= 5";
|
|
return $this->get_query_row();
|
|
}
|
|
|
|
|
|
function fGetGevuldeVersies($orgversieid, $orgid){
|
|
$this->sql =" SELECT filledversion_id as filledid
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id IN ({$orgid})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY S.filledversion_id
|
|
HAVING COUNT(S.id) >= 5";
|
|
$FVs= $this->get_query_result();
|
|
$lijst = '';
|
|
foreach ($FVs ? $FVs : [] as $FV){
|
|
if ($lijst != '') $lijst .=','.$FV->filledid;
|
|
else $lijst = $FV->filledid;
|
|
}
|
|
return $lijst;
|
|
}
|
|
|
|
function fTelGevuldeVersiesBijOrglist($orgversieid, $orglist){
|
|
$this->sql =" SELECT COUNT(DISTINCT(Q.filledversion_id)) AS aantalFV, COUNT(DISTINCT(Q.organisatie_id)) AS aantalorgs
|
|
FROM(
|
|
SELECT S.filledversion_id, FV.organisatie_id
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id IN ({$orglist})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
HAVING COUNT(S.id) >= 5) AS Q ";
|
|
return $this->get_query_row();
|
|
}
|
|
|
|
function fCountGevuldeBestuurVersies($orgversieid, $bgid){
|
|
$this->sql =" SELECT COUNT(DISTINCT filledversion_id) as aantal, COUNT(DISTINCT(O.id)) AS aantalorgs
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
JOIN tb_organisaties O ON FV.organisatie_id = O.id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND O.valtonder_id = {$bgid}
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
HAVING COUNT(S.id) >= 5";
|
|
return $this->get_query_row();
|
|
}
|
|
|
|
function fCountGevuldeVersiesNieuw($orgversieid, $orgids){
|
|
$this->sql =" SELECT SUM(CASE WHEN Q.aantal> 0 THEN Q.aantal
|
|
ELSE 0
|
|
END ) as aantal,
|
|
SUM(CASE WHEN Q.aantalorgs > 0 THEN Q.aantalorgs
|
|
ELSE 0
|
|
END ) as aantalorgs
|
|
FROM( SELECT COUNT(DISTINCT filledversion_id) as aantal, COUNT(DISTINCT(FV.organisatie_id)) AS aantalorgs
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id IN ({$orgids})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY FV.organisatie_id
|
|
HAVING COUNT(S.id) >= 5 ) AS Q ";
|
|
return $this->get_query_row();
|
|
}
|
|
|
|
|
|
|
|
function fGetGevuldeBestuurVersie($orgversieid, $bgid){
|
|
$this->sql =" SELECT filledversion_id as filledid
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
JOIN tb_organisaties O ON FV.organisatie_id = O.id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND O.valtonder_id = {$bgid}
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY S.filledversion_id
|
|
HAVING COUNT(S.id) >= 5";
|
|
$FVs= $this->get_query_result();
|
|
$lijst = '';
|
|
foreach ($FVs ? $FVs : [] as $FV){
|
|
if ($lijst != '') $lijst .=','.$FV->filledid;
|
|
else $lijst = $FV->filledid;
|
|
}
|
|
return $lijst;
|
|
}
|
|
|
|
function fGetGevuldeBestuurVersies($orgversieid, $bgids){
|
|
$this->sql =" SELECT filledversion_id as filledid
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
JOIN tb_organisaties O ON FV.organisatie_id = O.id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND O.valtonder_id IN {$bgids}
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY S.filledversion_id
|
|
HAVING COUNT(S.id) >= 5";
|
|
$FVs= $this->get_query_result();
|
|
$lijst = '';
|
|
foreach ($FVs ? $FVs : [] as $FV){
|
|
if ($lijst != '') $lijst .=','.$FV->filledid;
|
|
else $lijst = $FV->filledid;
|
|
}
|
|
return $lijst;
|
|
}
|
|
|
|
|
|
function fCountGevuldeKamerEnSWVVersies($orgversieid, $orgs){
|
|
$this->sql =" SELECT COUNT(DISTINCT filledversion_id) as aantal, COUNT(DISTINCT(O.id)) AS aantalorgs
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
JOIN tb_organisaties O ON FV.organisatie_id = O.id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND O.id IN ({$orgs})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
HAVING COUNT(S.id) >= 5 ";
|
|
|
|
|
|
return $this->get_query_row();
|
|
}
|
|
|
|
|
|
function fGetGevuldeKamerVersies($orgversieid, $bgs){
|
|
$this->sql =" SELECT filledversion_id as filledid
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
JOIN tb_organisaties O ON FV.organisatie_id = O.id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND O.valtonder_id IN ({$bgs})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY S.filledversion_id
|
|
HAVING COUNT(S.id) >= 5";
|
|
$FVs= $this->get_query_result();
|
|
$lijst = '';
|
|
foreach ($FVs ? $FVs : [] as $FV){
|
|
if ($lijst != '') $lijst .=','.$FV->filledid;
|
|
else $lijst = $FV->filledid;
|
|
}
|
|
return $lijst;
|
|
}
|
|
|
|
function fGetGevuldeSWVVersies($orgversieid, $orgstring){
|
|
$this->sql =" SELECT filledversion_id as filledid
|
|
FROM tb_scores S
|
|
JOIN tb_filledversions FV ON FV.id = S.filledversion_id
|
|
WHERE FV.orgversie_id = {$orgversieid}
|
|
AND FV.organisatie_id IN ({$orgstring})
|
|
AND FV.meetellen = 1
|
|
AND S.score > 0
|
|
GROUP BY S.filledversion_id
|
|
HAVING COUNT(S.id) >= 5";
|
|
$FVs= $this->get_query_result();
|
|
$lijst = '';
|
|
foreach ($FVs ? $FVs : [] as $FV){
|
|
if ($lijst != '') $lijst .=','.$FV->filledid;
|
|
else $lijst = $FV->filledid;
|
|
}
|
|
return $lijst;
|
|
}
|
|
|
|
function getgemscores($orgversieid, $orgids){
|
|
$gevuldeversies = $this->fGetGevuldeVersies($orgversieid, $orgids);
|
|
if ($gevuldeversies) {
|
|
$this->sql = " SELECT Q.omschrijving, Q.toelichting, Q.ijkpunt_id, Q.kleurnummer, Q.disabled, Q.scoretype,
|
|
CASE WHEN Q.aantalvier > 0 THEN
|
|
CASE WHEN Q.aantalvier = Q.aantalnvt THEN
|
|
'T'
|
|
ELSE 'F'
|
|
END
|
|
ELSE 'F'
|
|
END AS disablenvt,
|
|
Q.sumscores/Q.sumgewicht AS gem, Q.kleurcode, Q.nummer, Q.ondergrens, Q.bovengrens
|
|
FROM (
|
|
SELECT Y.omschrijving, Y.toelichting,Y.id as ijkpunt_id,
|
|
Y.nummer, Y.disabled, SC.scoretype, SK.nummer AS kleurnummer,
|
|
SK.kleurcode, SK.ondergrens, SK.bovengrens,
|
|
SUM(CASE WHEN Y.disabled = 'T' THEN 0
|
|
WHEN Y.disabled = 'F' THEN
|
|
CASE WHEN SC.scoretype = 1
|
|
THEN (SC.score * I.gewicht * 10)
|
|
WHEN SC.scoretype = 2
|
|
THEN (SC.score * I.gewicht)
|
|
WHEN SC.scoretype = 3
|
|
THEN
|
|
CASE WHEN SC.score = 0
|
|
THEN 0
|
|
WHEN SC.score = 1
|
|
THEN (100 * I.gewicht)
|
|
WHEN SC.score = 2
|
|
THEN 0
|
|
WHEN SC.score = 3
|
|
THEN (50 * I.gewicht)
|
|
END
|
|
WHEN SC.scoretype = 4
|
|
THEN
|
|
CASE WHEN SC.score = 1
|
|
THEN (100 * I.gewicht)
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 5
|
|
THEN
|
|
CASE WHEN SC.score = 0
|
|
THEN 0
|
|
WHEN SC.score = 1
|
|
THEN (100 * I.gewicht)
|
|
WHEN SC.score = 2
|
|
THEN 0
|
|
WHEN SC.score = 3
|
|
THEN (50 * I.gewicht)
|
|
END
|
|
WHEN SC.scoretype = 6
|
|
THEN
|
|
CASE WHEN SC.score = 2
|
|
THEN (50 * I.gewicht)
|
|
WHEN SC.score = 3
|
|
THEN (100 * I.gewicht)
|
|
ELSE 0
|
|
END
|
|
WHEN SC.scoretype = 7
|
|
THEN
|
|
CASE WHEN SC.score = 1
|
|
THEN (100 * I.gewicht)
|
|
WHEN SC.score = 2
|
|
THEN (66.6 * I.gewicht)
|
|
WHEN SC.score = 3
|
|
THEN (33.3 * I.gewicht)
|
|
ELSE 0
|
|
END
|
|
ELSE 0
|
|
END
|
|
ELSE 0
|
|
END)AS sumscores,
|
|
SUM(CASE WHEN SC.scoretype = 4 AND SC.score = 3 THEN 1
|
|
ELSE 0
|
|
END) AS aantalnvt,
|
|
SUM(CASE WHEN SC.scoretype = 4 THEN 1
|
|
ELSE 0
|
|
END) AS aantalvier,
|
|
SUM(I.gewicht) AS sumgewicht
|
|
FROM tb_scores SC
|
|
JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
JOIN tb_scorekleuren SK ON SK.scoretype = SC.scoretype
|
|
WHERE SC.filledversion_id IN ({$gevuldeversies})
|
|
AND SK.disabled = Y.disabled
|
|
GROUP BY SC.ijkpunt_id, SK.id
|
|
ORDER BY Y.nummer ) AS Q
|
|
HAVING Q.ondergrens <= gem AND Q.bovengrens > gem ";
|
|
}
|
|
else return false;
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getgemscoresoud($orgversieid, $orgid){
|
|
$gevuldeversies = $this->fGetGevuldeVersies($orgversieid, $orgid);
|
|
|
|
$p = "SC.scoretype = 7";
|
|
$q = "IF (SC.score = 1, (100 * I.gewicht),
|
|
IF (SC.score = 2,(66.6 * I.gewicht), IF (score = 3, (33.3 * I.gewicht), 0 )))";
|
|
$r = "0";
|
|
$o = "IF($p, $q, $r)";
|
|
|
|
|
|
$m = "SC.scoretype= 4";
|
|
$n = "IF (SC.score = 1, (100 * I.gewicht), 0)";
|
|
|
|
$l = "IF ($m, $n, $o)";
|
|
|
|
$j = "SC.scoretype = 6";
|
|
$k = "IF (SC.score = 2 , (50 * I.gewicht), IF (SC.score = 3, (100 * I.gewicht),0) )";
|
|
$i = "IF ($j, $k ,$l)";
|
|
|
|
$g = "(SC.scoretype=3 or SC.scoretype=5)";
|
|
$h = "IF (SC.score = 1, (100 * I.gewicht),
|
|
IF ((SC.score = 2 or SC.score = 0), (0 * I.gewicht), (50 * I.gewicht) ) ) ";
|
|
$f = "if ($g, $h, $i)";
|
|
|
|
$d = "SC.scoretype = 2";
|
|
$e = "(SC.score * I.gewicht)";
|
|
$c = "if($d, $e, $f)";
|
|
|
|
$a = "SC.scoretype = 1";
|
|
$b = "(SC.score * I.gewicht * 10)";
|
|
|
|
if ($gevuldeversies) {
|
|
$this->sql="SELECT sum(IF ({$a}, {$b} ,{$c}) )/ sum(IF ((SC.scoretype=4 && SC.score=3), 0, I.gewicht)) AS gem,
|
|
Y.omschrijving, Y.toelichting,Y.id as ijkpunt_id,
|
|
Y.nummer
|
|
FROM tb_scores SC
|
|
JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
WHERE SC.filledversion_id IN ({$gevuldeversies})
|
|
GROUP BY SC.ijkpunt_id
|
|
ORDER BY Y.nummer";
|
|
// $this->sql="SELECT sum(
|
|
// IF (SC.scoretype= 1, (SC.score * I.gewicht * 10),
|
|
// IF (SC.scoretype = 2, (SC.score * I.gewicht),
|
|
// IF ((SC.scoretype = 3 OR SC.scoretype =5 OR SC.scoretype = 6),
|
|
// ( IF (SC.score = 1, (100 * I.gewicht), IF ((SC.score = 2 or SC.score = 0), (0 * I.gewicht), (50 * I.gewicht)) ) ) ,
|
|
// IF (SC.scoretype=4, IF(SC.score=1, (100 * I.gewicht), IF ((SC.score= 0 or SC.score=2), (0 * I.gewicht), 0) ),0)
|
|
|
|
// ) ))) / sum(IF ((SC.scoretype=4 && SC.score=3), 0, I.gewicht)) AS gem,
|
|
// Y.omschrijving, Y.toelichting,
|
|
// Y.nummer
|
|
// FROM tb_scores SC
|
|
// JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
// JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
// WHERE SC.filledversion_id IN ({$gevuldeversies})
|
|
// GROUP BY SC.ijkpunt_id
|
|
// ORDER BY Y.nummer";
|
|
|
|
|
|
// $this->sql="SELECT sum(IF (SC.scoretype= 1, (SC.score * I.gewicht * 10),
|
|
// IF (SC.scoretype = 2, (SC.score * I.gewicht),
|
|
// IF ((SC.scoretype = 3 OR SC.scoretype =5), ( IF (SC.score = 1, (100 * I.gewicht), IF ((SC.score = 2 or SC.score = 0), (0 * I.gewicht), (50 * I.gewicht)) ) ) ,
|
|
// IF (SC.scoretype=4, IF(SC.score=1, (100 * I.gewicht), IF ((SC.score= 0 or SC.score=2), (0 * I.gewicht), 0) ),0)
|
|
|
|
// ) ))) / sum(IF ((SC.scoretype=4 && SC.score=3), 0, I.gewicht)) AS gem ,
|
|
|
|
// Y.nummer
|
|
// FROM (SELECT COUNT(*) AS aantal, filledversion_id as filledid
|
|
// FROM tb_scores
|
|
// WHERE score > 0
|
|
// GROUP BY filledversion_id)
|
|
// AS Q
|
|
// JOIN tb_filledversions FV ON Q.filledid = FV.id
|
|
// JOIN tb_scores SC ON FV.id = SC.filledversion_id
|
|
// JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
// JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
// WHERE FV.orgversie_id = {$orgversieid}
|
|
// AND FV.organisatie_id = {$orgid}
|
|
// AND FV.meetellen = 1
|
|
// AND Q.aantal >= 5
|
|
// GROUP BY SC.ijkpunt_id
|
|
// ORDER BY Y.nummer";
|
|
return $this->get_query_result();
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getgewenst($orgid, $orgversieid){
|
|
$gewenst = $this->Wenssituaties_model->getgewenst($orgversieid, $orgid);
|
|
if (!$gewenst){
|
|
$organisatie = $this->Organisaties_model->get_record_by_id($orgid);
|
|
$where = array("id" =>$organisatie->valtonder_id);
|
|
$org2id = $this->Organisaties_model->get_fieldvalue($where, 'id');
|
|
if ($org2id ) {
|
|
$gewenst =$this->Wenssituaties_model->getgewenst($orgversieid, $org2id);
|
|
if (!$gewenst){
|
|
$organisatie = $this->Organisaties_model->get_record_by_id($org2id);
|
|
$where = array("id" =>$organisatie->valtonder_id);
|
|
$org3id = $this->Organisaties_model->get_fieldvalue($where, 'id');
|
|
if ($org3id ) {
|
|
$gewenst =$this->Wenssituaties_model->getgewenst($orgversieid, $org3id);
|
|
if (!$gewenst){
|
|
$organisatie = $this->Organisaties_model->get_record_by_id($org3id);
|
|
$where = array("id" =>$organisatie->valtonder_id);
|
|
$org4id = $this->Organisaties_model->get_fieldvalue($where, 'id');
|
|
if ($org4id) {$gewenst =$this->Wenssituaties_model->getgewenst($orgversieid, $org4id);};
|
|
}; // bij org4
|
|
}; // if org3
|
|
}; // if nog gewenst bij org2 get org3
|
|
}; // bij org2
|
|
} ; // if nog gewenst
|
|
return $gewenst;
|
|
}
|
|
|
|
function getgewenstindividueel($orgid, $orgversieid, $orguserid){
|
|
$this->sql= "SELECT id, wens
|
|
FROM tb_wenssituaties
|
|
WHERE organisatie_id = {$orgid}
|
|
AND orgversie_id = {$orgversieid}
|
|
AND orguser_id = {$orguserid}
|
|
ORDER BY ijkpunt_id ";
|
|
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function getstandaardfrequenties($userid, $orglist,$orgversie){
|
|
$this->sql="SELECT sum(IF(SC.score = 1, 1,0)) AS onvol,
|
|
sum(IF(SC.score = 2 , 1,0)) AS vol,
|
|
sum(IF(SC.score = 3 , 1, 0)) AS goed,
|
|
Y.omschrijving,
|
|
Y.nummer,
|
|
FV.id as fvID,
|
|
Y.id as ijkpuntID,
|
|
O.id as oordeelid,
|
|
if(O.id IS NOT NULL, O.norm, '') as norm,
|
|
if (O.id IS NOT NULL, O.norm_id, NULL) as normid,
|
|
if (O.id IS NOT NULL, O.wens_id, NULL) as wensid,
|
|
Y.toelichting
|
|
FROM (SELECT COUNT(*) AS aantal, filledversion_id as filledid
|
|
FROM tb_scores
|
|
WHERE score > 0
|
|
GROUP BY filledversion_id)
|
|
AS Q
|
|
JOIN tb_filledversions FV ON Q.filledid = FV.id
|
|
JOIN tb_scores SC ON FV.id = SC.filledversion_id
|
|
JOIN tb_indicatoren I ON I.id = SC.indicator_id
|
|
JOIN tb_ijkpunten Y ON Y.id = SC.ijkpunt_id
|
|
LEFT JOIN tb_oordelen O ON (O.filledversion_id = FV.id and O.ijkpunt_id = SC.ijkpunt_id)
|
|
WHERE FV.orgversie_id = {$orgversie}
|
|
AND FV.meetellen = 1
|
|
AND Q.aantal >= 5
|
|
AND FV.organisatie_id IN ({$orglist}) ";
|
|
if ($userid){
|
|
$this->sql .= " AND FV.user_id = {$userid} ";
|
|
}
|
|
$this->sql .=" GROUP BY Y.id";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function telOordelen($orgid,$orgversie){
|
|
$this->sql="SELECT COUNT(O.id) as oordelen
|
|
FROM tb_oordelen O
|
|
JOIN tb_filledversions FV ON O.filledversion_id = FV.id
|
|
WHERE FV.orgversie_id = {$orgversie}
|
|
AND FV.organisatie_id = {$orgid} ";
|
|
return $this->get_query_result('oordelen');
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|