Skip to content

Commit

Permalink
wip add ban admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvanspauwen committed Nov 4, 2023
1 parent 794b83d commit a5b176a
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 7 deletions.
9 changes: 9 additions & 0 deletions module/ShopBundle/Component/NoShow/NoShowConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ public function __construct($configData) {
}

public function getBanInterval(int $warningCount) {
if ($warningCount >= count($this->banDaysDictionary)) {
$warningCount = count($this->banDaysDictionary) - 1;
}
return $this->banDaysDictionary[$warningCount];
}

public function getEmail(Person $person, int $warningCount) {
if ($warningCount >= count($this->banDaysDictionary)) {
$warningCount = count($this->banDaysDictionary) - 1;
}

$mailSubject = $this->emailDictionary[$warningCount]['subject'];
$mailContent = $this->emailDictionary[$warningCount]['content'];

$name = $person->getFirstName();
$mailContent = str_replace('{{ name }}', $name, $mailContent);

// sender address
$noreplyAddress = $this->getEntityManager()
Expand Down
42 changes: 42 additions & 0 deletions module/ShopBundle/Controller/Admin/BanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace ShopBundle\Controller\Admin;

use Laminas\View\Model\ViewModel;

class BanController extends \CommonBundle\Component\Controller\ActionController\AdminController
{
public function manageAction()
{
$paginator = $this->paginator()->createFromQuery(
$this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Ban')
->findActiveQuery(),
$this->getParam('page')
);

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

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),
)
);
}
}
5 changes: 2 additions & 3 deletions module/ShopBundle/Controller/Admin/ReservationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ public function noshowAction()
$noShowConfig = $this->getNoShowConfig();

// Get past amount of warnings
$pastWarningCount = $this->getEntityManager()
$warningCount = $this->getEntityManager()
->getRepository('ShopBundle\Entity\Reservation\Ban')
->findAllByPersonQuery($reservation->getPerson())
->getResult();
$warningCount = $pastWarningCount + 1;

// Create ban
$banStartTimestamp = new DateTime();
Expand All @@ -110,7 +109,7 @@ public function noshowAction()
$this->getEntityManager()->persist($ban);
$this->getEntityManager()->flush($ban);

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

if (getenv('APPLICATION_ENV') != 'development') {
Expand Down
31 changes: 28 additions & 3 deletions module/ShopBundle/Repository/Reservation/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ShopBundle\Repository\Reservation;

use CommonBundle\Entity\User\Person;
use DateTime;

/**
* Ban
Expand All @@ -15,12 +16,36 @@ class Ban extends \CommonBundle\Component\Doctrine\ORM\EntityRepository
/**
* @return \Doctrine\ORM\Query
*/
public function findAllQuery()
public function findActiveQuery()
{
$query = $this->getEntityManager()->createQueryBuilder();
return $query->select('e')
->from('ShopBundle\Entity\Reservation\Ban', 'e')
->where(
$query->expr()->orX(
$query->expr()->isNull('a.endTimestamp'),
$query->expr()->gte('a.endTimestamp', ':now')
)
)
->setParameter('now', new DateTime())
->getQuery();
}

return $query->select('b')
->from('ShopBundle\Entity\Reservation\Ban', 'b')
/**
* @return \Doctrine\ORM\Query
*/
public function findOldQuery()
{
$query = $this->getEntityManager()->createQueryBuilder();
return $query->select('e')
->from('ShopBundle\Entity\Reservation\Ban', 'e')
->where(
$query->expr()->andX(
$query->expr()->isNotNull('a.endTimestamp'),
$query->expr()->lt('a.endTimestamp', ':now')
)
)
->setParameter('now', new DateTime())
->getQuery();
}

Expand Down
4 changes: 4 additions & 0 deletions module/ShopBundle/Resources/config/admin.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
'action' => 'manage',
'title' => 'Sales Sessions',
),
'shop_admin_shop_ban' => array(
'action' => 'manage',
'title' => 'Bans',
),
'shop_admin_shop_reservationpermission' => array(
'action' => 'manage',
'title' => 'Permissions',
Expand Down
9 changes: 9 additions & 0 deletions module/ShopBundle/Resources/config/assetic.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
'@common_jqueryui_css',
'@common_remote_typeahead',
),
'shop_admin_shop_ban' => array(
'@common_jquery',
'@admin_css',
'@admin_js',
'@bootstrap_js_transition',
'@bootstrap_js_modal',
'@common_jquery_form',
'@common_remote_typeahead',
),
'shop_admin_shop_reservationpermission' => array(
'@common_jquery',
'@admin_css',
Expand Down
4 changes: 3 additions & 1 deletion module/ShopBundle/Resources/config/install/acl.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
'shop_admin_shop_reservation' => array(
'salessession', 'csv', 'delete', 'noshow', 'search',
),
'shop_admin_shop_ban' => array(
'manage', 'old', 'delete', 'add', 'search',
),
'shop_admin_shop_reservationpermission' => array(
'manage', 'delete', 'add', 'togglepermission', 'search',
),
Expand All @@ -23,6 +26,5 @@
'shop_admin_shop_openinghour' => array(
'add', 'edit', 'schedule', 'delete', 'manage', 'old',
),

),
);
18 changes: 18 additions & 0 deletions module/ShopBundle/Resources/config/router.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@
),
),
),
'shop_admin_shop_ban' => array(
'type' => 'Laminas\Router\Http\Segment',
'options' => array(
'route' => '/admin/shop/ban[/:action[/:id][/type/:type][/page/:page]][/:field/:string][/]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]*',
'type' => '[a-zA-Z]*',
'page' => '[0-9]*',
'field' => '[a-zA-Z][a-zA-Z0-9_-]*',
'string' => '[a-zA-Z][%a-zA-Z0-9:.,_-]*',
),
'defaults' => array(
'controller' => 'shop_admin_shop_ban',
'action' => 'manage',
),
),
),
'shop_admin_shop_reservationpermission' => array(
'type' => 'Laminas\Router\Http\Segment',
'options' => array(
Expand Down
32 changes: 32 additions & 0 deletions module/ShopBundle/Resources/views/shop/admin/ban/add.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'admin/base.twig' %}

{% block content %}
{% include 'shop/admin/reservation-permission/partials/navigation.twig' %}

{% include 'admin/partials/flashMessenger.twig' %}

<div id="controller_action">
{% import 'admin/partials/form.twig' as forms %}
{{ forms.renderForm(form) }}
</div>
{% endblock %}

{% block content_script %}
<script type="text/javascript">
$(document).ready(function () {
$('#person').typeaheadRemote(
{
source: '{{ url('common_admin_academic_typeahead', {})}}',
items: 20,
}
).change(function (e) {
if ($(this).data('value')) {
$('[name="person[id]"]').val($(this).data('value').id);
} else {
$('[name="person[id]"]').val('');
}
});
$('.item .delete').click(openModal);
});
</script>
{% endblock %}
3 changes: 3 additions & 0 deletions module/ShopBundle/Resources/views/shop/admin/ban/delete.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% autoescape false %}
{{ result|json_encode }}
{% endautoescape %}
Loading

0 comments on commit a5b176a

Please sign in to comment.