Completed
Push — master ( 3c5c0f...ec5ff6 )
by Laurent
01:40
created

BalloonSelect   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildOptions() 0 23 4
1
<?php
2
/**
3
 *
4
 */
5
6
namespace flightlog\form;
7
8
/**
9
 * @author Laurent De Coninck <[email protected]>
10
 */
11
class BalloonSelect extends Select
12
{
13
    /**
14
     * @var \DoliDB
15
     */
16
    private $db;
17
18
    /**
19
     * @inheritDoc
20
     */
21
    public function __construct($name, \DoliDB $db, array $options = [])
22
    {
23
        parent::__construct($name, $options);
24
        $this->db = $db;
25
        $this->buildOptions();
26
    }
27
28
    /**
29
     * Builds the options values of the select.
30
     */
31
    private function buildOptions()
32
    {
33
        $sql = "SELECT";
34
        $sql .= " t.rowid,";
35
        $sql .= " t.immat,";
36
        $sql .= " t.is_disable";
37
        $sql .= " FROM llx_bbc_ballons as t";
38
        $sql .= " WHERE t.is_disable = 0";
39
        $sql .= " ORDER BY t.immat";
40
41
        $resql = $this->db->query($sql);
42
        if ($resql) {
43
            $num = $this->db->num_rows($resql);
44
            $i = 0;
45
            if ($num) {
46
                while ($i < $num) {
47
                    $obj = $this->db->fetch_object($resql);
48
                    $this->addValueOption($obj->rowid, $obj->immat);
49
                    $i++;
50
                }
51
            }
52
        }
53
    }
54
}