mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
refactor code, use Lib for DrawIO XML generating functions, start work on Modulgrafik
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
/**
|
||||
* Description of OrganigrammTest
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
class ModulgrafikTest extends JOB_Controller
|
||||
{
|
||||
const DEFAULT_XOFFSET = 40;
|
||||
const DEFAULT_YOFFSET = 30;
|
||||
const DEFAULT_WIDTH = 160;
|
||||
const DEFAULT_HEIGHT = 50;
|
||||
const DEFAULT_SPACING = 40;
|
||||
const DEFAULT_FONTSIZE = 8;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('organisation/Studienplan_model', 'StudienplanModel');
|
||||
|
||||
$this->load->library('DrawIoLib', null, 'DrawIoLib');
|
||||
}
|
||||
|
||||
public function drawModulGrafik($studienplan_id)
|
||||
{
|
||||
$sql = <<<EOSQL
|
||||
SELECT
|
||||
sl.studienplan_lehrveranstaltung_id,
|
||||
sl.lehrveranstaltung_id,
|
||||
sl.studienplan_lehrveranstaltung_id_parent,
|
||||
COALESCE(sl.studienplan_lehrveranstaltung_id_parent, sl.studienplan_lehrveranstaltung_id) AS lvgrp,
|
||||
sl.semester,
|
||||
lv.bezeichnung,
|
||||
lv.ects,
|
||||
lv.lehrtyp_kurzbz
|
||||
FROM
|
||||
lehre.tbl_studienplan_lehrveranstaltung sl
|
||||
JOIN
|
||||
lehre.tbl_lehrveranstaltung lv USING(lehrveranstaltung_id)
|
||||
WHERE
|
||||
sl.studienplan_id = {$studienplan_id}
|
||||
AND
|
||||
ects > '0.00'
|
||||
ORDER BY
|
||||
sl.semester ASC,
|
||||
lvgrp ASC,
|
||||
lv.lehrtyp_kurzbz DESC
|
||||
EOSQL;
|
||||
|
||||
$result = $this->StudienplanModel->execReadOnlyQuery($sql);
|
||||
$lvs = getData($result);
|
||||
/*
|
||||
print_r($lvs);
|
||||
exit();
|
||||
*/
|
||||
$errors = array();
|
||||
$assoclvs = array();
|
||||
$semester = array();
|
||||
if($lvs)
|
||||
{
|
||||
foreach($lvs as &$lv)
|
||||
{
|
||||
if( !isset($semester[$lv->semester]) ) {
|
||||
$semester[$lv->semester] = array();
|
||||
}
|
||||
$lv->parent = null;
|
||||
$lv->childs = array();
|
||||
$assoclvs[$lv->studienplan_lehrveranstaltung_id] = $lv;
|
||||
}
|
||||
|
||||
foreach($assoclvs as &$assoclv)
|
||||
{
|
||||
if( $assoclv->studienplan_lehrveranstaltung_id_parent === NULL )
|
||||
{
|
||||
$semester[$assoclv->semester][] = $assoclv;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( isset($assoclvs[$assoclv->studienplan_lehrveranstaltung_id_parent]) )
|
||||
{
|
||||
$assoclv->parent = $assoclvs[$assoclv->studienplan_lehrveranstaltung_id_parent];
|
||||
$assoclvs[$assoclv->studienplan_lehrveranstaltung_id_parent]->childs[] = $assoclv;
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors[] = "ERROR: Missing parent lv " . $assoclv->studienplan_lehrveranstaltung_id_parent . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function printchilds($childs, $level) {
|
||||
if( count($childs) < 1 ) {
|
||||
return;
|
||||
}
|
||||
foreach($childs as $child) {
|
||||
echo $level . $child->bezeichnung . " (" . $child->ects . ") " . $child->lehrtyp_kurzbz . "\n";
|
||||
printchilds($child->childs, $level . "\t");
|
||||
}
|
||||
}
|
||||
|
||||
foreach($semester as $sem => $mods)
|
||||
{
|
||||
echo $sem . ". Semester: \n";
|
||||
foreach($mods as $mod)
|
||||
{
|
||||
$level = "\t";
|
||||
echo $level . $mod->bezeichnung . " (" . $mod->ects . ") " . $mod->lehrtyp_kurzbz . "\n";
|
||||
printchilds($mod->childs, $level . "\t");
|
||||
}
|
||||
}
|
||||
exit();
|
||||
|
||||
if(count($errors) === 0) {
|
||||
$this->DrawIoLib->renderFileStart();
|
||||
|
||||
foreach($roots AS &$root)
|
||||
{
|
||||
$this->maxxoffset = self::DEFAULT_XOFFSET;
|
||||
$this->DrawIoLib->renderDiagramStart($studienplan_id, 'Modulgrafik');
|
||||
$this->renderSemester($semster);
|
||||
$this->DrawIoLib->renderDiagramEnd();
|
||||
}
|
||||
$this->DrawIoLib->renderFileEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($errors as $error)
|
||||
{
|
||||
echo $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Keine LVs gefunden.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ class OrganigrammTest extends JOB_Controller
|
||||
|
||||
$this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
|
||||
|
||||
$this->load->library('DrawIoLib', null, 'DrawIoLib');
|
||||
|
||||
$this->maxxoffset = self::DEFAULT_XOFFSET;
|
||||
$this->donotrenderchildsoftype = array();
|
||||
}
|
||||
@@ -125,46 +127,18 @@ EOSQL;
|
||||
|
||||
if(count($errors) === 0) {
|
||||
$pages = count($roots);
|
||||
$modified = (new DateTime('now', new DateTimeZone('UTC')))->format(DateTime::ATOM);
|
||||
$agent = 'FH-Complete';
|
||||
echo <<<HEADER
|
||||
<mxfile modified="{$modified}" host="Electron" agent="{$agent}" type="device" pages="{$pages}">
|
||||
|
||||
HEADER;
|
||||
$this->DrawIoLib->renderFileStart($pages);
|
||||
|
||||
foreach($roots AS &$root)
|
||||
{
|
||||
$this->maxxoffset = self::DEFAULT_XOFFSET;
|
||||
$this->donotrenderchildsoftype = $root->donotrenderchildsoftype;
|
||||
$this->prepareChildsToRender($root);
|
||||
|
||||
$bezeichnung = htmlspecialchars($root->bezeichnung);
|
||||
|
||||
echo <<<STARTDIAGRAMM
|
||||
<diagram id="diagram_{$root->oe_kurzbz}" name="{$bezeichnung}">
|
||||
<mxGraphModel dx="1177" dy="687" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
|
||||
STARTDIAGRAMM;
|
||||
|
||||
$this->DrawIoLib->renderDiagramStart($root->oe_kurzbz, $root->bezeichnung);
|
||||
$this->renderOE($root, 0, 0);
|
||||
|
||||
echo <<<ENDDIAGRAMM
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
|
||||
ENDDIAGRAMM;
|
||||
|
||||
$this->DrawIoLib->renderDiagramEnd();
|
||||
}
|
||||
|
||||
echo <<<FOOTER
|
||||
</mxfile>
|
||||
|
||||
FOOTER;
|
||||
|
||||
$this->DrawIoLib->renderFileEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -284,12 +258,11 @@ FOOTER;
|
||||
'Kompetenzfeld' => '#f5f5f5'
|
||||
);
|
||||
$fillcolor = (isset($fillcolors[$oe->organisationseinheittyp_kurzbz])) ? $fillcolors[$oe->organisationseinheittyp_kurzbz] : '#ffffff';
|
||||
echo <<<OE
|
||||
<mxCell id="{$oe->oe_kurzbz}" value="<font style="font-size: {$fontsize}px;"><div style="">[{$oe->organisationseinheittyp_kurzbz}]</div><b style="">{$bezeichnung}</b><div>({$leitung})</div></font>" style="whiteSpace=wrap;html=1;align=center;verticalAlign=middle;treeFolding=1;treeMoving=1;newEdgeStyle={"edgeStyle":"elbowEdgeStyle","startArrow":"none","endArrow":"none"};fillColor={$fillcolor};" parent="1" vertex="1">
|
||||
<mxGeometry x="{$x}" y="{$y}" width="{$width}" height="{$height}" as="geometry" />
|
||||
</mxCell>
|
||||
$value = <<<EOVAL
|
||||
<font style="font-size: {$fontsize}px;"><div style="">[{$oe->organisationseinheittyp_kurzbz}]</div><b style="">{$bezeichnung}</b><div>({$leitung})</div></font>" style="whiteSpace=wrap;html=1;align=center;verticalAlign=middle;treeFolding=1;treeMoving=1;newEdgeStyle={"edgeStyle":"elbowEdgeStyle","startArrow":"none","endArrow":"none"};fillColor={$fillcolor};
|
||||
EOVAL;
|
||||
|
||||
OE;
|
||||
$this->DrawIoLib->renderCell($oe->oe_kurzbz, $value, $x, $y, $width, $height);
|
||||
|
||||
if( $oe->oe_parent_kurzbz !== NULL )
|
||||
{
|
||||
@@ -297,29 +270,21 @@ OE;
|
||||
$exitY = '1';
|
||||
$entryX = '0.5';
|
||||
$entryY = '0';
|
||||
$edgegeom = '<mxGeometry relative="1" as="geometry" />';
|
||||
$points = array();
|
||||
if( $oe->parent !== null && $oe->parent->renderchilds === self::RENDER_CHILDS_VERTICAL)
|
||||
{
|
||||
$exitX = '0';
|
||||
$exitY = '0.5';
|
||||
$entryX = '0';
|
||||
$entryY = '0.5';
|
||||
$pointx = $x - floor($spacing / 2);
|
||||
$pointy = $y + floor($height / 2);
|
||||
$edgegeom = <<<EDGEPOINTS
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="{$pointx}" y="{$pointy}" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
EDGEPOINTS;
|
||||
$points = array(
|
||||
(object) array(
|
||||
'x' => ($x - floor($spacing / 2)),
|
||||
'y' => ($y + floor($height / 2))
|
||||
)
|
||||
);
|
||||
}
|
||||
echo <<<EDGE
|
||||
<mxCell id="edge_{$oe->oe_parent_kurzbz}_{$oe->oe_kurzbz}" value="" style="edgeStyle=elbowEdgeStyle;elbow=vertical;sourcePerimeterSpacing=0;targetPerimeterSpacing=0;startArrow=none;endArrow=none;rounded=0;curved=0;exitX={$exitX};exitY={$exitY};exitDx=0;exitDy=0;entryX={$entryX};entryY={$entryY};entryDx=0;entryDy=0;" parent="1" source="{$oe->oe_parent_kurzbz}" target="{$oe->oe_kurzbz}" edge="1">
|
||||
{$edgegeom}
|
||||
</mxCell>
|
||||
|
||||
EDGE;
|
||||
$this->DrawIoLib->renderEdge($oe->oe_parent_kurzbz, $oe->oe_kurzbz, $exitX, $exitY, $entryX, $entryY, $points);
|
||||
}
|
||||
|
||||
if( $oe->parent !== null && $oe->parent->renderchilds === self::RENDER_CHILDS_VERTICAL )
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
* @package FHC-Helper
|
||||
* @author FHC-Team
|
||||
* @copyright Copyright (c) 2022 fhcomplete.net
|
||||
* @license GPLv3
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Description of DrawIoLib
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
class DrawIoLib
|
||||
{
|
||||
public function renderFileStart($pages=1, $agent='FH-Complete', $timemodified='now')
|
||||
{
|
||||
$modified = (new DateTime($timemodified, new DateTimeZone('UTC')))->format(DateTime::ATOM);
|
||||
echo <<<HEADER
|
||||
<mxfile modified="{$modified}" host="Electron" agent="{$agent}" type="device" pages="{$pages}">
|
||||
|
||||
HEADER;
|
||||
|
||||
}
|
||||
|
||||
public function renderFileEnd()
|
||||
{
|
||||
echo <<<FOOTER
|
||||
</mxfile>
|
||||
|
||||
FOOTER;
|
||||
|
||||
}
|
||||
|
||||
public function renderDiagramStart($diagram_id, $diagram_bezeichnung)
|
||||
{
|
||||
$bezeichnung = htmlspecialchars($diagram_bezeichnung);
|
||||
echo <<<STARTDIAGRAMM
|
||||
<diagram id="diagram_{$diagram_id}" name="{$bezeichnung}">
|
||||
<mxGraphModel dx="1177" dy="687" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
|
||||
STARTDIAGRAMM;
|
||||
|
||||
}
|
||||
|
||||
public function renderDiagramEnd()
|
||||
{
|
||||
echo <<<ENDDIAGRAMM
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
|
||||
ENDDIAGRAMM;
|
||||
|
||||
}
|
||||
|
||||
public function renderCell($id, $value, $x, $y, $width, $height)
|
||||
{
|
||||
echo <<<OE
|
||||
<mxCell id="{$id}" value="{$value}" parent="1" vertex="1">
|
||||
<mxGeometry x="{$x}" y="{$y}" width="{$width}" height="{$height}" as="geometry" />
|
||||
</mxCell>
|
||||
|
||||
OE;
|
||||
|
||||
}
|
||||
|
||||
public function renderEdge($source, $target, $exitX, $exitY, $entryX, $entryY, $points=array())
|
||||
{
|
||||
if( count($points) > 0 )
|
||||
{
|
||||
$pointsxml = '';
|
||||
foreach($points as $point)
|
||||
{
|
||||
$pointsxml .= <<<EOPOINT
|
||||
<mxPoint x="{$point->x}" y="{$point->y}" />
|
||||
EOPOINT;
|
||||
|
||||
}
|
||||
|
||||
$edgegeom = <<<EDGEPOINTS
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
{$pointsxml}
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
EDGEPOINTS;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$edgegeom = ' <mxGeometry relative="1" as="geometry" />';
|
||||
}
|
||||
|
||||
echo <<<EDGE
|
||||
<mxCell id="edge_{$source}_{$target}" value="" style="edgeStyle=elbowEdgeStyle;elbow=vertical;sourcePerimeterSpacing=0;targetPerimeterSpacing=0;startArrow=none;endArrow=none;rounded=0;curved=0;exitX={$exitX};exitY={$exitY};exitDx=0;exitDy=0;entryX={$entryX};entryY={$entryY};entryDx=0;entryDy=0;" parent="1" source="{$source}" target="{$target}" edge="1">
|
||||
{$edgegeom}
|
||||
</mxCell>
|
||||
|
||||
EDGE;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user