|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Form model for the movie filter |
|
5
|
|
|
* |
|
6
|
|
|
* @author Sam Stenvall <[email protected]> |
|
7
|
|
|
* @copyright Copyright © Sam Stenvall 2013- |
|
8
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
|
9
|
|
|
*/ |
|
10
|
|
|
class MovieFilterForm extends VideoFilterForm |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
const QUALITY_SD = 'sd'; |
|
14
|
|
|
const QUALITY_720 = 720; |
|
15
|
|
|
const QUALITY_1080 = 1080; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int the movie year |
|
19
|
|
|
*/ |
|
20
|
|
|
public $year; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string the video quality |
|
24
|
|
|
*/ |
|
25
|
|
|
public $quality; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var float rating of the movie |
|
29
|
|
|
*/ |
|
30
|
|
|
public $rating; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string the director of the movie |
|
34
|
|
|
*/ |
|
35
|
|
|
public $director; |
|
36
|
|
|
|
|
37
|
|
|
public function getGenreType() |
|
38
|
|
|
{ |
|
39
|
|
|
return VideoLibrary::GENRE_TYPE_MOVIE; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return array the attribute labels for this model |
|
44
|
|
|
*/ |
|
45
|
|
|
public function attributeLabels() |
|
46
|
|
|
{ |
|
47
|
|
|
return array_merge(parent::attributeLabels(), array( |
|
48
|
|
|
'year'=>Yii::t('FilterForm', 'Year'), |
|
49
|
|
|
'quality'=>Yii::t('FilterForm', 'Quality'), |
|
50
|
|
|
'rating'=>Yii::t('FilterForm', 'Minimum rating'), |
|
51
|
|
|
'director'=>Yii::t('FilterForm', 'Director'), |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array the validation rules for this model |
|
57
|
|
|
*/ |
|
58
|
|
|
public function rules() |
|
59
|
|
|
{ |
|
60
|
|
|
return array_merge(parent::rules(), array( |
|
61
|
|
|
array('year', 'numerical', 'integerOnly'=>true), |
|
62
|
|
|
array('quality', 'in', 'range'=>array_keys($this->getQualities())), |
|
63
|
|
|
array('rating', 'numerical', 'max'=>'10'), |
|
64
|
|
|
array('director', 'safe'), |
|
65
|
|
|
)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Pre-validation logic |
|
70
|
|
|
* @return boolean whether to perform validation at all |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function beforeValidate() |
|
73
|
|
|
{ |
|
74
|
|
|
// Convert commas to dots |
|
75
|
|
|
$this->rating = str_replace(',', '.', $this->rating); |
|
76
|
|
|
|
|
77
|
|
|
return parent::beforeValidate(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns the possible qualities |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getQualities() |
|
85
|
|
|
{ |
|
86
|
|
|
return array( |
|
87
|
|
|
self::QUALITY_SD=>'SD', |
|
88
|
|
|
self::QUALITY_720=>'720p', |
|
89
|
|
|
self::QUALITY_1080=>'1080p', |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the defined filter as an array |
|
95
|
|
|
* @return array the filter |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getFilterDefinitions() |
|
98
|
|
|
{ |
|
99
|
|
|
$filter = $this->getCommonFilterDefinitions(); |
|
100
|
|
|
|
|
101
|
|
|
$filter['year'] = array( |
|
102
|
|
|
'operator'=>'is', |
|
103
|
|
|
'value'=>$this->year); |
|
104
|
|
|
|
|
105
|
|
|
$filter['rating'] = array( |
|
106
|
|
|
'operator'=>'greaterthan', |
|
107
|
|
|
'value'=>$this->rating); |
|
108
|
|
|
|
|
109
|
|
|
$filter['director'] = array( |
|
110
|
|
|
'operator'=>'is', |
|
111
|
|
|
'value'=>$this->director, |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
$quality = $this->quality; |
|
115
|
|
|
|
|
116
|
|
|
// SD means anything less than 720p |
|
117
|
|
|
if ($quality == self::QUALITY_SD) |
|
118
|
|
|
{ |
|
119
|
|
|
$filter['videoresolution'] = array( |
|
120
|
|
|
'operator'=>'lessthan', |
|
121
|
|
|
'value'=>(string)self::QUALITY_720); |
|
122
|
|
|
} |
|
123
|
|
|
else |
|
124
|
|
|
{ |
|
125
|
|
|
$filter['videoresolution'] = array( |
|
126
|
|
|
'operator'=>'is', |
|
127
|
|
|
'value'=>$quality); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $filter; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|