Passed
Push — 1.11.x ( 74cfb8...84b0a2 )
by Julito
09:43
created

Career::parseVertexList()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 243
Code Lines 170

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 39
eloc 170
nc 24162
nop 7
dl 0
loc 243
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Fhaculty\Graph\Graph;
6
use Fhaculty\Graph\Vertex;
7
8
/**
9
 * Class Career.
10
 */
11
class Career extends Model
12
{
13
    public $table;
14
    public $columns = [
15
        'id',
16
        'name',
17
        'description',
18
        'status',
19
        'created_at',
20
        'updated_at',
21
    ];
22
23
    public function __construct()
24
    {
25
        $this->table = Database::get_main_table(TABLE_CAREER);
26
    }
27
28
    public function getCareerFromId($id)
29
    {
30
        if (api_get_configuration_value('use_career_external_id_as_identifier_in_diagrams')) {
31
            // Try with the external career id.
32
            $careerInfo = $this->getCareerFromExternalToInternal($id);
33
        } else {
34
            $careerInfo = $this->get($id);
35
        }
36
37
        return $careerInfo;
38
    }
39
40
    public function getCareerFromExternalToInternal($externalCareerId, $extraFieldVariable = 'external_career_id')
41
    {
42
        $careerExtraFieldValue = new ExtraFieldValue('career');
43
        $careerValue = $careerExtraFieldValue->get_item_id_from_field_variable_and_field_value(
44
            $extraFieldVariable,
45
            $externalCareerId
46
        );
47
48
        $careerInfo = [];
49
        if (isset($careerValue['item_id'])) {
50
            $careerInfo = $this->get($careerValue['item_id']);
51
        }
52
53
        return $careerInfo;
54
    }
55
56
    public function getCareerIdFromInternalToExternal($internalCareerId)
57
    {
58
        $careerExtraFieldValue = new ExtraFieldValue('career');
59
        $externalCareerValue = $careerExtraFieldValue->get_values_by_handler_and_field_variable(
60
            $internalCareerId,
61
            'external_career_id'
62
        );
63
64
        if (!empty($externalCareerValue) && isset($externalCareerValue['value'])) {
65
            return $externalCareerValue['value'];
66
        }
67
68
        return null;
69
    }
70
71
    /**
72
     * Get the count of elements.
73
     *
74
     * @return int
75
     */
76
    public function get_count()
77
    {
78
        $row = Database::select(
79
            'count(*) as count',
80
            $this->table,
81
            [],
82
            'first'
83
        );
84
85
        return $row['count'];
86
    }
87
88
    /**
89
     * @param array $where_conditions
90
     *
91
     * @return array
92
     */
93
    public function get_all($where_conditions = [])
94
    {
95
        return Database::select(
96
            '*',
97
            $this->table,
98
            ['where' => $where_conditions, 'order' => 'name ASC']
99
        );
100
    }
101
102
    /**
103
     * Update all promotion status by career.
104
     *
105
     * @param int $career_id
106
     * @param int $status    (1 or 0)
107
     */
108
    public function update_all_promotion_status_by_career_id($career_id, $status)
109
    {
110
        $promotion = new Promotion();
111
        $promotion_list = $promotion->get_all_promotions_by_career_id($career_id);
112
        if (!empty($promotion_list)) {
113
            foreach ($promotion_list as $item) {
114
                $params['id'] = $item['id'];
115
                $params['status'] = $status;
116
                $promotion->update($params);
117
                $promotion->update_all_sessions_status_by_promotion_id($params['id'], $status);
118
            }
119
        }
120
    }
121
122
    /**
123
     * Returns HTML the title + grid.
124
     *
125
     * @return string
126
     */
127
    public function display()
128
    {
129
        $html = '<div class="actions" style="margin-bottom:20px">';
130
        $html .= '<a href="career_dashboard.php">'.
131
            Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
132
        if (api_is_platform_admin()) {
133
            $html .= '<a href="'.api_get_self().'?action=add">'.
134
                    Display::return_icon('new_career.png', get_lang('Add'), '', ICON_SIZE_MEDIUM).'</a>';
135
        }
136
        $html .= '</div>';
137
        $html .= Display::grid_html('careers');
138
139
        return $html;
140
    }
141
142
    /**
143
     * @return array
144
     */
145
    public function get_status_list()
146
    {
147
        return [
148
            CAREER_STATUS_ACTIVE => get_lang('Unarchived'),
149
            CAREER_STATUS_INACTIVE => get_lang('Archived'),
150
        ];
151
    }
152
153
    /**
154
     * Returns a Form validator Obj.
155
     *
156
     * @todo the form should be auto generated
157
     *
158
     * @param string $url
159
     * @param string $action add, edit
160
     *
161
     * @return FormValidator
162
     */
163
    public function return_form($url, $action)
164
    {
165
        $form = new FormValidator('career', 'post', $url);
166
        // Setting the form elements
167
        $header = get_lang('Add');
168
        if ($action == 'edit') {
169
            $header = get_lang('Modify');
170
        }
171
172
        $id = isset($_GET['id']) ? (int) $_GET['id'] : '';
173
        $form->addHeader($header);
174
        $form->addHidden('id', $id);
175
        $form->addElement('text', 'name', get_lang('Name'), ['size' => '70']);
176
        $form->addHtmlEditor(
177
            'description',
178
            get_lang('Description'),
179
            false,
180
            false,
181
            [
182
                'ToolbarSet' => 'Careers',
183
                'Width' => '100%',
184
                'Height' => '250',
185
            ]
186
        );
187
        $status_list = $this->get_status_list();
188
        $form->addElement('select', 'status', get_lang('Status'), $status_list);
189
190
        if ($action == 'edit') {
191
            $extraField = new ExtraField('career');
192
            $extraField->addElements($form, $id);
193
194
            $form->addElement('text', 'created_at', get_lang('CreatedAt'));
195
            $form->freeze('created_at');
196
            $form->addButtonSave(get_lang('Modify'));
197
        } else {
198
            $form->addButtonCreate(get_lang('Add'));
199
        }
200
201
        // Setting the defaults
202
        $defaults = $this->get($id);
203
204
        if (!empty($defaults['created_at'])) {
205
            $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
206
        }
207
        if (!empty($defaults['updated_at'])) {
208
            $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
209
        }
210
211
        $form->setDefaults($defaults);
212
213
        // Setting the rules
214
        $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
215
216
        return $form;
217
    }
218
219
    /**
220
     * Copies the career to a new one.
221
     *
222
     * @param   int     Career ID
223
     * @param   bool     Whether or not to copy the promotions inside
224
     *
225
     * @return int New career ID on success, false on failure
226
     */
227
    public function copy($id, $copy_promotions = false)
228
    {
229
        $career = $this->get($id);
230
        $new = [];
231
        foreach ($career as $key => $val) {
232
            switch ($key) {
233
                case 'id':
234
                case 'updated_at':
235
                    break;
236
                case 'name':
237
                    $val .= ' '.get_lang('CopyLabelSuffix');
238
                    $new[$key] = $val;
239
                    break;
240
                case 'created_at':
241
                    $val = api_get_utc_datetime();
242
                    $new[$key] = $val;
243
                    break;
244
                default:
245
                    $new[$key] = $val;
246
                    break;
247
            }
248
        }
249
        $cid = $this->save($new);
250
        if ($copy_promotions) {
251
            //Now also copy each session of the promotion as a new session and register it inside the promotion
252
            $promotion = new Promotion();
253
            $promo_list = $promotion->get_all_promotions_by_career_id($id);
254
            if (!empty($promo_list)) {
255
                foreach ($promo_list as $item) {
256
                    $promotion->copy($item['id'], $cid, true);
257
                }
258
            }
259
        }
260
261
        return $cid;
262
    }
263
264
    /**
265
     * @param int $career_id
266
     *
267
     * @return bool
268
     */
269
    public function get_status($career_id)
270
    {
271
        $table = Database::get_main_table(TABLE_CAREER);
272
        $career_id = intval($career_id);
273
        $sql = "SELECT status FROM $table WHERE id = '$career_id'";
274
        $result = Database::query($sql);
275
        if (Database::num_rows($result) > 0) {
276
            $data = Database::fetch_array($result);
277
278
            return $data['status'];
279
        } else {
280
            return false;
281
        }
282
    }
283
284
    /**
285
     * @param array $params
286
     * @param bool  $show_query
287
     *
288
     * @return int
289
     */
290
    public function save($params, $show_query = false)
291
    {
292
        if (isset($params['description'])) {
293
            $params['description'] = Security::remove_XSS($params['description']);
294
        }
295
296
        $id = parent::save($params);
297
        if (!empty($id)) {
298
            Event::addEvent(
299
                LOG_CAREER_CREATE,
300
                LOG_CAREER_ID,
301
                $id,
302
                api_get_utc_datetime(),
303
                api_get_user_id()
304
            );
305
        }
306
307
        return $id;
308
    }
309
310
    /**
311
     * Delete a record from the career table and report in the default events log table.
312
     *
313
     * @param int $id The ID of the career to delete
314
     *
315
     * @return bool True if the career could be deleted, false otherwise
316
     */
317
    public function delete($id)
318
    {
319
        $res = parent::delete($id);
320
        if ($res) {
321
            $extraFieldValues = new ExtraFieldValue('career');
322
            $extraFieldValues->deleteValuesByItem($id);
323
            Event::addEvent(
324
                LOG_CAREER_DELETE,
325
                LOG_CAREER_ID,
326
                $id,
327
                api_get_utc_datetime(),
328
                api_get_user_id()
329
            );
330
        }
331
332
        return $res;
333
    }
334
335
    /**
336
     * {@inheritdoc}
337
     */
338
    public function update($params, $showQuery = false)
339
    {
340
        if (isset($params['description'])) {
341
            $params['description'] = Security::remove_XSS($params['description']);
342
        }
343
344
        return parent::update($params, $showQuery);
345
    }
346
347
    /**
348
     * @param array
349
     * @param Graph $graph
350
     *
351
     * @return string
352
     */
353
    public static function renderDiagram($careerInfo, $graph)
354
    {
355
        if (!($graph instanceof Graph)) {
356
            return '';
357
        }
358
359
        // Getting max column
360
        $maxColumn = 0;
361
        foreach ($graph->getVertices() as $vertex) {
362
            $groupId = (int) $vertex->getGroup();
363
            if ($groupId > $maxColumn) {
364
                $maxColumn = $groupId;
365
            }
366
        }
367
368
        $list = [];
369
        /** @var Vertex $vertex */
370
        foreach ($graph->getVertices() as $vertex) {
371
            $group = $vertex->getAttribute('Group');
372
            $groupData = explode(':', $group);
373
            $group = $groupData[0];
374
            $groupLabel = isset($groupData[1]) ? $groupData[1] : '';
375
            $subGroup = $vertex->getAttribute('SubGroup');
376
            $subGroupData = explode(':', $subGroup);
377
            $column = $vertex->getGroup();
378
            $row = $vertex->getAttribute('Row');
379
            $subGroupId = $subGroupData[0];
380
            $label = isset($subGroupData[1]) ? $subGroupData[1] : '';
381
            $list[$group][$subGroupId]['columns'][$column][$row] = $vertex;
382
            $list[$group][$subGroupId]['label'] = $label;
383
            $list[$group]['label'] = $groupLabel;
384
        }
385
386
        $maxGroups = count($list);
387
        $widthGroup = 30;
388
        if (!empty($maxGroups)) {
389
            $widthGroup = 85 / $maxGroups;
390
        }
391
392
        $connections = '';
393
        $groupDrawLine = [];
394
        $groupCourseList = [];
395
        // Read Connections column
396
        foreach ($list as $group => $subGroupList) {
397
            foreach ($subGroupList as $subGroupData) {
398
                $columns = isset($subGroupData['columns']) ? $subGroupData['columns'] : [];
399
                $showGroupLine = true;
400
                if (count($columns) == 1) {
401
                    $showGroupLine = false;
402
                }
403
                $groupDrawLine[$group] = $showGroupLine;
404
405
                //if ($showGroupLine == false) {
406
                /** @var Vertex $vertex */
407
                foreach ($columns as $row => $items) {
408
                    foreach ($items as $vertex) {
409
                        if ($vertex instanceof Vertex) {
410
                            $groupCourseList[$group][] = $vertex->getId();
411
                            $connectionList = $vertex->getAttribute('Connections');
412
                            $firstConnection = '';
413
                            $secondConnection = '';
414
                            if (!empty($connectionList)) {
415
                                $explode = explode('-', $connectionList);
416
                                $pos = strpos($explode[0], 'SG');
417
                                if ($pos === false) {
418
                                    $pos = strpos($explode[0], 'G');
419
                                    if (is_numeric($pos)) {
420
                                        // group_123 id
421
                                        $groupValueId = (int) str_replace(
422
                                            'G',
423
                                            '',
424
                                            $explode[0]
425
                                        );
426
                                        $firstConnection = 'group_'.$groupValueId;
427
                                        $groupDrawLine[$groupValueId] = true;
428
                                    } else {
429
                                        // Course block (row_123 id)
430
                                        if (!empty($explode[0])) {
431
                                            $firstConnection = 'row_'.(int) $explode[0];
432
                                        }
433
                                    }
434
                                } else {
435
                                    // subgroup__123 id
436
                                    $firstConnection = 'subgroup_'.(int) str_replace('SG', '', $explode[0]);
437
                                }
438
439
                                $pos = strpos($explode[1], 'SG');
440
                                if ($pos === false) {
441
                                    $pos = strpos($explode[1], 'G');
442
                                    if (is_numeric($pos)) {
443
                                        $groupValueId = (int) str_replace(
444
                                            'G',
445
                                            '',
446
                                            $explode[1]
447
                                        );
448
                                        $secondConnection = 'group_'.$groupValueId;
449
                                        $groupDrawLine[$groupValueId] = true;
450
                                    } else {
451
                                        // Course block (row_123 id)
452
                                        if (!empty($explode[0])) {
453
                                            $secondConnection = 'row_'.(int) $explode[1];
454
                                        }
455
                                    }
456
                                } else {
457
                                    $secondConnection = 'subgroup_'.(int) str_replace('SG', '', $explode[1]);
458
                                }
459
460
                                if (!empty($firstConnection) && !empty($firstConnection)) {
461
                                    $connections .= self::createConnection(
462
                                        $firstConnection,
463
                                        $secondConnection,
464
                                        ['Left', 'Right']
465
                                    );
466
                                }
467
                            }
468
                        }
469
                    }
470
                }
471
                //}
472
            }
473
        }
474
475
        $graphHtml = '<div class="container">';
476
        foreach ($list as $group => $subGroupList) {
477
            $showGroupLine = false;
478
            if (isset($groupDrawLine[$group]) && $groupDrawLine[$group]) {
479
                $showGroupLine = true;
480
            }
481
            $graphHtml .= self::parseSubGroups(
482
                $groupCourseList,
483
                $group,
484
                $list[$group]['label'],
485
                $showGroupLine,
486
                $subGroupList,
487
                $widthGroup
488
            );
489
        }
490
        $graphHtml .= '</div>';
491
        $graphHtml .= $connections;
492
493
        return $graphHtml;
494
    }
495
496
    /**
497
     * @param array    $careerInfo
498
     * @param Template $tpl
499
     * @param int      $loadUserIdData
500
     *
501
     * @return string
502
     */
503
    public static function renderDiagramByColumn($careerInfo, $tpl, $loadUserIdData = 0, $showFooter = true)
504
    {
505
        $careerId = isset($careerInfo['id']) ? $careerInfo['id'] : 0;
506
        if (empty($careerId)) {
507
            return '';
508
        }
509
510
        $extraFieldValue = new ExtraFieldValue('career');
511
        $item = $extraFieldValue->get_values_by_handler_and_field_variable(
512
            $careerId,
513
            'career_diagram',
514
            false,
515
            false,
516
            false
517
        );
518
519
        $graph = null;
520
        if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
521
            /** @var Graph $graph */
522
            $graph = UnserializeApi::unserialize('career', $item['value']);
523
        }
524
525
        if (!($graph instanceof Graph)) {
526
            return '';
527
        }
528
529
        // Getting max column
530
        $maxColumn = 0;
531
        foreach ($graph->getVertices() as $vertex) {
532
            $groupId = (int) $vertex->getGroup();
533
            if ($groupId > $maxColumn) {
534
                $maxColumn = $groupId;
535
            }
536
        }
537
538
        $userResult = [];
539
        if (!empty($loadUserIdData)) {
540
            $careerData = UserManager::getUserCareer($loadUserIdData, $careerId);
541
            if (isset($careerData['extra_data']) && !empty($careerData['extra_data'])) {
542
                $userResult = unserialize($careerData['extra_data']);
543
            }
544
        }
545
546
        $list = [];
547
        $subGroups = [];
548
        /** @var Vertex $vertex */
549
        foreach ($graph->getVertices() as $vertex) {
550
            $column = $vertex->getGroup();
551
            $group = $vertex->getAttribute('Group');
552
553
            $groupData = explode(':', $group);
554
            $group = $groupData[0];
555
            $groupLabel = isset($groupData[1]) ? $groupData[1] : '';
556
557
            $subGroup = $vertex->getAttribute('SubGroup');
558
            $subGroupData = explode(':', $subGroup);
559
560
            $row = $vertex->getAttribute('Row');
561
            $subGroupId = $subGroupData[0];
562
            $subGroupLabel = isset($subGroupData[1]) ? $subGroupData[1] : '';
563
564
            if (!empty($subGroupId) && !in_array($subGroupId, $subGroups)) {
565
                $subGroups[$subGroupId]['items'][] = $vertex->getId();
566
                $subGroups[$subGroupId]['label'] = $subGroupLabel;
567
            }
568
569
            $list[$column]['rows'][$row]['items'][] = $vertex;
570
            $list[$column]['rows'][$row]['label'] = $subGroupId;
571
            $list[$column]['rows'][$row]['group'] = $group;
572
            $list[$column]['rows'][$row]['group_label'] = $groupLabel;
573
            $list[$column]['rows'][$row]['subgroup'] = $subGroup;
574
            $list[$column]['rows'][$row]['subgroup_label'] = $subGroupLabel;
575
            $list[$column]['label'] = $groupLabel;
576
            $list[$column]['column'] = $column;
577
        }
578
579
        $groupCourseList = [];
580
        $simpleConnectionList = [];
581
582
        // Read Connections column
583
        foreach ($list as $column => $groupList) {
584
            foreach ($groupList['rows'] as $subGroupList) {
585
                /** @var Vertex $vertex */
586
                foreach ($subGroupList['items'] as $vertex) {
587
                    if ($vertex instanceof Vertex) {
588
                        $groupCourseList[$vertex->getAttribute('Column')][] = $vertex->getId();
589
                        $connectionList = $vertex->getAttribute('Connections');
590
                        if (empty($connectionList)) {
591
                            continue;
592
                        }
593
                        $simpleFirstConnection = '';
594
                        $simpleSecondConnection = '';
595
596
                        $explode = explode('-', $connectionList);
597
                        $pos = strpos($explode[0], 'SG');
598
                        if ($pos === false) {
599
                            $pos = strpos($explode[0], 'G');
600
                            if (is_numeric($pos)) {
601
                                // Is group
602
                                $groupValueId = (int) str_replace(
603
                                    'G',
604
                                    '',
605
                                    $explode[0]
606
                                );
607
                                $simpleFirstConnection = 'g'.(int) $groupValueId;
608
                            } else {
609
                                // Course block (row_123 id)
610
                                if (!empty($explode[0])) {
611
                                    $simpleFirstConnection = 'v'.$explode[0];
612
                                }
613
                            }
614
                        } else {
615
                            // subgroup__123 id
616
                            $simpleFirstConnection = 'sg'.(int) str_replace('SG', '', $explode[0]);
617
                        }
618
619
                        $pos = false;
620
                        if (isset($explode[1])) {
621
                            $pos = strpos($explode[1], 'SG');
622
                        }
623
                        if ($pos === false) {
624
                            if (isset($explode[1])) {
625
                                $pos = strpos($explode[1], 'G');
626
                                $value = $explode[1];
627
                            }
628
                            if (is_numeric($pos)) {
629
                                $groupValueId = (int) str_replace(
630
                                    'G',
631
                                    '',
632
                                    $value
633
                                );
634
                                $simpleSecondConnection = 'g'.(int) $groupValueId;
635
                            } else {
636
                                // Course block (row_123 id)
637
                                if (!empty($explode[0]) && isset($explode[1])) {
638
                                    $simpleSecondConnection = 'v'.(int) $explode[1];
639
                                }
640
                            }
641
                        } else {
642
                            $simpleSecondConnection = 'sg'.(int) str_replace('SG', '', $explode[1]);
643
                        }
644
645
                        if (!empty($simpleFirstConnection) && !empty($simpleSecondConnection)) {
646
                            $simpleConnectionList[] = [
647
                                'from' => $simpleFirstConnection,
648
                                'to' => $simpleSecondConnection,
649
                            ];
650
                        }
651
                    }
652
                }
653
            }
654
        }
655
656
        $graphHtml = '';
657
        $groupsBetweenColumns = [];
658
        foreach ($list as $column => $columnList) {
659
            foreach ($columnList['rows'] as $subGroupList) {
660
                $newGroup = $subGroupList['group'];
661
                $label = $subGroupList['group_label'];
662
                $newOrder[$newGroup]['items'][] = $subGroupList;
663
                $newOrder[$newGroup]['label'] = $label;
664
                $groupsBetweenColumns[$newGroup][] = $subGroupList;
665
            }
666
        }
667
668
        // Creates graph
669
        $graph = new stdClass();
670
        $graph->blockWidth = 280;
671
        $graph->blockHeight = 150;
672
673
        $graph->xGap = 70;
674
        $graph->yGap = 55;
675
676
        $graph->xDiff = 70;
677
        $graph->yDiff = 55;
678
679
        if (!empty($userResult)) {
680
            $graph->blockHeight = 180;
681
            $graph->yGap = 60;
682
            $graph->yDiff = 60;
683
        }
684
685
        foreach ($groupsBetweenColumns as $group => $items) {
686
            self::parseColumnList($groupCourseList, $items, $graph, $simpleConnectionList, $userResult);
687
        }
688
689
        $graphHtml .= '<style>
690
             .panel-title {
691
                font-size: 11px;
692
                height: 40px;
693
             }
694
695
             .panel-body{
696
                min-height: 55px;
697
             }
698
             </style>';
699
700
        // Create groups
701
        if (!empty($graph->groupList)) {
702
            $groupList = [];
703
            $groupDiffX = 20;
704
            $groupDiffY = 50;
705
            $style = 'whiteSpace=wrap;rounded;html=1;strokeColor=red;fillColor=none;strokeWidth=2;align=left;verticalAlign=top;';
706
            foreach ($graph->groupList as $id => $data) {
707
                if (empty($id)) {
708
                    continue;
709
                }
710
711
                $x = $data['min_x'] - $groupDiffX;
712
                $y = $data['min_y'] - $groupDiffY;
713
                $width = $data['max_width'] + ($groupDiffX * 2);
714
                $height = $data['max_height'] + $groupDiffY * 2;
715
                $label = '<h4>'.$data['label'].'</h4>';
716
                $vertexData = "var g$id = graph.insertVertex(parent, null, '$label', $x, $y, $width, $height, '$style');";
717
                $groupList[] = $vertexData;
718
            }
719
            $tpl->assign('group_list', $groupList);
720
        }
721
722
        // Create subgroups
723
        $subGroupList = [];
724
        $subGroupListData = [];
725
        foreach ($subGroups as $subGroupId => $vertexData) {
726
            $label = $vertexData['label'];
727
            $vertexIdList = $vertexData['items'];
728
            foreach ($vertexIdList as $rowId) {
729
                $data = $graph->allData[$rowId];
730
                $originalRow = $data['row'];
731
                $column = $data['column'];
732
                $x = $data['x'];
733
                $y = $data['y'];
734
                $width = $data['width'];
735
                $height = $data['height'];
736
737
                if (!isset($subGroupListData[$subGroupId])) {
738
                    $subGroupListData[$subGroupId]['min_x'] = 1000;
739
                    $subGroupListData[$subGroupId]['min_y'] = 1000;
740
                    $subGroupListData[$subGroupId]['max_width'] = 0;
741
                    $subGroupListData[$subGroupId]['max_height'] = 0;
742
                    $subGroupListData[$subGroupId]['label'] = $label;
743
                }
744
745
                if ($x < $subGroupListData[$subGroupId]['min_x']) {
746
                    $subGroupListData[$subGroupId]['min_x'] = $x;
747
                }
748
749
                if ($y < $subGroupListData[$subGroupId]['min_y']) {
750
                    $subGroupListData[$subGroupId]['min_y'] = $y;
751
                }
752
753
                $subGroupListData[$subGroupId]['max_width'] = ($column + 1) * ($width + $graph->xGap) - $subGroupListData[$subGroupId]['min_x'];
754
                $subGroupListData[$subGroupId]['max_height'] = ($originalRow + 1) * ($height + $graph->yGap) - $subGroupListData[$subGroupId]['min_y'];
755
            }
756
757
            $style = 'whiteSpace=wrap;rounded;dashed=1;strokeColor=blue;fillColor=none;strokeWidth=2;align=left;verticalAlign=bottom;';
758
            $subGroupDiffX = 5;
759
            foreach ($subGroupListData as $subGroupId => $data) {
760
                $x = $data['min_x'] - $subGroupDiffX;
761
                $y = $data['min_y'] - $subGroupDiffX;
762
763
                $spaceForSubGroupTitle = 0;
764
                if (!empty($data['label'])) {
765
                    $spaceForSubGroupTitle = 40;
766
                }
767
768
                $width = $data['max_width'] + $subGroupDiffX * 2;
769
                $height = $data['max_height'] + $subGroupDiffX * 2 + $spaceForSubGroupTitle;
770
771
                $label = '<h4 style="background: white">'.$data['label'].'</h4>';
772
                $vertexData = "var sg$subGroupId = graph.insertVertex(parent, null, '$label', $x, $y, $width, $height, '$style');";
773
                $subGroupList[] = $vertexData;
774
            }
775
        }
776
777
        // Create connections (arrows)
778
        if (!empty($simpleConnectionList)) {
779
            $connectionList = [];
780
            //$style = 'endArrow=classic;html=1;strokeWidth=4;exitX=1;exitY=0.5;entryX=0;entryY=0.5;';
781
            $style = '';
782
            foreach ($simpleConnectionList as $connection) {
783
                $from = $connection['from'];
784
                $to = $connection['to'];
785
                $vertexData = "var e1 = graph.insertEdge(parent, null, '', $from, $to, '$style')";
786
                $connectionList[] = $vertexData;
787
            }
788
            $tpl->assign('connections', $connectionList);
789
        }
790
791
        $tpl->assign('subgroup_list', $subGroupList);
792
        $tpl->assign('vertex_list', $graph->elementList);
793
794
        $graphHtml .= '<div id="graphContainer"></div>';
795
        if ($showFooter) {
796
            $graphHtml .= self::renderDiagramFooter();
797
        }
798
799
        return $graphHtml;
800
    }
801
802
    /**
803
     * @param $groupCourseList
804
     * @param $columnList
805
     * @param $graph
806
     * @param $connections
807
     * @param $userResult
808
     *
809
     * @return string
810
     */
811
    public static function parseColumnList($groupCourseList, $columnList, &$graph, &$connections, $userResult)
812
    {
813
        $graphHtml = '';
814
        $oldGroup = null;
815
        $newOrder = [];
816
        foreach ($columnList as $key => $subGroupList) {
817
            $newGroup = $subGroupList['group'];
818
            $label = $subGroupList['group_label'];
819
            $newOrder[$newGroup]['items'][] = $subGroupList;
820
            $newOrder[$newGroup]['label'] = $label;
821
        }
822
823
        foreach ($newOrder as $newGroup => $data) {
824
            $label = $data['label'];
825
            $subGroupList = $data['items'];
826
827
            if (!isset($graph->groupList[$newGroup])) {
828
                $graph->groupList[$newGroup]['min_x'] = 1000;
829
                $graph->groupList[$newGroup]['min_y'] = 1000;
830
                $graph->groupList[$newGroup]['max_width'] = 0;
831
                $graph->groupList[$newGroup]['max_height'] = 0;
832
                $graph->groupList[$newGroup]['label'] = $label;
833
            }
834
835
            $maxColumn = 0;
836
            $maxRow = 0;
837
            $minColumn = 100;
838
            $minRow = 100;
839
            foreach ($subGroupList as $item) {
840
                /** @var Vertex $vertex */
841
                foreach ($item['items'] as $vertex) {
842
                    $column = $vertex->getAttribute('Column');
843
                    $realRow = $vertex->getAttribute('Row');
844
845
                    if ($column > $maxColumn) {
846
                        $maxColumn = $column;
847
                    }
848
                    if ($realRow > $maxRow) {
849
                        $maxRow = $realRow;
850
                    }
851
852
                    if ($column < $minColumn) {
853
                        $minColumn = $column;
854
                    }
855
                    if ($realRow < $minRow) {
856
                        $minRow = $realRow;
857
                    }
858
                }
859
            }
860
861
            if (!empty($newGroup)) {
862
                $graphHtml .= '<div
863
                    id ="group_'.$newGroup.'"
864
                    class="group'.$newGroup.' group_class"
865
                    style="display:grid;
866
                        align-self: start;
867
                        grid-gap: 10px;
868
                        justify-items: stretch;
869
                        align-items: start;
870
                        align-content: start;
871
                        justify-content: stretch;
872
                        grid-area:'.$minRow.'/'.$minColumn.'/'.$maxRow.'/'.$maxColumn.'">'; //style="display:grid"
873
            }
874
875
            $addRow = 0;
876
            if (!empty($label)) {
877
                $graphHtml .= "<div class='my_label' style='grid-area:$minRow/$minColumn/$maxRow/$maxColumn'>$label</div>";
878
                $addRow = 1;
879
            }
880
881
            foreach ($subGroupList as $item) {
882
                $graphHtml .= self::parseVertexList(
883
                    $groupCourseList,
884
                    $item['items'],
885
                    $addRow,
886
                    $graph,
887
                    $newGroup,
888
                    $connections,
889
                    $userResult
890
                );
891
            }
892
893
            if (!empty($newGroup)) {
894
                $graphHtml .= '</div >';
895
            }
896
        }
897
898
        return $graphHtml;
899
    }
900
901
    /**
902
     * @param array    $groupCourseList
903
     * @param array    $vertexList
904
     * @param int      $addRow
905
     * @param stdClass $graph
906
     * @param int      $group
907
     * @param array    $connections
908
     * @param array    $userResult
909
     *
910
     * @return string
911
     */
912
    public static function parseVertexList($groupCourseList, $vertexList, $addRow, &$graph, $group, &$connections, $userResult)
913
    {
914
        if (empty($vertexList)) {
915
            return '';
916
        }
917
918
        $graphHtml = '';
919
        /** @var Vertex $vertex */
920
        foreach ($vertexList as $vertex) {
921
            $borderColor = 'green';
922
            $column = $vertex->getAttribute('Column');
923
            $realRow = $originalRow = $vertex->getAttribute('Row');
924
            if ($addRow) {
925
                $realRow = $realRow + $addRow;
926
            }
927
            $id = $vertex->getId();
928
            $area = "$realRow/$column";
929
            $graphHtml .= '<div
930
                id = "row_wrapper_'.$id.'"
931
                data= "'.$originalRow.'-'.$column.'"
932
                style="
933
                    align-self: start;
934
                    justify-content: stretch;
935
                    grid-area:'.$area.'"
936
            >';
937
            $color = '';
938
            if (!empty($vertex->getAttribute('DefinedColor'))) {
939
                $color = $vertex->getAttribute('DefinedColor');
940
            }
941
            $content = '<div class="pull-left">'.$vertex->getAttribute('Notes').'</div>';
942
            $content .= '<div class="pull-right">['.$id.']</div>';
943
944
            if (!empty($userResult) && isset($userResult[$id])) {
945
                $lastItem = end($userResult[$id]);
946
                if ($lastItem && isset($lastItem['BgColor']) && !empty($lastItem['BgColor'])) {
947
                    $color = $lastItem['BgColor'].'; color: '.$lastItem['Color'];
948
                    $borderColor = $lastItem['BorderColor'];
949
                }
950
                $results = '';
951
                $size = 2;
952
                foreach ($userResult[$id] as $resultId => $iconData) {
953
                    $icon = '';
954
                    switch ($iconData['Icon']) {
955
                        case 0:
956
                            $icon = Display::returnFontAwesomeIcon('times-circle', $size);
957
                            break;
958
                        case 1:
959
                            $icon = Display::returnFontAwesomeIcon('check-circle', $size);
960
                            break;
961
                        case 2:
962
                            $icon = Display::returnFontAwesomeIcon('info-circle', $size);
963
                            break;
964
                    }
965
966
                    if (substr($resultId, 0, 1) == 2) {
967
                        $iconData['Description'] = 'Result Id = '.$resultId;
968
                    }
969
970
                    if ('Joe Anonymous' === $iconData['TeacherUsername']) {
971
                        $iconData['TeacherUsername'] = '';
972
                    }
973
974
                    if (!empty($icon)) {
975
                        $params = [
976
                            'id' => 'course_'.$id.'_'.$resultId,
977
                            'data-toggle' => 'popover',
978
                            'title' => 'Popover title',
979
                            'class' => 'popup',
980
                            'data-description' => $iconData['Description'],
981
                            'data-period' => $iconData['Period'],
982
                            'data-teacher-text' => $iconData['TeacherText'],
983
                            'data-teacher' => $iconData['TeacherUsername'],
984
                            'data-score' => $iconData['ScoreText'],
985
                            'data-score-value' => $iconData['ScoreValue'],
986
                            'data-info' => $iconData['Info'],
987
                            'data-background-color' => $iconData['BgColor'],
988
                            'data-color' => $iconData['Color'],
989
                            'data-border-color' => $iconData['BorderColor'],
990
                            'style' => 'color:'.$iconData['IconColor'],
991
                        ];
992
                        $results .= Display::url($icon, 'javascript:void(0);', $params);
993
                    }
994
                }
995
996
                if (!empty($results)) {
997
                    $content .= '<div class="row"></div><div class="pull-left">'.$results.'</div>';
998
                }
999
            }
1000
1001
            $title = $vertex->getAttribute('graphviz.label');
1002
            if (!empty($vertex->getAttribute('LinkedElement'))) {
1003
                $title = Display::url($title, $vertex->getAttribute('LinkedElement'));
1004
            }
1005
1006
            $originalRow--;
1007
            $column--;
1008
1009
            $graphHtml .= Display::panel(
1010
                $content,
1011
                $title,
1012
                null,
1013
                null,
1014
                null,
1015
                "row_$id",
1016
                $color
1017
            );
1018
1019
            $panel = Display::panel(
1020
                $content,
1021
                $title,
1022
                null,
1023
                null,
1024
                null,
1025
                "row_$id",
1026
                $color
1027
            );
1028
1029
            $x = $column * $graph->blockWidth + $graph->xDiff;
1030
            $y = $originalRow * $graph->blockHeight + $graph->yDiff;
1031
1032
            $width = $graph->blockWidth - $graph->xGap;
1033
            $height = $graph->blockHeight - $graph->yGap;
1034
1035
            $style = 'text;html=1;strokeColor='.$borderColor.';fillColor=#ffffff;overflow=fill;rounded=0;align=left;';
1036
1037
            $panel = str_replace(["\n", "\r"], '', $panel);
1038
            $vertexData = "var v$id = graph.insertVertex(parent, null, '".addslashes($panel)."', $x, $y, $width, $height, '$style');";
1039
1040
            $graph->elementList[$id] = $vertexData;
1041
            $graph->allData[$id] = [
1042
                'x' => $x,
1043
                'y' => $y,
1044
                'width' => $width,
1045
                'height' => $height,
1046
                'row' => $originalRow,
1047
                'column' => $column,
1048
                'label' => $title,
1049
            ];
1050
1051
            if ($x < $graph->groupList[$group]['min_x']) {
1052
                $graph->groupList[$group]['min_x'] = $x;
1053
            }
1054
1055
            if ($y < $graph->groupList[$group]['min_y']) {
1056
                $graph->groupList[$group]['min_y'] = $y;
1057
            }
1058
1059
            $graph->groupList[$group]['max_width'] = ($column + 1) * ($width + $graph->xGap) - $graph->groupList[$group]['min_x'];
1060
            $graph->groupList[$group]['max_height'] = ($originalRow + 1) * ($height + ($graph->yGap)) - $graph->groupList[$group]['min_y'];
1061
1062
            $graphHtml .= '</div>';
1063
            $arrow = $vertex->getAttribute('DrawArrowFrom');
1064
            $found = false;
1065
            if (!empty($arrow)) {
1066
                $pos = strpos($arrow, 'SG');
1067
                if ($pos === false) {
1068
                    $pos = strpos($arrow, 'G');
1069
                    if (is_numeric($pos)) {
1070
                        $parts = explode('G', $arrow);
1071
                        if (empty($parts[0]) && count($parts) == 2) {
1072
                            $groupArrow = $parts[1];
1073
                            $graphHtml .= self::createConnection(
1074
                                "group_$groupArrow",
1075
                                "row_$id",
1076
                                ['Left', 'Right']
1077
                            );
1078
                            $found = true;
1079
                            $connections[] = [
1080
                              'from' => "g$groupArrow",
1081
                              'to' => "v$id",
1082
                            ];
1083
                        }
1084
                    }
1085
                } else {
1086
                    // Case is only one subgroup value example: SG1
1087
                    $parts = explode('SG', $arrow);
1088
                    if (empty($parts[0]) && count($parts) == 2) {
1089
                        $subGroupArrow = $parts[1];
1090
                        $graphHtml .= self::createConnection(
1091
                            "subgroup_$subGroupArrow",
1092
                            "row_$id",
1093
                            ['Left', 'Right']
1094
                        );
1095
                        $found = true;
1096
                        $connections[] = [
1097
                            'from' => "sg$subGroupArrow",
1098
                            'to' => "v$id",
1099
                        ];
1100
                    }
1101
                }
1102
1103
                if ($found == false) {
1104
                    // case is connected to 2 subgroups: Example SG1-SG2
1105
                    $parts = explode('-', $arrow);
1106
                    if (count($parts) == 2 && !empty($parts[0]) && !empty($parts[1])) {
1107
                        $defaultArrow = ['Top', 'Bottom'];
1108
                        $firstPrefix = '';
1109
                        $firstId = '';
1110
                        $secondId = '';
1111
                        $secondPrefix = '';
1112
                        if (is_numeric($pos = strpos($parts[0], 'SG'))) {
1113
                            $firstPrefix = 'sg';
1114
                            $firstId = str_replace('SG', '', $parts[0]);
1115
                        }
1116
1117
                        if (is_numeric($pos = strpos($parts[1], 'SG'))) {
1118
                            $secondPrefix = 'sg';
1119
                            $secondId = str_replace('SG', '', $parts[1]);
1120
                        }
1121
                        if (!empty($secondId) && !empty($firstId)) {
1122
                            $connections[] = [
1123
                                'from' => $firstPrefix.$firstId,
1124
                                'to' => $secondPrefix.$secondId,
1125
                                $defaultArrow,
1126
                            ];
1127
                            $found = true;
1128
                        }
1129
                    }
1130
                }
1131
1132
                if ($found == false) {
1133
                    // case DrawArrowFrom is an integer
1134
                    $defaultArrow = ['Left', 'Right'];
1135
                    if (isset($groupCourseList[$column]) &&
1136
                        in_array($arrow, $groupCourseList[$column])
1137
                    ) {
1138
                        $defaultArrow = ['Top', 'Bottom'];
1139
                    }
1140
                    $graphHtml .= self::createConnection(
1141
                        "row_$arrow",
1142
                        "row_$id",
1143
                        $defaultArrow
1144
                    );
1145
1146
                    $connections[] = [
1147
                        'from' => "v$arrow",
1148
                        'to' => "v$id",
1149
                    ];
1150
                }
1151
            }
1152
        }
1153
1154
        return $graphHtml;
1155
    }
1156
1157
    /**
1158
     * @param array  $groupCourseList list of groups and their courses
1159
     * @param int    $group
1160
     * @param string $groupLabel
1161
     * @param bool   $showGroupLine
1162
     * @param array  $subGroupList
1163
     * @param $widthGroup
1164
     *
1165
     * @return string
1166
     */
1167
    public static function parseSubGroups(
1168
        $groupCourseList,
1169
        $group,
1170
        $groupLabel,
1171
        $showGroupLine,
1172
        $subGroupList,
1173
        $widthGroup
1174
    ) {
1175
        $topValue = 90;
1176
        $defaultSpace = 40;
1177
        $leftGroup = $defaultSpace.'px';
1178
        if ($group == 1) {
1179
            $leftGroup = 0;
1180
        }
1181
1182
        $groupIdTag = "group_$group";
1183
        $borderLine = $showGroupLine === true ? 'border-style:solid;' : '';
1184
1185
        $graphHtml = '<div
1186
            id="'.$groupIdTag.'" class="career_group"
1187
            style=" '.$borderLine.' padding:15px; float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';
1188
1189
        if (!empty($groupLabel)) {
1190
            $graphHtml .= '<h3>'.$groupLabel.'</h3>';
1191
        }
1192
1193
        foreach ($subGroupList as $subGroup => $subGroupData) {
1194
            $subGroupLabel = isset($subGroupData['label']) ? $subGroupData['label'] : '';
1195
            $columnList = isset($subGroupData['columns']) ? $subGroupData['columns'] : [];
1196
1197
            if (empty($columnList)) {
1198
                continue;
1199
            }
1200
1201
            $line = '';
1202
            if (!empty($subGroup)) {
1203
                $line = 'border-style:solid;';
1204
            }
1205
1206
            // padding:15px;
1207
            $graphHtml .= '<div
1208
                id="subgroup_'.$subGroup.'" class="career_subgroup"
1209
                style="'.$line.' margin-bottom:20px; padding:15px; float:left; margin-left:0px; width:100%">';
1210
            if (!empty($subGroupLabel)) {
1211
                $graphHtml .= '<h3>'.$subGroupLabel.'</h3>';
1212
            }
1213
            foreach ($columnList as $column => $rows) {
1214
                $leftColumn = $defaultSpace.'px';
1215
                if ($column == 1) {
1216
                    $leftColumn = 0;
1217
                }
1218
                if (count($columnList) == 1) {
1219
                    $leftColumn = 0;
1220
                }
1221
1222
                $widthColumn = 85 / count($columnList);
1223
                $graphHtml .= '<div
1224
                    id="col_'.$column.'" class="career_column"
1225
                    style="padding:15px;float:left; margin-left:'.$leftColumn.'; width:'.$widthColumn.'%">';
1226
                $maxRow = 0;
1227
                foreach ($rows as $row => $vertex) {
1228
                    if ($row > $maxRow) {
1229
                        $maxRow = $row;
1230
                    }
1231
                }
1232
1233
                $newRowList = [];
1234
                $defaultSubGroup = -1;
1235
                $subGroupCountList = [];
1236
                for ($i = 0; $i < $maxRow; $i++) {
1237
                    /** @var Vertex $vertex */
1238
                    $vertex = isset($rows[$i + 1]) ? $rows[$i + 1] : null;
1239
                    if (!is_null($vertex)) {
1240
                        $subGroup = $vertex->getAttribute('SubGroup');
1241
                        if ($subGroup == '' || empty($subGroup)) {
1242
                            $defaultSubGroup = 0;
1243
                        } else {
1244
                            $defaultSubGroup = (int) $subGroup;
1245
                        }
1246
                    }
1247
                    $newRowList[$i + 1][$defaultSubGroup][] = $vertex;
1248
                    if (!isset($subGroupCountList[$defaultSubGroup])) {
1249
                        $subGroupCountList[$defaultSubGroup] = 1;
1250
                    } else {
1251
                        $subGroupCountList[$defaultSubGroup]++;
1252
                    }
1253
                }
1254
1255
                $subGroup = null;
1256
                $subGroupAdded = [];
1257
                /** @var Vertex $vertex */
1258
                foreach ($newRowList as $row => $subGroupList) {
1259
                    foreach ($subGroupList as $subGroup => $vertexList) {
1260
                        if (!empty($subGroup) && $subGroup != -1) {
1261
                            if (!isset($subGroupAdded[$subGroup])) {
1262
                                $subGroupAdded[$subGroup] = 1;
1263
                            } else {
1264
                                $subGroupAdded[$subGroup]++;
1265
                            }
1266
                        }
1267
1268
                        foreach ($vertexList as $vertex) {
1269
                            if (is_null($vertex)) {
1270
                                $graphHtml .= '<div class="career_empty" style="height: 130px">';
1271
                                $graphHtml .= '</div>';
1272
                                continue;
1273
                            }
1274
1275
                            $id = $vertex->getId();
1276
                            $rowId = "row_$row";
1277
                            $graphHtml .= '<div id = "row_'.$id.'" class="'.$rowId.' career_row" >';
1278
                            $color = '';
1279
                            if (!empty($vertex->getAttribute('DefinedColor'))) {
1280
                                $color = $vertex->getAttribute('DefinedColor');
1281
                            }
1282
                            $content = $vertex->getAttribute('Notes');
1283
                            $content .= '<div class="pull-right">['.$id.']</div>';
1284
1285
                            $title = $vertex->getAttribute('graphviz.label');
1286
                            if (!empty($vertex->getAttribute('LinkedElement'))) {
1287
                                $title = Display::url($title, $vertex->getAttribute('LinkedElement'));
1288
                            }
1289
1290
                            $graphHtml .= Display::panel(
1291
                                $content,
1292
                                $title,
1293
                                null,
1294
                                null,
1295
                                null,
1296
                                null,
1297
                                $color
1298
                            );
1299
                            $graphHtml .= '</div>';
1300
1301
                            $arrow = $vertex->getAttribute('DrawArrowFrom');
1302
                            $found = false;
1303
                            if (!empty($arrow)) {
1304
                                $pos = strpos($arrow, 'SG');
1305
                                if ($pos === false) {
1306
                                    $pos = strpos($arrow, 'G');
1307
                                    if (is_numeric($pos)) {
1308
                                        $parts = explode('G', $arrow);
1309
                                        if (empty($parts[0]) && count($parts) == 2) {
1310
                                            $groupArrow = $parts[1];
1311
                                            $graphHtml .= self::createConnection(
1312
                                                "group_$groupArrow",
1313
                                                "row_$id",
1314
                                                ['Left', 'Right']
1315
                                            );
1316
                                            $found = true;
1317
                                        }
1318
                                    }
1319
                                } else {
1320
                                    $parts = explode('SG', $arrow);
1321
                                    if (empty($parts[0]) && count($parts) == 2) {
1322
                                        $subGroupArrow = $parts[1];
1323
                                        $graphHtml .= self::createConnection(
1324
                                            "subgroup_$subGroupArrow",
1325
                                            "row_$id",
1326
                                            ['Left', 'Right']
1327
                                        );
1328
                                        $found = true;
1329
                                    }
1330
                                }
1331
                            }
1332
1333
                            if ($found == false) {
1334
                                $defaultArrow = ['Left', 'Right'];
1335
                                if (isset($groupCourseList[$group]) &&
1336
                                    in_array($arrow, $groupCourseList[$group])
1337
                                ) {
1338
                                    $defaultArrow = ['Top', 'Bottom'];
1339
                                }
1340
                                $graphHtml .= self::createConnection(
1341
                                    "row_$arrow",
1342
                                    "row_$id",
1343
                                    $defaultArrow
1344
                                );
1345
                            }
1346
                        }
1347
                    }
1348
                }
1349
                $graphHtml .= '</div>';
1350
            }
1351
            $graphHtml .= '</div>';
1352
        }
1353
        $graphHtml .= '</div>';
1354
1355
        return $graphHtml;
1356
    }
1357
1358
    /**
1359
     * @param string $source
1360
     * @param string $target
1361
     * @param array  $anchor
1362
     *
1363
     * @return string
1364
     */
1365
    public static function createConnection($source, $target, $anchor = [])
1366
    {
1367
        if (empty($anchor)) {
1368
            // Default
1369
            $anchor = ['Bottom', 'Right'];
1370
        }
1371
1372
        $anchor = implode('","', $anchor);
1373
        $html = '<script>
1374
1375
        var connectorPaintStyle = {
1376
            strokeWidth: 2,
1377
            stroke: "#a31ed3",
1378
            joinstyle: "round",
1379
            outlineStroke: "white",
1380
            outlineWidth: 2
1381
        },
1382
        // .. and this is the hover style.
1383
        connectorHoverStyle = {
1384
            strokeWidth: 3,
1385
            stroke: "#216477",
1386
            outlineWidth: 5,
1387
            outlineStroke: "white"
1388
        },
1389
        endpointHoverStyle = {
1390
            fill: "#E80CAF",
1391
            stroke: "#E80CAF"
1392
        };
1393
        jsPlumb.ready(function() { ';
1394
        $html .= 'jsPlumb.connect({
1395
            source:"'.$source.'",
1396
            target:"'.$target.'",
1397
            endpoint:[ "Rectangle", { width:1, height:1 }],
1398
            connector: ["Flowchart"],
1399
            paintStyle: connectorPaintStyle,
1400
            hoverPaintStyle: endpointHoverStyle,
1401
            anchor: ["'.$anchor.'"],
1402
            overlays: [
1403
                [
1404
                    "Arrow",
1405
                    {
1406
                        location:1,
1407
                        width:11,
1408
                        length:11
1409
                    }
1410
                ],
1411
            ],
1412
        });';
1413
        $html .= '});</script>'.PHP_EOL;
1414
1415
        return $html;
1416
    }
1417
1418
    public static function renderDiagramFooter(): string
1419
    {
1420
        $footer = '';
1421
        if (api_get_configuration_value('career_diagram_legend')) {
1422
            $footer .= get_lang('CareerDiagramLegend');
1423
        }
1424
        if (api_get_configuration_value('career_diagram_disclaimer')) {
1425
            $footer .= get_lang('CareerDiagramDisclaimer');
1426
        }
1427
1428
        return $footer;
1429
    }
1430
}
1431