/**
  * @param $data
  * @param $form
  * @return mixed
  */
 public function doUpload($data, $form)
 {
     $material = PresentationSlide::create();
     $material->SlideID = $data['Slide'];
     $material->write();
     $this->presentation->Materials()->filter(['ClassName' => 'PresentationSlide'])->removeAll();
     $this->presentation->Materials()->add($material);
     $token = SecurityToken::inst()->getValue();
     return $form->controller()->redirect(Controller::join_links($form->controller()->Link(), 'success', "?key={$token}&material={$material->ID}"));
 }
 /**
  * @param $data
  * @param Form $form
  * @return bool|SS_HTTPResponse
  */
 public function saveLink($data, Form $form)
 {
     $url = $data['Link'];
     // Attach a protocol if needed
     if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {
         $url = 'http://' . $url;
     }
     if (!filter_var($url, FILTER_VALIDATE_URL)) {
         $form->sessionMessage('That does not appear to be a valid URL', 'bad');
         return $this->Controller()->redirectBack();
     }
     $material = PresentationSlide::create();
     $material->Link = $url;
     $material->write();
     $this->presentation->Materials()->filter(['ClassName' => 'PresentationSlide'])->removeAll();
     $this->presentation->Materials()->add($material);
     $token = SecurityToken::inst()->getValue();
     return $this->Controller()->redirect(Controller::join_links($this->Controller()->Link(), 'success', "?key={$token}&material={$material->ID}"));
 }
 /**
  * @param SS_HTTPRequest $r
  * @return mixed
  */
 public function success(SS_HTTPRequest $r)
 {
     if (!SecurityToken::inst()->check($r->getVar('key'))) {
         $this->httpError(404);
     }
     $material = PresentationSlide::get()->byID($r->getVar('material'));
     if (!$material) {
         $this->httpError(404);
     }
     return $this->customise(['Material' => $material, 'Presentation' => $this->presentation])->renderWith(['PresentationSlideSubmissionController_success', 'Page']);
 }