Model.php
1.34 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
81
<?php
namespace ACP\Sorting;
use AC\Column;
use ACP;
use ACP\Sorting\Type\DataType;
/**
* @deprecated 5.2
*/
class Model extends AbstractModel {
/**
* @var Column
*/
protected $column;
/**
* @var string
*/
protected $orderby;
public function __construct( Column $column, DataType $data_type = null, $show_empty = null ) {
parent::__construct( $data_type, $show_empty );
$this->column = $column;
}
/**
* @param string $data_type_value
*/
public function set_data_type( $data_type_value ) {
$this->data_type = new DataType( $data_type_value );
}
/**
* Get the sorting vars
* @return array
* @since 4.0
*/
public function get_sorting_vars() {
if ( $this->orderby ) {
return [
'orderby' => $this->orderby,
];
}
return [
'ids' => ( new Sorter() )->sort( $this->get_raw_values(), $this->get_order(), $this->data_type, $this->show_empty ),
];
}
/**
* @return array
*/
public function get_raw_values() {
$values = [];
foreach ( $this->strategy->get_results() as $id ) {
$values[ $id ] = $this->column->get_raw_value( $id );
}
return $values;
}
/**
* @param string $orderby
*
* @return $this
* @deprecated 5.2
*/
public function set_orderby( $orderby ) {
_deprecated_function( __METHOD__, '5.2', 'ACP\Sorting\Model\OrderBy' );
$this->orderby = $orderby;
return $this;
}
}