1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <?php
namespace ASSO\ScheduleBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction()
{
$repository = $this
->getDoctrine()
->getManager()
->getRepository('ASSOAvailabilityBundle:Availability');
$listAvailability = $repository->findAll();
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'DROP VIEW v_recherche_plages_communes;
DROP VIEW v_plages_communes;
CREATE VIEW v_recherche_plages_communes AS
SELECT a1.id AS id_1, a1.dateFrom AS debut_1, a1.dateTo AS fin_1,
a2.id AS id_2, a2.dateFrom AS debut_2, a2.dateTo AS fin_2,
CASE
WHEN a1.dateFrom >= a2.DateFrom AND a1.dateFrom < a2.dateTo THEN a1.dateFrom
WHEN a1.dateTo <= a2.dateTo THEN a2.dateFrom
ELSE NULL
END AS date_debut_commune,
CASE
WHEN a1.dateTo <= a2.dateTo AND a1.dateTo > a2.dateFrom THEN a1.dateTo
WHEN a1.dateFrom <= a2.dateTo THEN a2.dateTo
ELSE NULL
END AS date_fin_commune
FROM Availability a1
INNER JOIN Availability a2 ON a1.id <> a2.id;
CREATE VIEW v_plages_communes AS
SELECT tmp.id_1,
MAX(tmp.date_debut_commune) AS debut_periode_commune,
MIN(tmp.date_fin_commune) AS fin_periode_commune,
COUNT(*) AS nb_plages_communes
FROM v_recherche_plages_communes tmp
WHERE tmp.date_debut_commune IS NOT NULL
AND tmp.date_fin_commune IS NOT NULL
GROUP BY tmp.id_1;
SELECT debut_periode_commune, fin_periode_commune
FROM v_plages_communes
WHERE nb_plages_communes =
(
SELECT MAX(nb_plages_communes) AS meilleur_score
FROM v_plages_communes
)'
);
$overlappedPeriod = $query->getResult();
return $this->render('ASSOScheduleBundle:Default:index.html.twig', array(
'availabilities' => $listAvailability,
'overlappedPeriods' => $overlappedPeriod
));
}
} |
Partager