231 lines
7.4 KiB
PHP
231 lines
7.4 KiB
PHP
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
|
|
|
|
class Sortering extends MY_Controller {
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$models = array(
|
|
"shared/Users_model",
|
|
"shared/Organisaties_model",
|
|
"shared/Orgusers_model",
|
|
"shared/Session_model",
|
|
"monpas/Sorteringen_model",
|
|
"monpas/Sorteerlabels_model",
|
|
"monpas/Sorteerlabelsorg_model",
|
|
);
|
|
$this->load->model( $models );
|
|
$this->load->helper( 'string' );
|
|
if ( ! $this->check_online_status() )
|
|
{
|
|
echo json_encode( array('offline' => TRUE) );
|
|
die;
|
|
};// if
|
|
}
|
|
|
|
function checkrechten()
|
|
{
|
|
// if ( ! $this->userid ) die;
|
|
// $orguserid = $this->Orgusers_model->get_fieldvalue( array("user_id" => $this->userid, "organisatie_id" => $this->globorgid), "id" );
|
|
// $niveau = $this->Autorisaties_model->get_fieldvalue( array("orguser_id" => $orguserid), "nivo_id" );
|
|
//
|
|
// if ( $niveau == 1 || $niveau == 2 )
|
|
// {
|
|
// echo json_encode( TRUE );
|
|
// }
|
|
// else
|
|
// {
|
|
// echo json_encode( FALSE );
|
|
// }
|
|
}
|
|
|
|
|
|
// function checkadmin(){
|
|
// $orguserid = $this->Orgusers_model->get_fieldvalue( array("user_id" => $this->userid, "organisatie_id" => $this->globorgid), "id" );
|
|
// $niveau = $this->Autorisaties_model->get_fieldvalue( array("orguser_id" => $orguserid), "nivo_id" );
|
|
//
|
|
// return $niveau;
|
|
// }
|
|
|
|
function getSortering(){
|
|
$swvID = $this->uri->segment(4);
|
|
$criteria = $this->Sorteringen_model->get_criteriabijSWV($swvID);
|
|
foreach($criteria as $criterium){
|
|
$labels = $this->Sorteerlabels_model->get_labels($criterium->id);
|
|
$label = new stdClass();
|
|
$label->id = 0;
|
|
$label->sortering_id = $criterium->id;
|
|
$label->naam ='niet ingedeeld';
|
|
$label->volgorde = 'LAATST';
|
|
array_push($labels, $label);
|
|
$criterium->labels = $labels;
|
|
}
|
|
|
|
echo json_encode($criteria);
|
|
|
|
}
|
|
|
|
function getSchoolIndelingen(){
|
|
$swvid = $this->clean_input('swvid');
|
|
$criteriumid = $this->clean_input('criteriumid');
|
|
$labels = $this->Sorteerlabels_model->get_labels($criteriumid);
|
|
$label = new stdClass();
|
|
$label->waardeid = 0;
|
|
$label->sortering_id = $criteriumid;
|
|
$label->naam ='niet ingedeeld';
|
|
$label->volgorde = 'LAATST';
|
|
array_push($labels, $label);
|
|
$swv = $this->Organisaties_model->get_record_by_id($swvid);
|
|
$swv->kamers = $this->Organisaties_model->getorgsvanaf($swvid);
|
|
|
|
if(!$swv->kamers){
|
|
echo json_encode(false);
|
|
}
|
|
|
|
if(!is_array($swv->kamers)){
|
|
$swv->kamers = objectToArray($swv->kamers);
|
|
}
|
|
foreach($swv->kamers as $kamer){
|
|
$kamer->bgs = $this->Organisaties_model->getorgsvanaf($kamer->id);
|
|
if ($kamer->bgs){
|
|
foreach($kamer->bgs as $bg){
|
|
$bg->scholen =$this->Organisaties_model->getorgsvanaf($bg->id);
|
|
if($bg->scholen) {
|
|
foreach ($bg->scholen as $school) {
|
|
|
|
$school->opties = $labels;
|
|
|
|
$school->indeling = $this->Sorteringen_model->getSchoolIndeling($school->id, $criteriumid);
|
|
if ( !$school->indeling) {
|
|
$school->indeling = new stdClass();
|
|
$school->indeling->waardeid = 0;
|
|
$school->indeling->waarde = 'niet ingedeeld';
|
|
$school->indeling->volgorde = 'LAATST';
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
echo json_encode($swv);
|
|
}
|
|
function saveCriterium(){
|
|
$swvID = $this->clean_input('swvID');
|
|
$naam = $this->clean_input('criterium');
|
|
$label1 = $this->clean_input('label1');
|
|
$label2 = $this->clean_input('label2');
|
|
$nieuwelabels = $this->clean_input('labelArray');
|
|
$labels = [];
|
|
array_push($labels, $label1, $label2);
|
|
|
|
if($nieuwelabels){
|
|
foreach($nieuwelabels as $label){
|
|
if(!empty($label['nieuwLabel'])){
|
|
array_push($labels, $label['nieuwLabel']);
|
|
}
|
|
}
|
|
}
|
|
$criteriumid = $this->Sorteringen_model->insert_record
|
|
(array('swv_id'=>$swvID,
|
|
'naam' =>$naam));
|
|
|
|
foreach($labels as $label){
|
|
$this->Sorteerlabels_model->insert_record
|
|
(array('sortering_id'=>$criteriumid,
|
|
'naam'=>$label));
|
|
}
|
|
echo json_encode($criteriumid);
|
|
}
|
|
|
|
function editCriterium(){
|
|
$swvID = $this->clean_input('swvID');
|
|
$criteriumid = $this->clean_input('criteriumid');
|
|
$naam = $this->clean_input('criterium');
|
|
$editlabels = $this->clean_input('labels');
|
|
$nieuwelabels = $this->clean_input('labelArray');
|
|
$labels = [];
|
|
if($editlabels){
|
|
foreach($editlabels as $label){
|
|
if(!empty($label['label'] && $label['label'] != "niet ingedeeld")){
|
|
array_push($labels, $label);
|
|
}
|
|
}
|
|
foreach($labels as $label){
|
|
$labelid = $label['waardeid'];
|
|
$waarde = $label['label'];
|
|
$this->Sorteerlabels_model->update_record_where(array('naam'=>$waarde),
|
|
array('id'=>$labelid));
|
|
}
|
|
}
|
|
|
|
$labelsNieuw = [];
|
|
if($nieuwelabels){
|
|
foreach($nieuwelabels as $label){
|
|
if(!empty($label['nieuwLabel'])){
|
|
array_push($labelsNieuw, $label['nieuwLabel']);
|
|
}
|
|
}
|
|
foreach($labelsNieuw as $label){
|
|
$this->Sorteerlabels_model->insert_record
|
|
(array('sortering_id'=>$criteriumid,
|
|
'naam'=>$label));
|
|
}
|
|
}
|
|
|
|
$this->Sorteringen_model->update_record
|
|
(array('swv_id'=>$swvID,
|
|
'naam' =>$naam), $criteriumid);
|
|
|
|
echo json_encode(true);
|
|
}
|
|
|
|
|
|
function deleteCriterium(){
|
|
$criteriumid = $this->uri->segment(4);
|
|
|
|
$this->Sorteerlabels_model->delete_record_where(array('sortering_id' =>$criteriumid));
|
|
$this->Sorteringen_model->delete_record($criteriumid);
|
|
|
|
echo json_encode(true);
|
|
|
|
}
|
|
|
|
function deleteLabel(){
|
|
$labelid = $this->uri->segment(4);
|
|
|
|
$this->Sorteerlabels_model->delete_record($labelid);
|
|
|
|
echo json_encode(true);
|
|
|
|
}
|
|
|
|
function updateSortering(){
|
|
$orgid = $this->clean_input('orgid');
|
|
$keuzeid = $this->clean_input('keuzeid');
|
|
$criteriumid = $this->clean_input('criteriumid');
|
|
$voorheen = $this->Sorteringen_model->getSchoolIndeling($orgid, $criteriumid);
|
|
|
|
if($voorheen){
|
|
$this->Sorteerlabelsorg_model->delete_record_where(array(
|
|
'label_id'=>$voorheen->waardeid,
|
|
'organisatie_id'=>$orgid ));
|
|
}
|
|
$id = $this->Sorteerlabelsorg_model->insert_record(array(
|
|
'label_id'=>$keuzeid,
|
|
'organisatie_id'=>$orgid));
|
|
|
|
echo json_encode($id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |