Completed
Push — master ( 88150f...580efa )
by Laurent
04:58 queued 02:17
created

InstructionFlightQueryHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 51 5
1
<?php
2
require_once __DIR__ . '/../class/bbcvols.class.php';
3
require_once __DIR__ . '/InstructionFlightQuery.php';
4
5
/**
6
 * Returns all instruction flights of a user.
7
 *
8
 * @author Laurent De Coninck <[email protected]>
9
 */
10
class InstructionFlightQueryHandler
11
{
12
    /**
13
     * @var DoliDB
14
     */
15
    private $db;
16
17
    /**
18
     * InstructionFlightQueryHandler constructor.
19
     *
20
     * @param DoliDB $db
21
     */
22
    public function __construct(DoliDB $db)
23
    {
24
        $this->db = $db;
25
    }
26
27
    /**
28
     * @param InstructionFlightQuery $query
29
     *
30
     * @return array|Bbcvols[]
31
     */
32
    public function __invoke(InstructionFlightQuery $query)
33
    {
34
        $sql = 'SELECT flights.* FROM llx_bbc_vols as flights';
35
        $sql .= ' WHERE ';
36
        $sql .= ' flights.fk_type = 6 ';
37
        $sql .= ' AND flights.fk_pilot = ' . $query->getStudentId();
38
        $sql .= ' ORDER BY flights.date ';
39
40
        $resql = $this->db->query($sql);
41
        $array = [];
42
43
        if ($resql) {
44
            $num = $this->db->num_rows($resql);
45
            $i = 0;
46
            if ($num) {
47
                while ($i < $num) {
48
                    $obj = $this->db->fetch_object($resql);
49
                    if ($obj) {
50
51
                        $flight = new Bbcvols($this->db);
52
                        $flight->id = $obj->idBBC_vols;
53
                        $flight->idBBC_vols = $obj->idBBC_vols;
54
                        $flight->date = $this->db->jdate($obj->date);
55
                        $flight->lieuD = $obj->lieuD;
56
                        $flight->lieuA = $obj->lieuA;
57
                        $flight->heureD = $obj->heureD;
58
                        $flight->heureA = $obj->heureA;
59
                        $flight->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons;
60
                        $flight->nbrPax = $obj->nbrPax;
61
                        $flight->remarque = $obj->remarque;
62
                        $flight->incidents = $obj->incidents;
63
                        $flight->fk_type = $obj->fk_type;
64
                        $flight->fk_pilot = $obj->fk_pilot;
65
                        $flight->fk_organisateur = $obj->fk_organisateur;
66
                        $flight->is_facture = $obj->is_facture;
67
                        $flight->kilometers = $obj->kilometers;
68
                        $flight->cost = $obj->cost;
69
                        $flight->fk_receiver = $obj->fk_receiver;
70
                        $flight->justif_kilometers = $obj->justif_kilometers;
71
                        $flight->date_creation = $obj->date_creation;
72
                        $flight->date_update = $obj->date_update;
73
74
                        $array[] = $flight;
75
                    }
76
                    $i++;
77
                }
78
            }
79
        }
80
81
        return $array;
82
    }
83
84
}