-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDatagridHelper.php
120 lines (103 loc) · 2.3 KB
/
DatagridHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Lykegenes\DatagridBuilder;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\View\Factory as View;
use Illuminate\Http\Request;
class DatagridHelper
{
/**
* @var View
*/
protected $view;
/**
* @var Config
*/
protected $config;
/**
* @var Request
*/
protected $request;
/**
* @var DatagridBuilder
*/
protected $datagridBuilder;
/**
* @param View $view
* @param Request $request
* @param array $config
*/
public function __construct(View $view, Request $request, Config $config)
{
$this->view = $view;
$this->config = $config;
$this->request = $request;
}
/**
* @param string $key
* @param string $default
* @return string
*/
public function getConfig($key, $default = null)
{
return $this->config->get('datagrid-builder.'.$key, $default);
}
/**
* @return View
*/
public function getView()
{
return $this->view;
}
/**
* @return Request
*/
public function getRequest()
{
return $this->request;
}
/**
* Merge options array.
*
* @param array $first
* @param array $second
* @return array
*/
public function mergeOptions(array $first, array $second)
{
return array_replace_recursive($first, $second);
}
/**
* Convert array of attributes to html attributes.
*
* @param $options
* @return string
*/
public function prepareAttributes($options)
{
if (! $options) {
return;
}
$attributes = [];
foreach ($options as $name => $option) {
if ($option !== null) {
$name = is_numeric($name) ? $option : $name;
$option = is_bool($option) ? ($option ? 'true' : 'false') : $option;
$attributes[] = $name.'="'.$option.'" ';
}
}
return implode('', $attributes);
}
/**
* Format the label to the proper format.
*
* @param string $name
* @return string
*/
public function formatLabel($name)
{
if (! $name) {
return;
}
return ucwords(str_replace('_', ' ', $name));
}
}