diff --git a/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMediaUpload.php b/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMediaUpload.php index 037824a0..252d532b 100644 --- a/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMediaUpload.php +++ b/app/Models/Foundation/Summit/Events/Presentations/Materials/PresentationMediaUpload.php @@ -83,6 +83,13 @@ class PresentationMediaUpload extends PresentationMaterial $this->media_upload_type = $media_upload_type; } + /** + * @return bool + */ + public function isMandatory():bool{ + return $this->media_upload_type->isMandatory(); + } + /** * @return int */ diff --git a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php index 385ddf12..831cbcae 100644 --- a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php +++ b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php @@ -57,21 +57,25 @@ class Presentation extends SummitEvent */ const PHASE_SUMMARY = 1; + /** + * defines a phase where a presentation has a UPLOADS + */ + const PHASE_UPLOADS = 2; + /** * defines a phase where a presentation has a tags */ - const PHASE_TAGS = 2; + const PHASE_TAGS = 3; /** * defines a phase where a presentation has a summary and speakers */ - const PHASE_SPEAKERS = 3; - + const PHASE_SPEAKERS = 4; /** * Defines a phase where a presentation has been submitted successfully */ - const PHASE_COMPLETE = 4; + const PHASE_COMPLETE = 5; /** * @@ -625,6 +629,9 @@ class Presentation extends SummitEvent case self::PHASE_SUMMARY: return 'SUMMARY'; break; + case self::PHASE_UPLOADS: + return 'UPLOADS'; + break; case self::PHASE_TAGS: return 'TAGS'; break; @@ -658,9 +665,10 @@ class Presentation extends SummitEvent /** * @param int $progress */ - public function setProgress($progress) + public function setProgress(int $progress) { - $this->progress = $progress; + if($this->progress < $progress) + $this->progress = $progress; } /** @@ -1004,4 +1012,13 @@ class Presentation extends SummitEvent ); } + /** + * @return int + */ + public function getMediaUploadsMandatoryCount():int{ + return $this->materials->filter(function( $element) { + return $element instanceof PresentationMediaUpload && $element->isMandatory(); + })->count(); + } + } diff --git a/app/Models/Foundation/Summit/Summit.php b/app/Models/Foundation/Summit/Summit.php index 9c8291fa..6e45fdc0 100644 --- a/app/Models/Foundation/Summit/Summit.php +++ b/app/Models/Foundation/Summit/Summit.php @@ -4839,6 +4839,29 @@ SQL; return $type === false ? null : $type; } + + public function getMediaUploadsMandatoryCount():int { + try { + $sql = <<prepareRawSQL($sql); + $stmt->execute([ + 'summit_id' => $this->id, + ]); + $res = $stmt->fetchAll(\PDO::FETCH_COLUMN); + $count = count($res) > 0 ? $res[0] : 0; + } catch (\Exception $ex) { + $count = 0; + } + + return $count; + } + /** * @param string $name * @return SummitMediaUploadType|null diff --git a/app/Services/Model/Imp/PresentationService.php b/app/Services/Model/Imp/PresentationService.php index dab38fb6..4a49c9d0 100644 --- a/app/Services/Model/Imp/PresentationService.php +++ b/app/Services/Model/Imp/PresentationService.php @@ -28,6 +28,7 @@ use App\Services\Model\AbstractService; use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackAnswer; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Log; use models\exceptions\EntityNotFoundException; use models\exceptions\ValidationException; use models\main\IFolderRepository; @@ -995,6 +996,7 @@ final class PresentationService $payload ) { + Log::debug(sprintf("PresentationService::addMediaUploadTo summit %s presentation %s", $summit->getId(), $presentation_id)); $presentation = $this->presentation_repository->getById($presentation_id); if (is_null($presentation) || !$presentation instanceof Presentation) @@ -1069,6 +1071,21 @@ final class PresentationService $mediaUpload->setFilename($fileName); $presentation->addMediaUpload($mediaUpload); + if(!$presentation->isCompleted()){ + Log::debug(sprintf("PresentationService::addMediaUploadTo presentation %s is not complete", $presentation_id)); + $summitMediaUploadCount = $summit->getMediaUploadsMandatoryCount(); + Log::debug(sprintf("PresentationService::addMediaUploadTo presentation %s got summitMediaUploadCount %s", $presentation_id, $summitMediaUploadCount)); + if($summitMediaUploadCount == 0) { + Log::debug(sprintf("PresentationService::addMediaUploadTo presentation %s marking as PHASE_UPLOADS ( no mandatories uploads)", $presentation_id)); + $presentation->setProgress(Presentation::PHASE_UPLOADS); + } + + if($summitMediaUploadCount > 0 && $summitMediaUploadCount == $presentation->getMediaUploadsMandatoryCount()){ + Log::debug(sprintf("PresentationService::addMediaUploadTo presentation %s marking as PHASE_UPLOADS ( mandatories completed)", $presentation_id)); + $presentation->setProgress(Presentation::PHASE_UPLOADS); + } + } + return $mediaUpload; }); } diff --git a/database/migrations/model/Version20201021172434.php b/database/migrations/model/Version20201021172434.php new file mode 100644 index 00000000..d57186a3 --- /dev/null +++ b/database/migrations/model/Version20201021172434.php @@ -0,0 +1,50 @@ +addSql($sql); + + $sql = <<addSql($sql); + + $sql = <<addSql($sql); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + + } +}