|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\models; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\base\Model; |
|
7
|
|
|
|
|
8
|
|
|
class IndexPageUiOptions extends Model |
|
9
|
|
|
{ |
|
10
|
|
|
public $sort; |
|
11
|
|
|
|
|
12
|
|
|
public $per_page; |
|
13
|
|
|
|
|
14
|
|
|
public $orientation; |
|
15
|
|
|
|
|
16
|
|
|
public $representation; |
|
17
|
|
|
|
|
18
|
|
|
public $representationOptions = []; |
|
19
|
|
|
|
|
20
|
|
|
public function fields() |
|
21
|
|
|
{ |
|
22
|
|
|
return ['sort', 'per_page', 'orientation', 'representation']; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function rules() |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
['per_page', 'default', 'value' => 25], |
|
29
|
|
|
['per_page', 'number', 'skipOnEmpty' => true], |
|
30
|
|
|
|
|
31
|
|
|
['sort', 'string', 'skipOnEmpty' => true], |
|
32
|
|
|
|
|
33
|
|
|
['orientation', 'default', 'value' => $this->getDefaultOrientation()], |
|
34
|
|
|
['orientation', 'in', 'range' => array_keys($this->getOrientationOptions())], |
|
35
|
|
|
|
|
36
|
|
|
['representation', 'in', 'range' => $this->representationOptions, 'skipOnEmpty' => true], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getOrientationOptions() |
|
44
|
|
|
{ |
|
45
|
|
|
return [ |
|
46
|
|
|
'horizontal' => Yii::t('hipanel', 'Horizontal'), |
|
47
|
|
|
'vertical' => Yii::t('hipanel', 'Vertical'), |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getDefaultOrientation() |
|
55
|
|
|
{ |
|
56
|
|
|
$settings = Yii::$app->themeManager->getSettings(); |
|
57
|
|
|
$orientationOptions = array_keys($this->getOrientationOptions()); |
|
58
|
|
|
|
|
59
|
|
|
if (property_exists($settings, 'filterOrientation') && in_array($settings->filterOrientation, $orientationOptions, true)) { |
|
60
|
|
|
return $settings->filterOrientation; |
|
61
|
|
|
} else { |
|
62
|
|
|
return reset($orientationOptions); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|