public function handleGetMemberSelections(SS_HTTPRequest $r) { if (!Member::currentUser()) { return $this->httpError(403); } $results = []; $categoryID = (int) $r->param('categoryID'); $results['category_id'] = $categoryID; $lists = SummitSelectedPresentationList::getAllListsByCategory($categoryID); foreach ($lists as $key => $list) { $selections = $list->SummitSelectedPresentations()->sort('Order ASC'); $count = $selections->count(); $listID = $list->ID; $data = array('list_name' => $list->name, 'list_type' => $list->ListType, 'list_id' => $listID, 'total' => $count, 'can_edit' => $list->memberCanEdit(), 'slots' => $list->maxPresentations(), 'mine' => $list->mine()); foreach ($selections as $s) { $data['selections'][] = array('title' => $s->Presentation()->Title, 'order' => $s->Order, 'id' => $s->PresentationID); } $results['lists'][] = $data; } return (new SS_HTTPResponse(Convert::array2json($results), 200))->addHeader('Content-Type', 'application/json'); }
/** * @param SS_HTTPRequest $r * @return SS_HTTPResponse */ public function handleGetMemberSelections(SS_HTTPRequest $r) { $results = []; $categoryID = (int) $r->param('categoryID'); $results['category_id'] = $categoryID; $category = PresentationCategory::get()->byID($categoryID); if (!$category) { return $this->notFound(sprintf('Category id %s not found!', $categoryID)); } $summitID = (int) Summit::get_active()->ID; if (intval($category->SummitID) !== $summitID) { return $this->validationError(sprintf('Category id %s does not belong to current summit!', $categoryID)); } $lists = SummitSelectedPresentationList::getAllListsByCategory($categoryID); foreach ($lists as $key => $list) { $selections = $list->SummitSelectedPresentations()->exclude('Collection', SummitSelectedPresentation::COLLECTION_PASS)->sort(['Collection DESC', 'Order ASC']); $count = $selections->count(); $listID = $list->ID; $data = ['id' => $listID, 'list_name' => $list->name, 'list_type' => $list->ListType, 'list_id' => $listID, 'total' => $count, 'can_edit' => $list->memberCanEdit(), 'slots' => $list->maxPresentations(), 'alternates' => $list->Category()->AlternateCount, 'mine' => $list->mine(), 'selections' => [], 'maybes' => []]; foreach ($selections as $s) { $p = $s->Presentation(); $selectionData = ['presentation' => ['title' => $p->Title, '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()), 'group_selected' => $p->isGroupSelected(), 'comment_count' => $p->Comments()->count(), 'level' => $p->Level], 'order' => $s->Order, 'id' => $s->PresentationID]; if ($s->isSelected()) { $data['selections'][] = $selectionData; } else { if ($s->isMaybe()) { $data['maybes'][] = $selectionData; } } } $results['lists'][] = $data; } return $this->ok($results); }