Skip to content

Commit

Permalink
implement reservationController
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvanspauwen committed Oct 23, 2023
1 parent 97371d0 commit 3080856
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 53 deletions.
19 changes: 5 additions & 14 deletions module/ShopBundle/Component/NoShow/NoShowConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ShopBundle\Component\NoShow;

use CommonBundle\Entity\User\Person;
use Nette\NotImplementedException;

class NoShowConfig {
/**
Expand All @@ -27,21 +28,11 @@ public function __construct($configJson) {
}
}

/**
* @return array Returns a dictionary with the emails for each warning
*/
public function getEmailDictionary() {
return $this->emailDictionary;
public function getBanInterval(int $banCount) {
throw new NotImplementedException();
}

/**
* @return array Returns a dictionary with the amount of ban days for each warning
*/
public function getBanDaysDictionary() {
return $this->banDaysDictionary;
}

public function createBan(Person $person, int $warningCount) {

public function getEmail(Person $person, int $banCount) {
throw new NotImplementedException();
}
}
57 changes: 21 additions & 36 deletions module/ShopBundle/Controller/Admin/ReservationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,48 +89,33 @@ public function noshowAction()
return new ViewModel();
}

// Retrieve configuration details
$noShowConfig = $this->getNoShowConfig();

$noShowEmails = $noShowConfig->getEmailDictionary();
$noShowBanDays = $noShowConfig->getBanDaysDictionary();

// Send email
// todo: use system no-reply
// $mailAddress = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_mail');
//
// $mailName = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_mail_name');
//
// $link = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_link');
//
// $mail = new Message();
// $mail->setBody($link)
// ->setFrom($mailAddress, $mailName)
// ->addTo($mailAddress, $mailName)
// ->setSubject('New student Job Request ' . $person->getCompany()->getName());
//
// if (getenv('APPLICATION_ENV') != 'development') {
// $this->getMailTransport()->send($mail);
// }
// Get past amount of warnings
$pastWarningCount = $this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Ban')
->findAllByPersonQuery($reservation->getPerson())
->getResult();
$warningCount = $pastWarningCount + 1;

// Create ban
// $currentTime = new DateTime();
//
// $interval = DateInterval::createFromDateString('1 week');
// $nextTime = $currentTime->add($interval);
//
// $ban = new Ban($reservation->getPerson(), $currentTime, $nextTime);
//
// $this->getEntityManager()->persist($ban);
// $this->getEntityManager()->flush($ban);
$banStartTimestamp = new DateTime();

$banIntervalStr = $noShowConfig->getBanInterval($warningCount);
$banInterval = DateInterval::createFromDateString($banIntervalStr);
$banEndTimestamp = $banStartTimestamp->add($banInterval);

$ban = new Ban($reservation->getPerson(), $banStartTimestamp, $banEndTimestamp);

$this->getEntityManager()->persist($ban);
$this->getEntityManager()->flush($ban);

// Send email
$mail = $noShowConfig->getEmail($reservation->getPerson(), $warningCount);

if (getenv('APPLICATION_ENV') != 'development') {
$this->getMailTransport()->send($mail);
}

return new ViewModel(
array(
Expand Down
26 changes: 25 additions & 1 deletion module/ShopBundle/Repository/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ShopBundle\Repository\Reservation;

use CommonBundle\Entity\User\Person;

/**
* Ban
*
Expand All @@ -18,7 +20,29 @@ public function findAllQuery()
$query = $this->getEntityManager()->createQueryBuilder();

return $query->select('b')
->from('ShopBundle\Entity\Reservation\Permission', 'b')
->from('ShopBundle\Entity\Reservation\Ban', 'b')
->getQuery();
}

/**
* @param Person $person
* @return \Doctrine\ORM\Query
*/
public function findAllByPersonQuery(Person $person)
{
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$query = $queryBuilder->select('count(s.id)')
->from('ShopBundle\Entity\Reservation\Ban', 'b');

$where = $query->expr()->eq('r.person', ':person');

$query->where(
$query->expr()->andX(
$query->expr()->lt('s.startDate', ':now'),
$where
)
);

return $query->getQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
),
array(
'key' => 'shop.email',
'value' => '',
'description' => 'The name of the shop',
'value' => '[email protected]',
'description' => 'The email of the shop',
),
array(
'key' => 'shop.reservation_threshold',
Expand Down Expand Up @@ -81,4 +81,52 @@
'value' => 'no-show configuration goes here',
'description' => 'The no-show configuration is used for warnings when a person does not show up for their reservation, holding for each warning the ban period and an email message',
),
array(
'key' => 'shop.no_show_configuration',
'value' => serialize(
array(
'1' => array(
'subject' => 'VTK Theokot Warning',
'content' => 'Dear {{ name }},
You forgot your sandwich for the first time. Ban of 3 days.
Kind regards,
Theokot',
),
'2' => array(
'subject' => 'VTK Theokot Warning',
'content' => 'Dear {{ name }},
You forgot your sandwich for the second time. Ban of 1 week.
Kind regards,
Theokot',
),
'3' => array(
'subject' => 'VTK Theokot Warning',
'content' => 'Dear {{ name }},
You forgot your sandwich for the third time. Ban of 3 weeks.
Kind regards,
Theokot',
),
'4' => array(
'subject' => 'VTK Theokot Warning',
'content' => 'Dear {{ name }},
You forgot your sandwich for the fourth time. Permanent ban.
Kind regards,
Theokot',
),
)
),
'description' => 'The no-show configuration is used for warnings when a person does not show up for their reservation, holding for each warning the ban period and an email message',
),
);

0 comments on commit 3080856

Please sign in to comment.