Browse Source

New UI changes see BT#12861

jmontoyaa 7 years ago
parent
commit
2c718f9b8d
3 changed files with 129 additions and 197 deletions
  1. 11 11
      main/admin/career_diagram.php
  2. 15 4
      main/admin/careers.php
  3. 103 182
      main/inc/lib/career.lib.php

+ 11 - 11
main/admin/career_diagram.php

@@ -34,6 +34,12 @@ if (empty($careerId)) {
     api_not_allowed(true);
 }
 
+$career = new Career();
+$careerInfo = $career->get($careerId);
+if (empty($careerInfo)) {
+    api_not_allowed(true);
+}
+
 // setting breadcrumbs
 $interbreadcrumb[] = array(
     'url' => 'index.php',
@@ -50,25 +56,18 @@ $interbreadcrumb[] = array(
 );
 
 $action = isset($_GET['action']) ? $_GET['action'] : null;
-
 $check = Security::check_token('request');
 $token = Security::get_token();
 
 if ($action == 'add') {
     $interbreadcrumb[] = array('url' => 'careers.php', 'name' => get_lang('Careers'));
-    $tool_name = get_lang('Add');
+    $toolName = get_lang('Add');
 } elseif ($action == 'edit') {
     $interbreadcrumb[] = array('url' => 'careers.php', 'name' => get_lang('Careers'));
     $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
-    $tool_name = get_lang('Edit');
+    $toolName = get_lang('Edit');
 } else {
-    $tool_name = get_lang('Careers');
-}
-
-$career = new Career();
-$careerInfo = $career->get($careerId);
-if (empty($careerInfo)) {
-    api_not_allowed(true);
+    $toolName = get_lang('Careers');
 }
 
 $extraFieldValue = new ExtraFieldValue('career');
@@ -82,8 +81,9 @@ $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);
     $tpl = new Template(get_lang('Diagram'));
+    $html = Display::page_subheader2($careerInfo['name']);
+    $html .= Career::renderDiagram($careerInfo, $graph);
     $tpl->assign('content', $html);
     $tpl->display_one_col_template();
 }

+ 15 - 4
main/admin/careers.php

@@ -57,13 +57,13 @@ $column_model = array(
     array(
         'name' => 'name',
         'index' => 'name',
-        'width' => '80',
+        'width' => '200',
         'align' => 'left',
     ),
     array(
         'name' => 'description',
         'index' => 'description',
-        'width' => '500',
+        'width' => '400',
         'align' => 'left',
         'sortable' => 'false',
     ),
@@ -100,7 +100,16 @@ $action_links = 'function action_formatter(cellvalue, options, rowObject) {
 $(function() {
 <?php
     // grid definition see the $career->display() function
-    echo Display::grid_js('careers', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
+    echo Display::grid_js(
+        'careers',
+        $url,
+        $columns,
+        $column_model,
+        $extra_params,
+        array(),
+        $action_links,
+        true
+    );
 ?>
 });
 </script>
@@ -110,7 +119,9 @@ $career = new Career();
 // Action handling: Add
 switch ($action) {
     case 'add':
-        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
+        if (api_get_session_id() != 0 &&
+            !api_is_allowed_to_session_edit(false, true)
+        ) {
             api_not_allowed();
         }
         Session::write('notebook_view', 'creation_date');

+ 103 - 182
main/inc/lib/career.lib.php

@@ -303,157 +303,142 @@ class Career extends Model
             }
         }
 
-        $defaultSpace = 40;
-        $group = 0;
-        $counter = 0;
-        $html = Display::page_header($careerInfo['name']);
-
         $list = [];
-        $vertexNoGroups = [];
         /** @var Vertex $vertex */
         foreach ($graph->getVertices() as $vertex) {
             $group = $vertex->getAttribute('Group');
             $subGroup = $vertex->getAttribute('SubGroup');
             $column = $vertex->getGroup();
             $row = $vertex->getAttribute('Row');
-            if (empty($group)) {
-                //$group = $column;
-                //$vertexNoGroups[$group][$subGroup][$column][$row] = $vertex;
-            } else {
-                //$list[$group][$subGroup][$column][$row] = $vertex;
-            }
             $list[$group][$subGroup][$column][$row] = $vertex;
         }
+
         $maxGroups = count($list);
         $widthGroup = 30;
         if (!empty($maxGroups)) {
             $widthGroup = 85 / $maxGroups;
         }
 
-        $graphHtml = '<div class="container">';
-        foreach ($list as $group => $subGroupList) {
-            $graphHtml .= self::parseColumns(
-                $list,
-                $group,
-                $subGroupList,
-                $maxColumn,
-                $widthGroup
-            );
-        }
-
-        $graphHtml .= '</div>';
+        $connections = '';
+        $groupDrawLine = [];
 
-        /*$graphHtml .= '<br/><div class="container">';
-        foreach ($vertexNoGroups as $group => $subGroupList) {
-            $graphHtml .= self::parseColumns(
-                $vertexNoGroups,
-                $group,
-                $subGroupList,
-                $maxColumn,
-                $widthGroup
-            );
-        }
-        $graphHtml .= '</div>';*/
-
-        foreach ($graph->getVertices() as $vertex) {
-            $id = $vertex->getId();
-            $windowId = "window_$id";
-            $groupId = $vertex->getGroup();
-            $groupJsId = "group_$groupId";
-
-            if ($group != $vertex->getGroup()) {
-                if ($group > 0) {
-                    $counter = 0;
-                    $html .= '</div>'.PHP_EOL;
-                }
-
-                $left =  ($defaultSpace).'px';
-                if ($group == 0) {
-                    $left = 0;
+        foreach ($list as $group => $subGroupList) {
+            $showGroupLine = true;
+            foreach ($subGroupList as $column => $rows) {
+                if (count($rows) == 1) {
+                    $showGroupLine = false;
                 }
-               // $html .= PHP_EOL.'<div id="'.$groupJsId.'" style="padding:15px;border-style:solid;float:left; margin-left:'.$left.'; width:'.$width.'%">';
-            }
-
-            if ($debug) {
-                echo ('->>>>>>>'.$vertex->getAttribute('graphviz.label')).' - '.$vertex->getGroup().PHP_EOL;
-            }
-
-            $group = $vertex->getGroup();
-            $content = $vertex->getAttribute('Notes');
-            $content .= '<div class="pull-right">['.$id.']</div>';
-            if ($debug) {
-                echo ('entering vertices: ').PHP_EOL;
-            }
+                $groupDrawLine[$group] = $showGroupLine;
 
-            /** @var Vertex $vertexTo */
-            foreach ($vertex->getVerticesEdgeTo() as $vertexTo) {
-                $childId = $vertexTo->getId();
-                if ($id == $childId) {
-                    continue;
-                }
+                //if ($showGroupLine == false) {
+                /** @var Vertex $vertex */
+                foreach ($rows as $row => $items) {
+                    foreach ($items as $vertex) {
+                        if ($vertex instanceof Vertex) {
+                            $connectionList = $vertex->getAttribute(
+                                'Connections'
+                            );
+                            $firstConnection = '';
+                            $secondConnection = '';
+                            if (!empty($connectionList)) {
+                                $explode = explode('-', $connectionList);
+                                $pos = strpos($explode[0], 'SG');
+                                if ($pos === false) {
+                                    $pos = strpos($explode[0], 'G');
+                                    if (is_numeric($pos)) {
+                                        // group_123 id
+                                        $groupValueId = (int)str_replace(
+                                            'G',
+                                            '',
+                                            $explode[0]
+                                        );
+                                        $firstConnection = 'group_'.$groupValueId;
+                                        $groupDrawLine[$groupValueId] = true;
+                                    } else {
+                                        // Course block (row_123 id)
+                                        if (!empty($explode[0])) {
+                                            $firstConnection = 'row_'.(int) $explode[0];
+                                        }
+                                    }
+                                } else {
+                                    // subgroup__123 id
+                                    $firstConnection = 'subgroup_'.(int)str_replace('SG', '', $explode[0]);
+                                }
 
-                $childId = "window_$childId";
-                $childGroupId = $vertexTo->getGroup();
-                $childJsGroupId = "group_$childGroupId";
-                if ($debug) {
-                    echo ($vertexTo->getAttribute('graphviz.label')).PHP_EOL;
-                }
+                                $pos = strpos($explode[1], 'SG');
+                                if ($pos === false) {
+                                    $pos = strpos($explode[1], 'G');
+                                    if (is_numeric($pos)) {
+                                        $groupValueId = (int)str_replace(
+                                            'G',
+                                            '',
+                                            $explode[1]
+                                        );
+                                        $secondConnection = 'group_'.$groupValueId;
+                                        $groupDrawLine[$groupValueId] = true;
+                                    } else {
+                                        // Course block (row_123 id)
+                                        if (!empty($explode[0])) {
+                                            $secondConnection = 'row_'.(int) $explode[1];
+                                        }
+                                    }
+                                } else {
+                                    $secondConnection = 'subgroup_'.(int)str_replace('SG', '', $explode[1]);
+                                }
 
-                if (($vertexTo->getGroup() - $groupId) == 1) {
-                    //$content .= self::createConnection($windowId, $childId, ['Left', 'Right']);
-                } else {
-                    /*
-                    if ($childGroupId > $groupId) {
-                        $content .= self::createConnection(
-                            $groupJsId,
-                            $childJsGroupId
-                        );
-                    } else {
-                        $anchor = ['Left', 'Right'];
-                        if ($childGroupId == 1) {
-                            $anchor = ['Right', 'Left'];
+                                if (!empty($firstConnection) && !empty($firstConnection)) {
+                                    $connections .= self::createConnection(
+                                        $firstConnection,
+                                        $secondConnection,
+                                        ['Left', 'Right']
+                                    );
+                                }
+                            }
                         }
-                        $content .= self::createConnection(
-                            $childJsGroupId,
-                            $groupJsId,
-                            $anchor
-                        );
-                    }**/
+                    }
                 }
+                //}
             }
+        }
 
-            $counter++;
-            /*$color = '';
-            if ($vertex->getAttribute('HasColor') == 1) {
-                $color = 'danger';
+        $graphHtml = '<div class="container">';
+        foreach ($list as $group => $subGroupList) {
+            $showGroupLine = false;
+            if (isset($groupDrawLine[$group]) && $groupDrawLine[$group]) {
+                $showGroupLine = true;
             }
-
-            $html .= PHP_EOL.'<div id="'.$windowId.'" class="window" style="float:left; width:100%; "  >';
-            $html .= Display::panel(
-                $content,
-                $vertex->getAttribute('graphviz.label'),
-                null,
-                $color,
-                null
-                //$windowId
+            $graphHtml .= self::parseColumns(
+                $list,
+                $group,
+                $showGroupLine,
+                $subGroupList,
+                $maxColumn,
+                $widthGroup
             );
-            $html .= '</div>';*/
         }
-        //$html .= '</div>'.PHP_EOL;
+        $graphHtml .= '</div>';
+        $graphHtml .= $connections;
 
         return $graphHtml;
     }
 
     /**
-     * @param $list
-     * @param $group
-     * @param $subGroupList
-     * @param $maxColumn
+     * @param array $list
+     * @param int $group
+     * @param bool $showGroupLine
+     * @param array $subGroupList
+     * @param int $maxColumn
      * @param $widthGroup
      * @return string
      */
-    public static function parseColumns($list, $group, $subGroupList, $maxColumn, $widthGroup)
-    {
+    public static function parseColumns(
+        $list,
+        $group,
+        $showGroupLine,
+        $subGroupList,
+        $maxColumn,
+        $widthGroup
+    ) {
         $topValue = 90;
         $defaultSpace = 40;
         $leftGroup = $defaultSpace.'px';
@@ -462,14 +447,7 @@ class Career extends Model
         }
 
         $groupIdTag = "group_$group";
-        $showGroupLine = true;
-        foreach ($subGroupList as $column => $rows) {
-            if (count($rows) == 1) {
-                $showGroupLine = false;
-            }
-        }
-
-        $borderLine = $showGroupLine ? 'border-style:solid;' : '';
+        $borderLine = $showGroupLine === true ? 'border-style:solid;' : '';
         // padding:15px;
         $graphHtml = '<div id="'.$groupIdTag.'" style=" '.$borderLine.' padding:15px; float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';
 
@@ -479,7 +457,7 @@ class Career extends Model
                 $line = 'border-style:solid;';
             }
             // padding:15px;
-            $graphHtml .= '<div id="subgroup_'.$subGroup.'" style="'.$line.' padding:15px; float:left; margin-left:0px; width:100%">';
+            $graphHtml .= '<div id="subgroup_'.$subGroup.'" style="'.$line.' margin-bottom:20px; padding:15px; float:left; margin-left:0px; width:100%">';
             foreach ($columnList as $column => $rows) {
                 $leftColumn = $defaultSpace.'px';
                 if ($column == 1) {
@@ -602,41 +580,6 @@ class Career extends Model
                                     ['Left', 'Right']
                                 );
                             }
-
-                            $connections = $vertex->getAttribute('Connections');
-                            $firstConnection = '';
-                            $secondConnection = '';
-                            if (!empty($connections)) {
-                                $explode = explode('-', $connections);
-
-                                $pos = strpos($explode[0], 'SG');
-
-                                if ($pos === false) {
-                                    $pos = strpos($explode[0], 'G');
-                                    if (is_numeric($pos)) {
-                                        $firstConnection = 'group_'.(int) str_replace('G', '', $explode[0]);
-                                    }
-                                } else {
-                                    $firstConnection = 'subgroup_'.(int) str_replace('SG', '', $explode[0]);
-                                }
-
-                                $pos = strpos($explode[1], 'SG');
-                                if ($pos === false) {
-                                    $pos = strpos($explode[1], 'G');
-                                    if (is_numeric($pos)) {
-                                        $secondConnection = 'group_'.(int) str_replace('G', '', $explode[1]);
-                                    }
-                                } else {
-                                    $secondConnection = 'subgroup_'.(int) str_replace('SG', '', $explode[1]);
-                                }
-                                if (!empty($firstConnection) && !empty($firstConnection)) {
-                                    $graphHtml .= self::createConnection(
-                                        $firstConnection,
-                                        $secondConnection,
-                                        ['Left', 'Right']
-                                    );
-                                }
-                            }
                         }
 
                         if (!empty($subGroup) && $subGroup != -1 && $subGroupCountList[$subGroup] == $subGroupAdded[$subGroup]) {
@@ -651,28 +594,6 @@ class Career extends Model
         $graphHtml .= '</div>';
 
         return $graphHtml;
-
-        $nextGroup = (int) $group + 1;
-        if (isset($list[$nextGroup])) {
-            $columnCount = 0;
-            foreach ($list[$group] as $cols) {
-                $columnCount .= count($cols);
-            }
-
-            $columnCountNext = 0;
-            foreach ($list[$nextGroup] as $cols) {
-                $columnCountNext .= count($cols);
-            }
-
-            if ($columnCount > 1 && $columnCountNext > 1) {
-                $nextGroupTag = "group_$nextGroup";
-                $graphHtml .= self::createConnection($groupIdTag, $nextGroupTag, ['Left', 'Right']);
-            }
-        }
-
-        $graphHtml .= '</div>';
-
-        return $graphHtml;
     }
 
     /**