Skip to content

Commit

Permalink
working admin ban panel
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvanspauwen committed Nov 6, 2023
1 parent a5b176a commit e2a03d0
Show file tree
Hide file tree
Showing 20 changed files with 250 additions and 299 deletions.
5 changes: 4 additions & 1 deletion module/ShopBundle/Controller/Admin/ReservationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public function noshowAction()
$banInterval = DateInterval::createFromDateString($banIntervalStr);
$banEndTimestamp = $banStartTimestamp->add($banInterval);

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

$this->getEntityManager()->persist($ban);
$this->getEntityManager()->flush($ban);
Expand Down
146 changes: 74 additions & 72 deletions module/ShopBundle/Controller/Admin/ReservationPermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ShopBundle\Controller\Admin;

use Laminas\View\Model\ViewModel;
use ShopBundle\Entity\Reservation\Permission as ReservationPermission;
use ShopBundle\Repository\Reservation\Ban;

/**
* ReservationPermissionController
Expand All @@ -16,8 +16,8 @@ public function manageAction()
{
$paginator = $this->paginator()->createFromQuery(
$this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Permission')
->findAllQuery(),
->getRepository('ShopBundle\Entity\Reservation\Ban')
->findActiveQuery(),
$this->getParam('page')
);

Expand All @@ -29,22 +29,44 @@ public function manageAction()
);
}

public function oldAction()
{
$paginator = $this->paginator()->createFromQuery(
$this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Ban')
->findOldQuery(),
$this->getParam('page')
);

return new ViewModel(
array(
'paginator' => $paginator,
'paginationControl' => $this->paginator()->createControl(true),
)
);
}

// shop_reservationPermission_add

public function addAction()
{
$form = $this->getForm('shop_reservationPermission_add');
$form = $this->getForm('shop_reservation_ban_add');

if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
$form->setData($formData);

if ($form->isValid()) {
$reservationPermission = $form->hydrateObject();
$this->getEntityManager()->persist($reservationPermission);
error_log("before hydrate");
$ban = $form->hydrateObject();
error_log("before persist");
$this->getEntityManager()->persist($ban);
error_log("before flush");
$this->getEntityManager()->flush();

$this->flashMessenger()->success(
'Success',
'The reservation permission was successfully created!'
'The ban was successfully created!'
);

$this->redirect()->toRoute(
Expand All @@ -65,37 +87,16 @@ public function addAction()
);
}

public function togglepermissionAction()
{
$this->initAjax();

$reservationPermission = $this->getReservationPermissionEntity();
if ($reservationPermission === null) {
return new ViewModel();
}
$reservationPermission->setReservationsAllowed(!$reservationPermission->getReservationsAllowed());
$this->getEntityManager()->persist($reservationPermission);
$this->getEntityManager()->flush();

return new ViewModel(
array(
'result' => array(
'status' => 'success',
),
)
);
}

public function deleteAction()
{
$this->initAjax();

$product = $this->getReservationPermissionEntity();
if ($product === null) {
$ban = $this->getBanEntity();
if ($ban === null) {
return new ViewModel();
}

$this->getEntityManager()->remove($product);
$this->getEntityManager()->remove($ban);
$this->getEntityManager()->flush();

return new ViewModel(
Expand All @@ -108,66 +109,67 @@ public function deleteAction()
}

/**
* @return ReservationPermission|null
* @return Ban|null
*/
private function getReservationPermissionEntity()
private function getBanEntity()
{
$person = $this->getEntityById('CommonBundle\Entity\User\Person');
$ban = $this->getEntityById('ShopBundle\Entity\Reservation\Ban');

$reservationPermission = $this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Permission')
->findOneByPerson($person);

if (!($reservationPermission instanceof ReservationPermission)) {
if (!($ban instanceof Ban)) {
$this->flashMessenger()->error(
'Error',
'No reservation permission was found!'
'No ban was found!'
);

$this->redirect()->toRoute(
'shop_admin_shop_reservationpermission',
array(
'action' => 'manage',
)
);
return;
}

return $reservationPermission;
return $ban;
}

public function searchAction()
{
$this->initAjax();

$numResults = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('search_max_results');

$reservationPermissions = $this->search()
->setMaxResults($numResults)
->getResult();

$result = array();
foreach ($reservationPermissions as $reservationPermission) {
$item = (object) array();
$item->id = $reservationPermission->getPerson()->getId();
$item->name = $reservationPermission->getPerson()->getFullName();
$item->reservationsAllowed = $reservationPermission->getReservationsAllowed();
$result[] = $item;
}

return new ViewModel(
array(
'result' => $result,
)
);
// $this->initAjax();
//
// $numResults = $this->getEntityManager()
// ->getRepository('CommonBundle\Entity\General\Config')
// ->getConfigValue('search_max_results');
//
// $reservationPermissions = $this->search()
// ->setMaxResults($numResults)
// ->getResult();
//
// $result = array();
// foreach ($reservationPermissions as $reservationPermission) {
// $item = (object) array();
// $item->id = $reservationPermission->getPerson()->getId();
// $item->name = $reservationPermission->getPerson()->getFullName();
// $item->reservationsAllowed = $reservationPermission->getReservationsAllowed();
// $result[] = $item;
// }
//
// return new ViewModel(
// array(
// 'result' => $result,
// )
// );
}

/**
* @return \Doctrine\ORM\Query|null
*/
private function search()
{
switch ($this->getParam('field')) {
case 'name':
return $this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Permission')
->findByNameQuery($this->getParam('string'));
}
// switch ($this->getParam('field')) {
// case 'name':
// return $this->getEntityManager()
// ->getRepository('ShopBundle\Entity\Reservation\Permission')
// ->findByNameQuery($this->getParam('string'));
// }
}
}
19 changes: 6 additions & 13 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,25 +45,18 @@ 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
77 changes: 77 additions & 0 deletions module/ShopBundle/Form/Admin/Reservation/Ban/Add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace ShopBundle\Form\Admin\Reservation\Ban;

/**
* Add Reservation Permission
*
* @author Floris Kint <[email protected]>
*/
class Add extends \CommonBundle\Component\Form\Admin\Form
{
protected $hydrator = 'ShopBundle\Hydrator\Reservation\Ban';

public function init()
{
parent::init();

$this->add(
array(
'type' => 'typeahead',
'name' => 'person',
'label' => 'User',
'required' => true,
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'TypeaheadPerson'),
),
),
),
)
);

$this->add(
array(
'type' => 'datetime',
'name' => 'start_timestamp',
'label' => 'Start Date',
'required' => true,
'attributes' => array(
'placeholder' => 'dd/mm/yyyy hh:mm',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
),
),
)
);

$this->add(
array(
'type' => 'datetime',
'name' => 'end_timestamp',
'label' => 'Start Date',
'required' => true,
'attributes' => array(
'placeholder' => 'dd/mm/yyyy hh:mm',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
),
),
)
);

$this->addSubmit('Add', 'add');
}
}
15 changes: 11 additions & 4 deletions module/ShopBundle/Hydrator/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ class Ban extends \CommonBundle\Component\Hydrator\Hydrator
{
protected function doExtract($object = null)
{
return array();
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)
{
error_log("hydrate");

if ($object === null) {
$object = new BanEntity();
}
Expand All @@ -29,4 +36,4 @@ protected function doHydrate(array $data, $object = null)

return $object;
}
}
}
Loading

0 comments on commit e2a03d0

Please sign in to comment.