|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Display\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use SleepingOwl\Admin\Display\Element; |
|
7
|
|
|
use KodiComponents\Support\HtmlAttributes; |
|
8
|
|
|
use SleepingOwl\Admin\Traits\ElementViewTrait; |
|
9
|
|
|
use SleepingOwl\Admin\Contracts\Display\Placable; |
|
10
|
|
|
use SleepingOwl\Admin\Traits\ElementPlacementTrait; |
|
11
|
|
|
|
|
12
|
|
|
class ColumnsTotal extends Extension implements Placable |
|
13
|
|
|
{ |
|
14
|
|
|
use HtmlAttributes, ElementPlacementTrait, ElementViewTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string|\Illuminate\View\View |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $view = 'display.extensions.columns_total'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $placement = 'table.header'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Collection |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $elements; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->elements = new Collection(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function set(array $elements, $columnsNumber = 0) |
|
37
|
|
|
{ |
|
38
|
|
|
array_map(function ($element) { |
|
39
|
|
|
if (! is_object($element)) { |
|
40
|
|
|
$element = Element::create($element); |
|
41
|
|
|
} |
|
42
|
|
|
$this->elements->push($element); |
|
43
|
|
|
}, |
|
44
|
|
|
array_pad($elements, max($columnsNumber, count($elements)), '') |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function toArray() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->setHtmlAttribute('class', 'table table-striped'); |
|
53
|
|
|
|
|
54
|
|
|
return [ |
|
55
|
|
|
'elements' => $this->elements, |
|
56
|
|
|
'attributes' => $this->htmlAttributesToString(), |
|
57
|
|
|
'tag' => $this->getPlacement() == 'table.header' ? 'thead' : 'tfoot', |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|