/** * Used by the track chair app to allow chairs to add a presentation to a personal list. **/ public function assignToIndividualList($collection) { // Check permissions of user on talk if (!$this->owner->CanAssign()) { return; } $maybe = $collection === SummitSelectedPresentation::COLLECTION_MAYBE; $pass = $collection === SummitSelectedPresentation::COLLECTION_PASS; $selected = $collection === SummitSelectedPresentation::COLLECTION_SELECTED; if (!$maybe && !$pass && !$selected) { throw new InvalidArgumentException("assignToIndividualList() must take a collection argument of COLLECTION_MAYBE, COLLECTION_PASS, or COLLECTION_SELECTED per the SummitSelectedPresentation class definition"); } $mySelections = SummitSelectedPresentationList::getMemberList($this->owner->CategoryID); // See if the presentation has already been assigned $selectedPresentation = $mySelections->SummitSelectedPresentations()->filter('PresentationID', $this->owner->ID)->first(); $category = $this->owner->Category(); $highestSelection = $mySelections->maxPresentations(); $highestOrderInList = $mySelections->SummitSelectedPresentations()->filter('Collection', $collection)->max('Order'); if ($selected && $highestOrderInList >= $highestSelection) { throw new EntityValidationException("Selection list is full. Currently at {$highestOrderInList}. Limit is {$highestSelection}."); } if (!$selectedPresentation) { $selectedPresentation = SummitSelectedPresentation::create(); $selectedPresentation->SummitSelectedPresentationListID = $mySelections->ID; $selectedPresentation->PresentationID = $this->owner->ID; $selectedPresentation->MemberID = Member::currentUser()->ID; } $selectedPresentation->Collection = $collection; $selectedPresentation->Order = $highestOrderInList + 1; $selectedPresentation->write(); }
/** * @param SS_HTTPRequest $r * @return SS_HTTPResponse * @throws ValidationException * @throws null */ public function handleReorderList(SS_HTTPRequest $r) { $vars = Convert::json2array($r->getBody()); $idList = $vars['order']; $listID = $vars['list_id']; $collection = $vars['collection']; $list = SummitSelectedPresentationList::get()->byId($listID); if (!$list->memberCanEdit()) { return $this->httpError(403, 'You cannot edit this list'); } $isTeam = $list->ListType === 'Group'; // Remove any presentations that are not in the list SummitSelectedPresentation::get()->filter(['SummitSelectedPresentationListID' => $listID, 'Collection' => $collection])->exclude(['PresentationID' => array_values($idList)])->removeAll(); if (is_array($idList)) { foreach ($idList as $order => $id) { $attributes = ['PresentationID' => $id, 'SummitSelectedPresentationListID' => $listID, 'Collection' => $collection]; $selection = SummitSelectedPresentation::get()->filter($attributes)->first(); if (!$selection) { $selection = SummitSelectedPresentation::create($attributes); if ($isTeam) { $presentation = Presentation::get()->byID($id); if ($presentation) { $presentation->addNotification('{member} added this presentation to the team list'); } } } $selection->Order = $order + 1; $selection->write(); } } return $this->ok(); }