Fix on event serializer
Change-Id: I5efad1a66d485a93ba0da9de0541c98311c29029 Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
4f9ae06f3c
commit
3b0dc89867
@ -22,6 +22,7 @@ use models\utils\IEntity;
|
||||
*/
|
||||
abstract class AbstractSerializer implements IModelSerializer
|
||||
{
|
||||
const MaxCollectionPage = 10;
|
||||
/**
|
||||
* @var IEntity
|
||||
*/
|
||||
|
@ -179,9 +179,15 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
{
|
||||
try
|
||||
{
|
||||
$expand = Request::input('expand', '');
|
||||
$fields = Request::input('fields', '');
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) :[];
|
||||
$fields = !empty($fields) ? explode(',', $fields) :[];
|
||||
|
||||
$strategy = new RetrievePublishedSummitEventsBySummitStrategy($this->repository, $this->event_repository, $this->resource_server_context);
|
||||
$response = $strategy->getEvents(['summit_id' => $summit_id]);
|
||||
return $this->ok($response->toArray(Request::input('expand', '')));
|
||||
return $this->ok($response->toArray($expand, $fields, $relations));
|
||||
}
|
||||
catch (EntityNotFoundException $ex1)
|
||||
{
|
||||
|
@ -26,5 +26,7 @@ class SummitMetricSerializer extends SilverStripeSerializer
|
||||
'Ip' => 'ip:json_string',
|
||||
'Origin' => 'origin:json_string',
|
||||
'Browser' => 'browser:json_string',
|
||||
'OutgressDate' => 'outgress_date:datetime_epoch',
|
||||
'IngressDate' => 'ingress_date:datetime_epoch'
|
||||
];
|
||||
}
|
@ -20,6 +20,7 @@ use models\summit\SummitEvent;
|
||||
*/
|
||||
class SummitEventSerializer extends SilverStripeSerializer
|
||||
{
|
||||
|
||||
protected static $array_mappings = [
|
||||
'Title' => 'title:json_string',
|
||||
'Abstract' => 'description:json_string',
|
||||
@ -85,7 +86,6 @@ class SummitEventSerializer extends SilverStripeSerializer
|
||||
'sponsors',
|
||||
'tags',
|
||||
'feedback',
|
||||
'attendance',
|
||||
'current_attendance',
|
||||
];
|
||||
|
||||
@ -120,28 +120,26 @@ class SummitEventSerializer extends SilverStripeSerializer
|
||||
if(in_array('feedback', $relations))
|
||||
{
|
||||
$feedback = [];
|
||||
$count = 0;
|
||||
foreach ($event->getFeedback() as $f) {
|
||||
$feedback[] = $f->getId();
|
||||
$count++;
|
||||
if(AbstractSerializer::MaxCollectionPage < $count) break;
|
||||
}
|
||||
$values['feedback'] = $feedback;
|
||||
}
|
||||
|
||||
if(in_array('current_attendance', $relations)){
|
||||
$attendance = [];
|
||||
$count = 0;
|
||||
foreach ($event->getCurrentAttendance() as $a){
|
||||
$attendance[] = SerializerRegistry::getInstance()->getSerializer($a)->serialize();
|
||||
$attendance[] = $a->getId();
|
||||
$count++;
|
||||
if(AbstractSerializer::MaxCollectionPage < $count) break;
|
||||
}
|
||||
$values['current_attendance'] = $attendance;
|
||||
}
|
||||
|
||||
if(in_array('attendance', $relations)){
|
||||
$attendance = [];
|
||||
foreach ($event->getAttendance() as $a){
|
||||
$attendance[] = SerializerRegistry::getInstance()->getSerializer($a)->serialize();
|
||||
}
|
||||
$values['attendance'] = $attendance;
|
||||
}
|
||||
|
||||
//if($event->hasAccess($this->resource_server_context->getCurrentUser())){
|
||||
$values['streaming_url'] = $event->getStreamingUrl();
|
||||
$values['etherpad_link'] = $event->getEtherpadLink();
|
||||
@ -151,6 +149,17 @@ class SummitEventSerializer extends SilverStripeSerializer
|
||||
foreach (explode(',', $expand) as $relation) {
|
||||
$relation = trim($relation);
|
||||
switch ($relation) {
|
||||
case 'current_attendance':
|
||||
{
|
||||
$attendance = [];
|
||||
$count = 0;
|
||||
foreach ($event->getCurrentAttendance() as $a){
|
||||
$attendance[] = SerializerRegistry::getInstance()->getSerializer($a)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
$count++;
|
||||
if(AbstractSerializer::MaxCollectionPage < $count) break;
|
||||
}
|
||||
$values['current_attendance'] = $attendance;
|
||||
}
|
||||
case 'feedback': {
|
||||
$feedback = [];
|
||||
foreach ($event->getFeedback() as $f) {
|
||||
|
@ -131,7 +131,7 @@ class Presentation extends SummitEvent
|
||||
protected $attending_media;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="moderated_presentations")
|
||||
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="moderated_presentations", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinColumn(name="ModeratorID", referencedColumnName="ID", onDelete="SET NULL")
|
||||
* @var PresentationSpeaker
|
||||
*/
|
||||
@ -139,33 +139,33 @@ class Presentation extends SummitEvent
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member")
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinColumn(name="CreatorID", referencedColumnName="ID", onDelete="SET NULL")
|
||||
* @var Member
|
||||
*/
|
||||
protected $creator;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Models\Foundation\Summit\SelectionPlan", inversedBy="presentations")
|
||||
* @ORM\ManyToOne(targetEntity="App\Models\Foundation\Summit\SelectionPlan", inversedBy="presentations", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinColumn(name="SelectionPlanID", referencedColumnName="ID")
|
||||
* @var SelectionPlan
|
||||
*/
|
||||
protected $selection_plan;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\PresentationMaterial", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OneToMany(targetEntity="models\summit\PresentationMaterial", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
|
||||
* @var PresentationMaterial[]
|
||||
*/
|
||||
protected $materials;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitPresentationComment", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitPresentationComment", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
|
||||
* @var SummitPresentationComment[]
|
||||
*/
|
||||
protected $comments;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\summit\PresentationSpeaker", inversedBy="presentations")
|
||||
* @ORM\ManyToMany(targetEntity="models\summit\PresentationSpeaker", inversedBy="presentations" , fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="Presentation_Speakers",
|
||||
* joinColumns={
|
||||
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="CASCADE")
|
||||
@ -179,7 +179,7 @@ class Presentation extends SummitEvent
|
||||
protected $speakers;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitSelectedPresentation", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitSelectedPresentation", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
|
||||
* @var SummitSelectedPresentation[]
|
||||
*/
|
||||
protected $selected_presentations;
|
||||
|
@ -141,7 +141,7 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
protected $rsvp_template;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\RSVP", mappedBy="event", cascade={"persist"})
|
||||
* @ORM\OneToMany(targetEntity="models\summit\RSVP", mappedBy="event", cascade={"persist"}, fetch="EXTRA_LAZY")
|
||||
* @var RSVP[]
|
||||
*/
|
||||
protected $rsvp;
|
||||
@ -189,14 +189,14 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
protected $sponsors;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitEventFeedback", mappedBy="event", cascade={"persist"})
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitEventFeedback", mappedBy="event", cascade={"persist"}, fetch="EXTRA_LAZY")
|
||||
* @ORM\Cache("NONSTRICT_READ_WRITE")
|
||||
* @var SummitEventFeedback[]
|
||||
*/
|
||||
protected $feedback;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\main\Tag", cascade={"persist"}, inversedBy="events")
|
||||
* @ORM\ManyToMany(targetEntity="models\main\Tag", cascade={"persist"}, inversedBy="events", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="SummitEvent_Tags",
|
||||
* joinColumns={@ORM\JoinColumn(name="SummitEventID", referencedColumnName="ID")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="TagID", referencedColumnName="ID")}
|
||||
@ -205,7 +205,7 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
protected $tags;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitEventAttendanceMetric", mappedBy="event", cascade={"persist","remove"}, orphanRemoval=true)
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitEventAttendanceMetric", mappedBy="event", cascade={"persist","remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
|
||||
* @var SummitEventAttendanceMetric[]
|
||||
*/
|
||||
protected $attendance_metrics;
|
||||
@ -1165,6 +1165,7 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
public function getCurrentAttendance(){
|
||||
$criteria = Criteria::create();
|
||||
$criteria = $criteria->where(Criteria::expr()->isNull('outgress_date'));
|
||||
$criteria = $criteria->orderBy(['created' => Criteria::DESC]);
|
||||
return $this->attendance_metrics->matching($criteria)->toArray();
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ use Doctrine\ORM\Mapping AS ORM;
|
||||
trait SummitOwned
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\Summit")
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\Summit", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinColumn(name="SummitID", referencedColumnName="ID")
|
||||
* @var Summit
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user