commit f0c49c8f833648addb4b662d5d2a963c5a65860e Author: smarcet Date: Tue Oct 6 13:49:37 2020 -0300 Added video column ( media upload) to CSV events export Change-Id: I680b09cadc5b9fa5242d82b82837ad1e11297c74 Signed-off-by: smarcet diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php index f1a63d0..1972f04 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php @@ -136,7 +136,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController $response = $strategy->getEvents(['summit_id' => $summit_id]); $filename = "events-" . date('Ymd'); - $list = $response->toArray(null, [], ['none']); + $list = $response->toArray(null, [], ['none'],[],SerializerRegistry::SerializerType_CSV); return $this->export ( diff --git a/app/ModelSerializers/SerializerRegistry.php b/app/ModelSerializers/SerializerRegistry.php index bfe6b5a..2f56be0 100644 --- a/app/ModelSerializers/SerializerRegistry.php +++ b/app/ModelSerializers/SerializerRegistry.php @@ -12,7 +12,6 @@ * limitations under the License. **/ -use App\Models\Foundation\Summit\Events\SummitEventAttendanceMetric; use App\ModelSerializers\CCLA\TeamSerializer; use App\ModelSerializers\FileSerializer; use App\ModelSerializers\ISummitAttendeeTicketSerializerTypes; @@ -178,16 +177,20 @@ final class SerializerRegistry $this->registry['TrackRadioButtonListQuestionTemplate'] = TrackMultiValueQuestionTemplateSerializer::class; $this->registry['TrackLiteralContentQuestionTemplate'] = TrackLiteralContentQuestionTemplateSerializer::class; // events - $this->registry['SummitEvent'] = SummitEventSerializer::class; + + $this->registry['SummitEvent'] = [ + self::SerializerType_Public => SummitEventSerializer::class, + ]; + $this->registry['SummitGroupEvent'] = SummitGroupEventSerializer::class; $this->registry['TrackTagGroup'] = TrackTagGroupSerializer::class; $this->registry['Presentation'] = [ self::SerializerType_Public => PresentationSerializer::class, - self::SerializerType_Private => AdminPresentationSerializer::class + self::SerializerType_Private => AdminPresentationSerializer::class, + self::SerializerType_CSV => AdminPresentationCSVSerializer::class ]; - $this->registry['SummitPresentationComment'] = SummitPresentationCommentSerializer::class; $this->registry['SummitMediaFileType'] = SummitMediaFileTypeSerializer::class; $this->registry['SummitMediaUploadType'] = SummitMediaUploadTypeSerializer::class; @@ -258,6 +261,7 @@ final class SerializerRegistry self::SerializerType_Public => SummitRegistrationInvitationSerializer::class, self::SerializerType_CSV => SummitRegistrationInvitationCSVSerializer::class, ]; + $this->registry['SummitAccessLevelType'] = SummitAccessLevelTypeSerializer::class; $this->registry['SummitTaxType'] = SummitTaxTypeSerializer::class; $this->registry['SummitBadgeType'] = SummitBadgeTypeSerializer::class; diff --git a/app/ModelSerializers/Summit/Presentation/AdminPresentationCSVSerializer.php b/app/ModelSerializers/Summit/Presentation/AdminPresentationCSVSerializer.php new file mode 100644 index 0000000..5635829 --- /dev/null +++ b/app/ModelSerializers/Summit/Presentation/AdminPresentationCSVSerializer.php @@ -0,0 +1,57 @@ +object; + if(!$presentation instanceof Presentation) return $values; + + $serializerType = SerializerRegistry::SerializerType_Public; + $currentUser = $this->resource_server_context->getCurrentUser(); + if(!is_null($currentUser) && $currentUser->isAdmin()){ + $serializerType = SerializerRegistry::SerializerType_Private; + } + + // add video column + $values['video'] = ''; + foreach ($presentation->getMediaUploads() as $mediaUpload) { + if(str_contains(strtolower($mediaUpload->getMediaUploadType()->getType()->getName()), "video")) { + $media_upload_csv = SerializerRegistry::getInstance()->getSerializer($mediaUpload, $serializerType)->serialize(AbstractSerializer::filterExpandByPrefix($expand, 'media_uploads'));; + if(!isset($media_upload_csv['private_url']) || !isset($media_upload_csv['filename'])){ + Log::warning(sprintf("AdminPresentationCSVSerializer::serialize can not process media upload %s", json_encode($media_upload_csv))); + continue; + } + $values['video'] = sprintf('=HYPERLINK("%s";"%s")', $media_upload_csv['private_url'], $media_upload_csv['filename']); + } + } + + return $values; + } +} \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php index c03bbeb..b45266a 100644 --- a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php +++ b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php @@ -478,6 +478,16 @@ class Presentation extends SummitEvent } /** + * @param SummitMediaUploadType $media_upload_type + * @return bool + */ + public function hasMediaUploadByType(SummitMediaUploadType $media_upload_type):bool{ + $res = $this->materials->filter(function( $element) use($media_upload_type) { + return $element instanceof PresentationMediaUpload && $element->getMediaUploadTypeId() == $media_upload_type->getId(); }); + return $res->count() > 0; + } + + /** * @param PresentationMediaUpload $mediaUpload * @return $this */ diff --git a/app/Services/Model/Imp/PresentationService.php b/app/Services/Model/Imp/PresentationService.php index f28d68c..b2bef6e 100644 --- a/app/Services/Model/Imp/PresentationService.php +++ b/app/Services/Model/Imp/PresentationService.php @@ -1031,6 +1031,17 @@ final class PresentationService throw new ValidationException(sprintf("File Extension %s is not valid", $fileExt)); } + if($presentation->hasMediaUploadByType($media_upload_type)){ + throw new ValidationException + ( + sprintf + ( + "Presentation %s already has a media upload for that type %s.", + $presentation_id, $media_upload_type->getName() + ) + ); + } + $mediaUpload = new PresentationMediaUpload(); $mediaUpload->setMediaUploadType($media_upload_type); $mediaUpload->setPresentation($presentation); diff --git a/tests/OAuth2SummitEventsApiTest.php b/tests/OAuth2SummitEventsApiTest.php index 3b0e41f..215606f 100644 --- a/tests/OAuth2SummitEventsApiTest.php +++ b/tests/OAuth2SummitEventsApiTest.php @@ -476,13 +476,11 @@ final class OAuth2SummitEventsApiTest extends ProtectedApiTest { $params = array ( - 'id' => 6, - 'expand' => 'feedback', - 'filter' => array - ( - 'tags=@design', - 'start_date>1445895000' - ) + 'id' => 31, + //'expand' => 'feedback', + 'filter' => [ + 'published==1' + ] ); $headers = array