Date.php
1.38 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
<?php
namespace ACA\MetaBox\Column;
use AC;
use ACA;
use ACA\MetaBox\Editing\StorageFactory;
use ACA\MetaBox\Search;
use ACA\MetaBox\Sorting;
use ACP;
use ACP\ConditionalFormat;
use ACP\ConditionalFormat\Formatter\DateFormatter;
use ACP\Editing\Service;
use ACP\Editing\View;
class Date extends ACA\MetaBox\Column implements ACP\Search\Searchable, ACP\Sorting\Sortable, ACP\Editing\Editable, ACP\ConditionalFormat\Formattable {
protected function register_settings() {
$this->add_setting( new AC\Settings\Column\Date( $this ) );
}
public function get_saved_format() {
$save_format = $this->get_field_setting( 'save_format' );
if ( ! $save_format ) {
$save_format = $this->is_timestamp() ? 'U' : 'Y-m-d';
}
return $save_format;
}
protected function is_timestamp() {
return $this->get_field_setting( 'timestamp' );
}
public function sorting() {
return ( new Sorting\Factory\Date )->create( $this );
}
public function search() {
return ( new Search\Factory\Date )->create( $this );
}
public function editing() {
return new Service\Date(
( new View\Date() )->set_clear_button( true ),
( new StorageFactory() )->create( $this ),
$this->get_saved_format()
);
}
public function conditional_format(): ?ConditionalFormat\FormattableConfig {
return new ConditionalFormat\FormattableConfig(
new DateFormatter\FormatFormatter( $this->get_saved_format() )
);
}
}