ReservationExport   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exportData() 0 19 2
A getStatusIdOptions() 0 4 1
1
<?php namespace VojtaSvoboda\Reservations\Models;
2
3
use Backend\Facades\BackendAuth;
4
use Backend\Models\ExportModel;
5
use Config;
6
7
/**
8
 * Reservation's export.
9
 *
10
 * @package VojtaSvoboda\Reservations\Models
11
 */
12
class ReservationExport extends ExportModel
13
{
14
    public $table = 'vojtasvoboda_reservations_reservations';
15
16
    public $dates = ['created_at', 'updated_at', 'deleted_at'];
17
18
    public $belongsTo = [
19
        'status' => 'VojtaSvoboda\Reservations\Models\Status',
20
    ];
21
22
    public $fillable = [
23
        'status_enabled', 'status',
24
    ];
25
26
    /**
27
     * Prepare data for export.
28
     *
29
     * @param $columns
30
     * @param $sessionKey
31
     *
32
     * @return array
33
     */
34
    public function exportData($columns, $sessionKey = null)
35
    {
36
        $query = Reservation::query();
37
38
        // filter by status
39
        if ($this->status_enabled) {
40
            $query->where('status_id', $this->status_id);
41
        }
42
43
        // prepare columns
44
        $reservations = $query->get();
45
        $reservations->each(function($item) use ($columns)
46
        {
47
            $item->addVisible($columns);
48
            $item->status_id = $item->status->name;
49
        });
50
51
        return $reservations->toArray();
52
    }
53
54
    /**
55
     * Get all available statuses.
56
     *
57
     * @return mixed
58
     */
59
    public static function getStatusIdOptions()
60
    {
61
        return Status::orderBy('sort_order')->lists('name', 'id');
62
    }
63
}
64