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

341 lines
13 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Groepen extends MY_Controller{
function __construct(){
parent::__construct();
$models = array("shared/Session_model",
"shared/Users_model",
"monpas/Ondersteuningsvormen_model",
"monpas/Aantalxondersteuningsvorm_model",
"shared/Orgusers_model",
"monpas/Labels_model",
"monpas/Groepen_model",
"monpas/Groepenxusers_model");
$this->load->model($models);
$this->load->helper('string');
if ( ! $this->check_online_status() ) {
echo json_encode( array('offline' => TRUE) );
die;
};// if
}
function getnewgroep(){
if (!$this->userid) die;
$orgid = $this->clean_input("schoolid");
$schooljaar = $this->clean_input("schooljaar");
$minnivo = $this->clean_input("minnivo");
$maxnivo = $this->clean_input("maxnivo");
$groepinfo = new stdClass;
$groepinfo->id = null;
$groepinfo->naam = '';
$groepinfo->orgid = $orgid;
$groepinfo->schooljaar = $schooljaar;
$groepinfo->niveau = null;
$groepinfo->lknaam = '';
$groepinfo->totaantal = 0;
$groepinfo->ondersteuningsvormen = $this->Ondersteuningsvormen_model->getvormen($orgid, $minnivo, $maxnivo);
if ($groepinfo->ondersteuningsvormen){
foreach($groepinfo->ondersteuningsvormen as $ondersteuningsvorm){
$ondersteuningsvorm->aantal =0;
}
}
echo json_encode($groepinfo);
}
function getgroep(){
if (!$this->userid) die;
$groepid = $this->clean_input("groepid");
$orgid = $this->clean_input("schoolid");
$minnivo = $this->clean_input("minnivo");
$maxnivo = $this->clean_input("maxnivo");
$groep = $this->Groepen_model->getgroepdetails($groepid);
$groep->niveau = explode(';', $groep->niveau);
$groep->leerkrachten = $this->Groepenxusers_model->getleerkrachten($groepid);
$groep->ondersteuningsvormen = $this->Ondersteuningsvormen_model->getvormen($orgid, $minnivo, $maxnivo);
if ($groep->ondersteuningsvormen){
foreach($groep->ondersteuningsvormen as $ondersteuningsvorm){
// hier get aantal
$ax = $this->Aantalxondersteuningsvorm_model->getaantal($groepid, $ondersteuningsvorm->id);
if ($ax){ $ondersteuningsvorm->aantal = $ax->aantal; }
else{ $ondersteuningsvorm->aantal =0; };
}
}
echo json_encode($groep);
}
function getleerkrachten(){
if (!$this->userid) die;
$schoolid = $this->uri->segment(4);
$leerkrachten = $this->Users_model->getleerkrachten($schoolid);
echo json_encode($leerkrachten);
}
function getlabels(){
if (!$this->userid) die;
$module = $this->uri->segment(4);
$label1 = "";
$label2 = "";
$label3 = "";
$label4 = "";
$labels = $this->Labels_model->getLabels($module);
foreach($labels as $label){
if($label->labelid == 5) $label1 = $label->waarde;
if($label->labelid == 6) $label2 = $label->waarde;
if($label->labelid == 7) $label3 = $label->waarde;
if($label->labelid == 8) $label4 = $label->waarde;
}
$data = [
'label1' => $label1,
'label2' => $label2,
'label3' => $label3,
'label4' => $label4
];
echo json_encode($data);
}
function insertorupdategroep(){
if (!$this->userid ) die;
$groepid = $this->clean_input('id');
$nivos = $this->clean_input("niveauarray");
$nstring = implode(';', $nivos);
$data=array('naam' => $this->clean_input('naam'),
'niveau' => $nstring,
'totaantal' => $this->clean_input('totaantal'),
'notitie' => $this->clean_input("notitie", TRUE),
'schooltype' => $this->clean_input('schooltype'),
'module' => $this->clean_input('module'));
if ($groepid <= 0 || $groepid == null || !$groepid ){
$data['schooljaarnr' ] = $this->clean_input('schooljaar');
$data['organisatie_id'] = $this->clean_input('orgid');
$groepid =$this->Groepen_model->insert_record($data);
}
else {
$this->Groepen_model->update_record($data, $groepid);
}
$groep = $this->Groepen_model->getgroep($groepid);
echo json_encode($groep);
}
function insertorupdateOS(){
//TODO clean input
if(!$this->userid) die;
$osid = $this->clean_input('id');
$orgid = $this->clean_input("orgid");
$aantal = $this->clean_input('aantal');
if (($osid == 0 || $osid == null) &&($aantal > 0)) {
$data=array("organisatie_id" => $orgid,
"naam" => $this->clean_input("naam"),
"nivo" => $this->clean_input('nivo')
);
$osid = $this->Ondersteuningsvormen_model->insert_record($data);
}
else {
if ($orgid > 0){
$data=array("naam" => $this->clean_input('naam'));
$this->Ondersteuningsvormen_model->update_record($data, $osid);
}
// update name
}
$data2= array("organisatie_id" => $orgid,
"groep_id" => $this->clean_input('groepid'),
"ondersteuningsvorm_id" => $osid);
$aos =$this->Aantalxondersteuningsvorm_model->get_records_where($data2, TRUE);
if($aos){
if ($this->clean_input('aantal') == 0) {
//delete de regel
$this->Aantalxondersteuningsvorm_model->delete_record($aos->id);
}
else {
// update de regel
$data=array( "aantal" => $this->clean_input('aantal') );
$this->Aantalxondersteuningsvorm_model->update_record($data, $aos->id);
}
}
else{
if ($this->clean_input('aantal') > 0){
$data = array( "organisatie_id" => $orgid,
"groep_id" => $this->clean_input('groepid'),
"ondersteuningsvorm_id" => $osid,
"aantal" => $this->clean_input('aantal'));
$aantalid = $this->Aantalxondersteuningsvorm_model->insert_record($data);
}
}
echo json_encode($osid);
}
function getgroepen(){
if (!$this->userid) die;
$orgid = $this->clean_input('schoolID');
$schooljaarnr = $this->clean_input('schooljaar');
$module = $this->clean_input('module');
$groepen = $this->Groepen_model->getgroepen($orgid, $schooljaarnr, $module);
if ($groepen){
foreach($groepen as $groep){
$groep->leerkrachten = $this->Groepenxusers_model->getleerkrachten($groep->id);
}
}
echo json_encode($groepen);
}
function getgekopieerdegroepen(){
if (!$this->userid) die;
$schooljaarnr = $this->clean_input('schooljaar');
$orgid = $this->clean_input('orgid');
$module = $this->clean_input('module');
$groepen = $this->Groepen_model->getgekopieerdegroepen($orgid, $schooljaarnr, $module);
if ($groepen){
foreach($groepen as $groep){
$groep->leerkrachten = $this->Groepenxusers_model->getleerkrachten($groep->id);
}
}
echo json_encode($groepen);
}
function getgroepenso(){
if (!$this->userid) die;
$orgid = $this->uri->segment(4);
$schooljaarnr = $this->uri->segment(5);
$ondersteuning = 'T';
$groepen = $this->Groepen_model->getgroepenSboSo($orgid, $schooljaarnr);
if ($groepen){
foreach($groepen as $groep){
$groep->leerkrachten = $this->Groepenxusers_model->getleerkrachten($groep->id);
if (isset($groep->ondersteuning) && $groep->ondersteuning == 'F') {
$ondersteuning = 'F';
}
}
}
echo json_encode(['groepen' =>$groepen, 'ondersteuning' =>$ondersteuning]);
}
function deletegroep(){
if (!$this->userid) die;
if (!$this->writer) return;
$groepid = $this->uri->segment(4);
$this->Aantalxondersteuningsvorm_model->delete_record_where(array('groep_id'=>$groepid) );
$this->Groepenxusers_model->delete_record_where(array("groep_id" =>$groepid));
$this->Groepen_model->delete_record($groepid);
}
function deleteOS(){
if (!$this->userid) die;
if (!$this->writer) return;
$osid = $this->uri->segment(4);
$this->Aantalxondersteuningsvorm_model->delete_record_where(array("ondersteuningsvorm_id" => $osid));
$this->Ondersteuningsvormen_model->delete_record($osid);
}
function getwriter(){
$writer = false;
if ($this->Autorisaties_model->check_autorisatie($this->userrole, 259) > 0){$writer = true;};
echo json_encode($writer);
}
function deletegroepxuser(){
if (!$this->userid) die;
$groepid = $this->uri->segment(4);
$this->Groepenxusers_model->delete_record_where(array("groep_id" =>$groepid));
}
function addgroepxuser(){
if(!$this->userid) die;
$groepid = $this->uri->segment(4);
$orgid = $this->uri->segment(5);
$userid = $this->uri->segment(6);
$orguserid = $this->Orgusers_model->get_fieldvalue(array("organisatie_id" =>$orgid, "user_id" => $userid),'id') ;
$newid= $this->Groepenxusers_model->insert_record(array("orguser_id"=> $orguserid, "groep_id"=>$groepid));
}
function updatenotitie(){
if (!$this->userid) die;
$groepid = $this->clean_input("groepid");
$notitie = $this->clean_input("notitie", TRUE);
$this->Groepen_model->update_record(array("notitie" =>$notitie), $groepid);
}
function copygroepregulier(){
if (!$this->userid) die;
$error = true;
$schooljaarnr = $this->clean_input('schooljaar');
$orgid = $this->clean_input('orgid');
$module = $this->clean_input('module');
$vorigegroepen = $this->Groepen_model->get(['schooljaarnr'=> $schooljaarnr - 1,
'organisatie_id' =>$orgid,
'schooltype' => 'R',
'module' => $module], false, false);
if ($vorigegroepen){
$error = false;
foreach($vorigegroepen as $vorigegroep){
$data=['schooljaarnr' => $schooljaarnr,
'organisatie_id' => $vorigegroep->organisatie_id,
'naam' => $vorigegroep->naam,
'niveau' => $vorigegroep->niveau,
'module' =>$vorigegroep->module,
'totaantal' => 0 ];
$newid = $this->Groepen_model->insert_record($data);
$leerkrachten = $this->Groepenxusers_model->get(['groep_id'=>$vorigegroep->id],false,false);
if ($leerkrachten){
foreach($leerkrachten as $leerkracht){
$data=['orguser_id' => $leerkracht->orguser_id,
'groep_id' => $newid];
$id= $this->Groepenxusers_model->insert_record($data);
}
}
}
}
echo json_encode($error);
}
function copygroepSOSBO(){
if (!$this->userid) die;
$error = true;
$schooljaarnr = $this->clean_input('schooljaar');
$orgid = $this->clean_input('orgid');
$vorigegroepen = $this->Groepen_model->get(['schooljaarnr'=> $schooljaarnr - 1,
'organisatie_id' =>$orgid,
'schooltype' => 'R',
'module' => 270], false, false);
if ($vorigegroepen){
$error = false;
foreach($vorigegroepen as $vorigegroep){
$data=['schooljaarnr' => $schooljaarnr,
'organisatie_id' => $vorigegroep->organisatie_id,
'naam' => $vorigegroep->naam,
'niveau' => $vorigegroep->niveau,
'module' =>$vorigegroep->module,
'totaantal' => 0 ];
$newid = $this->Groepen_model->insert_record($data);
$leerkrachten = $this->Groepenxusers_model->get(['groep_id'=>$vorigegroep->id],false,false);
if ($leerkrachten){
foreach($leerkrachten as $leerkracht){
$data=['orguser_id' => $leerkracht->orguser_id,
'groep_id' => $newid];
$id= $this->Groepenxusers_model->insert_record($data);
}
}
}
}
echo json_encode($error);
}
}