Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created

ReportRepository::getReport()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 8.6737
c 0
b 0
f 0
cc 6
nc 12
nop 5
1
<?php namespace App\Modules\Reporting\Repositories;
2
3
use App\Modules\Core\BaseClasses\BaseRepository;
4
use App\Modules\Reporting\Report;
5
6
class ReportRepository extends BaseRepository
7
{
8
    /**
9
     * Init new object.
10
     *
11
     * @param   Report $model
12
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
13
     */
14
    public function __construct(Report $model)
15
    {
16
        parent::__construct($model);
17
    }
18
19
    /**
20
     * Render the given report db view based on the given
21
     * condition.
22
     *
23
     * @param  mixed   $report
24
     * @param  array   $conditions
25
     * @param  integer $perPage
26
     * @return object
27
     */
28
    public function renderReport($report, $conditions = [], $perPage = 0)
29
    {
30
        $report = ! is_int($report) ? $report : $this->find($report);
31
        /**
32
         * Fetch data from the report based on the given conditions.
33
         */
34
        $report = \DB::table($report->view_name);
35
        unset($conditions['page']);
36
        if (count($conditions)) {
37
            $conditions = $this->constructConditions($conditions, $this->model);
38
            $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
39
        }
40
        /**
41
         * Paginate or all data.
42
         */
43
        if ($perPage) {
44
            return $report->paginate($perPage);
45
        } else {
46
            return $report->get();
47
        }
48
    }
49
}
50