From aad0292d5a3fbef9738beaf99c913460947c549d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Mon, 15 Apr 2019 17:30:55 +0200 Subject: [PATCH] Added function to get all Organisationsunits that are attachted to a course --- include/organisationseinheit.class.php | 372 ++++++++++++++----------- 1 file changed, 210 insertions(+), 162 deletions(-) diff --git a/include/organisationseinheit.class.php b/include/organisationseinheit.class.php index 405d73cd6..39c389a78 100644 --- a/include/organisationseinheit.class.php +++ b/include/organisationseinheit.class.php @@ -24,17 +24,17 @@ */ /** * Klasse Organisationseinheit - * + * */ require_once(dirname(__FILE__).'/basis_db.class.php'); class organisationseinheit extends basis_db { public static $oe_parents_array=array(); - public $new; // @var boolean + public $new; // @var boolean public $errormsg; // @var string public $result; - + //Tabellenspalten public $oe_kurzbz; public $oe_parent_kurzbz; @@ -43,13 +43,13 @@ class organisationseinheit extends basis_db public $aktiv=true; public $lehre=true; public $mailverteiler=false; - public $standort_id; - + public $standort_id; + public $oe_kurzbz_orig; public $beschreibung; public $oetyp_bezeichnung; - - + + /** * Konstruktor * @param $oe_kurzbz Kurzbz der Organisationseinheit @@ -57,7 +57,7 @@ class organisationseinheit extends basis_db public function __construct($oe_kurzbz=null) { parent::__construct(); - + if($oe_kurzbz != null) $this->load($oe_kurzbz); } @@ -76,17 +76,17 @@ class organisationseinheit extends basis_db if(!is_null($aktiv)) $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); - if(!is_null($lehre)) + if(!is_null($lehre)) $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); $qry .=" ORDER BY ".$order; - + if($this->db_query($qry)) { while($row = $this->db_fetch_object()) { $obj = new organisationseinheit(); - + $obj->oe_kurzbz = $row->oe_kurzbz; $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; $obj->bezeichnung = $row->bezeichnung; @@ -94,18 +94,18 @@ class organisationseinheit extends basis_db $obj->aktiv = $this->db_parse_bool($row->aktiv); $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); $obj->lehre = $this->db_parse_bool($row->lehre); - + $this->result[] = $obj; } return true; } - else + else { $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; return false; } } - + /** * Laedt eine Organisationseinheit * @param $oe_kurzbz @@ -136,7 +136,7 @@ class organisationseinheit extends basis_db $this->aktiv = $this->db_parse_bool($row->aktiv); $this->mailverteiler = $this->db_parse_bool($row->mailverteiler); $this->lehre = $this->db_parse_bool($row->lehre); - $this->standort_id = $row->standort_id; + $this->standort_id = $row->standort_id; $this->freigabegrenze = $row->freigabegrenze; } else @@ -147,7 +147,7 @@ class organisationseinheit extends basis_db return true; } - + /** * Laedt alle Organisationseinheiten an oberster Stelle * @@ -156,13 +156,13 @@ class organisationseinheit extends basis_db public function getHeads() { $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz is null"; - + if($this->db_query($qry)) { while($row = $this->db_fetch_object()) { $obj = new organisationseinheit(); - + $obj->oe_kurzbz = $row->oe_kurzbz; $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; $obj->bezeichnung = $row->bezeichnung; @@ -170,18 +170,18 @@ class organisationseinheit extends basis_db $obj->aktiv = $this->db_parse_bool($row->aktiv); $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); $obj->lehre = $this->db_parse_bool($row->lehre); - + $this->result[] = $obj; } return true; } - else + else { $this->errormsg = 'Fehler bei Abfrage'; return false; } } - + /** * Liefert die ChildNodes einer Organisationseinheit. Optional kann ein Typ übergeben werden, welchem das Child entspricht * @@ -192,23 +192,23 @@ class organisationseinheit extends basis_db public function getChilds($oe_kurzbz, $organisationseinheittyp_kurzbz = null) { $childs[] = $oe_kurzbz; - + $dbversion = $this->db_version(); if($dbversion['server']>=8.4) { //ab PostgreSQL Version 8.4 wird die Rekursion von der DB aufgeloest $qry = " - WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as ( - SELECT oe_kurzbz, oe_parent_kurzbz, organisationseinheittyp_kurzbz FROM public.tbl_organisationseinheit + SELECT oe_kurzbz, oe_parent_kurzbz, organisationseinheittyp_kurzbz FROM public.tbl_organisationseinheit WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." UNION ALL - SELECT o.oe_kurzbz, o.oe_parent_kurzbz, o.organisationseinheittyp_kurzbz FROM public.tbl_organisationseinheit o, oes + SELECT o.oe_kurzbz, o.oe_parent_kurzbz, o.organisationseinheittyp_kurzbz FROM public.tbl_organisationseinheit o, oes WHERE o.oe_parent_kurzbz=oes.oe_kurzbz ) SELECT oe_kurzbz, organisationseinheittyp_kurzbz FROM oes"; - + if ($organisationseinheittyp_kurzbz != '') { $qry .= " WHERE organisationseinheittyp_kurzbz = ".$this->db_add_param($organisationseinheittyp_kurzbz); @@ -221,17 +221,17 @@ class organisationseinheit extends basis_db $childs[] = $row->oe_kurzbz; } } - else + else { $this->errormsg = 'Fehler beim Ermitteln der Childs'; } return $childs; } - else - { + else + { //vor 8.4 muss die Rekursion in PHP aufgeloest werden $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz); - + if($myresult = $this->db_query($qry)) { while($row = $this->db_fetch_object($myresult)) @@ -239,14 +239,14 @@ class organisationseinheit extends basis_db $childs = array_merge($childs, $this->getChilds($row->oe_kurzbz)); } } - else + else { $this->errormsg = 'Fehler beim Ermitteln der Childs'; } return $childs; } } - + /** * Liefert die Direkten KindElemente der Organisationseinheit * @@ -254,10 +254,10 @@ class organisationseinheit extends basis_db * @return Array mit den Childs inkl derm Uebergebenen Element */ public function getDirectChilds($oe_kurzbz) - { + { $childs = array(); $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz)." ORDER BY organisationseinheittyp_kurzbz DESC, bezeichnung"; - + if($this->db_query($qry)) { while($row = $this->db_fetch_object()) @@ -265,13 +265,13 @@ class organisationseinheit extends basis_db $childs[] = $row->oe_kurzbz; } } - else + else { $this->errormsg = 'Fehler beim Ermitteln der Childs'; } return $childs; } - + /** * Speichert eine Organisationseinheit * @@ -282,11 +282,11 @@ class organisationseinheit extends basis_db { if(is_null($new)) $new = $this->new; - + if($new) { //Neu anlegen - $qry = 'INSERT INTO public.tbl_organisationseinheit(oe_kurzbz, oe_parent_kurzbz, bezeichnung, + $qry = 'INSERT INTO public.tbl_organisationseinheit(oe_kurzbz, oe_parent_kurzbz, bezeichnung, organisationseinheittyp_kurzbz, aktiv, mailverteiler, lehre) VALUES('. $this->db_add_param($this->oe_kurzbz).','. $this->db_add_param($this->oe_parent_kurzbz).','. @@ -296,19 +296,19 @@ class organisationseinheit extends basis_db $this->db_add_param($this->mailverteiler, FHC_BOOLEAN).','. $this->db_add_param($this->lehre, FHC_BOOLEAN).');'; } - else + else { if($this->oe_kurzbz=='') { $this->errormsg = 'Kurzbezeichnung darf nicht leer sein'; return false; } - + if($this->oe_kurzbz_orig=='') { $this->oe_kurzbz_orig=$this->oe_kurzbz; } - + $qry = 'UPDATE public.tbl_organisationseinheit SET '. ' oe_kurzbz='.$this->db_add_param($this->oe_kurzbz).','. ' oe_parent_kurzbz='.$this->db_add_param($this->oe_parent_kurzbz).','. @@ -319,7 +319,7 @@ class organisationseinheit extends basis_db ' lehre='.$this->db_add_param($this->lehre, FHC_BOOLEAN). " WHERE oe_kurzbz=".$this->db_add_param($this->oe_kurzbz_orig, FHC_STRING, false).";"; } - + if($this->db_query($qry)) { return true; @@ -330,7 +330,7 @@ class organisationseinheit extends basis_db return false; } } - + /** * Laedt alle Organisationseinheittypen * @@ -339,28 +339,28 @@ class organisationseinheit extends basis_db public function getTypen() { $qry = "SELECT * FROM public.tbl_organisationseinheittyp ORDER BY bezeichnung"; - + if($result = $this->db_query($qry)) { while($row = $this->db_fetch_object($result)) { $obj = new organisationseinheit(); - + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; $obj->bezeichnung = $row->bezeichnung; $obj->beschreibung = $row->beschreibung; - + $this->result[] = $obj; } return true; } - else + else { $this->errormsg = 'Fehler beim Laden der Typen'; return false; } } - + /** * Laedt die Organisationseinheiten die als Array uebergeben werden * @param $kurzbzs Array mit den kurzbezeichnungen @@ -372,9 +372,9 @@ class organisationseinheit extends basis_db { if(count($kurzbzs)==0) return true; - + $kurzbzs = $this->db_implode4SQL($kurzbzs); - + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE oe_kurzbz in('.$kurzbzs.')'; if ($aktiv) $qry.=' AND aktiv=true'; @@ -386,12 +386,12 @@ class organisationseinheit extends basis_db { $this->errormsg = 'Datensatz konnte nicht geladen werden'; return false; - } + } while($row = $this->db_fetch_object($result)) { $obj = new organisationseinheit(); - + $obj->oe_kurzbz = $row->oe_kurzbz; $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; $obj->bezeichnung = $row->bezeichnung; @@ -399,13 +399,13 @@ class organisationseinheit extends basis_db $obj->aktiv = $this->db_parse_bool($row->aktiv); $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); $obj->lehre = $this->db_parse_bool($row->lehre); - + $this->result[] = $obj; } return true; } - + /** * Laedt die Organisationseinheiten in ein Array * das Array enthaelt danach Key alle Organisationseinheiten und als Value dessen Parent OE @@ -413,7 +413,7 @@ class organisationseinheit extends basis_db public function loadParentsArray() { $qry = 'SELECT * FROM public.tbl_organisationseinheit'; - + if($this->db_query($qry)) { while($row = $this->db_fetch_object()) @@ -422,22 +422,22 @@ class organisationseinheit extends basis_db } } } - + /** * Liefert die OEs die im Tree ueberhalb der uebergebene OE liegen - * + * * @param $oe_kurzbz */ public function getParents($oe_kurzbz) { $parents=array(); - - $qry="WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + + $qry="WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as ( - SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit - WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." and aktiv = true + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." and aktiv = true UNION ALL - SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes WHERE o.oe_kurzbz=oes.oe_parent_kurzbz and aktiv = true ) SELECT oe_kurzbz @@ -454,46 +454,46 @@ class organisationseinheit extends basis_db { $this->errormsg='Fehler beim Laden der Daten'; return false; - } + } } - + /** - * Get names and types of ALL parent organisational units recursivly for all ascending + * Get names and types of ALL parent organisational units recursivly for all ascending * org units of given organisational unit. (All parent organisational units) * @param string $oe_kurzbz - * @return boolean True on success. If true, returns object-array with name - * and types of given organisational unit and of its parent organisational units. + * @return boolean True on success. If true, returns object-array with name + * and types of given organisational unit and of its parent organisational units. */ public function getParents_withOEType($oe_kurzbz) { $parents=array(); - + $qry=" - WITH RECURSIVE - oes (oe_kurzbz, oe_parent_kurzbz) AS + WITH RECURSIVE + oes (oe_kurzbz, oe_parent_kurzbz) AS ( - SELECT - oe_kurzbz, + SELECT + oe_kurzbz, oe_parent_kurzbz, bezeichnung AS oe_bezeichnung, - organisationseinheittyp_kurzbz + organisationseinheittyp_kurzbz FROM - public.tbl_organisationseinheit - WHERE - oe_kurzbz=".$this->db_add_param($oe_kurzbz)." - AND + public.tbl_organisationseinheit + WHERE + oe_kurzbz=".$this->db_add_param($oe_kurzbz)." + AND aktiv = true - + UNION ALL - + SELECT - o.oe_kurzbz, + o.oe_kurzbz, o.oe_parent_kurzbz, o.bezeichnung, o.organisationseinheittyp_kurzbz FROM - public.tbl_organisationseinheit o, oes - WHERE + public.tbl_organisationseinheit o, oes + WHERE o.oe_kurzbz = oes.oe_parent_kurzbz AND aktiv = true @@ -502,33 +502,33 @@ class organisationseinheit extends basis_db oe_kurzbz, oe_bezeichnung, tbl_organisationseinheittyp.bezeichnung AS oe_typ_bezeichnung - FROM + FROM oes JOIN public.tbl_organisationseinheittyp USING (organisationseinheittyp_kurzbz)"; - - - + + + if($result = $this->db_query($qry)) { while($row = $this->db_fetch_object($result)) { $obj = new stdClass(); - + $obj->oe_kurzbz = $row->oe_kurzbz; $obj->oe_bezeichnung = $row->oe_bezeichnung; $obj->oe_typ_bezeichnung = (!is_null($row->oe_typ_bezeichnung) ? $row->oe_typ_bezeichnung : ''); - + $this->result[]= $obj; - } + } return $this->result; } else { $this->errormsg='Fehler beim Laden der Daten'; return false; - } + } } /** * Prueft ob $child eine Organisationseinheit unterhalb der OE $oe_kurzbz ist @@ -543,13 +543,13 @@ class organisationseinheit extends basis_db { $this->loadParentsArray(); } - + if(!isset(organisationseinheit::$oe_parents_array[$child])) { $this->errormsg = 'Organisationseinheit existiert nicht'; return false; } - + $childs = array_keys(organisationseinheit::$oe_parents_array, $oe_kurzbz); foreach ($childs as $row) @@ -559,15 +559,15 @@ class organisationseinheit extends basis_db return true; } else - { + { if($this->isChild($row, $child)) return true; } } - - return false; + + return false; } - + /** * Baut die Datenstruktur für senden als JSON Objekt auf */ @@ -588,8 +588,8 @@ class organisationseinheit extends basis_db $obj->lehre = $oeEinheit->lehre; $data[]=$obj; } - } - else + } + else { $obj = new stdClass(); $obj->oe_kurzbz = $this->oe_kurzbz; @@ -603,7 +603,7 @@ class organisationseinheit extends basis_db } return $data; } - + /** * Lädt Organisationseinheiten nach ihrem Typ * @param type $oetyp_kurzbz @@ -611,10 +611,10 @@ class organisationseinheit extends basis_db */ public function getByTyp($oetyp_kurzbz) { - $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE organisationseinheittyp_kurzbz='.$this->db_add_param($oetyp_kurzbz).';'; - - if($this->db_query($qry)) - { + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE organisationseinheittyp_kurzbz='.$this->db_add_param($oetyp_kurzbz).';'; + + if($this->db_query($qry)) + { while($row = $this->db_fetch_object()) { $obj = new organisationseinheit(); @@ -630,14 +630,14 @@ class organisationseinheit extends basis_db $this->result[] = $obj; } return true; - } - else - { + } + else + { $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; return false; - } + } } - + /** * Sucht nach einer Organisationseinheit * @param type $searchItem @@ -645,21 +645,21 @@ class organisationseinheit extends basis_db */ public function search($searchItem) { - $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE - ( - LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') - OR - LOWER(organisationseinheittyp_kurzbz) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') - )'; - foreach($searchItem as $value) + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE + ( + LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') + OR + LOWER(organisationseinheittyp_kurzbz) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') + )'; + foreach($searchItem as $value) { $qry.=' OR (LOWER(oe_kurzbz)=LOWER('.$this->db_add_param($value).')) - OR (LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape($value).'%\'))'; + OR (LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape($value).'%\'))'; } - $qry.= ' ORDER BY organisationseinheittyp_kurzbz, bezeichnung;'; + $qry.= ' ORDER BY organisationseinheittyp_kurzbz, bezeichnung;'; - if($this->db_query($qry)) - { + if($this->db_query($qry)) + { while($row = $this->db_fetch_object()) { $obj = new organisationseinheit(); @@ -675,20 +675,20 @@ class organisationseinheit extends basis_db $this->result[] = $obj; } return true; - } - else - { + } + else + { $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; return false; - } + } } - + /** * Laedt alle Organisationseinheiten, sortiert nach den am haeufigsten vom User in der Zeitaufzeichnung verwendeten - * + * *

Optionaler Zeitraum (Tage in die Vergangenheit), in denen die OE verwendet wurde
* Optionale Anzahl an Ereignissen im angegebenen Zeitraum, um die OE zu beruecksichtigen

- * + * * @param string $user uid * @param integer $zeitraum Anzahl Tage in die Vergangenheit, die fuer das Auftreten der OE beruecksichtigt werden sollen * @param integer $anzahl_ereignisse default: 3 Wie oft soll diese OE mindestens in $zeitraum vorkommen, um beruecksichtigt zu werden @@ -701,13 +701,13 @@ class organisationseinheit extends basis_db $this->errormsg = "anzahl_ereignisse muss eine gueltige Zahl sein"; return false; } - + if (!is_null($zeitraum) && $zeitraum>0 && is_numeric($zeitraum)) $zeit = "AND tbl_zeitaufzeichnung.start>=(now()::date-$zeitraum)"; - else + else $zeit = ""; - - $qry = "SELECT + + $qry = "SELECT oe_kurzbz, oe_parent_kurzbz, bezeichnung, @@ -720,10 +720,10 @@ class organisationseinheit extends basis_db WHERE tbl_zeitaufzeichnung.uid=".$this->db_add_param($user)." $zeit GROUP BY tbl_organisationseinheit.oe_kurzbz HAVING COUNT(*) > $anzahl_ereignisse - + UNION - - SELECT + + SELECT oe_kurzbz, oe_parent_kurzbz, bezeichnung, @@ -738,8 +738,8 @@ class organisationseinheit extends basis_db $qry .=" ORDER BY count DESC,bezeichnung,oe_kurzbz"; - if($this->db_query($qry)) - { + if($this->db_query($qry)) + { while($row = $this->db_fetch_object()) { $obj = new organisationseinheit(); @@ -755,29 +755,29 @@ class organisationseinheit extends basis_db $this->result[] = $obj; } return true; - } - else - { + } + else + { $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; return false; - } + } } - - /** - * Gibt alle Standorte zurück - * @param $aktiv - * @param $lehre - * @return boolean|array false im Fehlerfall, ansonsten ein Array - */ - public function getAllStandorte($aktiv=null, $lehre=null) + + /** + * Gibt alle Standorte zurück + * @param $aktiv + * @param $lehre + * @return boolean|array false im Fehlerfall, ansonsten ein Array + */ + public function getAllStandorte($aktiv=null, $lehre=null) { $result = array(); - $qry = "SELECT DISTINCT standort FROM public.tbl_organisationseinheit WHERE standort IS NOT NULL"; + $qry = "SELECT DISTINCT standort FROM public.tbl_organisationseinheit WHERE standort IS NOT NULL"; if(!is_null($aktiv)) $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); - if(!is_null($lehre)) + if(!is_null($lehre)) $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); if($this->db_query($qry)) @@ -786,10 +786,10 @@ class organisationseinheit extends basis_db { $result[] = $row->standort; } - - return $result; + + return $result; } - else + else { $this->errormsg = 'Fehler beim Laden der Standorte'; return false; @@ -800,7 +800,7 @@ class organisationseinheit extends basis_db * Ermittelt die Stundenobergrenze fuer Lektoren * Dabei wird im OE Baum nach oben nach Stundengrenzen gesucht und die niedrigste Stundengrenze ermittelt * @param $oe_kurzbz Organisationseinheit - * @param $fixangestellt boolean legt fest ob die Grenze + * @param $fixangestellt boolean legt fest ob die Grenze * fuer Freie oder Fixangestellte Lektoren ermittelt werden soll * @return array(oe_kurzbz, numeric Anzahl der Stunden) */ @@ -812,16 +812,16 @@ class organisationseinheit extends basis_db $fixfrei='frei'; $qry = " - WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as ( - SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." UNION ALL - SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes WHERE o.oe_kurzbz=oes.oe_parent_kurzbz ) SELECT oe_kurzbz, warn_semesterstunden_".$fixfrei." as stunden - FROM oes JOIN public.tbl_organisationseinheit USING(oe_kurzbz) + FROM oes JOIN public.tbl_organisationseinheit USING(oe_kurzbz) ORDER BY warn_semesterstunden_".$fixfrei." asc limit 1"; if($result = $this->db_query($qry)) @@ -832,11 +832,11 @@ class organisationseinheit extends basis_db } } } - + /** * Get full term of organisational unit type * @param string $oetyp_kurzbz - * @return boolean True on success. If true, returns full term of given organisational unit type. + * @return boolean True on success. If true, returns full term of given organisational unit type. */ public function getOETypBezeichnung($oetyp_kurzbz) { @@ -849,7 +849,7 @@ class organisationseinheit extends basis_db public.tbl_organisationseinheittyp WHERE organisationseinheittyp_kurzbz = '. $this->db_add_param($oetyp_kurzbz). ';'; - + if ($this->db_query($qry)) { if ($row = $this->db_fetch_object()) @@ -860,7 +860,7 @@ class organisationseinheit extends basis_db else { return false; - } + } } else { @@ -868,11 +868,59 @@ class organisationseinheit extends basis_db return false; } } - else + else { $this->errormsg = 'OE Typ fehlt bzw. darf nicht leer sein.'; return false; } } + + /** + * Liefert alle Organisationseinheiten die bei Lehrveranstaltungen als + * Lehrfach verwendet werden. + * + * @return boolean true wenn erfolgreich, false im Fehlerfall + */ + public function getLehrfachOEs() + { + $qry = " + SELECT distinct tbl_organisationseinheit.* + FROM + lehre.tbl_lehrveranstaltung + JOIN public.tbl_organisationseinheit USING(oe_kurzbz) + WHERE + tbl_organisationseinheit.aktiv + AND EXISTS( + SELECT 1 FROM lehre.tbl_lehreinheit + WHERE lehrveranstaltung_id = tbl_lehrveranstaltung.lehrveranstaltung_id + ) + AND tbl_organisationseinheit.lehre + ORDER BY organisationseinheittyp_kurzbz, bezeichnung + "; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; + return false; + } + } } ?>