<?php
namespace App\Controller\Admin;
use App\Controller\AppBaseController;
use App\Entity\{Commande, EodriveClient};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Omines\DataTablesBundle\Adapter\ArrayAdapter;
use Omines\DataTablesBundle\Column\{DateTimeColumn, TextColumn};
use Omines\DataTablesBundle\Controller\DataTablesTrait;
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
use Doctrine\ORM\QueryBuilder;
/**
*
* @IsGranted("ROLE_USER")
* @Route("/")
*/
use App\Entity\Alert;
use App\Form\AlertType;
use App\Manager\{ClientManager, CommandeManager};
class DefaultController extends AppBaseController
{
use DataTablesTrait;
/**
* @Route("/", name="admin.homepage")
*/
public function listAction(Request $request){
$clients = $this->createDataTable()
->add('nom', TextColumn::class, ['label' => 'Nom', 'className' => 'bold', 'searchable' => true ])
->add('prenom', TextColumn::class, ['label' => 'Prénom', 'className' => 'bold', 'searchable' => true ])
->add('societe', TextColumn::class, ['label' => 'Société', 'className' => 'bold', 'searchable' => true ])
->add('tel', TextColumn::class, ['label' => 'Tel.', 'className' => 'bold', 'searchable' => true ])
->add('email', TextColumn::class, ['label' => 'Email', 'className' => 'bold', 'searchable' => true ])
->add('lastLogin', DateTimeColumn::class, ['label' => 'Dernière conexion', 'field' => 'user.lastLogin', 'format' => 'd/m/Y H:i:s', 'orderable' => true])
->add('etat', TextColumn::class, ['label' => 'Etat', 'className' => 'bold', 'searchable' => true ])
->add('nbConnexion', TextColumn::class, ['label' => 'Nombre de connexions', 'render' => function($value, $context) {
$nbConnexion = 0;
$users = $this->getRepository('App:Bflow\UserBO')->findBy(['clientEodrive' => $context]);
foreach ( $users as $user )
{
$nbConnexion += $user->getNombreConnexion();
}
return $nbConnexion;
}])
->add('tmpCommentaire', TextColumn::class, ['label' => 'Commentaires', 'render' => function($value, $context) {
$pathUpdateclientComment = $this->generateUrl('admin.client.update-comment');
$fullHtml = '<div class="row"><textarea rows="3" class="w-100 flatPickr txt-a-'.$context->getId().'" >' . $context->getCommentaire() . '</textarea></div>';
$fullHtml .= '<div class="row"><div class="col-sm-2 offset-10"><button class="btn btn-primary btn-xs btn-update-client-commentaire pull-right mt-1 ml-1" type="button" data-url-action="'.$pathUpdateclientComment.'" data-id="'.$context->getId().'"><i class="fa fa-check"></i></button>';
$fullHtml .= "</div></div>";
return $fullHtml;
}])
->createAdapter(ORMAdapter::class, [
'entity' => EodriveClient::class,
'query' => function (QueryBuilder $builder) {
$builder
->select('c')
->from(EodriveClient::class, 'c')
->leftJoin('c.userAdmin','user')
->where('c.etat IN (:etat_doit_paye, :etat_creation_sous_domaine)')
->setParameter(':etat_doit_paye', EodriveClient::ETAT_DOIT_PAYER)
->setParameter(':etat_creation_sous_domaine', EodriveClient::ETAT_CREATION_SOUS_DOMAINE)
;
},
])
->add('id', TextColumn::class, ['label' => 'Actions', 'render' => function($value, $context) {
$action =
'<div class="dropdown small">
<button class="btn btn-xs small border" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-bars"></i>
</button>
<div class="dropdown-menu small" aria-labelledby="dropdownMenuButton">
';
if($context->getEtat() == EodriveClient::ETAT_CREATION_SOUS_DOMAINE){
$action .= '<a class="dropdown-item small" href="'.$this->generateUrl('admin.client.domaineActif', ['id' => $value], true).'"><i class="fas fa-check"></i> Passé client à inscrit</a>';
}
$action .= '<a class="dropdown-item small" href="'.$this->generateUrl('admin.client.send-lien-paiement', ['id' => $value], true).'"><i class="fas fa-envelope"></i> Envoyer lien de paiement</a>';
$action .= '</div>
</div>';
return $action;
}])
->handleRequest($request);
if ($clients->isCallback()) {
return $clients->getResponse();
}
return $this->render('admin/dashboard/index.html.twig', ['clients' => $clients] );
}
}