コード例 #1
0
 public function handleAcceptCategoryChange(SS_HTTPResponse $r)
 {
     if (!Permission::check('ADMIN')) {
         return $this->httpError(403);
     }
     if (!is_numeric($r->param('ID'))) {
         return $this->httpError(500, "Invalid category change id");
     }
     $request = SummitCategoryChange::get()->byID($r->param('ID'));
     if ($request->exists()) {
         if ($request->Presentation()->isSelectedByAnyone()) {
             return new SS_HTTPResponse("The presentation has already been selected by chairs.", 500);
         }
         if ($request->Presentation()->CategoryID == $request->NewCategoryID) {
             $request->Done = TRUE;
             $request->write();
             return new SS_HTTPResponse("The presentation is already in this category.", 200);
         }
         // Make the category change
         $summit = Summit::get_active();
         $category = $summit->Categories()->filter('ID', $request->NewCategoryID)->first();
         if (!$category->exists()) {
             return $this->httpError(500, "Category not found in current summit");
         }
         $request->OldCategoryID = $request->Presentation()->CategoryID;
         $request->Presentation()->CategoryID = $request->NewCategoryID;
         $request->Presentation()->write();
         $comment = new SummitPresentationComment();
         $comment->Body = 'This presentaiton was moved into the category ' . $category->Title . '.' . ' The chage was approved by ' . Member::currentUser()->FirstName . ' ' . Member::currentUser()->Surname . '.';
         $comment->PresentationID = $request->Presentation()->ID;
         $comment->write();
         $request->AdminApproverID = Member::currentUserID();
         $request->Approved = TRUE;
         $request->Done = TRUE;
         $request->ApprovalDate = SS_Datetime::now();
         $request->write();
         return new SS_HTTPResponse("change request accepted.", 200);
     }
 }
コード例 #2
0
 /**
  * @param SS_HTTPRequest $r
  * @return SS_HTTPRequest
  */
 public function index(SS_HTTPRequest $r)
 {
     $p = $this->presentation;
     $speakers = [];
     $current_summit = $p->Summit();
     foreach ($p->getSpeakersAndModerators() as $s) {
         // if($s->Bio == NULL) $s->Bio = " ";
         $s->Bio = str_replace(array("\r", "\n"), "", $s->Bio);
         $speakerData = $s->toJSON();
         $speakerData['photo_url'] = $s->ProfilePhoto();
         $speakerData['available_for_bureau'] = intval($speakerData['available_for_bureau']);
         $speakerData['is_moderator'] = (bool) $s->ModeratorPresentations()->byID($p->ID);
         $expertise_areas = [];
         foreach ($s->AreasOfExpertise() as $a) {
             array_push($expertise_areas, ['id' => $a->ID, 'expertise' => $a->Expertise]);
         }
         $speakerData['expertise_areas'] = $expertise_areas;
         $former_presentations = [];
         $formerList = $s->Presentations()->exclude('SummitID', $current_summit->ID)->limit(5)->sort('StartDate', 'DESC');
         foreach ($formerList as $pf) {
             array_push($former_presentations, ['id' => $pf->ID, 'title' => $pf->Title, 'url' => $pf->Link]);
         }
         $speakerData['former_presentations'] = $former_presentations;
         $links = [];
         foreach ($s->OtherPresentationLinks() as $l) {
             array_push($links, ['id' => $l->ID, 'title' => $l->Title, 'url' => $l->LinkUrl]);
         }
         $speakerData['other_links'] = $links;
         $travel_preferences = [];
         foreach ($s->TravelPreferences() as $t) {
             array_push($travel_preferences, ['id' => $t->ID, 'country' => $t->Country]);
         }
         $speakerData['travel_preferences'] = $travel_preferences;
         $languages = [];
         foreach ($s->Languages() as $l) {
             array_push($languages, ['id' => $l->ID, 'language' => $l->Language]);
         }
         $speakerData['languages'] = $languages;
         $speakers[] = $speakerData;
     }
     $comments = [];
     foreach ($p->Comments() as $c) {
         $comment = $c->toJSON();
         $comment['name'] = $c->Commenter()->FirstName . ' ' . $c->Commenter()->Surname;
         $comment['ago'] = $c->obj('Created')->Ago(false);
         $comment['is_activity'] = (bool) $c->IsActivity;
         $comments[] = $comment;
     }
     // remove unsafe character for JSON
     $p->ShortDescription = $p->ShortDescription != null ? str_replace(array("\r", "\n"), "", $p->ShortDescription) : '(no description provided)';
     $p->ProblemAddressed = $p->ProblemAddressed != null ? str_replace(array("\r", "\n"), "", $p->ProblemAddressed) : '(no answer provided)';
     $p->AttendeesExpectedLearnt = $p->AttendeesExpectedLearnt != null ? str_replace(array("\r", "\n"), "", $p->AttendeesExpectedLearnt) : '(no answer provided)';
     $data = $p->toJSON();
     $data['title'] = $p->Title;
     $data['description'] = $p->ShortDescription != null ? $p->ShortDescription : '(no description provided)';
     $data['category_name'] = $p->Category()->Title;
     $data['speakers'] = $speakers;
     $data['total_votes'] = $p->Votes()->count();
     $data['vote_count'] = $p->CalcVoteCount();
     $data['vote_average'] = $p->CalcVoteAverage();
     $data['total_points'] = $p->CalcTotalPoints() > 0 ? $p->CalcTotalPoints() : '0';
     $data['creator'] = $p->Creator()->getName();
     $data['user_vote'] = $p->getUserVote() ? $p->getUserVote()->Vote : null;
     $data['comments'] = $comments;
     $data['can_assign'] = $p->canAssign(1) ? $p->canAssign(1) : null;
     $data['selected'] = $p->getSelectionType();
     $data['selectors'] = array_keys($p->getSelectors()->map('Name', 'Name')->toArray());
     $data['likers'] = array_keys($p->getLikers()->map('Name', 'Name')->toArray());
     $data['passers'] = array_keys($p->getPassers()->map('Name', 'Name')->toArray());
     $data['popularity'] = $p->getPopularityScore();
     $data['group_selected'] = $p->isGroupSelected();
     $data['moved_to_category'] = $p->movedToThisCategory();
     $data['change_requests_count'] = SummitCategoryChange::get()->filter(['PresentationID' => $p->ID, 'Status' => SummitCategoryChange::STATUS_PENDING])->count();
     return (new SS_HTTPResponse(Convert::array2json($data), 200))->addHeader('Content-Type', 'application/json');
 }