<?php
declare(strict_types=1);
/**
* @author Mehrez Labidi
*/
namespace App\Controller\Compte;
use Doctrine\ORM\EntityManagerInterface;
use App\Controller\EntityUsingController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Services\Compte\Annonces\AnnoncesManagers;
use App\Services\Compte\Alertes\AlertesManagers;
use App\Services\Compte\Favoris\FavorisManagers;
use App\Services\Compte\Commandes\CommandesManagers;
use App\Services\Compte\DI\DIManagers;
use App\Services\Compte\CvRepreneurs\CvRepreneursManagers;
use App\Services\ManagerEntity\DroitsAccesManagers;
use App\Services\Annonces\Elites\RechercheElite;
class IndexController extends EntityUsingController {
public function __construct(EntityManagerInterface $em, AnnoncesManagers $am, AlertesManagers $alm, FavorisManagers $fm, CommandesManagers $cm, CvRepreneursManagers $crm, DIManagers $dim, DroitsAccesManagers $dam) {
$this->am = $am;
$this->alm = $alm;
$this->em = $em;
$this->fm = $fm;
$this->cm = $cm;
$this->crm = $crm;
$this->dim = $dim;
$this->dam = $dam;
}
public function index(Request $request, $codePays): Response {
$this->denyAccessUnlessGranted('ROLE_USER'); // page inaccessible sans authentification
$nbAlertes = $this->alm->getNb();
$nbFavoris = $this->fm->getNb();
$nbCommandes = $this->cm->getNb();
$cv = $this->etatCVRepreneur();
$etatCV = ($cv) ? $cv->getModeProfil() : "";
$nbDIs = $this->dim->counterDIs();
$nbIncomplet = $this->am->getNbAnnoncesAcheteur("incomplet") + $this->am->getNbAnnoncesVendeur("incomplet");
if ($nbIncomplet > 0) {
$annonces = ["type_annonce" => "incomplet", "nb_annonce" => $nbIncomplet];
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV, "nbDIs" => $nbDIs,
"nbCommandes" => $nbCommandes, "annonces" => $annonces
]);
}
$nbPublique = $this->am->getNbAnnoncesAcheteur("publique") + $this->am->getNbAnnoncesVendeur("publique")+ $this->am->getNbAnnoncesVendeur("publique_elite");
if ($nbPublique > 0) {
$annonces = ["type_annonce" => "publique", "nb_annonce" => $nbPublique];
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV, "nbDIs" => $nbDIs,
"nbCommandes" => $nbCommandes, "annonces" => $annonces
]);
}
$nbValidation = $this->am->getNbAnnoncesAcheteur("demande_publication") + $this->am->getNbAnnoncesVendeur("demande_publication");
if ($nbValidation > 0) {
$annonces = ["type_annonce" => "validation", "nb_annonce" => $nbValidation];
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV, "nbDIs" => $nbDIs,
"nbCommandes" => $nbCommandes, "annonces" => $annonces
]);
}
$nbAttente = $this->am->getNbAnnoncesAcheteur("attente_envoi", "oui") + $this->am->getNbAnnoncesVendeur("attente_envoi", "oui");
if ($nbAttente > 0) {
$annonces = ["type_annonce" => "attente", "nb_annonce" => $nbAttente];
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV, "nbDIs" => $nbDIs,
"nbCommandes" => $nbCommandes, "annonces" => $annonces
]);
}
$nbCreation = $this->am->getNbAnnoncesAcheteur("attente_envoi", "non") + $this->am->getNbAnnoncesVendeur("attente_envoi", "non");
if ($nbCreation > 0) {
$annonces = ["type_annonce" => "creation", "nb_annonce" => $nbCreation];
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV, "nbDIs" => $nbDIs,
"nbCommandes" => $nbCommandes, "annonces" => $annonces
]);
}
return $this->render('compte/index.html.twig', [
"nbAlertes" => $nbAlertes, "nbDIs" => $nbDIs,
"nbFavoris" => $nbFavoris, "etatCV" => $etatCV,
"nbCommandes" => $nbCommandes
]);
}
public function colonneGauche(Request $request, $codePays): Response {
$this->denyAccessUnlessGranted('ROLE_USER'); // page inaccessible sans authentification
$nbAnnonces = $this->nbAnnonces();
$lang = $request->getSession()->get('lang');
$cv = $this->etatCVRepreneur();
$etatCV = ($cv) ? $cv->getModeProfil() : "";
$accessElite = $this->dam->checkIfThisUserHasDroitService($this->getUser(), RechercheElite::CODE_SERVICE); // ELITE
return $this->render('compte/colonne_gauche.html.twig', [
"nbAnnonces" => $nbAnnonces,
"etatCV" => $etatCV,
"accessElite" => $accessElite,
"codePaysWithUnderScore" => $codePays,
"lang" => $lang
]);
}
/**
*
* @return array
*/
private function nbAnnonces() {
$nbCreation = $this->am->getNbAnnoncesAcheteur("attente_envoi", "non") + $this->am->getNbAnnoncesVendeur("attente_envoi", "non");
$nbAttente = $this->am->getNbAnnoncesAcheteur("attente_envoi", "oui") + $this->am->getNbAnnoncesVendeur("attente_envoi", "oui");
$nbValidation = $this->am->getNbAnnoncesAcheteur("demande_publication") + $this->am->getNbAnnoncesVendeur("demande_publication");
$nbPublique = $this->am->getNbAnnoncesAcheteur("publique") + $this->am->getNbAnnoncesVendeur("publique");
return [
"creation" => $nbCreation,
"attente" => $nbAttente,
"validation" => $nbValidation,
"publique" => $nbPublique,
"sum" => (int) $nbCreation + (int) $nbAttente + (int) $nbValidation + (int) $nbPublique
];
}
private function etatCVRepreneur() {
$user = $this->getUser();
return $this->crm->getCvByLoginUtilisateur($user->getLogin());
}
}