I am using ezpublish Search API to get the list of session content type objects ordered by their parent's training field (field name is code).
So if I have two sessions S1 (linked to training with code T1) and S2 (linked to training with code T2) I want to have session S1 listed before S2 in the list.
$criterions = array (
new Criterion\ContentTypeIdentifier( 'session' )
);
$locationQuery = new LocationQuery();
$locationQuery->query = $criteriaArray;
$locationQuery->sortClauses = array(
//new SortClause\Field('session','price'),<- this works
new SortClause\Field('training','code',Query::SORT_ASC)
//this second sorClause does not work as code is not a field of session while price is
);
There might be a solution to this problem using native mysql query but it's not portable and some ids will be hardcoded.
My questions is can we achieve a sort of the sesssions according to their parent's training'code`field ?
I managed to get it working thanks to @Edi and a colleague at my job.
The two clasess to create are : The field class:
The handler class:
Declare the handler as a service:
And To call the pieces together in the cotroller I did this: