<?php

namespace AppBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * MuseRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * 	repository methods below.
 */
class MuseRepository extends \Doctrine\ORM\EntityRepository
{
	 public function findMoyNote($id)
	  {
	      $queryNote = $this->getEntityManager()
		  ->createQuery(
			    'SELECT AVG(c.note) AS MOY, sum(m.id) as nbVot FROM AppBundle:Muse m  JOIN m.commentaires c WHERE m.id = :id'
		  )->setParameter('id', $id);

	      try {
		  return  $queryNote->getSingleResult();
	      } catch (\Doctrine\ORM\NoResultException $e) {
		  return null;
	      }
	  }
}
