Completed
Push — master ( 7bb44a...72105c )
by Laurent
02:19
created

card.lib.php ➔ prepareFlightTabs()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 47
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 30
nc 12
nop 1
dl 0
loc 47
rs 8.5125
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Prepare tabs for flight card
5
 *
6
 * @param Bbcvols $flight
7
 *
8
 * @return array
9
 */
10
function prepareFlightTabs(Bbcvols $flight)
11
{
12
    global $user, $langs, $conf;
13
14
    dol_include_once('/flightLog/class/card/Tab.php');
15
    dol_include_once('/flightLog/class/card/TabCollection.php');
16
17
    $tabUrls = [
18
        DOL_URL_ROOT . '/flightLog/card.php?id=' . $flight->idBBC_vols,
19
        ($user->rights->flightLog->vol->financial || $user->id != $flight->fk_pilot) ? DOL_URL_ROOT . '/flightLog/card_tab_financial.php?id=' . $flight->idBBC_vols : '',
20
        DOL_URL_ROOT . '/flightLog/card_tab_comments.php?id=' . $flight->idBBC_vols,
21
        DOL_URL_ROOT . '/flightLog/card_tab_follow.php?id=' . $flight->idBBC_vols,
22
    ];
23
24
    $tabNames = [
25
        'general',
26
        'financial',
27
        'comments',
28
        'follow',
29
    ];
30
31
    $tabTitle = [
32
        'Vol',
33
        'Finances',
34
        'Remarques',
35
        'Suivis',
36
    ];
37
38
    $tabCollection = new TabCollection();
39
40
    $countUrls = count($tabUrls);
41
    for ($i = 0; $i < $countUrls; $i++) {
42
        if (empty($tabUrls[$i])) {
43
            continue;
44
        }
45
46
        $tab = new Tab($tabTitle[$i], $tabNames[$i], $tabUrls[$i]);
47
        $tabCollection->addTab($tab);
48
    }
49
50
    $head = $tabCollection->toArray();
51
    $tabCount = count($tabCollection);
52
53
    complete_head_from_modules($conf, $langs, $flight, $head, $tabCount, 'bbcFlight');
54
55
    return $head;
56
}