Jelajahi Sumber

Update diagram UI see BT#12861

jmontoyaa 7 tahun lalu
induk
melakukan
82683603f8
3 mengubah file dengan 140 tambahan dan 9 penghapusan
  1. 3 1
      main/admin/career_diagram.php
  2. 8 3
      main/cron/import_csv.php
  3. 129 5
      main/inc/lib/career.lib.php

+ 3 - 1
main/admin/career_diagram.php

@@ -65,6 +65,8 @@ if ($action == 'add') {
     $tool_name = get_lang('Careers');
 }
 
+
+
 $career = new Career();
 $careerInfo = $career->get($careerId);
 if (empty($careerInfo)) {
@@ -82,7 +84,7 @@ $item = $extraFieldValue->get_values_by_handler_and_field_variable(
 
 if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
     $graph = unserialize($item['value']);
-    $html .= Career::renderDiagram($careerInfo, $graph);
+    $html = Career::renderDiagram($careerInfo, $graph);
     $tpl = new Template('');
     $tpl->assign('content', $html);
     $tpl->display_one_col_template();

+ 8 - 3
main/cron/import_csv.php

@@ -2362,7 +2362,6 @@ class ImportCsv
             foreach ($values as $column => $rowList) {
                 foreach ($rowList as $row) {
                     $careerId = $row['CareerId'];
-
                     $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
                         $extraFieldName,
                         $careerId,
@@ -2401,11 +2400,13 @@ class ImportCsv
                         $careerList[$careerId] = $graph;
                     }
 
-                    $currentCourseId = (int)$row['CourseId'];
+                    $currentCourseId = (int) $row['CourseId'];
                     $name = $row['CourseName'];
                     $hasColor = $row['HasColor'];
                     $notes = $row['Notes'];
-
+                    $groupValue = $row['Group'];
+                    $rowValue = $row['Row'];
+                    $arrow = $row['DrawArrowFrom'];
                     if ($graph->hasVertex($currentCourseId)) {
                         // Avoid double insertion
                         continue;
@@ -2414,6 +2415,10 @@ class ImportCsv
                         $current->setAttribute('graphviz.label', $name);
                         $current->setAttribute('HasColor', $hasColor);
                         $current->setAttribute('Notes', $notes);
+                        $current->setAttribute('Row', $rowValue);
+                        $current->setAttribute('Group', $groupValue);
+                        $current->setAttribute('DrawArrowFrom', $arrow);
+
                         //$current->setAttribute('graphviz.color', 'blue');
                         $current->setAttribute('graphviz.shape', 'box');
                         $current->setGroup($column);

+ 129 - 5
main/inc/lib/career.lib.php

@@ -300,7 +300,7 @@ class Career extends Model
         }
 
         $width = 80 / $maxColumn;
-        //var_dump($maxColumn);
+
         //$width = 100;
         //$groupWidth = $width + 30;
         $defaultSpace = 40;
@@ -309,6 +309,39 @@ class Career extends Model
         $counter = 0;
 
         $html = Display::page_header($careerInfo['name']);
+
+        $list = [];
+        $vertexNoGroups = [];
+        foreach ($graph->getVertices() as $vertex) {
+            $group = $vertex->getAttribute('Group');
+            $column = $vertex->getGroup();
+            $row = $vertex->getAttribute('Row');
+            //$id = $vertex->getId();
+            //$vertex->setAttribute('noGroup');
+            if (empty($group)) {
+                $group = $column;
+                $vertexNoGroups[$group][$column][$row] = $vertex;
+            } else {
+                $list[$group][$column][$row] = $vertex;
+            }
+        }
+
+        $graphHtml = '<div class="container">';
+        $maxGroups = count($list);
+        $widthGroup = 85 / $maxGroups;
+        foreach ($list as $group => $columnList) {
+            $graphHtml .= self::parseColumns($list, $group, $columnList, $maxColumn, $widthGroup);
+        }
+
+         $graphHtml .= '</div>';
+         $graphHtml .= '<br/><div class="container">';
+
+        foreach ($vertexNoGroups as $group => $columnList) {
+            $graphHtml .= self::parseColumns($vertexNoGroups, $group, $columnList, $maxColumn, $widthGroup);
+        }
+
+        $graphHtml .= '</div>';
+
         foreach ($graph->getVertices() as $vertex) {
             $id = $vertex->getId();
             $windowId = "window_$id";
@@ -354,8 +387,9 @@ class Career extends Model
                 }
 
                 if (($vertexTo->getGroup() - $groupId) == 1) {
-                    $content .= self::createConnection($windowId, $childId, ['Left', 'Right']);
+                    //$content .= self::createConnection($windowId, $childId, ['Left', 'Right']);
                 } else {
+                    /*
                     if ($childGroupId > $groupId) {
                         $content .= self::createConnection(
                             $groupJsId,
@@ -371,7 +405,7 @@ class Career extends Model
                             $groupJsId,
                             $anchor
                         );
-                    }
+                    }**/
                 }
             }
 
@@ -394,7 +428,97 @@ class Career extends Model
         }
         $html .= '</div>'.PHP_EOL;
 
-        return $html;
+        return $graphHtml;
+    }
+
+    /**
+     * @param $list
+     * @param $group
+     * @param $columnList
+     * @param $maxColumn
+     * @param $widthGroup
+     * @return string
+     */
+    public static function parseColumns($list, $group, $columnList, $maxColumn, $widthGroup)
+    {
+        $width = 80 / $maxColumn;
+
+        //$width = 100;
+        //$groupWidth = $width + 30;
+        $defaultSpace = 40;
+        //$group = 0;
+
+        $leftGroup = ($defaultSpace).'px';
+        if ($group == 1) {
+            $leftGroup = 0;
+        }
+        $groupIdTag = "group_$group";
+        $graphHtml = '<div id="'.$groupIdTag.'" style="padding:15px;border-style:solid;float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';
+        foreach ($columnList as $column => $rows) {
+            $leftColumn = ($defaultSpace).'px';
+            if ($column == 1) {
+                $leftColumn = 0;
+            }
+            if (count($columnList) == 1) {
+                $leftColumn = 0;
+            }
+
+            $widthColumn = 85 / count($columnList);
+            $graphHtml .= '<div id="col_'.$column.'" style="padding:15px;float:left; margin-left:'.$leftColumn.'; width:'.$widthColumn.'%">';
+            /** @var  \Fhaculty\Graph\Vertex $vertex */
+            foreach ($rows as $row => $vertex) {
+                $id = $vertex->getId();
+                $rowId = "row_$row";
+                $graphHtml .= '<div id = "row_'.$id.'" class="'.$rowId.'">';
+                $color = '';
+                if ($vertex->getAttribute('HasColor') == 1) {
+                    $color = 'danger';
+                }
+                $content = $vertex->getAttribute('Notes');
+                $content .= '<div class="pull-right">['.$id.']</div>';
+
+                $graphHtml .= Display::panel(
+                    $content,
+                    $vertex->getAttribute('graphviz.label'),
+                    null,
+                    $color,
+                    null
+                );
+                $graphHtml .= '</div>';
+
+                $arrow = $vertex->getAttribute('DrawArrowFrom');
+
+                if (!empty($arrow)) {
+                    $parts = explode('G', $arrow);
+                    if (empty($parts[0]) && count($parts) == 2) {
+                        $groupArrow = $parts[1];
+                        //var_dump($id);var_dump($rowId, "group_$groupArrow");
+                        $graphHtml .= self::createConnection(
+                            "group_$groupArrow",
+                            "row_$id",
+                            ['Left', 'Right']
+                        );
+                    } else {
+                        $graphHtml .= self::createConnection(
+                            "row_$arrow",
+                            "row_$id",
+                            ['Left', 'Right']
+                        );
+                    }
+                }
+            }
+            $graphHtml .= '</div>';
+        }
+
+        $nextGroup = (int) $group + 1;
+        if (isset($list[$nextGroup])) {
+            $nextGroupTag = "group_$nextGroup";
+            //$graphHtml .= self::createConnection($groupIdTag, $nextGroupTag, ['Left', 'Right']);
+        }
+
+        $graphHtml .= '</div>';
+
+        return $graphHtml;
     }
 
     /**
@@ -419,7 +543,7 @@ class Career extends Model
                         connector: ["Flowchart"],                                        
                         anchor: ["'.$anchor.'"],
                         overlays: [
-                            [ "Arrow", { location:0.9 } ],
+                            [ "Arrow", { location:0.7 } ],
                         ],
                       });';
         $html .= '});</script>'.PHP_EOL;