我想在谁已完成一定数量的任务,每一个用户的实体执行查询。有与每个任务相关联的不同点的值,我需要创建一个查询,将排序依据那些与他们所有的在$ timeArray如下所示的时间段任务的最高分。
我已经使用SUM查询像这样已经尝试:
- >选择( 'SUM(t.points)') - > ORDERBY( 't.points', 'DESC')
但这只是给出了每个人总积分的数组,我需要返回一个对象,我可以遍历并显示用户在指定时间段的所有任务的最高分。
public function getTimePeriodUsers($userType = null)
{
$timeArray = [
'-1 year',
'-3 month',
'-1 month',
'-1 week',
];
foreach($timeArray as $time){
$date = new \DateTime();
$date->modify($time);
if($userType == null){
$resultsArray[$time] = $this->createQueryBuilder('u')
->leftJoin('u.userTasks', 'ut')
->leftJoin('ut.task', 't')
->leftJoin('t.challenges', 'ch')
->andWhere('ut.completed > :date')
->andWhere('u.enabled = :enabled')
->setParameter('enabled', true)
->setParameter('date', $date)
->getQuery()
->getResult();
}
return $resultsArray;
}