<?php
declare(strict_types=1);
/**
* @author Mehrez Labidi
*/
namespace App\Controller;
use App\Services\MetaTag;
use App\Entity\InvestisseursPrives;
use App\Entity\Panier;
use App\Services\ManagerEntity\{
AnnuairesManagers,
SecteursActiviteManagers,
BusinessAngelManagers,
LocalisationsManagers,
DroitsAccesManagers,
CommandesManager
};
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\{
Request,
Response
};
use App\Repository\{
SecteursActiviteFondsRepository,
InvestisseursPrivesRepository,
CommandesRepository
};
use App\Helper\Utils;
use App\Twig\TranslationExtension;
use App\Helper\ParametersProvider;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use App\Services\TelephoneInternational;
use App\Services\Compte\Commandes\CommandesManagers;
use App\Services\PDFGenerator;
use App\Services\GoogleTag;
/**
* Description of AnnuairesInvestisseursPrivesController
*
* @author mehrez
*/
class AnnuairesInvestisseursPrivesController extends EntityUsingController {
public const MAX_AGE = 43200; // 12heures
/**
* @var AnnuairesManagers
*/
private $am;
/**
* @var SecteursActiviteManagers
*/
private $sam;
/**
* @var BusinessAngelManagers
*/
private $bam;
/**
* @var type
*/
private $safRepo;
/**
*
* @var type
*/
private $ipRepo;
/**
* @var LocalisationsManagers
*/
private $lm;
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var CommandesManager
*/
private $cm;
/**
* @var DroitsAccesManagers
*/
private $dam;
/**
* @var MetaTag
*/
private $metaTag;
/*
* @var PDFGenerator
*/
private $pf;
/**
*
* @param AnnuairesManagers $am
* @param SecteursActiviteFondsRepository $safRepo
* @param InvestisseursPrivesRepository $ipRepo
*/
public function __construct(AnnuairesManagers $am, SecteursActiviteFondsRepository $safRepo, InvestisseursPrivesRepository $ipRepo, SecteursActiviteManagers $sam, BusinessAngelManagers $bam, LocalisationsManagers $lm, DroitsAccesManagers $dam, EntityManagerInterface $em, CommandesManager $cm, MetaTag $metaTag, PDFGenerator $pf) {
$this->am = $am;
$this->lm = $lm;
$this->sam = $sam;
$this->bam = $bam;
$this->safRepo = $safRepo;
$this->ipRepo = $ipRepo;
$this->em = $em;
$this->cm = $cm;
$this->dam = $dam;
$this->metaTag = $metaTag;
$this->pf = $pf;
}
public function index(Request $request, $codePays, PaginatorInterface $paginator, $filters = []): Response {
foreach ($request->query->all() as $input => $value) {
if (!in_array($value, [NULL, "", "0", "indifferent"])) {
$filters[$input] = trim($value);
}
}
$investisseurs = $this->am->getInvestisseursPrivesList($request, $paginator, $filters); // InvestisseursPrives avec pagination
$response = $this->render(
'annuaires/investisseurs_prives/index.html.twig',
[
'investisseurs' => $investisseurs, "filters" => $filters,
"stade_investissement" => InvestisseursPrives::$STADE_INVESTISSEMENT,
"capital_detenu" => InvestisseursPrives::$CAPITAL_DETENU,
'controller_name' => 'AnnuairesInvestisseursPrivesController'
]
);
$response->setPublic();
$response->setMaxAge(self::MAX_AGE); // 12heures
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
// version Annuaires Investisseurs Prives (obsolète)
/* public function details(Request $request, InvestisseursPrives $investisseur, $codePays): Response {
if (!$investisseur) {
throw $this->createNotFoundException('No investisseur found for id ' . $investisseur);
}
$investisseur = Utils::convertObjectToArray($investisseur);
$investisseur["type_investisseur"] = (!empty($investisseur["type_investisseur"])) ? InvestisseursPrives::$TYPE_INVESTISSEUR[$investisseur["type_investisseur"]] : NULL;
$investisseur["capital_detenu"] = (!empty($investisseur["capital_detenu"])) ? InvestisseursPrives::$CAPITAL_DETENU[$investisseur["capital_detenu"]] : NULL;
$investisseur["role_souhaite"] = (!empty($investisseur["role_souhaite"])) ? InvestisseursPrives::$ROLE_SOUHAITE[$investisseur["role_souhaite"]] : NULL;
if (!empty($investisseur["stade_investissement"])) {
$investisseur["stade_investissement"] = array_map(
function ($item) {
return InvestisseursPrives::$STADE_INVESTISSEMENT[$item];
},
array_filter(explode(",", $investisseur["stade_investissement"]))
);
}
if (!empty($investisseur["id_secteurs_activite"])) {
$id_secteurs_activite = array_filter(explode(",", $investisseur["id_secteurs_activite"]));
$result = $this->safRepo->getNomSecteurActiviteFondsByIds($id_secteurs_activite);
$nom_secteurs = array_column($result, 'nom_secteur_activite');
$investisseur["id_secteurs_activite"] = $nom_secteurs;
}
$ids = $this->ipRepo->getInvestisseursPrivesList($request->query->all(), true);
$lienNext = (Utils::getNextFromArray($investisseur["id_investisseur"], $ids)) ? $this->generateUrl('investisseurs_prives_details', ['codePays' => $codePays, 'id_investisseur' => Utils::getNextFromArray($investisseur["id_investisseur"], $ids)]) : NULL;
$lienPrevious = (Utils::getPrevFromArray($investisseur["id_investisseur"], $ids)) ? $this->generateUrl('investisseurs_prives_details', ['codePays' => $codePays, 'id_investisseur' => Utils::getPrevFromArray($investisseur["id_investisseur"], $ids)]) : NULL;
$lienRetourList = $this->generateUrl('investisseurs_prives_index', ['codePays' => $codePays]);
if (!empty($request->query->all())) { // des param GET à garder
$lienNext = ($lienNext) ? $lienNext . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
$lienPrevious = ($lienPrevious) ? $lienPrevious . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
$lienRetourList = ($lienRetourList) ? $lienRetourList . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
}
$response = $this->render(
'annuaires/investisseurs_prives/details.html.twig',
[
'investisseur' => $investisseur,
"lienPrev" => $lienPrevious, "lienNext" => $lienNext, "lienRetourList" => $lienRetourList,
'controller_name' => 'AnnuairesInvestisseursPrivesController'
]
);
$response->setPublic();
$response->setMaxAge(self::MAX_AGE); // 12heures
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
} */
// version Ouvrir Capital - Business Angel
public function detail(Request $request, InvestisseursPrivesRepository $investisseurRepo, TranslationExtension $translationExtension, CommandesRepository $commandesRepository, GoogleTag $googleTag, $idInvestisseurPrive, $codePays): Response {
$lang = $request->getSession()->get('lang');
$from = $request->query->get('from');
$parametres = $request->query->all();
$parametres = ParametersProvider::prepareRechercheAvanceeOuvrirCapitalParameters($parametres);
$string_params = $string_params_without_page = $this->serializeParams($parametres);
$hasForfait = false;
$hasServiceBA = false;
$lignePanier = false;
$dejaCommande = false;
$forfaitAUtiliser = array();
$investisseur_prive = $investisseurRepo->findOneBy(['id_investisseur' => $idInvestisseurPrive, 'mode' => 'publique']);
if (!$investisseur_prive) {
$this->addFlash('error', $translationExtension->translate("une erreur s'est produite, veuillez réessayer", $lang, '', 'M', ''));
if ($from == "ouvrir-capital") {
return $this->redirectToRoute('ouvrir_capital_resultats_business_angel', ['codePays' => $codePays]);
} else {
return $this->redirectToRoute('investisseurs_prives_index', ['codePays' => $codePays]);
}
}
// On efface les anciens parametres s'ils existent, puis on insert les nouveaux
$googleTag->removeParametresPub();
if ($investisseur_prive->_get('id_localisations_recherchees')) {
$id_localisations_recherchees = trim($investisseur_prive->_get('id_localisations_recherchees'), ',');
$array_id_localisations_recherchees = explode(",", $id_localisations_recherchees);
// On prend le premier id_localisation
if ($array_id_localisations_recherchees[0]) {
// Si c'est un département
if (substr_count($array_id_localisations_recherchees[0], "_") == 2) {
$googleTag->setIdDepartement($array_id_localisations_recherchees[0]);
$googleTag->setIdRegion(substr($array_id_localisations_recherchees[0], 0, -3));
$googleTag->setIdPays(substr($array_id_localisations_recherchees[0], 0, strpos($array_id_localisations_recherchees[0], "_")));
// Si c'est une region
} elseif (substr_count($array_id_localisations_recherchees[0], "_") == 1) {
$googleTag->setIdRegion($array_id_localisations_recherchees[0]);
$googleTag->setIdPays(substr($array_id_localisations_recherchees[0], 0, strpos($array_id_localisations_recherchees[0], "_")));
// Sinon c'est un pays
} else {
$googleTag->setIdPays($array_id_localisations_recherchees[0]);
}
}
}
if ($investisseur_prive->_get('id_secteurs_activite')) {
$id_secteur_activite_recherche = trim($investisseur_prive->_get('id_secteurs_activite'), ",");
$array_secteur_activite_recherche = explode(",", $id_secteur_activite_recherche);
// On prend le premier id_secteur_activite
if ($array_secteur_activite_recherche[0]) {
$googleTag->setIdSecteurActiviteFonds($array_secteur_activite_recherche[0]);
}
}
$user = $this->getUser();
if (!empty($user)) {
$lignePanier = $this->em->getRepository(Panier::class)->findOneBy(
['login_utilisateur' => $user->_get('login_utilisateur'), "type_object" => 'annonce_BA', "id_object" => $idInvestisseurPrive]
);
$dejaCommande = $this->cm->hasAnnonceCommande($user->_get('login_utilisateur'), $idInvestisseurPrive, 'investisseur_prive');
$forfaitAUtiliser = $this->dam->getFrofaitAnnonceToUse($user);
if (!empty($forfaitAUtiliser)) {
$hasForfait = true;
}
$hasServiceBA = $this->dam->checkIfThisUserHasDroitService($user, [27]); // 27 = annuaire des business angel
}
$tab_commande_ba = [];
// On récupère la liste des investisseurs privés commandés par l'utilisateur
if (!empty($user)) {
$idUtilisateur = $user->_get('id_utilisateur');
$userCommandes = $commandesRepository->getUserCommandesAnnuaireBusinessAngel($idUtilisateur);
$string_id_investisseur = "";
foreach ($userCommandes as $commande) {
$string_id_investisseur .= $commande->_get('liste_investisseurs');
}
$tab_commande_ba = array_filter(explode(",", $string_id_investisseur));
}
/* $investisseur_prive->nom_affichage = substr(ucfirst($investisseur_prive->_get('prenom_contact')), 0, 1) . '.' . substr(ucfirst($investisseur_prive->_get('nom_contact')), 0, 1) . ' (INV_'.$investisseur_prive->_get('id_investisseur').')';
$deja_commande = false;
if ($tab_commande_ba) {
if (in_array($investisseur_prive->_get('id_investisseur'), $tab_commande_ba)) {
$investisseur_prive->nom_affichage = ucfirst($investisseur_prive->_get('prenom_contact')) . ' ' . ucfirst($investisseur_prive->_get('nom_contact')) . ' (INV_' . $investisseur_prive->_get('id_investisseur').')';
$deja_commande = true;
}
} */
$investisseur_prive->nom_affichage = $investisseur_prive->_get('titre_investisseur');
$deja_commande = false;
if ($dejaCommande || ($tab_commande_ba && in_array($investisseur_prive->_get('id_investisseur'), $tab_commande_ba)) || $hasServiceBA) {
$investisseur_prive->nom_affichage = ucfirst($investisseur_prive->_get('prenom_contact')) . ' ' . ucfirst($investisseur_prive->_get('nom_contact')) . ' - ' . $investisseur_prive->_get('titre_investisseur');
if ($dejaCommande || ($tab_commande_ba && in_array($investisseur_prive->_get('id_investisseur'), $tab_commande_ba))) {
$deja_commande = true;
}
}
$id_secteurs_activite = array_filter(explode(',', $investisseur_prive->_get('id_secteurs_activite')));
$secteurs_activite = [];
foreach ($id_secteurs_activite as $id_secteur) {
$secteurs_activite[] = $this->sam->getNomSecteurActiviteFondsById($id_secteur);
}
if ($investisseur_prive->_get('id_localisations_recherchees') != "") {
$id_localisations_recherchees = array_filter(explode(',', $investisseur_prive->_get('id_localisations_recherchees')));
} else {
$id_localisations_recherchees = [];
}
$localisations_recherchees = [];
foreach ($id_localisations_recherchees as $id_localisation_recherchee) {
$localisations_recherchees[] = $this->lm->getStringNomLocalisationById($id_localisation_recherchee);
}
if ($from == "ouvrir-capital") {
$colorClass = "orange-new";
$titreClass = "titre_annonce_orange";
$btnClass = "btn-orange-new";
// Navigation Ouvrir Capital Business Angel
$index = $request->query->get('index');
$page = (int) $request->query->get('page', 1);
if ($page > 1) {
$string_params .= "&page=" . $page;
}
$urlList = $request->query->get('urlList');
$urlRetourList = $urlList ? $urlList . '?' . $string_params : null;
$previousAnnonce = $this->bam->getIndexNAnnonceFromBusinessAngelList($parametres, "", $page, $index - 1);
$nextAnnonce = $this->bam->getIndexNAnnonceFromBusinessAngelList($parametres, "", $page, $index + 1);
$lienPrevious = null;
$lienNext = null;
$lienRetourList = null;
$metaTitle = 'investisseur privé, %$titre_investisseur%$';
$metaDescription = 'consultez ce Business Angel, %$titre_investisseur%$';
} else {
$colorClass = "bleu";
$titreClass = "titre_annonce";
$btnClass = "button-rond";
// Navigation Annuaire Investisseurs Prives
$ids = $this->ipRepo->getInvestisseursPrivesList($request->query->all(), true);
$slugNext = $investisseur_prive->_get('titre_investisseur') != "" ? Utils::slugify($investisseur_prive->_get('titre_investisseur')) : "";
$slugPrevious = $investisseur_prive->_get('titre_investisseur') != "" ? Utils::slugify($investisseur_prive->_get('titre_investisseur')) : "";
$lienNext = (Utils::getNextFromArray($investisseur_prive->_get('id_investisseur'), $ids)) ? $this->generateUrl('investisseurs_prives_detail', ['slug' => $slugNext, 'codePays' => $codePays, 'idInvestisseurPrive' => Utils::getNextFromArray($investisseur_prive->_get('id_investisseur'), $ids)]) : NULL;
$lienPrevious = (Utils::getPrevFromArray($investisseur_prive->_get('id_investisseur'), $ids)) ? $this->generateUrl('investisseurs_prives_detail', ['slug' => $slugPrevious, 'codePays' => $codePays, 'idInvestisseurPrive' => Utils::getPrevFromArray($investisseur_prive->_get('id_investisseur'), $ids)]) : NULL;
$lienRetourList = $this->generateUrl('investisseurs_prives_index', ['codePays' => $codePays]);
if (!empty($request->query->all())) { // des param GET à garder
$lienNext = ($lienNext) ? $lienNext . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
$lienPrevious = ($lienPrevious) ? $lienPrevious . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
$lienRetourList = ($lienRetourList) ? $lienRetourList . Utils::convertArrayToUrlFormat($request->query->all()) : NULL;
}
$index = null;
$urlList = null;
$urlRetourList = null;
$string_params = null;
$previousAnnonce = null;
$nextAnnonce = null;
$metaTitle = 'investisseur privé, %$titre_investisseur%$';
$metaDescription = 'consultez ce profil de Business Angel, %$titre_investisseur%$';
}
$http_host = $request->server->get('HTTP_HOST');
$url = substr($request->server->get('REDIRECT_URL'), 0, -4);
$canonical = $http_host . $url;
$arrayVarsTrans['titre_investisseur'] = $investisseur_prive->nom_affichage;
$metaTag = $this->metaTag
->setTitle($translationExtension->translate($metaTitle, $lang, "", "M", "", $arrayVarsTrans))
->setDescription($translationExtension->translate($metaDescription, $lang, "", "M", "", $arrayVarsTrans))
->setCanonical($canonical);
return $this->render(
'annuaires/investisseurs_prives/detail.html.twig',
[
'metaTag' => $metaTag,
'investisseur_prive' => $investisseur_prive,
'secteurs_activite' => $secteurs_activite,
'localisations_recherchees' => $localisations_recherchees,
'string_params' => $string_params,
'string_params_without_page' => $string_params_without_page,
'previousAnnonce' => $previousAnnonce,
'nextAnnonce' => $nextAnnonce,
'urlList' => $urlList,
'urlRetourList' => $urlRetourList,
'urlRetourListPanier'=>$urlRetourList,
'string_params' => $string_params,
'index' => $index,
'indexPrevious' => $index - 1,
'indexNext' => $index + 1,
"lienPrev" => $lienPrevious,
"lienNext" => $lienNext,
"lienRetourList" => $lienRetourList,
'deja_commande' => $deja_commande,
'hasServiceBA' => $hasServiceBA,
'from' => $from,
'colorClass' => $colorClass,
'titreClass' => $titreClass,
'btnClass' => $btnClass,
'lignePanier' => $lignePanier,
'dejaCommande' => $dejaCommande,
'hasForfait' => $hasForfait,
'forfaitAUtiliser' => $forfaitAUtiliser,
'googleTag' => $googleTag,
]
);
}
public function imprimerInvestisseurPrive(InvestisseursPrivesRepository $investisseurRepo, CommandesRepository $cr, TelephoneInternational $ti, LocalisationsManagers $localisationManager, CommandesManagers $cm, $idInvestisseurPrive,$codePays, $lang)
{
$user = $this->getUser();
$investisseur_prive = $investisseurRepo->findOneBy(['id_investisseur' => $idInvestisseurPrive]);
$coordonnees = [];
$annee_passee = false; // Variable pour savoir si 1 an est passé depuis la commande, si oui, on n'affiche pas les coordonnées complètes (RGPD)
// Si l'utilisateur a déjà commandé ce repreneur
if ($user && $cr->hasAnnonceCommande($user->_get('login_utilisateur'), $idInvestisseurPrive, "investisseur_prive")) {
$coordonnees['nom_contact'] = ucfirst($investisseur_prive->_get('prenom_contact')) . ' ' . strtoupper($investisseur_prive->_get('nom_contact'));
$coordonnees['telephone'] = $investisseur_prive->_get('telephone_contact') ? $ti->getInternationalPhone($investisseur_prive->_get('telephone_contact'), $investisseur_prive->_get('indicatif_telephone_contact'))['affichage'] : null;
$coordonnees['email'] = $investisseur_prive->_get('email_contact');
$commande = $cm->getArrayCommandeByIdElement($investisseur_prive->getId(), "investisseur_prive");
if ($commande) {
$annee_passee = $commande['annee_passee'];
}
} elseif ('publique' != $investisseur_prive->_get('mode')) {
throw $this->createNotFoundException('Investisseur introuvable');
}
$id_secteurs_activite = array_filter(explode(',', $investisseur_prive->_get('id_secteurs_activite')));
$secteurs_activite = [];
foreach ($id_secteurs_activite as $id_secteur) {
$secteurs_activite[] = $this->sam->getNomSecteurActiviteFondsById($id_secteur);
}
if ($investisseur_prive->_get('id_localisations_recherchees') != "") {
$id_localisations_recherchees = array_filter(explode(',', $investisseur_prive->_get('id_localisations_recherchees')));
} else {
$id_localisations_recherchees = [];
}
$localisations_recherchees = [];
foreach ($id_localisations_recherchees as $id_localisation_recherchee) {
$localisations_recherchees[] = $this->lm->getStringNomLocalisationById($id_localisation_recherchee);
}
return $this->pf->generatePDFviewBrowser(
'templates_pdf/annuaires/investisseurs_prives/investisseur_prive_details.html.twig',
[
'lang' => $lang,
'coordonnees' => $coordonnees,
'annee_passee' => $annee_passee,
'investisseur_prive' => $investisseur_prive,
'secteurs_activite' => $secteurs_activite,
'localisations_recherchees' => $localisations_recherchees,
],
'investisseur_prive',
'investisseur_prive_title'
);
}
private function serializeParams($parametres) {
$string_params = "";
foreach ($parametres as $name => $value) {
if ($name != "rechercher" && $name != "type" && $name != "array_localisation") {
if ($string_params == "") {
$string_params .= $name . "=" . $value;
} else {
$string_params .= "&" . $name . "=" . $value;
}
}
}
return $string_params;
}
/**
* @param Request $request
* @param type $codePays
* @return Response
*/
public function ajoutProfil(Request $request, $codePays): Response {
$this->denyAccessUnlessGranted('ROLE_USER'); // page inaccessible sans authentification
return new RedirectResponse('/compte?module=investisseur_prive&action=ajout_investisseur&from=liste_investisseurs');
}
}