I created a seperate class for one of my DataTables (lets say MyTableType
). Inside ORMAdapter
I've created a custom query, which gets quite long and complicated. This is why I'd like to seperate it from the code that's responsible for creating a table itself and move it into some other class (like MyTableQuery
).
I am using Symfony 4.2 and omines/datatables-bundle bundle.
What should that class for queries return? And what's the best way then to get the returned query in MyTableType
?
class MyTableType implements DataTableTypeInterface
{
public function configure(DataTable $dataTable, array $options)
{
$request = $options['request'];
$dataTable
->add('id',
NumberColumn::class,
array(
'label' => 'ID',
'globalSearchable' => false
)
)
Some more columns
->createAdapter(ORMAdapter::class,
array(
'entity' => MyEntity::class,
'query' => function (QueryBuilder $builder) use ($request)
{
//Long query I'd prefer to get from somewhere else
}
)
)
;
}
}
Inside my query
option I'd like to get the return from that custom class MyTypeQuery
. It'd make MyTableType
class much cleaner. What's the best way to accomplish that?