@@ -42,9 +42,12 @@ class PresentationVotingPage_Controller extends Page_Controller
4242 'handleAPI ' ,
4343 'handleIndex '
4444 );
45- /**
46- *
47- */
45+
46+
47+ public function getCurrentSummit (){
48+ return Summit::get_active ();
49+ }
50+
4851 public function init ()
4952 {
5053 parent ::init ();
@@ -188,9 +191,8 @@ public function handlePresentations(SS_HTTPRequest $r)
188191 {
189192 $ presentations = [];
190193 $ offset = $ r ->getVar ('offset ' ) ?: 0 ;
191- $ m = Member::currentUser ();
192- $ list = $ m ? $ m ->getRandomisedPresentations (null , $ this ->summit ) : $ this ->summit ->VoteablePresentations ();
193- $ list = Presentation::get ()->sort ('Created DESC ' )->limit (100 );
194+ $ m = Member::currentUser ();
195+ $ list = $ m ? $ m ->getRandomisedPresentations (null , $ this ->summit ) : $ this ->summit ->VoteablePresentations ();
194196 if ($ list ) {
195197 if ($ r ->getVar ('category ' )) {
196198 $ list = $ list ->filter (['CategoryID ' => $ r ->getVar ('category ' )]);
@@ -227,11 +229,13 @@ public function handlePresentations(SS_HTTPRequest $r)
227229 */
228230 public function handleReadPresentation (SS_HTTPRequest $ r )
229231 {
230- $ presentation = $ this ->getFromFilename ($ r ->param ('ID ' ), 'Presentation ' );
231- $ presentation = Presentation::get ()->byID (explode ('. ' , $ r ->param ('ID ' ))[0 ]);
232- if (!$ presentation ) {
232+ $ id = intval ($ r ->param ('ID ' ));
233+ $ presentation = Presentation::get ()->byID ($ id );
234+
235+ if (!$ presentation || !$ presentation ->Category ()->VotingVisible ) {
233236 return $ this ->httpError (404 );
234237 }
238+
235239 $ vote = $ presentation ->getUserVote ();
236240 $ json = [
237241 'id ' => $ presentation ->ID ,
@@ -245,7 +249,7 @@ public function handleReadPresentation(SS_HTTPRequest $r)
245249 'date ' => $ vote ->obj ('Created ' )->Format ('F j, Y ' ),
246250 'ago ' => $ vote ->obj ('Created ' )->Ago ()
247251 ] : null ,
248- 'abstract ' => $ presentation ->Description ,
252+ 'abstract ' => $ presentation ->Abstract ,
249253 'attendees_expected_learnt ' => $ presentation ->AttendeesExpectedLearnt
250254 ];
251255 foreach ($ presentation ->getSpeakersAndModerators () as $ s ) {
@@ -293,14 +297,18 @@ public function handleUpdatePresentation(SS_HTTPRequest $r)
293297 if (!Member::currentUser ()) {
294298 return $ this ->httpError (403 , 'You must be logged in to vote ' );
295299 }
296- $ presentation = $ this ->getFromFilename ($ r ->param ('ID ' ), 'Presentation ' );
297- $ presentation = Presentation::get ()->byID (explode ('. ' , $ r ->param ('ID ' ))[0 ]);
298- if (!$ presentation ) {
300+
301+ $ id = intval ($ r ->param ('ID ' ));
302+ $ presentation = Presentation::get ()->byID ($ id );
303+
304+ if (!$ presentation || !$ presentation ->Category ()->VotingVisible ) {
299305 return $ this ->httpError (404 );
300306 }
307+
301308 if (!$ presentation ->Summit ()->isVotingOpen ()) {
302- // return $this->httpError(403,'Voting is closed');
309+ return $ this ->httpError (403 ,'Voting is closed ' );
303310 }
311+
304312 $ vars = Convert::json2array ($ r ->getBody ());
305313 if (isset ($ vars ['vote ' ])) {
306314 $ presentation ->setUserVote ((int )$ vars ['vote ' ]);
@@ -326,11 +334,14 @@ public function handleDeleteComment(SS_HTTPRequest $r)
326334 if (!Member::currentUser ()) {
327335 return $ this ->httpError (403 , 'You must be logged in to vote ' );
328336 }
329- $ presentation = $ this ->getFromFilename ($ r ->param ('ID ' ), 'Presentation ' );
330- $ presentation = Presentation::get ()->byID (explode ('. ' , $ r ->param ('ID ' ))[0 ]);
331- if (!$ presentation ) {
337+
338+ $ id = intval ($ r ->param ('ID ' ));
339+ $ presentation = Presentation::get ()->byID ($ id );
340+
341+ if (!$ presentation || !$ presentation ->Category ()->VotingVisible ) {
332342 return $ this ->httpError (404 );
333343 }
344+
334345 if (!$ presentation ->Summit ()->isVotingOpen ()) {
335346 return $ this ->httpError (403 ,'Voting is closed ' );
336347 }
@@ -364,19 +375,5 @@ public function handleCategories(SS_HTTPRequest $r)
364375 return (new SS_HTTPResponse (Convert::array2json ($ result ), 200 ))
365376 ->addHeader ('Content-Type ' , 'application/json ' );
366377 }
367- /**
368- * @param $file
369- * @param $class
370- * @return mixed
371- */
372- protected function getFromFilename ($ file , $ class )
373- {
374- $ info = pathinfo ($ file );
375- $ id = $ info ['filename ' ];
376- $ list = $ class ::get ();
377- if ($ class === 'Presentation ' ) {
378- $ list = $ list ->filter ('Category.VotingVisible ' , true );
379- }
380- return $ list ->byID ($ id );
381- }
378+
382379}
0 commit comments