Completed
Push — feature/api ( 725c17 )
by Laurent
02:31 queued 42s
created

Flightlog   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A get() 0 17 4
1
<?php
2
3
use Luracast\Restler\RestException;
4
5
dol_include_once('/flightlog/class/bbcvols.class.php');
6
7
/**
8
 * @author Laurent De Coninck <[email protected]>
9
 *
10
 * @smart-auto-routing false
11
 * @access protected
12
 * @class  DolibarrApiAccess {@requires user,external}
13
 */
14
class Flightlog extends DolibarrApi
15
{
16
    /**
17
     * @var array   $FIELDS     Mandatory fields, checked when create and update object
18
     */
19
    static $FIELDS = array(
20
        'id'
21
    );
22
23
    public $flight;
24
25
    public function __construct()
26
    {
27
        global $db, $conf;
28
29
        $this->db = $db;
30
        $this->flight = new Bbcvols($this->db);
31
    }
32
33
    /**
34
     * Get properties of a commercial proposal object
35
     *
36
     * Return an array with commercial proposal informations
37
     *
38
     * @param       int         $id         ID of commercial proposal
39
     * @return 	array|mixed data without useless information
40
     *
41
     * @throws 	RestException
42
     */
43
    public function get($id)
44
    {
45
        if(! DolibarrApiAccess::$user->rights->propal->lire) {
46
            throw new RestException(401);
47
        }
48
49
        $result = $this->flight->fetch($id);
50
        if( ! $result ) {
51
            throw new RestException(404, 'Flight not found');
52
        }
53
54
        if( ! DolibarrApi::_checkAccessToResource('flight',$this->flight->id)) {
55
            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
56
        }
57
58
        return $this->_cleanObjectDatas($this->flight);
59
    }
60
}