Skip to content

Commit 102f977

Browse files
authored
feat: code couleur sur le taux d'utilisation des tokens sponsors (#2418)
1 parent d98aff4 commit 102f977

4 files changed

Lines changed: 128 additions & 2 deletions

File tree

‎db/seeds/SponsorTickets.php‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Seed\AbstractSeed;
6+
7+
class SponsorTickets extends AbstractSeed
8+
{
9+
public const string TOKEN_GREEN = 'token-sponsor-tickets-vert-test';
10+
public const string TOKEN_ORANGE = 'token-sponsor-tickets-orange-test';
11+
public const string TOKEN_RED = 'token-sponsor-tickets-rouge-test';
12+
13+
public function run(): void
14+
{
15+
$now = new DateTime('now');
16+
17+
// Seed idempotent : suppression de la donnee de test si elle existe deja
18+
$this->execute(sprintf(
19+
"DELETE FROM afup_forum_sponsors_tickets WHERE token IN ('%s', '%s', '%s')",
20+
self::TOKEN_GREEN,
21+
self::TOKEN_ORANGE,
22+
self::TOKEN_RED,
23+
));
24+
25+
$data = [
26+
[
27+
'id' => 101,
28+
'company' => 'Sponsor Zéro Utilisé',
29+
'token' => self::TOKEN_GREEN,
30+
'contact_email' => 'vert@sponsor-test.com',
31+
'max_invitations' => 4,
32+
'used_invitations' => 0,
33+
'id_forum' => Event::ID_FORUM,
34+
'created_on' => $now->format('Y-m-d H:i:s'),
35+
'edited_on' => $now->format('Y-m-d H:i:s'),
36+
'creator_id' => Users::ID_USER_ADMIN,
37+
'qr_codes_scanner_available' => 0,
38+
],
39+
[
40+
'id' => 102,
41+
'company' => 'Sponsor Deux Tiers Utilisé',
42+
'token' => self::TOKEN_ORANGE,
43+
'contact_email' => 'deuxtiers@sponsor-test.com',
44+
'max_invitations' => 3,
45+
'used_invitations' => 2,
46+
'id_forum' => Event::ID_FORUM,
47+
'created_on' => $now->format('Y-m-d H:i:s'),
48+
'edited_on' => $now->format('Y-m-d H:i:s'),
49+
'creator_id' => Users::ID_USER_ADMIN,
50+
'qr_codes_scanner_available' => 0,
51+
],
52+
[
53+
'id' => 103,
54+
'company' => 'Sponsor Complet',
55+
'token' => self::TOKEN_RED,
56+
'contact_email' => 'complet@sponsor-test.com',
57+
'max_invitations' => 1,
58+
'used_invitations' => 1,
59+
'id_forum' => Event::ID_FORUM,
60+
'created_on' => $now->format('Y-m-d H:i:s'),
61+
'edited_on' => $now->format('Y-m-d H:i:s'),
62+
'creator_id' => Users::ID_USER_ADMIN,
63+
'qr_codes_scanner_available' => 0,
64+
],
65+
];
66+
67+
$this->table('afup_forum_sponsors_tickets')->insert($data)->saveData();
68+
}
69+
}

‎templates/admin/event/sponsor_ticket.html.twig‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<th>Token</th>
4848
<th class="right aligned">Invitations totales</th>
4949
<th class="right aligned">Invitations utilisées</th>
50+
<th class="right aligned">Tokens restants</th>
5051
<th class="right aligned">Peut scanner QR Codes</th>
5152
<th colspan="3"></th>
5253
</tr>
@@ -62,6 +63,22 @@
6263
<td>{{ token.token }}</td>
6364
<td class="right aligned">{{ token.maxInvitations }}</td>
6465
<td class="right aligned">{{ token.usedInvitations }}</td>
66+
<td class="right aligned">
67+
{% set pending = token.pendingInvitations %}
68+
{% if token.maxInvitations > 0 %}
69+
{% set remainingRate = pending / token.maxInvitations %}
70+
{% else %}
71+
{% set remainingRate = 0 %}
72+
{% endif %}
73+
{% if remainingRate > 0.5 %}
74+
{% set color = 'red' %}
75+
{% elseif remainingRate == 0 %}
76+
{% set color = 'green' %}
77+
{% else %}
78+
{% set color = 'orange' %}
79+
{% endif %}
80+
<span class="ui {{ color }} label">{{ (remainingRate * 100)|round }}%</span>
81+
</td>
6582
<td class="right aligned">{% if token.qrCodesScannerAvailable %}OUI{% else %}-{% endif %}</td>
6683
<td class="right aligned">
6784
<form class="sponsor--token-admin-view" method="post" action="{{ url('sponsor_ticket_home', {eventSlug: event.path}) }}">
@@ -112,6 +129,21 @@
112129
<th colspan="2"><strong>Total</strong></th>
113130
<th class="right aligned">{{ totalInvitations }}</th>
114131
<th class="right aligned">{{ totalUsedInvitations }}</th>
132+
<th class="right aligned">
133+
{% if totalInvitations > 0 %}
134+
{% set remainingRate = (totalInvitations - totalUsedInvitations) / totalInvitations %}
135+
{% else %}
136+
{% set remainingRate = 0 %}
137+
{% endif %}
138+
{% if remainingRate > 0.5 %}
139+
{% set color = 'red' %}
140+
{% elseif remainingRate == 0 %}
141+
{% set color = 'green' %}
142+
{% else %}
143+
{% set color = 'orange' %}
144+
{% endif %}
145+
<span class="ui {{ color }} label">{{ (remainingRate * 100)|round }}%</span>
146+
</th>
115147
<th colspan="4"></th>
116148
</tr>
117149
</tfoot>

‎tests/behat/bootstrap/FeatureContext.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ public function pressButtonOfTooltip(string $tooltip): void
125125
$button->press();
126126
}
127127

128+
#[When('/^I press "(?P<button>(?:[^"]|\\")*)" in the row of "(?P<row>(?:[^"]|\\")*)"$/')]
129+
public function pressButtonInRow(string $button, string $row): void
130+
{
131+
$input = $this->minkContext->getSession()->getPage()->find(
132+
'xpath',
133+
sprintf('//tr[contains(., "%s")]//input[@value="%s"]', $row, $button),
134+
);
135+
136+
if (null === $input) {
137+
throw new ExpectationException(
138+
sprintf('Button "%s" in row "%s" not found', $button, $row),
139+
$this->minkContext->getSession()->getDriver(),
140+
);
141+
}
142+
143+
$input->press();
144+
}
145+
128146
#[Then('/^the rows of table "(?P<selector>[^"]+)" should be in the following order:$/')]
129147
public function assertTableRowsInOrder(string $selector, PyStringNode $expectedRows): void
130148
{

‎tests/behat/features/Admin/Events/TokensSponsors.feature‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Feature: Administration - Évènements - Tokens Sponsors
1919
# Listing des tokens
2020
Then I should see "Invitations totales"
2121
And I should see tooltip "Supprimer"
22-
When I press "Voir les invitations"
22+
# Les 3 cas de taux d'utilisation des tokens (100% restant, 33% restant, 0% restant)
23+
And I should see a red label "100%"
24+
And I should see a orange label "33%"
25+
And I should see a green label "0%"
26+
When I press "Voir les invitations" in the row of "Ma société"
2327
# Listing des invitations vides
2428
Then I should see "Billetterie sponsor: forum - Ma société"
2529
And I should see "VOS PLACES GRATUITES"
@@ -46,13 +50,16 @@ Feature: Administration - Évènements - Tokens Sponsors
4650
Then I should see "Places disponibles: 1 / 2 "
4751
# Envoi de l'email de rappel
4852
When I am on "/admin/event/sponsor"
53+
Then I should see a orange label "50%"
4954
Then I follow "Envoyer le mail de rappel"
50-
And I should see "1 mails de relance ont été envoyés"
55+
And I should see "3 mails de relance ont été envoyés"
5156
And I should only receive the following emails:
5257
| to | subject |
5358
| <testToken1@mail.com> | Toutes les informations concernant votre sponsoring du forum |
5459
| <personneinvitee@masociete.com> | [forum] Merci ! |
5560
| <personneinvitee@masociete.com> | [forum] Merci ! |
61+
| <vert@sponsor-test.com> | Sponsor: enregistrez-vous pour le forum |
62+
| <deuxtiers@sponsor-test.com> | Sponsor: enregistrez-vous pour le forum |
5663
| <testToken1@mail.com> | Sponsor: enregistrez-vous pour le forum |
5764

5865
@reloadDbWithTestData

0 commit comments

Comments
 (0)