<?php

namespace AppBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * ResultatRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ResultatRepository extends EntityRepository
{
	function getClassement($quizz,$offset = null,$limit = null)
	{
		$query = $this->createQueryBuilder('r');
		$query->where('r.quizz = :quizz')
			->orderBy('r.score','DESC')
			->addOrderBy(
				$query->expr()->diff('r.responseTime','r.timeStart'),'ASC'
			)
			->setParameter(':quizz',$quizz);

		if($offset != null && $limit != null)
		{
			$query->setFirstResult($offset);
			$query->setMaxResults($limit);
		}

		return $query->getQuery()->getResult();
	}
}
