Skip to content

Commit

Permalink
add configuration decoding & send mail wip
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvanspauwen committed Oct 23, 2023
1 parent 2a86a4e commit 97371d0
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 71 deletions.
47 changes: 47 additions & 0 deletions module/ShopBundle/Component/NoShow/NoShowConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace ShopBundle\Component\NoShow;

use CommonBundle\Entity\User\Person;

class NoShowConfig {
/**
* @var array Stores the email related to each warning
*/
private array $emailDictionary;

/**
* @var array Stores the amount of ban days related to each warning
*/
private array $banDaysDictionary;

public function __construct($configJson) {
$decodedConfig = json_decode($configJson, true);

$this->emailDictionary = [];
$this->banDaysDictionary = [];

foreach ($decodedConfig['warnings'] as $index => $warning) {
$this->emailDictionary[$index] = $warning['email_message'];
$this->banDaysDictionary[$index] = $warning['ban_days'];
}
}

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

/**
* @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) {

}
}
97 changes: 54 additions & 43 deletions module/ShopBundle/Controller/Admin/ReservationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

use CommonBundle\Component\Document\Generator\Csv as CsvGenerator;
use CommonBundle\Component\Util\File\TmpFile\Csv as CsvFile;
use DateInterval;
use DateTime;
use Laminas\Http\Headers;
use Laminas\Mail\Message;
use Laminas\View\Model\ViewModel;
use ShopBundle\Component\NoShow\NoShowConfig;
use ShopBundle\Entity\Reservation;
use ShopBundle\Entity\Reservation\Ban;
use ShopBundle\Entity\Reservation\Permission as ReservationPermission;
Expand Down Expand Up @@ -85,61 +89,53 @@ public function noshowAction()
return new ViewModel();
}

$ban = new Ban();
$ban->SetPerson($reservation->getPerson());
$ban->setStartTimestamp(time());
$ban->setEndTimestamp(time() + (7 * 24 * 60 * 60));
error_log("after ban");

$this->getEntityManager()->persist($ban);
$this->getEntityManager()->flush();
error_log("after flush");
// Retrieve configuration details
$noShowConfig = $this->getNoShowConfig();

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

// $this->initAjax();
// Send email
// todo: use system no-reply
// $mailAddress = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_mail');
//
// $reservation = $this->getReservationEntity();
// if ($reservation === null) {
// return new ViewModel();
// }
// $mailName = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_mail_name');
//
// $reservation->setNoShow(!$reservation->getNoShow());
// $blacklisted = false;
// $blacklistAvoided = false;
// $link = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('br.student_job_link');
//
// $this->getEntityManager()->persist($reservation);
// $this->getEntityManager()->flush();
// $mail = new Message();
// $mail->setBody($link)
// ->setFrom($mailAddress, $mailName)
// ->addTo($mailAddress, $mailName)
// ->setSubject('New student Job Request ' . $person->getCompany()->getName());
//
// if ($reservation->getNoShow()) {
// $maxNoShows = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('shop.maximal_no_shows');
// $currentNoShows = $this->getEntityManager()
// ->getRepository('ShopBundle\Entity\Reservation')
// ->getNoShowSessionCount($reservation->getPerson());
// if ($currentNoShows >= $maxNoShows) {
// $reservationPermission = $this->getEntityManager()
// ->getRepository('ShopBundle\Entity\Reservation\Permission')
// ->find($reservation->getPerson());
// if ($reservationPermission) {
// $blacklistAvoided = $reservationPermission->getReservationsAllowed();
// } else {
// $blacklisted = true;
// $reservationPermission = new ReservationPermission();
// $reservationPermission->setPerson($reservation->getPerson());
// $reservationPermission->setReservationsAllowed(false);
// $this->getEntityManager()->persist($reservationPermission);
// $this->getEntityManager()->flush();
// }
// }
// if (getenv('APPLICATION_ENV') != 'development') {
// $this->getMailTransport()->send($mail);
// }

// 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);



return new ViewModel(
array(
'result' => array(
'status' => 'success',
// 'blacklisted' => $blacklisted,
// 'blacklistAvoided' => $blacklistAvoided,
),
)
);
Expand Down Expand Up @@ -291,4 +287,19 @@ private function search()
->getAllReservationsByPersonAndSalesSessionQuery($this->getParam('string'), $this->getSalesSessionEntity());
}
}

private function getNoShowConfig()
{
$noShowConfigJson = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('shop.no_show_configuration');

if ($noShowConfigJson === null) {
error_log('Error parsing the configuration file.');
}

$noShowConfig = new NoShowConfig($noShowConfigJson);

return $noShowConfig;
}
}
17 changes: 13 additions & 4 deletions module/ShopBundle/Entity/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Ban
/**
* @var DateTime The timestamp at which the ban starts
*
* @ORM\Column(type="datetime")
*
*/
private $startTimestamp;

Expand All @@ -45,16 +45,25 @@ class Ban
*/
private $endTimestamp;

public function __construct() {
}

/**
* @return Person The person this ban applies to
*/
public function GetPerson() {
return $this->person;
}

/**
* @param Person $person The person this ban belongs to
* @param DateTime $startTimestamp The timestamp at which the ban starts
* @param DateTime|null $endTimestamp The timestamp at which the ban ends (null if it does not end)
*/
public function __construct(Person $person, DateTime $startTimestamp, DateTime $endTimestamp=null)
{
$this->person = $person;
$this->startTimestamp = $startTimestamp;
$this->endTimestamp = $endTimestamp;
}

/**
* @param $person
* @return $this
Expand Down
32 changes: 8 additions & 24 deletions module/ShopBundle/Hydrator/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@ class Ban extends \CommonBundle\Component\Hydrator\Hydrator
{
protected function doExtract($object = null)
{
error_log("extract");
return array();
// error_log("extract");
// if ($object === null) {
// return array();
// }
//
// $data = $this->stdExtract($object);
// $data['start_timestamp'] = $object->getStartTimestamp()->format('d/m/Y H:i');
// $data['end_timestamp'] = $object->getEndTimestamp() ? $object->getEndTimestamp()->format('d/m/Y H:i') : ' ';
//// $data['person']['id'] = $object->getPerson()->getId();
//
// return $data;
}

protected function doHydrate(array $data, $object = null)
Expand All @@ -31,18 +19,14 @@ protected function doHydrate(array $data, $object = null)
$object = new BanEntity();
}

$object->setStartTimestamp(self::loadDateTime($data['start_timestamp']));
$object->setEndTimestamp(self::loadDateTime($data['end_timestamp']));

$person = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person')
->find($data['person']['id']);
$object->setPerson($person);

return $object;
//
//
//
// $object->setStartTimestamp(self::loadDateTime($data['start_timestamp']));
// $object->setEndTimestamp(self::loadDateTime($data['end_timestamp']));
//
// $person = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\User\Person')
// ->find($data['person']['id']);
// $object->setPerson($person);
//
// return $object;
}
}
16 changes: 16 additions & 0 deletions module/ShopBundle/Repository/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@

namespace ShopBundle\Repository\Reservation;

/**
* Ban
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class Ban extends \CommonBundle\Component\Doctrine\ORM\EntityRepository
{
/**
* @return \Doctrine\ORM\Query
*/
public function findAllQuery()
{
$query = $this->getEntityManager()->createQueryBuilder();

return $query->select('b')
->from('ShopBundle\Entity\Reservation\Permission', 'b')
->getQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
'value' => 'Theokot',
'description' => 'The name of the shop',
),
array(
'key' => 'shop.email',
'value' => '',
'description' => 'The name of the shop',
),
array(
'key' => 'shop.reservation_threshold',
'value' => 'P1D',
Expand Down Expand Up @@ -71,4 +76,9 @@
'value' => 1,
'description' => 'Enable the winner column when exporting a sales session to csv',
),
array(
'key' => 'shop.no_show_configuration',
'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',
),
);

0 comments on commit 97371d0

Please sign in to comment.