|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File class of WPS_Mass_List_Table. |
|
4
|
|
|
* |
|
5
|
|
|
* @package wps-mass-interface3 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
9
|
|
|
exit; |
|
10
|
|
|
} |
|
11
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
|
12
|
|
|
include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13
|
|
|
} |
|
14
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
|
15
|
|
|
exit( 'class-wp-list-table.php not found.' ); |
|
16
|
|
|
} |
|
17
|
|
|
/** |
|
18
|
|
|
* Custom WP_List_Table to edit attributes from WPShop EAV. |
|
19
|
|
|
*/ |
|
20
|
|
|
class WPS_Mass_List_Table extends WP_List_Table { |
|
21
|
|
|
/** |
|
22
|
|
|
* Static variable to keep values options from getted attributes. |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
public static $wpsdb_values_options = array(); |
|
27
|
|
|
/** |
|
28
|
|
|
* Stock of getted items from request. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
public $columns_items = array(); |
|
33
|
|
|
/** |
|
34
|
|
|
* Columns to show |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
public $show_columns = array(); |
|
39
|
|
|
/** |
|
40
|
|
|
* Current screen. |
|
41
|
|
|
* |
|
42
|
|
|
* @var WP_Screen |
|
43
|
|
|
*/ |
|
44
|
|
|
public $screen; |
|
45
|
|
|
/** |
|
46
|
|
|
* Product entity. See wpshop_entities::get_entity_identifier_from_code(). |
|
47
|
|
|
* |
|
48
|
|
|
* @var int |
|
49
|
|
|
*/ |
|
50
|
|
|
public $entity_id; |
|
51
|
|
|
/** |
|
52
|
|
|
* Attributes codes exception in query. |
|
53
|
|
|
* |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
public $exclude_attribute_codes = array(); |
|
57
|
|
|
/** |
|
58
|
|
|
* Current view. Attribute group. |
|
59
|
|
|
* |
|
60
|
|
|
* @var int |
|
61
|
|
|
*/ |
|
62
|
|
|
public $current_view = null; |
|
63
|
|
|
/** |
|
64
|
|
|
* Instance of each views count. |
|
65
|
|
|
* |
|
66
|
|
|
* @var array |
|
67
|
|
|
*/ |
|
68
|
|
|
private $_views = null; |
|
69
|
|
|
/** |
|
70
|
|
|
* Requested post types. |
|
71
|
|
|
* |
|
72
|
|
|
* @var array |
|
73
|
|
|
*/ |
|
74
|
|
|
private $_post_types; |
|
75
|
|
|
/** |
|
76
|
|
|
* Construct with args value like WP_List_Table. See WP_List_Table::__construct(). |
|
77
|
|
|
* |
|
78
|
|
|
* @method __construct |
|
79
|
|
|
* @param array $args New key : exclude_attribute_codes. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __construct( $args ) { |
|
82
|
|
|
if ( isset( $args['exclude_attribute_codes'] ) ) { |
|
83
|
|
|
$this->exclude_attribute_codes = $args['exclude_attribute_codes']; |
|
84
|
|
|
} |
|
85
|
|
|
parent::__construct( |
|
86
|
|
|
array( |
|
87
|
|
|
'plural' => 'posts', |
|
88
|
|
|
'ajax' => true, |
|
89
|
|
|
'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
90
|
|
|
) |
|
91
|
|
|
); |
|
92
|
|
|
$this->current_view = (int) substr( $this->screen->id, strpos( $this->screen->id, '_att_set_' ) + 9 ); |
|
93
|
|
|
$this->entity_id = (int) wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
94
|
|
|
$this->_post_types = array( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ); |
|
95
|
|
|
} |
|
96
|
|
|
/** |
|
97
|
|
|
* List columns. |
|
98
|
|
|
* |
|
99
|
|
|
* @method get_columns |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
public function get_columns() { |
|
103
|
|
|
$columns = array( |
|
104
|
|
|
'cb' => '<input type="checkbox" />', |
|
105
|
|
|
'title' => __( 'Title' ), |
|
106
|
|
|
'thumbnail' => __( 'Thumbnail' ), |
|
107
|
|
|
); |
|
108
|
|
|
foreach ( $this->request_items_columns() as $column => $data_column ) { |
|
109
|
|
|
if ( ! empty( $column ) && ! empty( $data_column ) ) { |
|
110
|
|
|
$columns[ $column ] = $data_column['name']; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
$columns['date'] = __( 'Date' ); |
|
114
|
|
|
return $columns; |
|
115
|
|
|
} |
|
116
|
|
|
/** |
|
117
|
|
|
* List sortable columns. |
|
118
|
|
|
* |
|
119
|
|
|
* @method get_sortable_columns |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
protected function get_sortable_columns() { |
|
123
|
|
|
$sortable_columns = array( |
|
124
|
|
|
'title' => array( 'title', false ), |
|
125
|
|
|
'thumbnail' => array( 'thumbnail', false ), |
|
126
|
|
|
'date' => array( 'p.post_date', false ), |
|
127
|
|
|
); |
|
128
|
|
|
foreach ( $this->request_items_columns() as $column => $data_column ) { |
|
129
|
|
|
$sortable_columns[ $column ] = array( $data_column['code'], false ); |
|
130
|
|
|
} |
|
131
|
|
|
return $sortable_columns; |
|
132
|
|
|
} |
|
133
|
|
|
/** |
|
134
|
|
|
* Default display of content column. |
|
135
|
|
|
* |
|
136
|
|
|
* @method column_default |
|
137
|
|
|
* @param array $item Result of sql query. |
|
138
|
|
|
* @param string $column_name Current column. |
|
139
|
|
|
* @return string |
|
140
|
|
|
*/ |
|
141
|
|
|
public function column_default( $item, $column_name ) { |
|
142
|
|
|
if ( isset( $this->columns_items[ $column_name ] ) && is_callable( array( $this, "column_data_{$this->columns_items[ $column_name ]['type']}" ) ) ) { |
|
143
|
|
|
$callable_ext = str_replace( '-', '_', $this->columns_items[ $column_name ]['type'] ); |
|
144
|
|
|
if ( ! method_exists( $this, "column_data_{$callable_ext}" ) ) { |
|
145
|
|
|
$callable_ext = 'text'; |
|
146
|
|
|
} |
|
147
|
|
|
$callable = array( $this, "column_data_{$callable_ext}" ); |
|
148
|
|
|
return call_user_func( |
|
149
|
|
|
$callable, |
|
150
|
|
|
(int) $this->columns_items[ $column_name ]['id'], |
|
151
|
|
|
$this->columns_items[ $column_name ]['code'], |
|
152
|
|
|
$this->columns_items[ $column_name ]['data'], |
|
153
|
|
|
$item |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
return print_r( $item[ $column_name ], true ); |
|
157
|
|
|
} |
|
158
|
|
|
/** |
|
159
|
|
|
* Column content for checkbox. |
|
160
|
|
|
* |
|
161
|
|
|
* @method column_cb |
|
162
|
|
|
* @param array $item Result of sql query. |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
|
|
public function column_cb( $item ) { |
|
166
|
|
|
return sprintf( |
|
167
|
|
|
'<input type="checkbox" name="cb[]" value="%d" />', |
|
168
|
|
|
$item['ID'] |
|
169
|
|
|
); |
|
170
|
|
|
} |
|
171
|
|
|
/** |
|
172
|
|
|
* Column content for thumbnail. |
|
173
|
|
|
* |
|
174
|
|
|
* @method column_thumbnail |
|
175
|
|
|
* @param array $item Result of sql query. |
|
176
|
|
|
* @return string |
|
177
|
|
|
*/ |
|
178
|
|
|
public function column_thumbnail( $item ) { |
|
179
|
|
|
$thumbnail_id = ''; |
|
180
|
|
|
$link_content = get_the_post_thumbnail( $item['ID'], array( 25, 25 ) ); |
|
181
|
|
|
if ( ! empty( $link_content ) ) { |
|
182
|
|
|
$link_content = "<span class=\"img\">{$link_content}</span>"; |
|
183
|
|
|
$thumbnail_id = get_post_thumbnail_id( $item['ID'] ); |
|
184
|
|
|
} |
|
185
|
|
|
$popup_title = __( 'Choose Image' ); |
|
|
|
|
|
|
186
|
|
|
return sprintf( |
|
187
|
|
|
'<input type="hidden" name="row_%1$s[thumbnail]" value="%2$s"><a href="#thumbnail" data-media-title="%3$s">%4$s<span class="text">%3$s</span></a>', |
|
188
|
|
|
$item['ID'], |
|
189
|
|
|
$thumbnail_id, |
|
190
|
|
|
__( 'Choose Image' ), |
|
191
|
|
|
$link_content |
|
192
|
|
|
); |
|
193
|
|
|
} |
|
194
|
|
|
public function column_date( $item ) { |
|
195
|
|
|
global $mode; |
|
196
|
|
|
|
|
197
|
|
|
if ( '0000-00-00 00:00:00' === $item['pdate'] ) { |
|
198
|
|
|
$t_time = $h_time = __( 'Unpublished' ); |
|
199
|
|
|
$time_diff = 0; |
|
200
|
|
|
} else { |
|
201
|
|
|
$t_time = get_the_time( __( 'Y/m/d g:i:s a' ) ); |
|
202
|
|
|
$m_time = $item['pdate']; |
|
203
|
|
|
$time = get_post_time( 'G', true, $item['ID'] ); |
|
204
|
|
|
|
|
205
|
|
|
$time_diff = time() - $time; |
|
206
|
|
|
|
|
207
|
|
|
if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { |
|
208
|
|
|
$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); |
|
209
|
|
|
} else { |
|
210
|
|
|
$h_time = mysql2date( __( 'Y/m/d' ), $m_time ); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
if ( 'publish' === $item['status'] ) { |
|
215
|
|
|
_e( 'Published' ); |
|
216
|
|
|
} elseif ( 'future' === $item['status'] ) { |
|
217
|
|
|
if ( $time_diff > 0 ) { |
|
218
|
|
|
echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>'; |
|
219
|
|
|
} else { |
|
220
|
|
|
_e( 'Scheduled' ); |
|
221
|
|
|
} |
|
222
|
|
|
} else { |
|
223
|
|
|
_e( 'Last Modified' ); |
|
224
|
|
|
} |
|
225
|
|
|
echo '<br />'; |
|
226
|
|
|
echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; |
|
227
|
|
|
} |
|
228
|
|
|
/** |
|
229
|
|
|
* Column content for title. |
|
230
|
|
|
* |
|
231
|
|
|
* @method column_title |
|
232
|
|
|
* @param array $item Result of sql query. |
|
233
|
|
|
* @return string |
|
234
|
|
|
*/ |
|
235
|
|
|
public function column_title( $item ) { |
|
236
|
|
|
if ( 'private' === $item['status'] ) { |
|
237
|
|
|
$post_states['private'] = __( 'Private' ); |
|
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
if ( 'draft' === $item['status'] ) { |
|
240
|
|
|
$post_states['draft'] = __( 'Draft' ); |
|
|
|
|
|
|
241
|
|
|
} |
|
242
|
|
|
if ( 'pending' === $item['status'] ) { |
|
243
|
|
|
$post_states['pending'] = _x( 'Pending', 'post status' ); |
|
244
|
|
|
} |
|
245
|
|
|
if ( 'future' === $item['status'] ) { |
|
246
|
|
|
$post_states['scheduled'] = __( 'Scheduled' ); |
|
247
|
|
|
} |
|
248
|
|
|
if ( current_user_can( 'edit_post', $item['ID'] ) && 'trash' !== $item['status'] ) { |
|
249
|
|
|
$result = sprintf( |
|
250
|
|
|
'<a class="row-title" href="%s" aria-label="%s">%s</a>', |
|
251
|
|
|
get_edit_post_link( $item['ID'] ), |
|
252
|
|
|
// translators: WordPress translate. |
|
253
|
|
|
esc_attr( sprintf( __( '“%s” (Edit)' ), $item['title'] ) ), |
|
254
|
|
|
$item['title'] |
|
255
|
|
|
); |
|
256
|
|
|
} else { |
|
257
|
|
|
$result = $item['title']; |
|
258
|
|
|
} |
|
259
|
|
|
if ( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item['type'] ) { |
|
260
|
|
|
$attr_def = get_post_meta( $item['ID'], '_wpshop_variations_attribute_def', true ); |
|
261
|
|
|
$columns_items = $this->request_items_columns(); |
|
262
|
|
|
$first_variation = true; |
|
263
|
|
|
$parent = $this->items[ $item['parent'] ]; |
|
264
|
|
|
foreach ( $attr_def as $key => $value ) { |
|
265
|
|
|
foreach ( $this->get_select_items_option( $columns_items[ $key ]['id'] ) as $all_value ) { |
|
266
|
|
|
if ( $all_value['id'] === $value ) { |
|
267
|
|
|
if ( $first_variation ) { |
|
268
|
|
|
$result = $parent['title'] . ' : '; |
|
269
|
|
|
$first_variation = false; |
|
270
|
|
|
} else { |
|
271
|
|
|
$result .= ' / '; |
|
272
|
|
|
} |
|
273
|
|
|
$result .= $all_value['label']; |
|
274
|
|
|
break; |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
if ( ! empty( $post_states ) ) { |
|
280
|
|
|
$state_count = count( $post_states ); |
|
281
|
|
|
$i = 0; |
|
282
|
|
|
$result .= ' — '; |
|
283
|
|
|
foreach ( $post_states as $state ) { |
|
284
|
|
|
++$i; |
|
285
|
|
|
( $i === $state_count ) ? $sep = '' : $sep = ', '; |
|
286
|
|
|
$result .= "<span class='post-state'>$state$sep</span>"; |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
return sprintf( |
|
290
|
|
|
'<strong>%s</strong>', |
|
291
|
|
|
isset( $item['lvl'] ) ? $item['lvl'] . $result : $result |
|
292
|
|
|
); |
|
293
|
|
|
} |
|
294
|
|
|
/** |
|
295
|
|
|
* Column default content for EAV data. (Not used) |
|
296
|
|
|
* |
|
297
|
|
|
* @method column_data_default |
|
298
|
|
|
* @param int $attribute_id Attribute ID. |
|
299
|
|
|
* @param string $attribute_code Attribute code. |
|
300
|
|
|
* @param string $attribute_data Attribute type ( ex:Varchar, Integer, Datetime ... ). |
|
301
|
|
|
* @param array $item Result of sql query. |
|
302
|
|
|
* @return string |
|
303
|
|
|
*/ |
|
304
|
|
|
public function column_data_default( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
305
|
|
|
return 'default'; |
|
306
|
|
|
} |
|
307
|
|
|
/** |
|
308
|
|
|
* Column content for EAV data displayed as text (replace column default). |
|
309
|
|
|
* |
|
310
|
|
|
* @method column_data_text |
|
311
|
|
|
* @param int $attribute_id Attribute ID. |
|
312
|
|
|
* @param string $attribute_code Attribute code. |
|
313
|
|
|
* @param string $attribute_data Attribute type ( ex:Varchar, Integer, Datetime ... ). |
|
314
|
|
|
* @param array $item Result of sql query. |
|
315
|
|
|
* @return string |
|
316
|
|
|
*/ |
|
317
|
|
View Code Duplication |
public function column_data_text( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
|
|
|
|
|
318
|
|
|
$unit = ''; |
|
319
|
|
|
if ( is_array( $item[ $attribute_code ] ) ) { |
|
320
|
|
|
$unit = ' ' . $item[ $attribute_code ]['unit']; |
|
321
|
|
|
$value = $item[ $attribute_code ]['value']; |
|
322
|
|
|
} else { |
|
323
|
|
|
$value = $item[ $attribute_code ]; |
|
324
|
|
|
} |
|
325
|
|
|
return sprintf( |
|
326
|
|
|
'<input type="text" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]" value="%4$s">', |
|
327
|
|
|
$attribute_code, |
|
328
|
|
|
$item['ID'], |
|
329
|
|
|
$attribute_data, |
|
330
|
|
|
$value, |
|
331
|
|
|
$unit |
|
332
|
|
|
); |
|
333
|
|
|
} |
|
334
|
|
|
/** |
|
335
|
|
|
* Column content for EAV data displayed as select. |
|
336
|
|
|
* |
|
337
|
|
|
* @method column_data_select |
|
338
|
|
|
* @param int $attribute_id Attribute ID. |
|
339
|
|
|
* @param string $attribute_code Attribute code. |
|
340
|
|
|
* @param string $attribute_data Attribute type ( ex:Varchar, Integer, Datetime ... ). |
|
341
|
|
|
* @param array $item Result of sql query. |
|
342
|
|
|
* @return string |
|
343
|
|
|
*/ |
|
344
|
|
|
public function column_data_select( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
345
|
|
|
$unit = ''; |
|
346
|
|
|
if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) { |
|
347
|
|
|
$unit = ' ' . $item[ $attribute_code ]['unit']; |
|
348
|
|
|
$value = $item[ $attribute_code ]['value']; |
|
349
|
|
|
} else { |
|
350
|
|
|
$value = $item[ $attribute_code ]; |
|
351
|
|
|
} |
|
352
|
|
|
$has_selected = false; |
|
353
|
|
|
$select_items = array(); |
|
354
|
|
|
foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) { |
|
355
|
|
|
if ( is_array( $value ) ) { |
|
356
|
|
|
foreach ( $value as $val ) { |
|
357
|
|
|
$selected = selected( $val, $option_item['id'], false ); |
|
358
|
|
|
if ( ! empty( $selected ) ) { |
|
359
|
|
|
break; |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
} else { |
|
363
|
|
|
$selected = selected( $value, $option_item['id'], false ); |
|
364
|
|
|
} |
|
365
|
|
|
$has_selected = empty( $selected ) ? $has_selected : true; |
|
366
|
|
|
$select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>"; |
|
|
|
|
|
|
367
|
|
|
} |
|
368
|
|
|
if ( ! $has_selected ) { |
|
369
|
|
|
array_unshift( $select_items, '<option selected disabled>' . __( 'None' ) . '</option>' ); |
|
370
|
|
|
} |
|
371
|
|
|
$select_items = implode( '', $select_items ); |
|
372
|
|
|
return sprintf( |
|
373
|
|
|
'<select name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</select>', |
|
374
|
|
|
$attribute_code, |
|
375
|
|
|
$item['ID'], |
|
376
|
|
|
$attribute_data, |
|
377
|
|
|
$select_items, |
|
378
|
|
|
$unit |
|
379
|
|
|
); |
|
380
|
|
|
} |
|
381
|
|
|
/** |
|
382
|
|
|
* Column content for EAV data displayed as textarea. |
|
383
|
|
|
* |
|
384
|
|
|
* @method column_data_textarea |
|
385
|
|
|
* @param int $attribute_id Attribute ID. |
|
386
|
|
|
* @param string $attribute_code Attribute code. |
|
387
|
|
|
* @param string $attribute_data Attribute type ( ex:Varchar, Integer, Datetime ... ). |
|
388
|
|
|
* @param array $item Result of sql query. |
|
389
|
|
|
* @return string |
|
390
|
|
|
*/ |
|
391
|
|
View Code Duplication |
public function column_data_textarea( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
|
|
|
|
|
392
|
|
|
$unit = ''; |
|
393
|
|
|
if ( is_array( $item[ $attribute_code ] ) ) { |
|
394
|
|
|
$unit = ' ' . $item[ $attribute_code ]['unit']; |
|
395
|
|
|
$value = $item[ $attribute_code ]['value']; |
|
396
|
|
|
} else { |
|
397
|
|
|
$value = $item[ $attribute_code ]; |
|
398
|
|
|
} |
|
399
|
|
|
return sprintf( |
|
400
|
|
|
'<textarea name="row_%2$s[wpshop_product_attribute][%3$s][%1$s]">%4$s</textarea>', |
|
401
|
|
|
$attribute_code, |
|
402
|
|
|
$item['ID'], |
|
403
|
|
|
$attribute_data, |
|
404
|
|
|
$value, |
|
405
|
|
|
$unit |
|
406
|
|
|
); |
|
407
|
|
|
} |
|
408
|
|
|
/** |
|
409
|
|
|
* Column content for EAV data displayed as multiple values. |
|
410
|
|
|
* |
|
411
|
|
|
* @method column_data_multiple_select |
|
412
|
|
|
* @param int $attribute_id Attribute ID. |
|
413
|
|
|
* @param string $attribute_code Attribute code. |
|
414
|
|
|
* @param string $attribute_data Attribute type ( ex:Varchar, Integer, Datetime ... ). |
|
415
|
|
|
* @param array $item Result of sql query. |
|
416
|
|
|
* @return string |
|
417
|
|
|
*/ |
|
418
|
|
|
public function column_data_multiple_select( $attribute_id, $attribute_code, $attribute_data, $item ) { |
|
419
|
|
|
$unit = ''; |
|
420
|
|
|
if ( is_array( $item[ $attribute_code ] ) && isset( $item[ $attribute_code ]['unit'] ) ) { |
|
421
|
|
|
$unit = ' ' . $item[ $attribute_code ]['unit']; |
|
422
|
|
|
$value = $item[ $attribute_code ]['value']; |
|
423
|
|
|
} else { |
|
424
|
|
|
$value = $item[ $attribute_code ]; |
|
425
|
|
|
} |
|
426
|
|
|
$select_items = array(); |
|
427
|
|
|
foreach ( $this->get_select_items_option( $attribute_id ) as $option_item ) { |
|
428
|
|
|
if ( is_array( $value ) ) { |
|
429
|
|
|
foreach ( $value as $val ) { |
|
430
|
|
|
$selected = selected( $val, $option_item['id'], false ); |
|
431
|
|
|
if ( ! empty( $selected ) ) { |
|
432
|
|
|
break; |
|
433
|
|
|
} |
|
434
|
|
|
} |
|
435
|
|
|
} else { |
|
436
|
|
|
$selected = selected( $value, $option_item['id'], false ); |
|
437
|
|
|
} |
|
438
|
|
|
$select_items[] = "<option value=\"{$option_item['id']}\"{$selected}>{$option_item['label']}</option>"; |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
$select_items = implode( '', $select_items ); |
|
441
|
|
|
return sprintf( |
|
442
|
|
|
'<select class="chosen-select" multiple data-placeholder="%6$s" name="row_%2$s[wpshop_product_attribute][%3$s][%1$s][]">%4$s</select>', |
|
443
|
|
|
$attribute_code, |
|
444
|
|
|
$item['ID'], |
|
445
|
|
|
$attribute_data, |
|
446
|
|
|
$select_items, |
|
447
|
|
|
$unit, |
|
448
|
|
|
'Select some options' |
|
449
|
|
|
); |
|
450
|
|
|
} |
|
451
|
|
|
/** |
|
452
|
|
|
* Query function. |
|
453
|
|
|
* |
|
454
|
|
|
* @method request |
|
455
|
|
|
* @param Mixed $id_post Null = all / Int = single. |
|
456
|
|
|
* @return array Return all values with ARRAY_A. |
|
457
|
|
|
*/ |
|
458
|
|
|
public function request( $id_post = null ) { |
|
459
|
|
|
global $wpdb; |
|
460
|
|
|
$per_page = $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) ); |
|
461
|
|
|
$include_states = array( |
|
462
|
|
|
'publish', |
|
463
|
|
|
'future', |
|
464
|
|
|
'draft', |
|
465
|
|
|
'pending', |
|
466
|
|
|
'private', |
|
467
|
|
|
'trash', |
|
468
|
|
|
'scheduled', |
|
469
|
|
|
); |
|
470
|
|
|
$include_states = implode( "','", $include_states ); |
|
471
|
|
|
$post_types = implode( "','", $this->_post_types ); |
|
472
|
|
|
$orderby = isset( $_REQUEST['orderby'] ) ? esc_sql( $_REQUEST['orderby'] ) : 'p.post_date'; // WPCS: CSRF ok. |
|
473
|
|
|
$order = isset( $_REQUEST['order'] ) ? esc_sql( strtoupper( $_REQUEST['order'] ) ) : 'DESC'; // WPCS: CSRF ok. |
|
474
|
|
|
$cast = isset( $_REQUEST['cast'] ) ? esc_sql( $_REQUEST['cast'] ) : ''; // WPCS: CSRF ok. |
|
475
|
|
|
$cast = strtoupper( $cast ); |
|
476
|
|
|
$s = isset( $_REQUEST['s'] ) ? esc_sql( $_REQUEST['s'] ) : ''; // WPCS: CSRF ok. |
|
477
|
|
|
$exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes ); |
|
478
|
|
|
$items_count = $wpdb->prepare( "SELECT FOUND_ROWS() FROM {$wpdb->posts} WHERE 1 = %d", 1 ); |
|
479
|
|
|
$true = true; |
|
480
|
|
|
if ( $true ) { // FOUND_ROWS incompatibilities ? |
|
481
|
|
|
$items_count = $wpdb->prepare( |
|
482
|
|
|
"SELECT COUNT(*) |
|
483
|
|
|
FROM {$wpdb->posts} p |
|
484
|
|
|
INNER JOIN {$wpdb->postmeta} AS PM ON PM.post_id = p.ID AND PM.meta_key = '_wpshop_product_attribute_set_id' AND PM.meta_value LIKE %s |
|
485
|
|
|
WHERE p.post_status IN ( '{$include_states}' ) |
|
486
|
|
|
AND p.post_type IN ( '{$post_types}' ) |
|
487
|
|
|
AND p.post_title LIKE %s", |
|
488
|
|
|
$this->request_current_view(), |
|
489
|
|
|
"%{$s}%" |
|
490
|
|
|
); |
|
491
|
|
|
} |
|
492
|
|
|
$wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE; |
|
493
|
|
|
$wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS; |
|
494
|
|
|
$wpsdb_unit = WPSHOP_DBT_ATTRIBUTE_UNIT; |
|
495
|
|
|
$wpsdb_values_decimal = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL; |
|
496
|
|
|
$wpsdb_values_datetime = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME; |
|
497
|
|
|
$wpsdb_values_integer = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER; |
|
498
|
|
|
$wpsdb_values_varchar = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; |
|
499
|
|
|
$wpsdb_values_text = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; |
|
500
|
|
|
$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
|
501
|
|
|
$extra_select = ''; |
|
502
|
|
|
if ( ! in_array( $orderby, apply_filters( 'wps_mass_list_custom_orderby', array( 'title', 'ID', 'thumbnail', 'p.post_date' ) ), true ) ) { |
|
503
|
|
|
$extra_select = "SELECT GROUP_CONCAT( IFNULL( val_dec1.value, |
|
504
|
|
|
IFNULL( val_dat1.value, |
|
505
|
|
|
IFNULL( val_tex1.value, |
|
506
|
|
|
IFNULL( val_var1.value, |
|
507
|
|
|
IFNULL( val_opt1.value, |
|
508
|
|
|
val_int1.value |
|
509
|
|
|
) |
|
510
|
|
|
) |
|
511
|
|
|
) |
|
512
|
|
|
) |
|
513
|
|
|
) SEPARATOR ' ' ) |
|
514
|
|
|
FROM {$wpdb->posts} p1 |
|
515
|
|
|
LEFT JOIN {$wpsdb_attribute} attr1 ON attr1.status = 'valid' AND attr1.code = '{$orderby}' |
|
516
|
|
|
LEFT JOIN {$wpsdb_values_decimal} val_dec1 ON val_dec1.attribute_id = attr1.id AND val_dec1.entity_id = p1.ID |
|
517
|
|
|
LEFT JOIN {$wpsdb_values_datetime} val_dat1 ON val_dat1.attribute_id = attr1.id AND val_dat1.entity_id = p1.ID |
|
518
|
|
|
LEFT JOIN {$wpsdb_values_integer} val_int1 ON val_int1.attribute_id = attr1.id AND val_int1.entity_id = p1.ID |
|
519
|
|
|
LEFT JOIN {$wpsdb_values_text} val_tex1 ON val_tex1.attribute_id = attr1.id AND val_tex1.entity_id = p1.ID |
|
520
|
|
|
LEFT JOIN {$wpsdb_values_varchar} val_var1 ON val_var1.attribute_id = attr1.id AND val_var1.entity_id = p1.ID |
|
521
|
|
|
LEFT JOIN {$wpsdb_values_options} val_opt1 ON val_opt1.attribute_id = attr1.id AND val_opt1.id = val_int1.value |
|
522
|
|
|
WHERE p1.ID = p.ID"; |
|
523
|
|
|
$extra_select = "( {$extra_select} )"; |
|
524
|
|
|
if ( ! empty( $cast ) ) { |
|
525
|
|
|
$extra_select = "CAST( {$extra_select} AS {$cast} )"; |
|
526
|
|
|
} |
|
527
|
|
|
$extra_select = ", |
|
528
|
|
|
{$extra_select} AS {$orderby}"; |
|
529
|
|
|
} |
|
530
|
|
|
if ( 'thumbnail' === $orderby ) { |
|
531
|
|
|
$ids = $wpdb->get_col( $wpdb->prepare( |
|
532
|
|
|
"SELECT CAST( pm.post_id AS SIGNED INTEGER ) as col |
|
533
|
|
|
FROM {$wpdb->postmeta} pm |
|
534
|
|
|
JOIN {$wpdb->posts} p ON pm.post_id = p.ID AND p.post_type IN ( '{$post_types}' ) |
|
535
|
|
|
WHERE pm.meta_key = %s |
|
536
|
|
|
AND pm.meta_value != %d |
|
537
|
|
|
ORDER BY pm.meta_value {$order}", |
|
538
|
|
|
'_thumbnail_id', |
|
539
|
|
|
0 |
|
540
|
|
|
) ); |
|
541
|
|
|
$ids = implode( ', ', $ids ); |
|
542
|
|
|
$orderby = "FIELD( p.ID, {$ids} )"; |
|
543
|
|
|
} |
|
544
|
|
|
$orderby = apply_filters( 'wps_mass_list_custom_orderby_query', $orderby ); |
|
545
|
|
|
$extra = "GROUP BY p.ID |
|
546
|
|
|
ORDER BY {$orderby} {$order} |
|
547
|
|
|
LIMIT %d, %d"; |
|
548
|
|
|
if ( ! is_null( $id_post ) ) { |
|
549
|
|
|
$id_post = intval( $id_post ); |
|
550
|
|
|
$extra = "AND p.ID = {$id_post}"; |
|
551
|
|
|
$s = ''; |
|
552
|
|
|
} |
|
553
|
|
|
$wpdb->query( |
|
554
|
|
|
$wpdb->prepare( 'SET SESSION group_concat_max_len = %d', 1000000 ) |
|
555
|
|
|
); |
|
556
|
|
|
$datas = $wpdb->get_results( |
|
557
|
|
|
$wpdb->prepare( |
|
558
|
|
|
"SELECT SQL_CALC_FOUND_ROWS |
|
559
|
|
|
p.ID, |
|
560
|
|
|
p.post_title as title, |
|
561
|
|
|
p.post_parent as parent, |
|
562
|
|
|
p.post_status as status, |
|
563
|
|
|
p.post_type as type, |
|
564
|
|
|
p.post_date as pdate, |
|
565
|
|
|
GROUP_CONCAT( |
|
566
|
|
|
CONCAT( |
|
567
|
|
|
attr.id, '&', |
|
568
|
|
|
attr.code, '&', |
|
569
|
|
|
attr.frontend_label, '&', |
|
570
|
|
|
CONCAT( |
|
571
|
|
|
IFNULL( val_dec.value, '' ), |
|
572
|
|
|
IFNULL( val_dat.value, '' ), |
|
573
|
|
|
IFNULL( val_int.value, '' ), |
|
574
|
|
|
IFNULL( val_tex.value, '' ), |
|
575
|
|
|
IFNULL( val_var.value, '' ) |
|
576
|
|
|
), '&', |
|
577
|
|
|
attr.is_requiring_unit, '&', |
|
578
|
|
|
IFNULL( unit.unit, '' ), '&', |
|
579
|
|
|
attr.backend_input, '&', |
|
580
|
|
|
attr.data_type |
|
581
|
|
|
) SEPARATOR '&data;' |
|
582
|
|
|
) as data{$extra_select} |
|
583
|
|
|
FROM {$wpdb->posts} p |
|
584
|
|
|
INNER JOIN {$wpdb->postmeta} postmeta ON postmeta.post_id = p.ID AND postmeta.meta_key = %s AND postmeta.meta_value = %d |
|
585
|
|
|
LEFT JOIN {$wpsdb_attribute_set} attr_set ON attr_set.status = 'valid' AND attr_set.entity_type_id = %d AND attr_set.attribute_set_id = %d |
|
586
|
|
|
LEFT JOIN {$wpsdb_attribute} attr ON attr.status = 'valid' AND attr.entity_id = %d AND attr.code NOT IN ( '{$exclude_attribute_codes}' ) AND attr.id = attr_set.attribute_id |
|
587
|
|
|
LEFT JOIN {$wpsdb_values_decimal} val_dec ON val_dec.attribute_id = attr.id AND val_dec.entity_id = p.ID |
|
588
|
|
|
LEFT JOIN {$wpsdb_values_datetime} val_dat ON val_dat.attribute_id = attr.id AND val_dat.entity_id = p.ID |
|
589
|
|
|
LEFT JOIN {$wpsdb_values_integer} val_int ON val_int.attribute_id = attr.id AND val_int.entity_id = p.ID |
|
590
|
|
|
LEFT JOIN {$wpsdb_values_text} val_tex ON val_tex.attribute_id = attr.id AND val_tex.entity_id = p.ID |
|
591
|
|
|
LEFT JOIN {$wpsdb_values_varchar} val_var ON val_var.attribute_id = attr.id AND val_var.entity_id = p.ID |
|
592
|
|
|
LEFT JOIN {$wpsdb_unit} unit ON ( |
|
593
|
|
|
unit.id = val_dec.unit_id |
|
594
|
|
|
OR unit.id = val_dat.unit_id |
|
595
|
|
|
OR unit.id = val_int.unit_id |
|
596
|
|
|
OR unit.id = val_tex.unit_id |
|
597
|
|
|
OR unit.id = val_var.unit_id |
|
598
|
|
|
) |
|
599
|
|
|
WHERE p.post_status IN ( '{$include_states}' ) |
|
600
|
|
|
AND p.post_type IN ( '{$post_types}' ) |
|
601
|
|
|
AND p.post_title LIKE %s |
|
602
|
|
|
{$extra}", |
|
603
|
|
|
WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, |
|
604
|
|
|
$this->request_current_view(), |
|
605
|
|
|
$this->entity_id, |
|
606
|
|
|
$this->request_current_view(), |
|
607
|
|
|
$this->entity_id, |
|
608
|
|
|
'%' . $s . '%', |
|
609
|
|
|
( $this->get_pagenum() -1 ) * $per_page, |
|
610
|
|
|
$per_page |
|
611
|
|
|
), |
|
612
|
|
|
ARRAY_A |
|
613
|
|
|
); |
|
614
|
|
|
if ( ! is_array( $datas ) ) { |
|
615
|
|
|
$datas = array(); |
|
616
|
|
|
} |
|
617
|
|
|
if ( ! isset( $this->_pagination_args['total_items'] ) && ! isset( $this->_pagination_args['per_page'] ) ) { |
|
618
|
|
|
$this->set_pagination_args( |
|
619
|
|
|
array( |
|
620
|
|
|
'total_items' => (int) $wpdb->get_var( $items_count ), |
|
621
|
|
|
'per_page' => $this->get_items_per_page( $this->screen->get_option( 'per_page', 'option' ) ), |
|
622
|
|
|
) |
|
623
|
|
|
); |
|
624
|
|
|
} |
|
625
|
|
|
return array_map( array( $this, 'data_reorganize' ), $datas ); |
|
626
|
|
|
} |
|
627
|
|
|
/** |
|
628
|
|
|
* Main function to call before display WP_List_Table. See parent class. |
|
629
|
|
|
* |
|
630
|
|
|
* @method prepare_items |
|
631
|
|
|
* @return void Same results as request() but id as key. |
|
632
|
|
|
*/ |
|
633
|
|
|
public function prepare_items() { |
|
634
|
|
|
foreach ( $this->request() as $item ) { |
|
635
|
|
|
$this->items[ $item['ID'] ] = $item; |
|
636
|
|
|
} |
|
637
|
|
|
} |
|
638
|
|
|
/** |
|
639
|
|
|
* Set cast sort as case. |
|
640
|
|
|
* |
|
641
|
|
|
* @method cast_column |
|
642
|
|
|
* @param string $column_key Current column. |
|
643
|
|
|
* @return string |
|
644
|
|
|
*/ |
|
645
|
|
|
public function cast_column( $column_key ) { |
|
646
|
|
|
$columns_items = $this->request_items_columns(); |
|
647
|
|
|
if ( isset( $columns_items[ $column_key ] ) ) { |
|
648
|
|
|
$cast = $columns_items[ $column_key ]['data']; |
|
649
|
|
|
if ( in_array( $cast, array( 'varchar', 'text' ), true ) ) { |
|
650
|
|
|
$cast = 'char'; |
|
651
|
|
|
} |
|
652
|
|
|
if ( 'tx_tva' === $column_key ) { |
|
653
|
|
|
return 'decimal'; |
|
654
|
|
|
} |
|
655
|
|
|
if ( 'integer' === $cast && 'select' === $columns_items[ $column_key ]['type'] ) { |
|
656
|
|
|
return null; |
|
657
|
|
|
} |
|
658
|
|
|
if ( 'integer' === $cast && 'multiple-select' === $columns_items[ $column_key ]['type'] ) { |
|
659
|
|
|
return null; |
|
660
|
|
|
} |
|
661
|
|
|
return $cast; |
|
662
|
|
|
} |
|
663
|
|
|
return null; |
|
664
|
|
|
} |
|
665
|
|
|
/** |
|
666
|
|
|
* Reorganize item for compatibility. |
|
667
|
|
|
* |
|
668
|
|
|
* @method data_reorganize |
|
669
|
|
|
* @param array $item Result of sql query. |
|
670
|
|
|
* @return array Item reorganized. |
|
671
|
|
|
*/ |
|
672
|
|
|
public function data_reorganize( $item ) { |
|
673
|
|
|
$values = explode( '&data;', $item['data'] ); |
|
674
|
|
|
foreach ( $values as $value ) { |
|
675
|
|
|
$value = explode( '&', $value ); |
|
676
|
|
|
if ( ! isset( $this->columns_items[ $value[1] ] ) ) { |
|
677
|
|
|
$this->columns_items[ $value[1] ] = array( |
|
678
|
|
|
'id' => $value[0], |
|
679
|
|
|
'code' => $value[1], |
|
680
|
|
|
'name' => $value[2], |
|
681
|
|
|
'type' => $value[6], |
|
682
|
|
|
'data' => $value[7], |
|
683
|
|
|
); |
|
684
|
|
|
} |
|
685
|
|
|
if ( 'yes' === $value[4] ) { |
|
686
|
|
|
if ( isset( $item[ $value[1] ]['value'] ) ) { |
|
687
|
|
|
if ( is_array( $item[ $value[1] ]['value'] ) ) { |
|
688
|
|
|
$item[ $value[1] ]['value'][] = $value[3]; |
|
689
|
|
|
} else { |
|
690
|
|
|
$item[ $value[1] ]['value'] = array( $item[ $value[1] ]['value'], $value[3] ); |
|
691
|
|
|
} |
|
692
|
|
|
} else { |
|
693
|
|
|
$item[ $value[1] ] = array( |
|
694
|
|
|
'value' => $value[3], |
|
695
|
|
|
'unit' => $value[5], |
|
696
|
|
|
); |
|
697
|
|
|
} |
|
698
|
|
|
} else { |
|
699
|
|
|
if ( isset( $item[ $value[1] ] ) ) { |
|
700
|
|
|
if ( is_array( $item[ $value[1] ] ) ) { |
|
701
|
|
|
$item[ $value[1] ][] = $value[3]; |
|
702
|
|
|
} elseif ( $item[ $value[1] ] !== $value[3] ) { |
|
703
|
|
|
$item[ $value[1] ] = array( $item[ $value[1] ], $value[3] ); |
|
704
|
|
|
} |
|
705
|
|
|
} else { |
|
706
|
|
|
$item[ $value[1] ] = $value[3]; |
|
707
|
|
|
} |
|
708
|
|
|
} |
|
709
|
|
|
}// End foreach(). |
|
|
|
|
|
|
710
|
|
|
unset( $item['data'] ); |
|
711
|
|
|
return $item; |
|
712
|
|
|
} |
|
713
|
|
|
/** |
|
714
|
|
|
* Get values for select display. |
|
715
|
|
|
* |
|
716
|
|
|
* @method get_select_items_option |
|
717
|
|
|
* @param int $attribute_id Attribute ID. |
|
718
|
|
|
* @return array |
|
719
|
|
|
*/ |
|
720
|
|
|
public function get_select_items_option( $attribute_id ) { |
|
721
|
|
|
if ( ! isset( self::$wpsdb_values_options[ $attribute_id ] ) ) { |
|
722
|
|
|
global $wpdb; |
|
723
|
|
|
$wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
|
724
|
|
|
self::$wpsdb_values_options[ $attribute_id ] = $wpdb->get_results( |
|
725
|
|
|
$wpdb->prepare( |
|
726
|
|
|
"SELECT * |
|
727
|
|
|
FROM {$wpsdb_values_options} |
|
728
|
|
|
WHERE attribute_id = %d |
|
729
|
|
|
ORDER BY position", |
|
730
|
|
|
$attribute_id |
|
731
|
|
|
), |
|
732
|
|
|
ARRAY_A |
|
733
|
|
|
); |
|
734
|
|
|
} |
|
735
|
|
|
return self::$wpsdb_values_options[ $attribute_id ]; |
|
736
|
|
|
} |
|
737
|
|
|
/** |
|
738
|
|
|
* Get all views available. |
|
739
|
|
|
* |
|
740
|
|
|
* @method request_views |
|
741
|
|
|
* @return array |
|
742
|
|
|
*/ |
|
743
|
|
|
public function request_views() { |
|
744
|
|
|
global $wpdb; |
|
745
|
|
|
if ( is_null( $this->_views ) ) { |
|
746
|
|
|
$wpsdb_sets = WPSHOP_DBT_ATTRIBUTE_SET; |
|
747
|
|
|
$include_states = array( |
|
748
|
|
|
'publish', |
|
749
|
|
|
'future', |
|
750
|
|
|
'draft', |
|
751
|
|
|
'pending', |
|
752
|
|
|
'private', |
|
753
|
|
|
'trash', |
|
754
|
|
|
'scheduled', |
|
755
|
|
|
); |
|
756
|
|
|
$include_states = implode( "','", $include_states ); |
|
757
|
|
|
$post_types = implode( "','", $this->_post_types ); |
|
758
|
|
|
$this->_views = $wpdb->get_results( |
|
759
|
|
|
$wpdb->prepare( |
|
760
|
|
|
"SELECT s.id, name, slug, default_set, COUNT(p.ID) AS count |
|
761
|
|
|
FROM {$wpsdb_sets} s |
|
762
|
|
|
JOIN {$wpdb->postmeta} pm ON meta_key = %s AND id = meta_value |
|
763
|
|
|
JOIN {$wpdb->posts} p ON p.ID = post_id AND post_status IN ( '{$include_states}' ) AND post_type IN ( '{$post_types}' ) |
|
764
|
|
|
WHERE entity_id = %d |
|
765
|
|
|
AND status = %s |
|
766
|
|
|
GROUP BY id", |
|
767
|
|
|
WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, |
|
768
|
|
|
$this->entity_id, |
|
769
|
|
|
'valid' |
|
770
|
|
|
), |
|
771
|
|
|
ARRAY_A |
|
772
|
|
|
); |
|
773
|
|
|
} |
|
774
|
|
|
return $this->_views; |
|
775
|
|
|
} |
|
776
|
|
|
/** |
|
777
|
|
|
* Get current view. If empty, try recover default_set. |
|
778
|
|
|
* |
|
779
|
|
|
* @method request_current_view |
|
780
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
781
|
|
|
*/ |
|
782
|
|
|
public function request_current_view() { |
|
783
|
|
|
if ( is_null( $this->current_view ) ) { |
|
784
|
|
|
foreach ( $this->request_views() as $view ) { |
|
785
|
|
|
if ( filter_var( $view['default_set'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
786
|
|
|
$this->current_view = $view['id']; |
|
787
|
|
|
} |
|
788
|
|
|
} |
|
789
|
|
|
} |
|
790
|
|
|
return $this->current_view; |
|
791
|
|
|
} |
|
792
|
|
|
/** |
|
793
|
|
|
* Request attributes for current view. |
|
794
|
|
|
* |
|
795
|
|
|
* @method request_items_columns |
|
796
|
|
|
* @return array See :754 order columns. |
|
797
|
|
|
*/ |
|
798
|
|
|
public function request_items_columns() { |
|
799
|
|
|
if ( empty( $this->columns_items ) ) { |
|
800
|
|
|
global $wpdb; |
|
801
|
|
|
$wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE; |
|
802
|
|
|
$wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS; |
|
803
|
|
|
$exclude_attribute_codes = implode( "','", $this->exclude_attribute_codes ); |
|
804
|
|
|
foreach ( $wpdb->get_results( |
|
805
|
|
|
$wpdb->prepare( |
|
806
|
|
|
"SELECT attr.id, attr.code, attr.frontend_label AS name, attr.backend_input AS type, attr.data_type AS data |
|
807
|
|
|
FROM {$wpsdb_attribute} attr |
|
808
|
|
|
LEFT JOIN {$wpsdb_attribute_set} attr_set ON attr_set.status = 'valid' AND attr_set.entity_type_id = %d AND attr_set.attribute_set_id = %d |
|
809
|
|
|
WHERE attr.status = 'valid' |
|
810
|
|
|
AND attr.entity_id = %d |
|
811
|
|
|
AND attr.code NOT IN ( '{$exclude_attribute_codes}' ) |
|
812
|
|
|
AND attr.id = attr_set.attribute_id", |
|
813
|
|
|
$this->entity_id, |
|
814
|
|
|
$this->request_current_view(), |
|
815
|
|
|
$this->entity_id |
|
816
|
|
|
), |
|
817
|
|
|
ARRAY_A |
|
818
|
|
|
) as $column ) { |
|
819
|
|
|
$this->columns_items[ $column['code'] ] = $column; |
|
820
|
|
|
} |
|
821
|
|
|
} |
|
822
|
|
|
ksort( $this->columns_items ); |
|
823
|
|
|
return $this->columns_items; |
|
824
|
|
|
} |
|
825
|
|
|
/** |
|
826
|
|
|
* Content display views. |
|
827
|
|
|
* |
|
828
|
|
|
* @method get_views |
|
829
|
|
|
* @return array |
|
830
|
|
|
*/ |
|
831
|
|
|
public function get_views() { |
|
832
|
|
|
$result = array(); |
|
833
|
|
|
foreach ( $this->request_views() as $view ) { |
|
834
|
|
|
$class = ''; |
|
835
|
|
|
if ( (int) $view['id'] === (int) $this->request_current_view() ) { |
|
836
|
|
|
$class = ' class="current"'; |
|
837
|
|
|
} |
|
838
|
|
|
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
839
|
|
|
$link = add_query_arg( |
|
840
|
|
|
array( |
|
841
|
|
|
'page' => |
|
842
|
|
|
str_replace( |
|
843
|
|
|
"{$this->screen->post_type}_page_", |
|
844
|
|
|
'', |
|
845
|
|
|
substr( $this->screen->id, 0, strpos( $this->screen->id, '_att_set_' ) ) . '_att_set_' . $view['id'] |
|
846
|
|
|
), |
|
847
|
|
|
), |
|
848
|
|
|
$current_url |
|
849
|
|
|
); |
|
850
|
|
|
$link = remove_query_arg( 'paged', $link ); |
|
851
|
|
|
$result[ $view['id'] ] = sprintf( |
|
852
|
|
|
'<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
|
853
|
|
|
esc_url( $link ), |
|
854
|
|
|
$class, |
|
855
|
|
|
$view['name'], |
|
856
|
|
|
number_format_i18n( $view['count'] ) |
|
857
|
|
|
); |
|
858
|
|
|
} |
|
859
|
|
|
return $result; |
|
860
|
|
|
} |
|
861
|
|
|
/** |
|
862
|
|
|
* Bulk actions display. |
|
863
|
|
|
* |
|
864
|
|
|
* @method bulk_actions |
|
865
|
|
|
* @param string $which Can be top or bottom. |
|
866
|
|
|
* @return void Direct display. |
|
867
|
|
|
*/ |
|
868
|
|
|
public function bulk_actions( $which = '' ) { |
|
869
|
|
|
submit_button( __( 'Save changes', 'wpshop' ), 'bulk-save', 'bulk-save', false, array( |
|
870
|
|
|
'data-nonce' => wp_create_nonce( 'bulk-save-mass-edit-interface-3' ), |
|
871
|
|
|
) ); |
|
872
|
|
|
?><span class="spinner"></span><?php |
|
873
|
|
|
} |
|
874
|
|
|
/** |
|
875
|
|
|
* Recursive function for display hierarchy. This function group & search also childs & parent. |
|
876
|
|
|
* When parent is always traited, it add childs after. Or get parent before traited (on list or not) and add childs after. |
|
877
|
|
|
* |
|
878
|
|
|
* @method _display_row |
|
879
|
|
|
* @param int $lvl Represent current level of child. |
|
880
|
|
|
* @param int $item_id Current ID row. |
|
881
|
|
|
* @param array $item Data row. |
|
882
|
|
|
* @param array $rows List of rows always traited. |
|
883
|
|
|
* @return void |
|
884
|
|
|
*/ |
|
885
|
|
|
private function _display_row( &$lvl, $item_id, $item, &$rows ) { |
|
886
|
|
|
if ( array_key_exists( $item_id, $rows ) ) { |
|
887
|
|
|
return; |
|
888
|
|
|
} |
|
889
|
|
|
if ( ! array_key_exists( $item['parent'], $this->items ) && 0 !== (int) $item['parent'] ) { |
|
890
|
|
|
$parent_item = $this->request( $item['parent'] ); |
|
891
|
|
|
if ( isset( $parent_item[0] ) ) { |
|
892
|
|
|
$this->items[ $item['parent'] ] = $parent_item[0]; |
|
893
|
|
|
} else { |
|
894
|
|
|
$this->items[ $item['parent'] ] = null; |
|
895
|
|
|
} |
|
896
|
|
|
} |
|
897
|
|
|
if ( array_key_exists( $item['parent'], $rows ) ) { |
|
898
|
|
|
$offset = array_search( $item['parent'], array_keys( $rows ), true ); |
|
899
|
|
|
$rows_a = array_slice( $rows, $offset, null, true ); |
|
900
|
|
|
$rows_a[ $item_id ] = $item; |
|
901
|
|
|
$rows_b = array_slice( $rows, 0, $offset, true ); |
|
902
|
|
|
$rows = array_replace( $rows_a, $rows_b ); |
|
903
|
|
|
// $rows = $rows_a + $rows_b; FASTER ? |
|
904
|
|
|
$lvl++; |
|
905
|
|
|
} elseif ( 0 !== (int) $item['parent'] ) { |
|
906
|
|
|
$this->_display_row( $lvl, $item['parent'], $this->items[ $item['parent'] ], $rows ); |
|
907
|
|
|
$lvl++; |
|
908
|
|
|
} |
|
909
|
|
|
if ( ! empty( $item ) ) { |
|
910
|
|
|
$item['lvl'] = str_repeat( '— ', $lvl ); |
|
911
|
|
|
} |
|
912
|
|
|
$rows[ $item_id ] = $item; |
|
913
|
|
|
} |
|
914
|
|
|
/** |
|
915
|
|
|
* See WP_List_Table. |
|
916
|
|
|
* |
|
917
|
|
|
* @method display_rows |
|
918
|
|
|
* @return void Direct display. |
|
919
|
|
|
*/ |
|
920
|
|
|
public function display_rows() { |
|
921
|
|
|
$rows = array(); |
|
922
|
|
|
foreach ( $this->items as $item_id => $item ) { |
|
923
|
|
|
$lvl = 0; |
|
924
|
|
|
$this->_display_row( $lvl, $item_id, $item, $rows ); |
|
925
|
|
|
} |
|
926
|
|
|
foreach ( $rows as $item ) { |
|
927
|
|
|
if ( ! empty( $item ) ) { |
|
928
|
|
|
$this->single_row( $item ); |
|
929
|
|
|
} |
|
930
|
|
|
} |
|
931
|
|
|
} |
|
932
|
|
|
/** |
|
933
|
|
|
* See WP_List_Table. |
|
934
|
|
|
* |
|
935
|
|
|
* @method views |
|
936
|
|
|
* @return void Direct display. |
|
937
|
|
|
*/ |
|
938
|
|
|
public function views() { |
|
939
|
|
|
parent::views(); |
|
940
|
|
|
$current_view = $this->request_current_view(); |
|
|
|
|
|
|
941
|
|
|
} |
|
942
|
|
|
/** |
|
943
|
|
|
* Add cast parameter for sort. Copy of print_column_headers function in wp_list_table class. |
|
944
|
|
|
* |
|
945
|
|
|
* @method print_column_headers |
|
946
|
|
|
* @param boolean $with_id See wp_list_table::print_column_headers. |
|
947
|
|
|
* @return void Direct display. |
|
948
|
|
|
*/ |
|
949
|
|
|
public function print_column_headers( $with_id = true ) { |
|
950
|
|
|
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
|
951
|
|
|
|
|
952
|
|
|
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
953
|
|
|
$current_url = remove_query_arg( 'paged', $current_url ); |
|
954
|
|
|
|
|
955
|
|
|
if ( isset( $_GET['orderby'] ) ) { // WPCS: CSRF ok. |
|
956
|
|
|
$current_orderby = $_GET['orderby']; // WPCS: CSRF ok. |
|
957
|
|
|
} else { |
|
958
|
|
|
$current_orderby = ''; |
|
959
|
|
|
} |
|
960
|
|
|
|
|
961
|
|
|
if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { // WPCS: CSRF ok. |
|
962
|
|
|
$current_order = 'desc'; |
|
963
|
|
|
} else { |
|
964
|
|
|
$current_order = 'asc'; |
|
965
|
|
|
} |
|
966
|
|
|
|
|
967
|
|
|
if ( ! empty( $columns['cb'] ) ) { |
|
968
|
|
|
static $cb_counter = 1; |
|
969
|
|
|
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>' |
|
970
|
|
|
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />'; |
|
971
|
|
|
$cb_counter++; |
|
972
|
|
|
} |
|
973
|
|
|
|
|
974
|
|
|
foreach ( $columns as $column_key => $column_display_name ) { |
|
975
|
|
|
$class = array( 'manage-column', "column-$column_key" ); |
|
976
|
|
|
|
|
977
|
|
|
if ( in_array( $column_key, $hidden, true ) ) { |
|
978
|
|
|
$class[] = 'hidden'; |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
if ( 'cb' === $column_key ) { |
|
982
|
|
|
$class[] = 'check-column'; |
|
983
|
|
|
} elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) { |
|
984
|
|
|
$class[] = 'num'; |
|
985
|
|
|
} |
|
986
|
|
|
|
|
987
|
|
|
if ( $column_key === $primary ) { |
|
988
|
|
|
$class[] = 'column-primary'; |
|
989
|
|
|
} |
|
990
|
|
|
|
|
991
|
|
|
if ( isset( $sortable[ $column_key ] ) ) { |
|
992
|
|
|
list( $orderby, $desc_first ) = $sortable[ $column_key ]; |
|
993
|
|
|
|
|
994
|
|
|
if ( $current_orderby === $orderby ) { |
|
995
|
|
|
$order = 'asc' === $current_order ? 'desc' : 'asc'; |
|
996
|
|
|
$class[] = 'sorted'; |
|
997
|
|
|
$class[] = $current_order; |
|
998
|
|
|
} else { |
|
999
|
|
|
$order = $desc_first ? 'desc' : 'asc'; |
|
1000
|
|
|
$class[] = 'sortable'; |
|
1001
|
|
|
$class[] = $desc_first ? 'asc' : 'desc'; |
|
1002
|
|
|
} |
|
1003
|
|
|
|
|
1004
|
|
|
$cast = $this->cast_column( $column_key ); |
|
1005
|
|
|
|
|
1006
|
|
|
$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order', 'cast' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; |
|
1007
|
|
|
} |
|
1008
|
|
|
|
|
1009
|
|
|
$tag = ( 'cb' === $column_key ) ? 'td' : 'th'; |
|
1010
|
|
|
$scope = ( 'th' === $tag ) ? 'scope="col"' : ''; |
|
1011
|
|
|
$id = $with_id ? "id='$column_key'" : ''; |
|
1012
|
|
|
|
|
1013
|
|
|
if ( ! empty( $class ) ) { |
|
1014
|
|
|
$class = "class='" . join( ' ', $class ) . "'"; |
|
1015
|
|
|
} |
|
1016
|
|
|
|
|
1017
|
|
|
echo "<$tag $scope $id $class>$column_display_name</$tag>"; // WPCS: XSS ok. |
|
1018
|
|
|
}// End foreach(). |
|
|
|
|
|
|
1019
|
|
|
} |
|
1020
|
|
|
} |
|
1021
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.