Raw.php
1.1 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
<?php
namespace ACA\MetaBox\Export\Model;
use AC;
use ACA\MetaBox\Column;
use ACP;
class Raw implements ACP\Export\Service {
protected $column;
public function __construct( Column $column ) {
$this->column = $column;
}
public function get_value( $id ) {
if ( $this->column->is_clonable() ) {
return (string) $this->get_multiple_values( $id );
}
$single_value = $this->get_rmwb_value( (int) $id );
return $this->format_single_value( $single_value, $id );
}
private function get_rmwb_value( int $id ) {
return rwmb_get_value(
$this->column->get_meta_key(),
[
'object_type' => $this->column->get_meta_type(),
],
$id
);
}
public function format_single_value( $value, $id = null ) {
return $value
? (string) $value
: '';
}
public function get_multiple_values( $id ) {
$value = $this->get_rmwb_value( (int) $id );
if ( ! $value ) {
return null;
}
$collection = new AC\Collection( (array) $value );
$result = [];
foreach ( $collection as $value ) {
$result[] = $this->format_single_value( $value );
}
return implode( "\r\n", $result );
}
}