AbstractModel.php
1.35 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
<?php
namespace ACP\Sorting;
use ACP;
use ACP\Sorting\Type\DataType;
abstract class AbstractModel {
/**
* @var DataType
*/
protected $data_type;
/**
* @var Strategy\Comment|Strategy\Post|Strategy\User
*/
protected $strategy;
public function __construct( DataType $data_type = null ) {
if ( null === $data_type ) {
$data_type = new DataType( DataType::STRING );
}
$this->data_type = $data_type;
}
/**
* @return array
*/
public abstract function get_sorting_vars();
/**
* @param Strategy $strategy
*/
public function set_strategy( Strategy $strategy ) {
$this->strategy = $strategy;
}
/**
* @return DataType
*/
public function get_data_type() {
return $this->data_type;
}
/**
* Return the default or set order from the strategy.
* Falls back to ASC if an invalid order is found
* @return string ASC|DESC
*/
public function get_order() {
$order = strtoupper( $this->strategy->get_order() );
if ( 'ASC' !== $order ) {
$order = 'DESC';
}
return $order;
}
/**
* Sorts an array ascending, maintains index association and returns keys
*
* @param array $array
*
* @return array Returns the array keys of the sorted array
* @deprecated 5.2
*/
public function sort( array $array ) {
_deprecated_function( __METHOD__, '6.0' );
return ( new Sorter() )->sort( $array, $this->data_type );
}
}