diff --git a/application/controllers/jobs/OrganigrammTest.php b/application/controllers/jobs/OrganigrammTest.php index 0ea15ef4e..2e82c7d32 100644 --- a/application/controllers/jobs/OrganigrammTest.php +++ b/application/controllers/jobs/OrganigrammTest.php @@ -8,12 +8,17 @@ if (!defined("BASEPATH")) exit("No direct script access allowed"); */ class OrganigrammTest extends JOB_Controller { + const DEFAULT_XOFFSET = 100; + + protected $xoffsetperlevel; - public function __construct() + public function __construct() { parent::__construct(); $this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel'); + + $this->xoffsetperlevel = array(); } public function getAllActiveOes() @@ -109,7 +114,7 @@ HEADER; STARTDIAGRAMM; - renderOE($root, 0, 0, 100); + $this->renderOE($root, 0); echo << @@ -139,49 +144,82 @@ FOOTER; echo "Keine Oes gefunden.\n"; } } -} -function renderOE($oe, $level, $parentchildcount, $minxoffset) -{ - $nextlevel = $level + 1; - $ownchildcount = 0; - $childsmaxxoffset = $minxoffset; - foreach($oe->childs AS $child) + protected function renderOE($oe, $level) { - $childsmaxxoffset = renderOE($child, $nextlevel, $ownchildcount, $childsmaxxoffset); - $ownchildcount++; - } - - $width = 200; - $height = 100; - $spacing = 80; - $x = $minxoffset; - $y = 180 + ($level * ($height + $spacing)); - $bezeichnung = htmlspecialchars($oe->bezeichnung); - $leitung = ($oe->leitung_uid !== null) ? htmlspecialchars($oe->leitung_uid) : 'N.N.'; - $fillcolors = array( - 'Team' => '#ffe6cc', - 'Abteilung' => '#e6ffcc', - 'Studiengang' => '#cce6ff', - 'Lehrgang' => '#e6ccff' - ); - $fillcolor = (isset($fillcolors[$oe->organisationseinheittyp_kurzbz])) ? $fillcolors[$oe->organisationseinheittyp_kurzbz] : '#ffffff'; - echo << - - + $width = 200; + $height = 100; + $spacing = 80; + $nextlevel = $level + 1; + $ownchildcount = 0; + $firstelementinlevel = false; + + if( !isset($this->xoffsetperlevel[$level]) ) + { + $this->xoffsetperlevel[$level] = (object) array( + 'min' => self::DEFAULT_XOFFSET, + 'max' => self::DEFAULT_XOFFSET + ); + $firstelementinlevel = true; + } + + fwrite(STDERR, print_r($this->xoffsetperlevel, true) . PHP_EOL); + + foreach($oe->childs AS $child) + { + $this->renderOE($child, $nextlevel); + $ownchildcount++; + } + + if( count($oe->childs) === 0 ) + { + if( !isset($this->xoffsetperlevel[$nextlevel]) ) + { + $this->xoffsetperlevel[$nextlevel] = (object) array( + 'min' => $this->xoffsetperlevel[$level]->max + $width + $spacing, + 'max' => $this->xoffsetperlevel[$level]->max + $width + $spacing + ); + } + } + + if( count($oe->childs) > 0 && count($oe->childs) === $ownchildcount ) + { + $this->xoffsetperlevel[$level]->max = + floor((($this->xoffsetperlevel[$nextlevel]->max - $this->xoffsetperlevel[$nextlevel]->min) / 2)) - floor(($width / 2)); + if( $firstelementinlevel ) + { + $this->xoffsetperlevel[$level]->min = $this->xoffsetperlevel[$level]->max; + } + } + + $x = $this->xoffsetperlevel[$level]->max; + $y = 180 + ($level * ($height + $spacing)); + $bezeichnung = htmlspecialchars($oe->bezeichnung); + $leitung = ($oe->leitung_uid !== null) ? htmlspecialchars($oe->leitung_uid) : 'N.N.'; + $fillcolors = array( + 'Team' => '#ffe6cc', + 'Abteilung' => '#e6ffcc', + 'Studiengang' => '#cce6ff', + 'Lehrgang' => '#e6ccff' + ); + $fillcolor = (isset($fillcolors[$oe->organisationseinheittyp_kurzbz])) ? $fillcolors[$oe->organisationseinheittyp_kurzbz] : '#ffffff'; + echo << + + OE; - - if( $oe->oe_parent_kurzbz !== NULL ) - { - echo << - - - + + if( $oe->oe_parent_kurzbz !== NULL ) + { + echo << + + + EDGE; - } - - return ($x + $width + $spacing); + } + + $this->xoffsetperlevel[$level]->max = ($x + $width + $spacing); + } }