Permalink
Browse files

You has to be able to book when you have played the same day.

  • Loading branch information...
1 parent 39f24f5 commit 933858476bfa3b5d06dc405ef1b7cdc3f468b4cc @hollodk hollodk committed Apr 23, 2012
Showing with 81 additions and 51 deletions.
  1. +81 −51 src/Club/BookingBundle/Helper/Booking.php
@@ -140,53 +140,6 @@ public function bindGuest(\Club\BookingBundle\Entity\Interval $interval, \DateTi
$this->bind();
}
- protected function validateBookingPartnerDay(\DateTime $date, \Club\UserBundle\Entity\User $user, \Club\UserBundle\Entity\User $partner)
- {
- $res = $this->em->createQueryBuilder()
- ->select('COUNT(b)')
- ->from('ClubBookingBundle:Booking', 'b')
- ->leftJoin('b.users', 'u')
- ->where('b.first_date >= :start')
- ->andWhere('b.first_date <= :end')
- ->andWhere('b.user = :user')
- ->andWhere('u.id = :partner')
- ->andWhere('b.guest = :is_guest')
- ->setParameter('start', $date->format('Y-m-d 00:00:00'))
- ->setParameter('end', $date->format('Y-m-d 23:59:59'))
- ->setParameter('user', $user->getId())
- ->setParameter('partner', $partner->getId())
- ->setParameter('is_guest', false)
- ->getQuery()
- ->getSingleResult();
-
- if ($res[1] >= $this->container->getParameter('club_booking.num_book_same_partner_day'))
- return false;
-
- return true;
- }
-
- protected function validateBookingPartnerFuture(\Club\UserBundle\Entity\User $user, \Club\UserBundle\Entity\User $partner)
- {
- $res = $this->em->createQueryBuilder()
- ->select('COUNT(b)')
- ->from('ClubBookingBundle:Booking', 'b')
- ->leftJoin('b.users', 'u')
- ->where('b.first_date >= CURRENT_DATE()')
- ->andWhere('b.user = :user')
- ->andWhere('u.id = :partner')
- ->andWhere('b.guest = :is_guest')
- ->setParameter('user', $user->getId())
- ->setParameter('partner', $partner->getId())
- ->setParameter('is_guest', false)
- ->getQuery()
- ->getSingleResult();
-
- if ($res[1] >= $this->container->getParameter('club_booking.num_book_same_partner_future'))
- return false;
-
- return true;
- }
-
public function getError()
{
return $this->error;
@@ -450,15 +403,25 @@ protected function validateAvailable(\DateTime $date)
protected function validateBookingDay(\DateTime $date, \Club\UserBundle\Entity\User $user)
{
+ $start = clone $date;
+ $end = clone $date;
+
+ if ($start->format('Ymd') == date('Ymd')) {
+ $start = new \DateTime();
+ } else {
+ $start->setHour(0,0,0);
+ }
+ $end->setHour(23,59,59);
+
$res = $this->em->createQueryBuilder()
->select('COUNT(b)')
->from('ClubBookingBundle:Booking', 'b')
->where('b.first_date >= :start')
->andWhere('b.first_date <= :end')
->andWhere('b.user = :user')
->setParameter('user', $user->getId())
- ->setParameter('start', $date->format('Y-m-d 00:00:00'))
- ->setParameter('end', $date->format('Y-m-d 23:59:59'))
+ ->setParameter('start', $start)
+ ->setParameter('end', $end)
->getQuery()
->getSingleResult();
@@ -488,6 +451,16 @@ protected function validateBookingFuture(\Club\UserBundle\Entity\User $user)
protected function validateBookingGuestDay(\DateTime $date, \Club\UserBundle\Entity\User $user)
{
+ $start = clone $date;
+ $end = clone $date;
+
+ if ($start->format('Ymd') == date('Ymd')) {
+ $start = new \DateTime();
+ } else {
+ $start->setHour(0,0,0);
+ }
+ $end->setHour(23,59,59);
+
$res = $this->em->createQueryBuilder()
->select('COUNT(b)')
->from('ClubBookingBundle:Booking', 'b')
@@ -497,8 +470,8 @@ protected function validateBookingGuestDay(\DateTime $date, \Club\UserBundle\Ent
->andWhere('b.guest = :is_guest')
->setParameter('user', $user->getId())
->setParameter('is_guest', true)
- ->setParameter('start', $date->format('Y-m-d 00:00:00'))
- ->setParameter('end', $date->format('Y-m-d 23.59:59'))
+ ->setParameter('start', $start)
+ ->setParameter('end', $end)
->getQuery()
->getSingleResult();
@@ -526,4 +499,61 @@ protected function validateBookingGuestFuture(\Club\UserBundle\Entity\User $user
return true;
}
+
+ protected function validateBookingPartnerDay(\DateTime $date, \Club\UserBundle\Entity\User $user, \Club\UserBundle\Entity\User $partner)
+ {
+ $start = clone $date;
+ $end = clone $date;
+
+ if ($start->format('Ymd') == date('Ymd')) {
+ $start = new \DateTime();
+ } else {
+ $start->setHour(0,0,0);
+ }
+ $end->setHour(23,59,59);
+
+ $res = $this->em->createQueryBuilder()
+ ->select('COUNT(b)')
+ ->from('ClubBookingBundle:Booking', 'b')
+ ->leftJoin('b.users', 'u')
+ ->where('b.first_date >= :start')
+ ->andWhere('b.first_date <= :end')
+ ->andWhere('b.user = :user')
+ ->andWhere('u.id = :partner')
+ ->andWhere('b.guest = :is_guest')
+ ->setParameter('start', $start)
+ ->setParameter('end', $end)
+ ->setParameter('user', $user->getId())
+ ->setParameter('partner', $partner->getId())
+ ->setParameter('is_guest', false)
+ ->getQuery()
+ ->getSingleResult();
+
+ if ($res[1] >= $this->container->getParameter('club_booking.num_book_same_partner_day'))
+ return false;
+
+ return true;
+ }
+
+ protected function validateBookingPartnerFuture(\Club\UserBundle\Entity\User $user, \Club\UserBundle\Entity\User $partner)
+ {
+ $res = $this->em->createQueryBuilder()
+ ->select('COUNT(b)')
+ ->from('ClubBookingBundle:Booking', 'b')
+ ->leftJoin('b.users', 'u')
+ ->where('b.first_date >= CURRENT_DATE()')
+ ->andWhere('b.user = :user')
+ ->andWhere('u.id = :partner')
+ ->andWhere('b.guest = :is_guest')
+ ->setParameter('user', $user->getId())
+ ->setParameter('partner', $partner->getId())
+ ->setParameter('is_guest', false)
+ ->getQuery()
+ ->getSingleResult();
+
+ if ($res[1] >= $this->container->getParameter('club_booking.num_book_same_partner_future'))
+ return false;
+
+ return true;
+ }
}

0 comments on commit 9338584

Please sign in to comment.