Added video column ( media upload) to
CSV events export Change-Id: I680b09cadc5b9fa5242d82b82837ad1e11297c74 Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
affdcd569a
commit
f0c49c8f83
@ -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
|
||||
(
|
||||
|
@ -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;
|
||||
|
@ -0,0 +1,57 @@
|
||||
<?php namespace ModelSerializers;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Libs\ModelSerializers\AbstractSerializer;
|
||||
use models\summit\Presentation;
|
||||
/**
|
||||
* Class AdminPresentationCSVSerializer
|
||||
* @package ModelSerializers
|
||||
*/
|
||||
final class AdminPresentationCSVSerializer extends AdminPresentationSerializer
|
||||
{
|
||||
/**
|
||||
* @param null $expand
|
||||
* @param array $fields
|
||||
* @param array $relations
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [] )
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$presentation = $this->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;
|
||||
}
|
||||
}
|
@ -477,6 +477,16 @@ class Presentation extends SummitEvent
|
||||
return $this->materials->filter(function( $element) { return $element instanceof PresentationMediaUpload; });
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user