Separator.php
1.74 KB
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
<?php
namespace AC\Settings\Column;
use AC\ApplyFilter;
use AC\Collection;
use AC\Settings;
use AC\View;
class Separator extends Settings\Column
implements Settings\FormatCollection {
const NAME = 'separator';
/**
* @var string
*/
private $separator;
protected function define_options() {
return [ 'separator' => 'comma' ];
}
public function create_view() {
$options = [
'comma' => __( 'Comma Separated', 'codepress-admin-columns' ),
'horizontal_rule' => __( 'Horizontal Rule', 'codepress-admin-columns' ),
'newline' => __( 'New Line', 'codepress-admin-columns' ),
'none' => __( 'None', 'codepress-admin-columns' ),
'white_space' => __( 'Whitespace', 'codepress-admin-columns' ),
];
natcasesort( $options );
$options = [ '' => __( 'Default', 'codepress-admin-columns' ) ] + $options;
$select = $this
->create_element( 'select' )
->set_options( $options );
$view = new View( [
'label' => __( 'Separator', 'codepress-admin-columns' ),
'setting' => $select,
] );
return $view;
}
public function get_separator() {
return $this->separator;
}
public function set_separator( $separator ) {
$this->separator = $separator;
return $this;
}
public function get_separator_formatted() {
switch ( $this->separator ) {
case 'comma' :
return ', ';
case 'newline' :
return "<br/>";
case 'none' :
return '';
case 'white_space' :
return ' ';
case 'horizontal_rule' :
return '<hr>';
default :
return ( new ApplyFilter\ColumnSeparator( $this->column ) )->apply_filters( ', ' );
}
}
public function format( Collection $collection, $original_value ) {
return $collection->filter()->implode( $this->get_separator_formatted() );
}
}