From 03006a6072a5ca14bdcc06608886647433c8d0bb Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 29 Jun 2017 13:44:13 +0200 Subject: [PATCH] Add SubGroup label, use DefinedColor instead of hasColor see BT#12861 --- main/cron/import_csv.php | 4 +-- main/inc/lib/career.lib.php | 51 ++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index 44d1f771a2..6ac6491b21 100755 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -2409,7 +2409,7 @@ class ImportCsv $currentCourseId = (int) $row['CourseId']; $name = $row['CourseName']; - $hasColor = $row['HasColor']; + $color = $row['DefinedColor']; $notes = $row['Notes']; $groupValue = $row['Group']; $rowValue = $row['Row']; @@ -2423,7 +2423,7 @@ class ImportCsv } else { $current = $graph->createVertex($currentCourseId); $current->setAttribute('graphviz.label', $name); - $current->setAttribute('HasColor', $hasColor); + $current->setAttribute('DefinedColor', $color); $current->setAttribute('Notes', $notes); $current->setAttribute('Row', $rowValue); $current->setAttribute('Group', $groupValue); diff --git a/main/inc/lib/career.lib.php b/main/inc/lib/career.lib.php index 17a836a81d..c4a81d2dc0 100755 --- a/main/inc/lib/career.lib.php +++ b/main/inc/lib/career.lib.php @@ -309,9 +309,13 @@ class Career extends Model foreach ($graph->getVertices() as $vertex) { $group = $vertex->getAttribute('Group'); $subGroup = $vertex->getAttribute('SubGroup'); + $subGroupData = explode(':', $subGroup); $column = $vertex->getGroup(); $row = $vertex->getAttribute('Row'); - $list[$group][$subGroup][$column][$row] = $vertex; + $subGroupId = $subGroupData[0]; + $label = isset($subGroupData[1]) ? $subGroupData[1] : ''; + $list[$group][$subGroupId]['columns'][$column][$row] = $vertex; + $list[$group][$subGroupId]['label'] = $label; } $maxGroups = count($list); @@ -322,20 +326,24 @@ class Career extends Model $connections = ''; $groupDrawLine = []; + $groupCourseList = []; + // Read Connections column foreach ($list as $group => $subGroupList) { - $showGroupLine = true; - foreach ($subGroupList as $column => $rows) { - if (count($rows) == 1) { + foreach ($subGroupList as $subGroupData) { + $columns = $subGroupData['columns']; + $showGroupLine = true; + if (count($columns) == 1) { $showGroupLine = false; } $groupDrawLine[$group] = $showGroupLine; //if ($showGroupLine == false) { /** @var Vertex $vertex */ - foreach ($rows as $row => $items) { + foreach ($columns as $row => $items) { foreach ($items as $vertex) { if ($vertex instanceof Vertex) { + $groupCourseList[$group][] = $vertex->getId(); $connectionList = $vertex->getAttribute( 'Connections' ); @@ -409,7 +417,7 @@ class Career extends Model $showGroupLine = true; } $graphHtml .= self::parseSubGroups( - $list, + $groupCourseList, $group, $showGroupLine, $subGroupList, @@ -423,7 +431,7 @@ class Career extends Model } /** - * @param array $list + * @param array $groupCourseList list of groups and their courses * @param int $group * @param bool $showGroupLine * @param array $subGroupList @@ -431,7 +439,7 @@ class Career extends Model * @return string */ public static function parseSubGroups( - $list, + $groupCourseList, $group, $showGroupLine, $subGroupList, @@ -449,13 +457,19 @@ class Career extends Model // padding:15px; $graphHtml = '
'; - foreach ($subGroupList as $subGroup => $columnList) { + foreach ($subGroupList as $subGroup => $subGroupData) { + $subGroupLabel = $subGroupData['label']; + $columnList = $subGroupData['columns']; + $line = ''; if (!empty($subGroup)) { $line = 'border-style:solid;'; } // padding:15px; $graphHtml .= '
'; + if (!empty($subGroupLabel)) { + $graphHtml .= '

'.$subGroupLabel.'

'; + } foreach ($columnList as $column => $rows) { $leftColumn = $defaultSpace.'px'; if ($column == 1) { @@ -518,11 +532,10 @@ class Career extends Model $id = $vertex->getId(); $rowId = "row_$row"; - $top = $topValue * ($row - 1); $graphHtml .= '
'; $color = ''; - if (!empty($vertex->getAttribute('HasColor'))) { - $color = $vertex->getAttribute('HasColor'); + if (!empty($vertex->getAttribute('DefinedColor'))) { + $color = $vertex->getAttribute('DefinedColor'); } $content = $vertex->getAttribute('Notes'); $content .= '
['.$id.']
'; @@ -559,9 +572,11 @@ class Career extends Model } else { $parts = explode('SG', $arrow); if (empty($parts[0]) && count($parts) == 2) { - $groupArrow = $parts[1]; + $subGroupArrow = $parts[1]; + /*var_dump($subGroupArrow); + var_dump(array_keys($subGroupList));*/ $graphHtml .= self::createConnection( - "subgroup_$groupArrow", + "subgroup_$subGroupArrow", "row_$id", ['Left', 'Right'] ); @@ -571,10 +586,16 @@ class Career extends Model } if ($found == false) { + $defaultArrow = ['Left', 'Right']; + if (isset($groupCourseList[$group]) && + in_array($arrow, $groupCourseList[$group]) + ) { + $defaultArrow = ['Top', 'Bottom']; + } $graphHtml .= self::createConnection( "row_$arrow", "row_$id", - ['Left', 'Right'] + $defaultArrow ); } }