1 | <?php |
||
13 | abstract class MediaController extends Controller |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @return array list of actions that a spectator should be prohibited from |
||
18 | * performing |
||
19 | */ |
||
20 | abstract protected function getSpectatorProhibitedActions(); |
||
21 | |||
22 | /** |
||
23 | * Some parts of the code assume we're in either Movie or TvShowController |
||
24 | * so make sure the common actions are actually available |
||
25 | */ |
||
26 | abstract public function actionDetails($id); |
||
27 | |||
28 | /** |
||
29 | * Override parent implementation to add access control filter |
||
30 | * @return array the filters for this controller |
||
31 | */ |
||
32 | public function filters() |
||
39 | |||
40 | /** |
||
41 | * @return array the access rules for this controller |
||
42 | */ |
||
43 | public function accessRules() |
||
44 | { |
||
45 | return array( |
||
46 | // Prevent spectators from performing certain actions |
||
47 | array('deny', |
||
48 | 'actions'=>$this->getSpectatorProhibitedActions(), |
||
49 | 'expression'=>function() { |
||
50 | return Yii::app()->user->role === User::ROLE_SPECTATOR; |
||
51 | } |
||
52 | ), |
||
53 | array('deny', |
||
54 | 'actions'=>array('playOnBackend'), |
||
55 | 'expression'=>function() { |
||
56 | return Yii::app()->user->role !== User::ROLE_ADMIN; |
||
57 | } |
||
58 | ), |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Sets the display mode for the specified context and redirects the user |
||
64 | * back to where he came from. |
||
65 | * @param string $mode the desired display mode |
||
66 | * @param string $context the context |
||
67 | */ |
||
68 | public function actionSetDisplayMode($mode, $context) |
||
84 | |||
85 | /** |
||
86 | * Returns the current display mode for the specified context |
||
87 | * @param string $context the context |
||
88 | * @return string the display mode |
||
89 | */ |
||
90 | public function getDisplayMode($context) |
||
102 | |||
103 | /** |
||
104 | * Returns the default display mode for the specified context |
||
105 | * @param string $context the context |
||
106 | * @return string the display mode |
||
107 | */ |
||
108 | private function getDefaultDisplayMode($context) |
||
116 | |||
117 | /** |
||
118 | * Generates a playlist from the specified media item |
||
119 | * @param IStreamable $media the media item |
||
120 | * @param string $format the desired playlist format. Defaults to null, |
||
121 | * meaning the configured default format will be used |
||
122 | * @return Playlist the playlist |
||
123 | */ |
||
124 | private function createPlaylist($media, $format = null) |
||
141 | |||
142 | /** |
||
143 | * Creates and serves a playlist based on the specified media item |
||
144 | * @param IStreamable $media a media item |
||
145 | * @param string $format the desired playlist format. Defaults to null, |
||
146 | * meaning the configured default format will be used |
||
147 | */ |
||
148 | protected function servePlaylist($media, $format = null) |
||
157 | |||
158 | /** |
||
159 | * Tells the current backend to play the specified file, then redirects |
||
160 | * to the previous page |
||
161 | * @param string $file the file path |
||
162 | */ |
||
163 | public function actionPlayOnBackend($file) |
||
174 | |||
175 | /** |
||
176 | * Plays the specified URL in the in-browser player |
||
177 | * @param string $url the URL to the media |
||
178 | */ |
||
179 | public function actionWatchInBrowser($url) |
||
189 | } |
||
190 |