Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ docker-compose/mysql/model/*.sql
package.xml
.env.dev
rector.php
public/apc.php
public/apc.php
.claude
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ public function getEvents($summit_id)
$current_user = $this->resource_server_context->getCurrentUser(true);
return $this->withReplica(function() use ($summit_id, $current_user) {
$strategy = new RetrieveAllSummitEventsBySummitStrategy($this->repository, $this->event_repository, $this->resource_server_context);
$response = $strategy->getEvents(['summit_id' => $summit_id]);
$expand = SerializerUtils::getExpand();
$response = $strategy->getEvents(['summit_id' => $summit_id, 'expand' => $expand]);
return $this->ok
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
[
Expand Down Expand Up @@ -234,12 +235,13 @@ public function getEventsCSV($summit_id)
$this->event_repository,
$this->resource_server_context
);
$response = $strategy->getEvents(['summit_id' => $summit_id]);
$expand = SerializerUtils::getExpand();
$response = $strategy->getEvents(['summit_id' => $summit_id, 'expand' => $expand]);

$filename = "activities-" . date('Ymd');
$list = $response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
['none'],
[
Expand Down Expand Up @@ -328,18 +330,20 @@ public function getScheduledEvents($summit_id)
$summit = SummitFinderStrategyFactory::build($this->getRepository(), $this->getResourceServerContext())->find($summit_id);
if (is_null($summit)) return $this->error404();

$expand = SerializerUtils::getExpand();
$params = [
'summit_id' => $summit_id,
'summit' => $summit,
'published' => true,
'current_user' => $current_user
'current_user' => $current_user,
'expand' => $expand,
];

$strategy = new RetrievePublishedSummitEventsBySummitStrategy($this->repository, $this->event_repository, $this->resource_server_context);
$response = $strategy->getEvents($params);
return $this->ok($response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
$params,
Expand Down Expand Up @@ -430,13 +434,14 @@ public function getAllEvents()
$current_user = $this->resource_server_context->getCurrentUser(true);

return $this->withReplica(function() use($current_user){
$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllSummitEventsStrategy($this->event_repository);
$response = $strategy->getEvents();
$response = $strategy->getEvents(['expand' => $expand]);
return $this->ok
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
[
Expand Down Expand Up @@ -482,16 +487,17 @@ public function getAllPresentations($summit_id)
$current_user = $this->resource_server_context->getCurrentUser(true);

return $this->withReplica(function() use($current_user, $summit_id){
$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllSummitPresentationsStrategy($this->repository, $this->event_repository, $this->resource_server_context);
$response = $strategy->getEvents(['summit_id' => intval($summit_id)]);
$response = $strategy->getEvents(['summit_id' => intval($summit_id), 'expand' => $expand]);
$params = [
'current_user' => $current_user,
];
return $this->ok
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
$params,
Expand Down Expand Up @@ -536,14 +542,15 @@ public function getAllVoteablePresentations($summit_id)
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) throw new EntityNotFoundException;

$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllSummitVoteablePresentationsStrategy
(
$this->repository,
$this->event_repository,
$this->resource_server_context
);

$response = $strategy->getEvents(['summit_id' => intval($summit_id)]);
$response = $strategy->getEvents(['summit_id' => intval($summit_id), 'expand' => $expand]);

$params = [
'current_user' => $this->resource_server_context->getCurrentUser(true),
Expand All @@ -554,7 +561,7 @@ public function getAllVoteablePresentations($summit_id)
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
$params,
Expand Down Expand Up @@ -599,13 +606,14 @@ public function getAllVoteablePresentationsV2($summit_id)
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) throw new EntityNotFoundException;

$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllSummitVoteablePresentationsStrategy
(
$this->repository,
$this->event_repository,
$this->resource_server_context
);
$response = $strategy->getEvents(['summit_id' => intval($summit_id)]);
$response = $strategy->getEvents(['summit_id' => intval($summit_id), 'expand' => $expand]);

$params = [
'current_user' => $this->resource_server_context->getCurrentUser(true),
Expand All @@ -628,7 +636,7 @@ public function getAllVoteablePresentationsV2($summit_id)
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
$params,
Expand Down Expand Up @@ -667,14 +675,15 @@ public function getAllVoteablePresentationsV2CSV($summit_id)
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) throw new EntityNotFoundException;

$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllSummitVoteablePresentationsStrategyCSV
(
$this->repository,
$this->event_repository,
$this->resource_server_context
);

$response = $strategy->getEvents(['summit_id' => intval($summit_id)]);
$response = $strategy->getEvents(['summit_id' => intval($summit_id), 'expand' => $expand]);

$params = [
'current_user' => $this->resource_server_context->getCurrentUser(true),
Expand All @@ -697,7 +706,7 @@ public function getAllVoteablePresentationsV2CSV($summit_id)
$filename = "voteable-presentations-" . date('Ymd');
$list = $response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
['none'],
$params,
Expand Down Expand Up @@ -784,13 +793,14 @@ public function getAllScheduledEvents()
$current_user = $this->resource_server_context->getCurrentUser(true);

return $this->withReplica(function () use ($current_user) {
$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllPublishedSummitEventsStrategy($this->event_repository);
$response = $strategy->getEvents();
$response = $strategy->getEvents(['expand' => $expand]);
return $this->ok
(
$response->toArray
(
SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
[
Expand Down Expand Up @@ -1970,13 +1980,14 @@ public function getUnpublishedEvents($summit_id)
}

return $this->withReplica(function() use($summit_id, $serializer_type){
$expand = SerializerUtils::getExpand();
$strategy = new RetrieveAllUnPublishedSummitEventsStrategy($this->repository, $this->event_repository, $this->resource_server_context);

$response = $strategy->getEvents(['summit_id' => $summit_id]);
$response = $strategy->getEvents(['summit_id' => $summit_id, 'expand' => $expand]);
return $this->ok($response->toArray
(

SerializerUtils::getExpand(),
$expand,
SerializerUtils::getFields(),
SerializerUtils::getRelations(),
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected function buildFilter(){
* @param Order|null $order
* @return PagingResponse
*/
public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null): PagingResponse
public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null, array $expands = []): PagingResponse
{
return $this->events_repository->getAllByPage($paging_info, $filter, $order);
return $this->events_repository->getAllByPage($paging_info, $filter, $order, $expands);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function __construct(ISummitEventRepository $event_repository)
* @param Order|null $order
* @return PagingResponse
*/
public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null)
public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null, array $expands = [])
{
return $this->event_repository->getAllByPage($paging_info, $filter, $order);
return $this->event_repository->getAllByPage($paging_info, $filter, $order, $expands);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public function getEvents(array $params = [])

list($page, $per_page) = $this->getPaginationParams();

// Parse expand parameter into array for repository batch-loading
$expandStr = $params['expand'] ?? '';
$expands = !empty($expandStr) ? array_map('trim', explode(',', $expandStr)) : [];

return $this->retrieveEventsFromSource
(
new PagingInfo($page, $per_page), $this->buildFilter(), $this->buildOrder()
new PagingInfo($page, $per_page), $this->buildFilter(), $this->buildOrder(), $expands
);
}

Expand Down Expand Up @@ -152,7 +156,7 @@ protected function buildOrder()
* @param Order|null $order
* @return PagingResponse
*/
abstract public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null);
abstract public function retrieveEventsFromSource(PagingInfo $paging_info, Filter $filter = null, Order $order = null, array $expands = []);

/**
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function serialize($expand = null, array $fields = [], array $relations =
$allowed_access_levels[] = intval($access_level->getId());
}

$values['allowed_access_levels'] = $allowed_access_levels;
$values['.'] = $allowed_access_levels;
}

if(in_array('proposed_schedule_allowed_locations', $relations)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getPublishedOnSameTimeFrame(IPublishableEvent $event): array;
* @param Order|null $order
* @return PagingResponse
*/
public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null);
public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null, array $expands = []);

/**
* @param PagingInfo $paging_info
Expand Down
3 changes: 3 additions & 0 deletions app/Repositories/DoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\Selectable;
use App\libs\Utils\Doctrine\GraphLoaderTrait;
use Illuminate\Support\Facades\Log;
use LaravelDoctrine\ORM\Facades\Registry;
use models\utils\IBaseRepository;
Expand All @@ -40,6 +41,8 @@
*/
abstract class DoctrineRepository extends EntityRepository implements IBaseRepository
{
use GraphLoaderTrait;

protected $fetchJoinCollection = true;

public function __construct(EntityManagerInterface $em, ClassMetadata $class)
Expand Down
57 changes: 55 additions & 2 deletions app/Repositories/Summit/DoctrineSummitEventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ final class DoctrineSummitEventRepository
SummitGroupEvent::ClassName,
];

/**
* Maps serializer expand names to Doctrine field names — only for mismatches.
* The trait's ClassMetadata auto-detection handles association type and entity ownership.
*/
private static array $expandFieldMap = [
'track' => 'category',
'creator' => 'created_by',
'current_attendance' => 'attendance_metrics',
'slides' => 'materials',
'videos' => 'materials',
'media_uploads' => 'materials',
'links' => 'materials',
'extra_questions' => 'extra_question_answers',
'public_comments' => 'comments',
];

public static function getExpandFieldMap(): array
{
return self::$expandFieldMap;
}


private function ensureJoin(QueryBuilder $qb, string $alias): void
{
Expand Down Expand Up @@ -709,7 +730,7 @@ public function getAllIdsByPage(PagingInfo $paging_info, Filter $filter = null,
* @param Order|null $order
* @return PagingResponse
*/
public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null)
public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null, array $expands = [])
{

$start = time();
Expand All @@ -726,7 +747,21 @@ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Ord
->where('e.id IN (:ids)')
->setParameter('ids', $ids);


$em = $this->getEntityManager();

// Fetch-join requested toOne associations into the hydration query
if (!empty($expands)) {
$query = $this->addExpandFetchJoins(
$em,
$query,
$expands,
'e',
SummitEvent::class,
self::$expandFieldMap,
[Presentation::class => 'p'],
['type'] // already inner-joined
);
}

$rows = $query->getQuery()->getResult();
$byId = [];
Expand All @@ -750,6 +785,24 @@ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Ord
if (isset($byId[$id])) $data[] = $byId[$id];
}

// Batch-load toMany collections (level 1) and nested relations (level 2+)
if (!empty($expands) && !empty($data)) {
$this->batchLoadExpandedRelations(
$em,
$data,
$expands,
SummitEvent::class,
self::$expandFieldMap,
[
// Presentation.speakers returns PresentationSpeakerAssignment items;
// the serializer calls $assignment->getSpeaker() to get the actual speaker.
'speakers' => fn($assignment) => method_exists($assignment, 'getSpeaker')
? $assignment->getSpeaker()
: $assignment,
]
);
}

$end = time() - $start;
Log::debug("DoctrineSummitEventRepository::getAllByPage", ['seconds'=>$end]);

Expand Down
Loading
Loading