Question

I have 3 entities, two(with Sonata Admins) of which are referenced in the third through one-to-many relationships which also has extra fields. 1st Entity is Journalist which basically manages journalists, 2nd Entity is Event which manages events. Last admin is JournalistEvent which has Journalists who have indicated they want to cover Event and also includes extra fields like isApproved etc.

I want to create a custom list action in the Event Admin to show journalists attending that event. How do i go about it?

Do I create a custom action on Event Admin or do I create a custom query on Journalist Admin to filter journalists attending the event? I have an idea of the former but the latter seems a better way of creating the solution.

Was it helpful?

Solution

You can first list the events and then you can list the Journalists attending each event by using sonata_type_collection form type. If you want to filter out the event list, you may have to write a custom query for that. You can add the following function to the admin class for that.

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query
            ->orderBy($query->getRootAlias().".eventName", "ASC")
            ->andWhere(
                $query->expr()->orX(
                   $query->expr()->eq($query->getRootAlias().".isActive", 1),
                   $query->expr()->isNull($query->getRootAlias().".isActive")));

    return $query;
}

This is just a sample query. You will have to modify it. Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top