Completed
Push — master ( 928d8a...2f7023 )
by Arjay
07:15
created

RowProcessor::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\DataTables\Processors;
4
5
use Illuminate\Support\Arr;
6
use Yajra\DataTables\Utilities\Helper;
7
8
class RowProcessor
9
{
10
    /**
11
     * @var mixed
12
     */
13
    private $data;
14
15
    /**
16
     * @var mixed
17
     */
18
    private $row;
19
20
    /**
21
     * @param mixed $data
22
     * @param mixed $row
23
     */
24
    public function __construct($data, $row)
25
    {
26
        $this->data = $data;
27
        $this->row  = $row;
28
    }
29
30
    /**
31
     * Process DT RowId and Class value.
32
     *
33
     * @param string          $attribute
34
     * @param string|callable $template
35
     * @return $this
36
     */
37
    public function rowValue($attribute, $template)
38
    {
39
        if (!empty($template)) {
40
            if (!is_callable($template) && Arr::get($this->data, $template)) {
41
                $this->data[$attribute] = Arr::get($this->data, $template);
42
            } else {
43
                $this->data[$attribute] = Helper::compileContent($template, $this->data, $this->row);
44
            }
45
        }
46
47
        return $this;
48
    }
49
50
    /**
51
     * Process DT Row Data and Attr.
52
     *
53
     * @param string $attribute
54
     * @param array  $template
55
     * @return $this
56
     */
57
    public function rowData($attribute, array $template)
58
    {
59
        if (count($template)) {
60
            $this->data[$attribute] = [];
61
            foreach ($template as $key => $value) {
62
                $this->data[$attribute][$key] = Helper::compileContent($value, $this->data, $this->row);
63
            }
64
        }
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    public function getData()
73
    {
74
        return $this->data;
75
    }
76
}
77