1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
6
|
|
|
* @package Admin |
7
|
|
|
* @subpackage JQAdm |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Admin\JQAdm\Dashboard\Job; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of dashboard job JQAdm client. |
16
|
|
|
* |
17
|
|
|
* @package Admin |
18
|
|
|
* @subpackage JQAdm |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base |
22
|
|
|
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** admin/jqadm/dashboard/job/name |
25
|
|
|
* Name of the job subpart used by the JQAdm dashboard implementation |
26
|
|
|
* |
27
|
|
|
* Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Dashboard\Job\Myname". |
28
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
29
|
|
|
* |
30
|
|
|
* @param string Last part of the JQAdm class name |
31
|
|
|
* @since 2017.08 |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Deletes a resource |
37
|
|
|
* |
38
|
|
|
* @return string|null Output to display or null for none |
39
|
|
|
*/ |
40
|
|
|
public function delete() : ?string |
41
|
|
|
{ |
42
|
|
|
$view = $this->view(); |
43
|
|
|
$context = $this->context(); |
44
|
|
|
$manager = \Aimeos\MAdmin::create( $context, 'job' ); |
45
|
|
|
$manager->begin(); |
46
|
|
|
|
47
|
|
|
try |
48
|
|
|
{ |
49
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) |
50
|
|
|
{ |
51
|
|
|
$msg = $this->context()->translate( 'admin', 'Required parameter "%1$s" is missing' ); |
52
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, 'id' ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$fs = $context->fs( 'fs-admin' ); |
56
|
|
|
$item = $manager->get( $id ); |
57
|
|
|
|
58
|
|
|
if( ( $path = $item->getPath() ) && $fs->has( $path ) ) { |
59
|
|
|
$fs->rm( $path ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$manager->delete( $id ); |
63
|
|
|
$manager->commit(); |
64
|
|
|
} |
65
|
|
|
catch( \Exception $e ) |
66
|
|
|
{ |
67
|
|
|
$manager->rollback(); |
68
|
|
|
$this->report( $e, 'delete' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->search(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns a single resource |
77
|
|
|
* |
78
|
|
|
* @return string|null Output to display or null for none |
79
|
|
|
*/ |
80
|
|
|
public function get() : ?string |
81
|
|
|
{ |
82
|
|
|
$view = $this->object()->data( $this->view() ); |
83
|
|
|
$context = $this->context(); |
84
|
|
|
|
85
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) |
86
|
|
|
{ |
87
|
|
|
$msg = $this->context()->translate( 'admin', 'Required parameter "%1$s" is missing' ); |
88
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, 'id' ) ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$fs = $context->fs( 'fs-admin' ); |
92
|
|
|
$item = \Aimeos\MAdmin::create( $context, 'job' )->get( $id ); |
93
|
|
|
|
94
|
|
|
if( ( $path = $item->getPath() ) && $fs->has( $path ) ) |
95
|
|
|
{ |
96
|
|
|
$stream = $view->response()->createStream( $fs->reads( $path ) ); |
97
|
|
|
$view->response()->withHeader( 'Content-Disposition', 'attachment; filename="' . $path . '"' ); |
98
|
|
|
$view->response()->withHeader( 'Content-Type', 'text/csv' ); |
99
|
|
|
$view->response()->withBody( $stream ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns a list of resource according to the conditions |
108
|
|
|
* |
109
|
|
|
* @return string Output to display |
110
|
|
|
*/ |
111
|
|
|
public function search() : ?string |
112
|
|
|
{ |
113
|
|
|
$view = $this->view(); |
114
|
|
|
$manager = \Aimeos\MAdmin::create( $this->context(), 'job' ); |
115
|
|
|
|
116
|
|
|
$search = $manager->filter()->order( ['-job.ctime', '-job.id'] ); |
117
|
|
|
$total = 0; |
118
|
|
|
|
119
|
|
|
$view->jobItems = $manager->search( $search, [], $total ); |
120
|
|
|
$view->jobBody = parent::search(); |
121
|
|
|
$view->jobTotal = $total; |
122
|
|
|
|
123
|
|
|
/** admin/jqadm/dashboard/job/template-list |
124
|
|
|
* Relative path to the HTML body template of the job subpart for the dashboard. |
125
|
|
|
* |
126
|
|
|
* The template file contains the HTML code and processing instructions |
127
|
|
|
* to generate the result shown in the body of the frontend. The |
128
|
|
|
* configuration string is the path to the template file relative |
129
|
|
|
* to the templates directory (usually in templates/admin/jqadm). |
130
|
|
|
* |
131
|
|
|
* You can overwrite the template file configuration in extensions and |
132
|
|
|
* provide alternative templates. These alternative templates should be |
133
|
|
|
* named like the default one but with the string "default" replaced by |
134
|
|
|
* an unique name. You may use the name of your project for this. If |
135
|
|
|
* you've implemented an alternative client class as well, "default" |
136
|
|
|
* should be replaced by the name of the new class. |
137
|
|
|
* |
138
|
|
|
* @param string Relative path to the template creating the HTML code |
139
|
|
|
* @since 2017.08 |
140
|
|
|
*/ |
141
|
|
|
$tplconf = 'admin/jqadm/dashboard/job/template-list'; |
142
|
|
|
$default = 'dashboard/list-job'; |
143
|
|
|
|
144
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Returns the sub-client given by its name. |
150
|
|
|
* |
151
|
|
|
* @param string $type Name of the client type |
152
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
153
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
154
|
|
|
*/ |
155
|
|
|
public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Admin\JQAdm\Iface |
156
|
|
|
{ |
157
|
|
|
/** admin/jqadm/dashboard/job/decorators/excludes |
158
|
|
|
* Excludes decorators added by the "common" option from the dashboard JQAdm client |
159
|
|
|
* |
160
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
161
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
162
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
163
|
|
|
* modify what is returned to the caller. |
164
|
|
|
* |
165
|
|
|
* This option allows you to remove a decorator added via |
166
|
|
|
* "admin/jqadm/common/decorators/default" before they are wrapped |
167
|
|
|
* around the JQAdm client. |
168
|
|
|
* |
169
|
|
|
* admin/jqadm/dashboard/job/decorators/excludes = array( 'decorator1' ) |
170
|
|
|
* |
171
|
|
|
* This would remove the decorator named "decorator1" from the list of |
172
|
|
|
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via |
173
|
|
|
* "admin/jqadm/common/decorators/default" to the JQAdm client. |
174
|
|
|
* |
175
|
|
|
* @param array List of decorator names |
176
|
|
|
* @since 2017.08 |
177
|
|
|
* @see admin/jqadm/common/decorators/default |
178
|
|
|
* @see admin/jqadm/dashboard/job/decorators/global |
179
|
|
|
* @see admin/jqadm/dashboard/job/decorators/local |
180
|
|
|
*/ |
181
|
|
|
|
182
|
|
|
/** admin/jqadm/dashboard/job/decorators/global |
183
|
|
|
* Adds a list of globally available decorators only to the dashboard JQAdm client |
184
|
|
|
* |
185
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
186
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
187
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
188
|
|
|
* modify what is returned to the caller. |
189
|
|
|
* |
190
|
|
|
* This option allows you to wrap global decorators |
191
|
|
|
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. |
192
|
|
|
* |
193
|
|
|
* admin/jqadm/dashboard/job/decorators/global = array( 'decorator1' ) |
194
|
|
|
* |
195
|
|
|
* This would add the decorator named "decorator1" defined by |
196
|
|
|
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. |
197
|
|
|
* |
198
|
|
|
* @param array List of decorator names |
199
|
|
|
* @since 2017.08 |
200
|
|
|
* @see admin/jqadm/common/decorators/default |
201
|
|
|
* @see admin/jqadm/dashboard/job/decorators/excludes |
202
|
|
|
* @see admin/jqadm/dashboard/job/decorators/local |
203
|
|
|
*/ |
204
|
|
|
|
205
|
|
|
/** admin/jqadm/dashboard/job/decorators/local |
206
|
|
|
* Adds a list of local decorators only to the dashboard JQAdm client |
207
|
|
|
* |
208
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
209
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
210
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
211
|
|
|
* modify what is returned to the caller. |
212
|
|
|
* |
213
|
|
|
* This option allows you to wrap local decorators |
214
|
|
|
* ("\Aimeos\Admin\JQAdm\Dashboard\Decorator\*") around the JQAdm client. |
215
|
|
|
* |
216
|
|
|
* admin/jqadm/dashboard/job/decorators/local = array( 'decorator2' ) |
217
|
|
|
* |
218
|
|
|
* This would add the decorator named "decorator2" defined by |
219
|
|
|
* "\Aimeos\Admin\JQAdm\Dashboard\Decorator\Decorator2" only to the JQAdm client. |
220
|
|
|
* |
221
|
|
|
* @param array List of decorator names |
222
|
|
|
* @since 2017.08 |
223
|
|
|
* @see admin/jqadm/common/decorators/default |
224
|
|
|
* @see admin/jqadm/dashboard/job/decorators/excludes |
225
|
|
|
* @see admin/jqadm/dashboard/job/decorators/global |
226
|
|
|
*/ |
227
|
|
|
return $this->createSubClient( 'dashboard/job/' . $type, $name ); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Returns the list of sub-client names configured for the client. |
233
|
|
|
* |
234
|
|
|
* @return array List of JQAdm client names |
235
|
|
|
*/ |
236
|
|
|
protected function getSubClientNames() : array |
237
|
|
|
{ |
238
|
|
|
/** admin/jqadm/dashboard/job/subparts |
239
|
|
|
* List of JQAdm sub-clients rendered within the dashboard job section |
240
|
|
|
* |
241
|
|
|
* The output of the frontend is composed of the code generated by the JQAdm |
242
|
|
|
* clients. Each JQAdm client can consist of serveral (or none) sub-clients |
243
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
244
|
|
|
* sub-clients can contain JQAdm clients themselves and therefore a |
245
|
|
|
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates |
246
|
|
|
* the output that is placed inside the container of its parent. |
247
|
|
|
* |
248
|
|
|
* At first, always the JQAdm code generated by the parent is printed, then |
249
|
|
|
* the JQAdm code of its sub-clients. The job of the JQAdm sub-clients |
250
|
|
|
* determines the job of the output of these sub-clients inside the parent |
251
|
|
|
* container. If the configured list of clients is |
252
|
|
|
* |
253
|
|
|
* array( "subclient1", "subclient2" ) |
254
|
|
|
* |
255
|
|
|
* you can easily change the job of the output by reordering the subparts: |
256
|
|
|
* |
257
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) |
258
|
|
|
* |
259
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
260
|
|
|
* |
261
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1" ) |
262
|
|
|
* |
263
|
|
|
* As the clients only generates structural JQAdm, the layout defined via CSS |
264
|
|
|
* should support adding, removing or reordering content by a fluid like |
265
|
|
|
* design. |
266
|
|
|
* |
267
|
|
|
* @param array List of sub-client names |
268
|
|
|
* @since 2017.08 |
269
|
|
|
*/ |
270
|
|
|
return $this->context()->config()->get( 'admin/jqadm/dashboard/job/subparts', [] ); |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|