/**
  * @param SS_HTTPRequest $r
  * @return SS_HTTPRequest
  */
 public function handlePresentations(SS_HTTPRequest $r)
 {
     $presentations = [];
     $offset = $r->getVar('offset') ?: 0;
     $m = Member::currentUser();
     $list = $m ? $m->getRandomisedPresentations(null, $this->summit) : $this->summit->VoteablePresentations();
     if ($list) {
         if ($r->getVar('category')) {
             $list = $list->filter(['CategoryID' => $r->getVar('category')]);
         }
         if ($r->getVar('search')) {
             $list = Presentation::apply_search_query($list, $r->getVar('search'));
         }
         $total = $list->count();
         $list = $list->limit($this->limit, $offset);
     } else {
         $list = [];
         $total = 0;
     }
     foreach ($list as $p) {
         $vote = $p->getUserVote();
         $presentations[] = ['id' => $p->ID, 'title' => $p->Title, 'user_vote' => $vote ? $vote->Vote : null];
     }
     $result = ['presentations' => $presentations, 'total' => $total];
     return (new SS_HTTPResponse(Convert::array2json($result), 200))->addHeader('Content-Type', 'application/json');
 }
 /**
  * @param SS_HTTPRequest $r
  * @return SS_HTTPResponse
  */
 public function handleGetAllPresentations(SS_HTTPRequest $r)
 {
     // Gets a list of presentations that have chair comments
     $page_size = $r->getVar('page_size') ?: $this->config()->default_page_size;
     $page = $r->getVar('page') ?: 1;
     $summitID = Summit::get_active()->ID;
     // Get a collection of chair-visible presentation categories
     $presentations = Presentation::get()->filter(['Category.ChairVisible' => true, 'SummitEvent.SummitID' => $summitID, 'Presentation.Status' => Presentation::STATUS_RECEIVED]);
     if ($r->getVar('category')) {
         $presentations = $presentations->filter('CategoryID', (int) $r->getVar('category'));
     }
     if ($r->getVar('keyword')) {
         $presentations = Presentation::apply_search_query($presentations, $r->getVar('keyword'));
     }
     $offset = ($page - 1) * $page_size;
     $count = $presentations->count();
     $presentations = $presentations->limit($page_size, $offset);
     $data = ['results' => [], 'page' => $page, 'total_pages' => ceil($count / $page_size), 'results' => [], 'has_more' => $count > $page_size * $page, 'total' => $count, 'remaining' => $count - $page_size * $page];
     foreach ($presentations as $p) {
         $data['results'][] = ['id' => $p->ID, 'title' => $p->Title, 'viewed' => $p->isViewedByTrackChair(), 'selected' => $p->getSelectionType(), 'selectors' => array_keys($p->getSelectors()->map('Name', 'Name')->toArray()), 'likers' => array_keys($p->getLikers()->map('Name', 'Name')->toArray()), 'passers' => array_keys($p->getPassers()->map('Name', 'Name')->toArray()), 'comment_count' => $p->Comments()->count(), 'popularity' => $p->getPopularityScore(), 'vote_count' => $p->CalcVoteCount(), 'vote_average' => $p->CalcVoteAverage(), 'total_points' => $p->CalcTotalPoints(), 'moved_to_category' => $p->movedToThisCategory(), 'speakers' => $p->getSpeakersCSV()];
     }
     return $this->ok($data);
 }