280 lines
7.6 KiB
PHP
280 lines
7.6 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Description of Organisaties_model
|
|
*
|
|
* @author Theo Weijmer
|
|
* @date april 26, 2013 4:09 PM
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
class Organisaties_model extends MY_Model{
|
|
|
|
|
|
protected $tablename = 'tb_organisaties';
|
|
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array();
|
|
$this->load->model($models);
|
|
}
|
|
|
|
|
|
function get_details($where=FALSE, $like=FALSE){
|
|
if($like){
|
|
$records = $this->get_searchbgs($like);
|
|
}else{
|
|
$records = $this->get_records_where($where);
|
|
}
|
|
|
|
if($records){
|
|
|
|
foreach($records as $record){
|
|
$details[] = $this->get_organisatie_details($record);
|
|
}
|
|
}
|
|
|
|
if(!isset($details)) $details = FALSE;
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_organisatie_details($record){
|
|
$details = new stdClass;
|
|
|
|
$details->id = $record->id;
|
|
|
|
$details->orgnaam = $record->naam;
|
|
$details->orgkort = $record->naamkort;
|
|
|
|
$details->brin = $record->organisatie_brin;
|
|
$details->vestiging = $record->organisatie_vestiging;
|
|
|
|
$details->adres = $record->organisatie_adres;
|
|
$details->postcode = $record->organisatie_postcode;
|
|
$details->plaats = $record->organisatie_plaats;
|
|
|
|
$details->email = $record->organisatie_email;
|
|
$details->telefoon = $record->organisatie_telefoon;
|
|
|
|
if($record->id==$record->organisatie_id){
|
|
$data = array('organisatie_id'=>$record->id, 'id !=' =>$record->organisatie_id, 'partituur' => 'T');
|
|
$details->scholen = $this->get_details($data);
|
|
$details->bg = TRUE;
|
|
}else{
|
|
$details->scholen = FALSE;
|
|
$details->bg = FALSE;
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
|
|
function get_partituur_bgs($isbg){
|
|
$this->sql = "
|
|
SELECT *
|
|
FROM tb_organisaties O
|
|
JOIN ( SELECT DISTINCT organisatie_id
|
|
FROM tb_organisaties
|
|
WHERE partituur='T'
|
|
) Q1
|
|
ON Q1.organisatie_id = O.id ";
|
|
|
|
if(!$this->admin){
|
|
if($isbg){
|
|
$this->sql .="
|
|
WHERE O.organisatie_id = {$this->orgid} ";
|
|
}else{
|
|
$orgs =$this->get_orgs_by_orguserID($this->userid);
|
|
if(!$orgs){
|
|
return FALSE;
|
|
}else{
|
|
$wherein = array();
|
|
foreach($orgs as $org){
|
|
array_push($wherein, $org->id);
|
|
}
|
|
$this->sql .="
|
|
WHERE O.id IN() {$wherein} ";
|
|
}
|
|
}
|
|
}
|
|
|
|
$records = $this->get_query_result();
|
|
if($records){
|
|
foreach($records as $record){
|
|
$details[] = $this->get_organisatie_details($record);
|
|
}
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
|
|
function check_isbg($orgid){
|
|
$org = $this->Organisaties_model->get_record_by_id($orgid);
|
|
if($org->id == $org->organisatie_id){
|
|
return TRUE;
|
|
}else{
|
|
return FALSE;
|
|
}
|
|
}
|
|
function get_orgs($orgid = false, $row = false){
|
|
$this->sql="SELECT id, organisatie_naamkort as naamkort,
|
|
COALESCE(organisatie_plaats,'onbekend') as plaats
|
|
FROM tb_organisaties";
|
|
if ($orgid > 0){
|
|
$this->sql .=" WHERE organisatie_id = {$orgid} ";
|
|
} ;
|
|
$this->sql .=" ORDER BY organisatie_id, organisatie_naamkort ";
|
|
if ($row) {return $this->get_query_row() ;}
|
|
else {return $this->get_query_result();};
|
|
}
|
|
function get_org_by_id($orgid = false){
|
|
$this->sql="SELECT id, organisatie_naamkort as naamkort,
|
|
COALESCE(organisatie_plaats,'onbekend') as plaats
|
|
FROM tb_organisaties
|
|
WHERE id = {$orgid} ";
|
|
return $this->get_query_row() ;
|
|
}
|
|
function get_bgs(){
|
|
$this->sql="SELECT id, organisatie_naamkort as naamkort,
|
|
COALESCE(organisatie_plaats,'onbekend') as plaats
|
|
FROM tb_organisaties
|
|
WHERE id = organisatie_id ";
|
|
return $this->get_query_result() ;
|
|
}
|
|
function get_BG_by_id($BGid){
|
|
$this->sql="SELECT organisatie_naam,
|
|
organisatie_naamkort as naamkort,
|
|
organisatie_brin,
|
|
organisatie_adres,
|
|
organisatie_postcode,
|
|
organisatie_plaats,
|
|
organisatie_email,
|
|
organisatie_telefoon
|
|
FROM tb_organisaties
|
|
WHERE id = {$BGid}";
|
|
return $this->get_query_row() ;
|
|
}
|
|
function get_orgs_per_bg($BGid){
|
|
$this->sql= " SELECT organisatie_naam,
|
|
organisatie_naamkort as naamkort,
|
|
organisatie_brin,
|
|
organisatie_adres,
|
|
organisatie_postcode,
|
|
organisatie_plaats,
|
|
organisatie_email,
|
|
organisatie_telefoon
|
|
FROM tb_organisaties
|
|
WHERE organisatie_id = {$BGid}
|
|
AND id <> {$BGid}";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function get_orgs_by_orguserid ($userID){
|
|
$this->sql = "SELECT o.*
|
|
FROM tb_organisaties o
|
|
INNER JOIN tb_orgusers ou
|
|
ON o.id = ou.orguser_organisatie_id
|
|
WHERE ou.orguser_user_id = {$userID}
|
|
ORDER BY o.organisatie_id, o.id, o.organisatie_naam";
|
|
$res = $this->get_query_result();
|
|
|
|
if($res){
|
|
foreach($res as $record){
|
|
$details[] = $this->get_organisatie_details($record);
|
|
}
|
|
}
|
|
if(!isset($details)) $details = FALSE;
|
|
return $details;
|
|
}
|
|
|
|
function table_def(){
|
|
$this->sql = "
|
|
|
|
";
|
|
|
|
}
|
|
function getorgsfororguser($userid){
|
|
$this->sql= "SELECT O.id
|
|
FROM tb_organisaties O
|
|
JOIN tb_orgusers OU ON (OU.orguser_user_id = 838 AND OU.orguser_organisatie_id = O.id)";
|
|
return $this->get_query_result();
|
|
}
|
|
function getallorgs($targetorgs,$system){
|
|
$this->sql = " SELECT id, organisatie_naam, concat_ws('-',organisatie_naamkort,organisatie_plaats, organisatie_brin) AS orgnaam
|
|
FROM tb_organisaties
|
|
WHERE id in ({$targetorgs}) OR
|
|
(organisatie_id IN ({$targetorgs}) AND id != organisatie_id) OR
|
|
$system
|
|
ORDER BY organisatie_naamkort";
|
|
return $this->get_query_result();
|
|
}
|
|
|
|
function getorglist($orgid){
|
|
// get een lijst van id's van alle organisaties die onder hetzelfde swv vallen als $orgid.
|
|
// $orgid kan een organisatie op alle niveaus betreffen, dus dat moet wel eerst opgezocht worden
|
|
$toporg =$this->getswvrecursief($orgid);
|
|
$orglist = array();
|
|
if ($toporg) $orglist = $this->getlistrecursief($toporg->id, $orglist);
|
|
return $orglist;
|
|
}
|
|
|
|
function getlistrecursief($orgid,$lijst){
|
|
$lijst = array_merge($lijst, array($orgid));
|
|
$this->sql = "select id
|
|
from tb_organisaties
|
|
where organisatie_id = {$orgid}
|
|
and id <> {$orgid}";
|
|
$newlijst = $this->get_query_result();
|
|
if ($newlijst){
|
|
foreach($newlijst as $newid){
|
|
$lijst= $this->getlistrecursief($newid->id, $lijst);
|
|
}
|
|
}
|
|
|
|
return $lijst;
|
|
}
|
|
|
|
|
|
function getswvrecursief($orgid){
|
|
$organisatie = $this->get_record_by_id($orgid);
|
|
if ($organisatie ){
|
|
$this->sql = "SELECT id, soort, organisatie_id, organisatie_naam
|
|
FROM tb_organisaties
|
|
WHERE id = {$organisatie->organisatie_id}
|
|
AND id != {$organisatie->id}";
|
|
$org = $this->get_query_row();
|
|
|
|
if ($org) {
|
|
$organisatie = $this->getswvrecursief($org->id);
|
|
}
|
|
}
|
|
return $organisatie;
|
|
}
|
|
function getorgs($type, $orgid=FALSE){
|
|
$this->sql = "SELECT id, soort, organisatie_naam AS naam,
|
|
organisatie_brin AS brin,
|
|
organisatie_vestiging AS vestiging,
|
|
organisatie_plaats AS plaats
|
|
FROM tb_organisaties
|
|
WHERE soort = {$type}";
|
|
if ($orgid) {
|
|
$this->sql .= " AND organisatie_id = {$orgid} ";
|
|
}
|
|
$this->sql .= " ORDER BY organisatie_naamkort";
|
|
return $this->get_query_result();
|
|
}
|
|
function searchorgs($orgnaam){
|
|
$this->sql="SELECT id, concat_ws('-', organisatie_brin, organisatie_vestiging) AS brin,
|
|
organisatie_naamkort AS naam, organisatie_plaats AS plaats
|
|
FROM tb_organisaties
|
|
WHERE UPPER(organisatie_naam) LIKE '%{$orgnaam}%'
|
|
OR UPPER(organisatie_naamkort) LIKE '%{$orgnaam}%'
|
|
ORDER BY organisatie_naamkort
|
|
LIMIT 200";
|
|
return $this->get_query_result();
|
|
}
|
|
} |