public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     parent::saveInto($dataObject, $fieldList);
     if (!$dataObject instanceof Presentation) {
         return;
     }
     $presentation = $dataObject;
     $old_materials = $presentation->Materials()->filter('ClassName', 'PresentationLink');
     foreach ($old_materials as $o) {
         $o->Delete();
     }
     for ($i = 1; $i <= 5; $i++) {
         $field = $this->fields->fieldByName("PresentationLink[{$i}]");
         if (is_null($field)) {
             continue;
         }
         $val = $field->Value();
         if (empty($val)) {
             continue;
         }
         $presentation->Materials()->add(PresentationLink::create(array('Link' => trim($val))));
     }
 }
 /**
  * @param IPresentation $presentation
  * @param array $data
  * @return IPresentation
  */
 public function updatePresentationSummary(IPresentation $presentation, array $data)
 {
     return $this->tx_manager->transaction(function () use($presentation, $data) {
         $presentation->Title = trim($data['Title']);
         $presentation->TypeID = intval($data['TypeID']);
         $presentation->Level = trim($data['Level']);
         $presentation->ShortDescription = trim($data['ShortDescription']);
         $presentation->ProblemAddressed = trim($data['ProblemAddressed']);
         $presentation->AttendeesExpectedLearnt = trim($data['AttendeesExpectedLearnt']);
         $presentation->CategoryID = intval(trim($data['CategoryID']));
         $creator = Member::get()->byID($presentation->CreatorID);
         $summit = $presentation->Summit();
         $speaker = $creator->getSpeakerProfile();
         // if the user changed the presentation type from panel to presentation we need to remove the moderator
         if ($presentation->Type()->Type != 'Panel') {
             $presentation->ModeratorID = 0;
         }
         // SANTI: why do we check limit on edition?
         /*if(intval($presentation->CategoryID) > 0)
                     {
                         $category = PresentationCategory::get()->byID($presentation->CategoryID);
                         if(is_null($category)) throw new NotFoundEntityException('category not found!.');
         
                         $limit    = $this->getSubmissionLimitFor($speaker, $category);
                         $count    = $summit->isPublicCategory($category) ?
                             (
                                 intval($speaker->getPublicCategoryPresentationsBySummit($summit)->count()) +
                                 intval($speaker->getPublicCategoryOwnedPresentationsBySummit($summit)->count())
                             ):
                             (
                                 intval($speaker->getPrivateCategoryPresentationsBySummit($summit, $summit->getPrivateGroupFor($category))->count()) +
                                 intval($speaker->getPrivateCategoryOwnedPresentationsBySummit($summit, $summit->getPrivateGroupFor($category))->count())
                             );
         
                         if ($count >= $limit)
                             throw new EntityValidationException(sprintf('You reached the limit (%s) of presentations.', $limit));
                     }*/
         if (isset($data['OtherTopic'])) {
             $presentation->OtherTopic = trim($data['OtherTopic']);
         }
         $old_materials = $presentation->Materials()->filter('ClassName', 'PresentationLink');
         foreach ($old_materials as $o) {
             $o->Delete();
         }
         if (isset($data["PresentationLink"])) {
             foreach ($data["PresentationLink"] as $id => $val) {
                 if (empty($val)) {
                     continue;
                 }
                 $presentation->Materials()->add(PresentationLink::create(array('Link' => trim($val))));
             }
         }
         $extra_questions = $presentation->Category()->Exists() ? $presentation->Category()->ExtraQuestions() : array();
         foreach ($extra_questions as $question) {
             if (!isset($data[$question->Name])) {
                 continue;
             }
             if (!$data[$question->Name]) {
                 continue;
             }
             $answer_value = $data[$question->Name];
             if (empty($answer_value)) {
                 continue;
             }
             if (!($answer = $presentation->findAnswerByQuestion($question))) {
                 $answer = new TrackAnswer();
             }
             if (is_array($answer_value)) {
                 $answer_value = str_replace('{comma}', ',', $answer_value);
                 $answer->Value = implode(',', $answer_value);
             } else {
                 $answer->Value = $answer_value;
             }
             $answer->QuestionID = $question->getIdentifier();
             $answer->write();
             $presentation->ExtraAnswers()->add($answer);
         }
         $presentation->write();
         return $presentation;
     });
 }
 public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     parent::saveInto($dataObject, $fieldList);
     if (!$dataObject instanceof Presentation) {
         return;
     }
     $presentation = $dataObject;
     $old_materials = $presentation->Materials()->filter('ClassName', 'PresentationLink');
     foreach ($old_materials as $o) {
         $o->Delete();
     }
     for ($i = 1; $i <= 5; $i++) {
         $field = $this->fields->fieldByName("PresentationLink[{$i}]");
         if (is_null($field)) {
             continue;
         }
         $val = $field->Value();
         if (empty($val)) {
             continue;
         }
         $presentation = PresentationLink::create(['Name' => trim($val), 'Link' => trim($val)]);
         $presentation->Materials()->add($presentation);
     }
     $extra_questions = $presentation->Category()->Exists() ? $presentation->Category()->ExtraQuestions() : array();
     foreach ($extra_questions as $question) {
         $field = $this->fields->fieldByName($question->Name);
         if (is_null($field)) {
             continue;
         }
         $answer_value = $field->Value();
         if (empty($answer_value)) {
             continue;
         }
         if (!($answer = $presentation->findAnswerByQuestion($question))) {
             $answer = new TrackAnswer();
         }
         if (is_array($answer_value)) {
             $answer_value = str_replace('{comma}', ',', $answer_value);
             $answer->Value = implode(',', $answer_value);
         } else {
             $answer->Value = $answer_value;
         }
         $answer->QuestionID = $question->getIdentifier();
         $answer->write();
         $presentation->ExtraAnswers()->add($answer);
     }
 }