Skip to content
Snippets Groups Projects
Commit 036746fb authored by François Agneray's avatar François Agneray
Browse files

Gestion badge PDF

parent e0e56f93
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,10 @@ $container[App\Action\DashboardGenerateBadgeAction::class] = function ($c) {
return new App\Action\DashboardGenerateBadgeAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardGenerateBadgeListAction::class] = function ($c) {
return new App\Action\DashboardGenerateBadgeListAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
// =============================================================
// Dashboard Participant
// =============================================================
......
......@@ -44,6 +44,11 @@ $app->get('/dashboard-generate-badge', App\Action\DashboardGenerateBadgeAction::
->add(App\Middleware\TokenMiddleware::class)
->setName('generate-badge');
$app->get('/dashboard-generate-badge-list', App\Action\DashboardGenerateBadgeListAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('generate-badge-list');
// =============================================================
// Dashboard Participant
// =============================================================
......
......@@ -24,12 +24,17 @@ final class DashboardGenerateBadgeAction
{
$this->logger->info("Dashboard generate action dispatched");
$email = $request->getAttribute('email');
$params = $request->getQueryParams();
$email = $params['email'];
$participant = $this->getParticipant($email);
if (!$participant) {
return $response->write('Email invalide')->withStatus(400);
}
// Parametres par defaut
$width = 600;
$height = 400;
$width = 890;
$height = 600;
$imagefile = './public/images/badge.png';
$fontroboto = './config/Roboto-Black.ttf';
$fontrobotolight = './config/Roboto-Light.ttf';
......@@ -44,31 +49,50 @@ final class DashboardGenerateBadgeAction
// Textes
if ($participant->getEvenementSocial()) {
imagettftext($image, 25, 20, 50, 230, $black, $fontTopSecret, 'Event');
imagettftext($image, 25, 20, 75, 350, $black, $fontTopSecret, 'Event');
}
imagettftext($image, 30, 0, 190, 70, $black, $fontroboto, $participant->getPrenom());
imagettftext($image, 30, 0, 190, 115, $black, $fontroboto, strtoupper($participant->getNom()));
imagettftext($image, 20, 0, 190, 170, $black, $fontrobotolight, $participant->getOrganisme()->getLabel());
imagettftext($image, 40, 0, 255, 100, $black, $fontroboto, $participant->getPrenom());
imagettftext($image, 40, 0, 255, 160, $black, $fontroboto, strtoupper($participant->getNom()));
imagettftext($image, 29, 0, 255, 250, $black, $fontrobotolight, $participant->getOrganisme()->getLabel());
$roleString = $participant->getRole();
if ($roleString == 'Invité') {
$roleString = 'Invite';
}
$idRoleOrga = $participant->getRoleOrga();
if($idRoleOrga) {
$role = $this->em->find('App\Entity\Role', $idRoleOrga);
$roleString .= ' - ' . $role->getLabel();
}
if($roleString == 'Participant') {
imagettftext($image, 20, 0, 315, 260, $black, $fontroboto, $roleString);
imagettftext($image, 35, 0, 400, 380, $black, $fontroboto, $roleString);
} else {
imagettftext($image, 20, 0, 255, 260, $red, $fontroboto, strtoupper($roleString));
imagettftext($image, 35, 0, 350, 380, $red, $fontroboto, strtoupper($roleString));
}
// Récupération du flux dans l'image dans un string
// Copie l'image du badge dans un fichier temp
$badgeFileName = 'temp' . uniqid() . '.png';
imagepng($image, 'data/' . $badgeFileName);
// Génére le PDF avec l'image à l'intérieur
$pdf = new \FPDF('P','mm','A4');
$pdf->AddPage();
//$pdf->SetFont('Arial', 'B', 16);
//$pdf->Cell(40, 10, 'Badge utilisateur');
//$pdf->Ln();
//$pdf->Ln();
$pdf->Image('data/' . $badgeFileName, null, null, 89);
// Stockage du pdf en mémoire
ob_start();
imagepng($image);
$image_data = ob_get_contents();
$pdf->Output();
$pdf_data = ob_get_contents();
ob_end_clean();
// Envoi du string de l'image dans la reponse slim
return $response->write($image_data)->withHeader('Content-type', 'image/png');;
// Suppression du fichier temporaire
unlink('data/' . $badgeFileName);
// Envoi du string du PDF dans la reponse slim
return $response->write($pdf_data)->withHeader('Content-type', 'application/pdf');
}
private function getParticipant($email)
......
<?php
namespace App\Action;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
final class DashboardGenerateBadgeListAction
{
private $view;
private $logger;
private $em;
public function __construct(Twig $view, LoggerInterface $logger, EntityManagerInterface $em)
{
$this->view = $view;
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, $args)
{
$this->logger->info("Dashboard generate action dispatched");
$params = $request->getQueryParams();
$role = $this->verifRole($params['role']);
if (!$role) {
return $response->write('Role invalide')->withStatus(400);
}
$participants = $this->getParticipants($role);
// Génére le PDF
$pdf = new \FPDF('P','mm','A4');
$pdf->AddPage();
$nbParticipants = count($participants);
$z = 0;
$cntForPage = 0;
while ($z < $nbParticipants) {
$y = $pdf->GetY();
$badgeFileName1 = $this->createBadge($participants[$z]);
$pdf->Image('data/' . $badgeFileName1, 10, $y, 89);
unlink('data/' . $badgeFileName1);
if ($z + 1 < $nbParticipants) {
$badgeFileName2 = $this->createBadge($participants[$z + 1]);
$pdf->Image('data/' . $badgeFileName2, 99, $y, 89);
unlink('data/' . $badgeFileName2);
$pdf->Ln(60);
$cntForPage += 2;
if ($cntForPage == 8) {
$pdf->AddPage();
$cntForPage = 0;
}
}
$z += 2;
}
// Stockage du pdf en mémoire
ob_start();
$pdf->Output();
$pdf_data = ob_get_contents();
ob_end_clean();
// Envoi du string du PDF dans la reponse slim
return $response->write($pdf_data)->withHeader('Content-type', 'application/pdf');
}
private function createBadge($participant)
{
// Parametres par defaut
$width = 890;
$height = 600;
$imagefile = './public/images/badge.png';
$fontroboto = './config/Roboto-Black.ttf';
$fontrobotolight = './config/Roboto-Light.ttf';
$fontTopSecret = './config/top_secret.ttf';
$fontarial = './config/arial.ttf';
// Création de l'image badge
$image = imagecreatefrompng($imagefile);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 204, 0, 0);
// Textes
if ($participant->getEvenementSocial()) {
imagettftext($image, 25, 20, 75, 350, $black, $fontTopSecret, 'Event');
}
imagettftext($image, 40, 0, 255, 100, $black, $fontroboto, $participant->getPrenom());
imagettftext($image, 40, 0, 255, 160, $black, $fontroboto, strtoupper($participant->getNom()));
imagettftext($image, 29, 0, 255, 250, $black, $fontrobotolight, $participant->getOrganisme()->getLabel());
$roleString = $participant->getRole();
if ($roleString == 'Invité') {
$roleString = 'Invite';
}
$idRoleOrga = $participant->getRoleOrga();
if($idRoleOrga) {
$role = $this->em->find('App\Entity\Role', $idRoleOrga);
$roleString .= ' - ' . $role->getLabel();
}
if($roleString == 'Participant') {
imagettftext($image, 35, 0, 400, 380, $black, $fontroboto, $roleString);
} else {
imagettftext($image, 35, 0, 350, 380, $red, $fontroboto, strtoupper($roleString));
}
// Copie l'image du badge dans un fichier temp
$badgeFileName = 'temp' . uniqid() . '.png';
imagepng($image, 'data/' . $badgeFileName);
return $badgeFileName;
}
private function verifRole($role)
{
if ($role == 'organisateur') {
return 'Organisateur';
} elseif ($role == 'invite') {
return 'Invité';
} elseif ($role == 'sponsor') {
return 'Sponsor';
} elseif ($role == 'exposant') {
return 'Exposant';
} elseif ($role == 'participant') {
return 'Participant';
} else {
return false;
}
}
private function getParticipants($role)
{
$dql = "SELECT p FROM App\Entity\Participant p WHERE p.role = '" . $role . "' ORDER BY p.nom";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
......@@ -16,7 +16,14 @@
</div>
<div id="admin_home" hidden>
<h4><i class="fa fa-check-square-o"></i> Validation des inscriptions de type Organisateur</h4>
<h4>
<i class="fa fa-check-square-o"></i>
Validation des inscriptions de type Organisateur
<a target="_blank" href="dashboard-generate-badge-list?token={{ token }}&role=organisateur"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération de la liste des badges">
</a>
</h4>
{% if organisateurs %}
<div class="table-responsive">
<table id="Torganisateurs" class="table table-striped table-bordered">
......@@ -27,7 +34,8 @@
<td>Organisme</td>
<td>Region</td>
<td>Statut</td>
<td>Paiement</td>
<td>Paiement</td>
<td>Badge</td>
</tr>
</thead>
<tbody>
......@@ -53,6 +61,12 @@
{% else %}
<td><i class="fa fa-pause"></i></td>
{% endif %}
<td class="text-center">
<a target="_blank" href="dashboard-generate-badge?token={{ token }}&email={{ organisateur.email }}"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération du badge">
</a>
</td>
</tr>
{% endfor %}
......@@ -63,7 +77,14 @@
<p>pas encore d'inscrits</p>
{% endif %}
<hr>
<h4><i class="fa fa-check-square-o"></i> Validation des inscriptions de type Invité</h4>
<h4>
<i class="fa fa-check-square-o"></i>
Validation des inscriptions de type Invité
<a target="_blank" href="dashboard-generate-badge-list?token={{ token }}&role=invite"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération de la liste des badges">
</a>
</h4>
{% if invites %}
<div class="table-responsive">
<table id="Tinvites" class="table table-striped table-bordered">
......@@ -74,7 +95,8 @@
<td>Organisme</td>
<td>Region</td>
<td>Statut</td>
<td>Paiement</td>
<td>Paiement</td>
<td>Badge</td>
</tr>
</thead>
<tbody>
......@@ -99,7 +121,12 @@
{% else %}
<td><i class="fa fa-pause"></i></td>
{% endif %}
<td class="text-center">
<a target="_blank" href="dashboard-generate-badge?token={{ token }}&email={{ invite.email }}"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération du badge">
</a>
</td>
</tr>
{% endfor %}
</tbody>
......@@ -109,7 +136,14 @@
<p>pas encore d'inscrits</p>
{% endif %}
<hr>
<h4><i class="fa fa-check-square-o"></i> Validation des inscriptions de type Sponsor</h4>
<h4>
<i class="fa fa-check-square-o"></i>
Validation des inscriptions de type Sponsor
<a target="_blank" href="dashboard-generate-badge-list?token={{ token }}&role=sponsor"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération de la liste des badges">
</a>
</h4>
{% if sponsors %}
<div class="table-responsive">
<table id="Tsponsors" class="table table-striped table-bordered">
......@@ -120,7 +154,8 @@
<td>Organisme</td>
<td>Region</td>
<td>Statut</td>
<td>Paiement</td>
<td>Paiement</td>
<td>Badge</td>
</tr>
</thead>
<tbody>
......@@ -145,6 +180,12 @@
{% else %}
<td><i class="fa fa-pause"></i></td>
{% endif %}
<td class="text-center">
<a target="_blank" href="dashboard-generate-badge?token={{ token }}&email={{ sponsor.email }}"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération du badge">
</a>
</td>
</tr>
{% endfor %}
......@@ -155,7 +196,14 @@
<p>pas encore d'inscrits</p>
{% endif %}
<hr>
<h4><i class="fa fa-check-square-o"></i> Validation des inscriptions de type Exposant</h4>
<h4>
<i class="fa fa-check-square-o"></i>
Validation des inscriptions de type Exposant
<a target="_blank" href="dashboard-generate-badge-list?token={{ token }}&role=exposant"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération de la liste des badges">
</a>
</h4>
{% if exposants %}
<div class="table-responsive">
<table id="Texposants" class="table table-striped table-bordered">
......@@ -166,7 +214,8 @@
<td>Organisme</td>
<td>Region</td>
<td>Statut</td>
<td>Paiement</td>
<td>Paiement</td>
<td>Badge</td>
</tr>
</thead>
<tbody>
......@@ -191,7 +240,12 @@
{% else %}
<td><i class="fa fa-pause"></i></td>
{% endif %}
<td class="text-center">
<a target="_blank" href="dashboard-generate-badge?token={{ token }}&email={{ exposant.email }}"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération du badge">
</a>
</td>
</tr>
{% endfor %}
</tbody>
......
......@@ -19,6 +19,10 @@
<div id="tabs_participant_gestion">
{% if participants %}
<a target="_blank" href="dashboard-generate-badge-list?token={{ token }}&role=participant"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération de la liste des badges">
</a>
<div class="table-responsive">
<table id="tab-admin-participants" class="table table-striped table-bordered">
<thead>
......@@ -31,6 +35,7 @@
<th>Présence</th>
<th>Parcours</th>
<th>Badge</th>
</tr>
</thead>
......@@ -78,7 +83,13 @@
class="btn btn-warning fa fa-calendar btn-info"
data-toggle="tooltip" title="Parcours">
</a>
</td>
</td>
<td class="text-center">
<a target="_blank" href="dashboard-generate-badge?token={{ token }}&email={{ participant.email }}"
class="btn btn-primary fa fa-id-badge btn-info"
data-toggle="tooltip" title="Génération du badge">
</a>
</td>
</tr>
{% endfor %}
</tbody>
......
public/images/badge.png

30.9 KiB | W: | H:

public/images/badge.png

36.7 KiB | W: | H:

public/images/badge.png
public/images/badge.png
public/images/badge.png
public/images/badge.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment