In a Symfony2 project, I have a very simple query like this:
public function getEntries()
{
return $this->createQueryBuilder('e')
->select([
't.published date',
'e.valueCategory1',
'e.valueCategory2',
'e.valueCategory3',
'e.valueCategory4',
'e.valueCategory5'
])
->getQuery()->getArrayResult();
}
I get a set of entries which contains five different category fields with individual values. For each entry, a date exists.
My goal:
In the end, for each category, I would like to have a category array which for each month (for which an entry exists) contains the average value for a month.
A simple example for a Category 1 array:
The following entries are available:
date: 5th of January 2015; valueCategory1: 5
date: 13th of January 2015; valueCategory1: 3
date: 29th of January 2015; valueCategory1: 4
date: 2th of March 2015; valueCategory1: 8
date: 10th of March 2015; valueCategory1: 7
date: 19th of March 2015; valueCategory1: 10
date: 26th of March 2015; valueCategory1: 3
date: 5th of April 2015; valueCategory1: 2
date: 15th of April 2015; valueCategory1: 1
So in the end the Category 1 array will have a structure like this with the following monthly average values:
[['2015-01-01', 4'], ['2015-03-01', '7'], ['2015-04-01', '1.5']]
What would be the easiest way to achieve that within my EntriesRepository file?