|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\DataTables\Html\Editor; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Fluent; |
|
6
|
|
|
|
|
7
|
|
|
class Editor extends Fluent |
|
8
|
|
|
{ |
|
9
|
|
|
use HasEvents; |
|
10
|
|
|
|
|
11
|
|
|
const DISPLAY_LIGHTBOX = 'lightbox'; |
|
12
|
|
|
const DISPLAY_ENVELOPE = 'envelope'; |
|
13
|
|
|
const DISPLAY_BOOTSTRAP = 'bootstrap'; |
|
14
|
|
|
const DISPLAY_FOUNDATION = 'foundation'; |
|
15
|
|
|
const DISPLAY_JQUERYUI = 'jqueryui'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Editor constructor. |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $instance |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct($instance = 'editor') |
|
23
|
|
|
{ |
|
24
|
|
|
$attributes['instance'] = $instance; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
parent::__construct($attributes); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Make new Editor instance. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $instance |
|
33
|
|
|
* @return Editor |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function make($instance = 'editor') |
|
36
|
|
|
{ |
|
37
|
|
|
return new static($instance); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Append raw scripts. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $scripts |
|
44
|
|
|
* @return Editor |
|
45
|
|
|
*/ |
|
46
|
|
|
public function scripts($scripts) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->attributes['scripts'] = $scripts; |
|
49
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Set Editor's variable name / instance. |
|
55
|
|
|
* |
|
56
|
|
|
* @param $instance |
|
57
|
|
|
* @return $this |
|
58
|
|
|
*/ |
|
59
|
|
|
public function instance($instance) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->attributes['instance'] = $instance; |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Set Editor's ajax parameter. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string|array $ajax |
|
70
|
|
|
* @return $this |
|
71
|
|
|
* @see https://editor.datatables.net/reference/option/ajax |
|
72
|
|
|
*/ |
|
73
|
|
|
public function ajax($ajax) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->attributes['ajax'] = $ajax; |
|
76
|
|
|
|
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Set Editor's table source. |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $table |
|
84
|
|
|
* @return $this |
|
85
|
|
|
* @see https://editor.datatables.net/reference/option/table |
|
86
|
|
|
*/ |
|
87
|
|
|
public function table($table) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->attributes['table'] = $table; |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Set Editor's idSrc option. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $idSrc |
|
98
|
|
|
* @return $this |
|
99
|
|
|
* @see https://editor.datatables.net/reference/option/idSrc |
|
100
|
|
|
*/ |
|
101
|
|
|
public function idSrc($idSrc = 'DT_RowId') |
|
102
|
|
|
{ |
|
103
|
|
|
$this->attributes['idSrc'] = $idSrc; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Set Editor's display option. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $display |
|
112
|
|
|
* @return $this |
|
113
|
|
|
* @see https://editor.datatables.net/reference/option/display |
|
114
|
|
|
*/ |
|
115
|
|
|
public function display($display) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->attributes['display'] = $display; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Set Editor's fields. |
|
124
|
|
|
* |
|
125
|
|
|
* @param array $fields |
|
126
|
|
|
* @return $this |
|
127
|
|
|
* @see https://editor.datatables.net/reference/option/fields |
|
128
|
|
|
*/ |
|
129
|
|
|
public function fields(array $fields) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->attributes['fields'] = $fields; |
|
132
|
|
|
|
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Set Editor's language. |
|
138
|
|
|
* |
|
139
|
|
|
* @param array $language |
|
140
|
|
|
* @return $this |
|
141
|
|
|
* @see https://editor.datatables.net/reference/option/i18n |
|
142
|
|
|
*/ |
|
143
|
|
|
public function language(array $language) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->attributes['language'] = $language; |
|
146
|
|
|
|
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Set Editor's template. |
|
152
|
|
|
* |
|
153
|
|
|
* @param string $template |
|
154
|
|
|
* @return $this |
|
155
|
|
|
* @see https://editor.datatables.net/reference/option/template |
|
156
|
|
|
*/ |
|
157
|
|
|
public function template($template) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->attributes['template'] = $template; |
|
160
|
|
|
|
|
161
|
|
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.