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