<?php
// src/Controller/ClassementFusionAcquisitionController.php
namespace App\Controller;
use App\Entity\BuzzOperations;
use App\Entity\BuzzRoles;
use App\Entity\BuzzActualites;
use App\Entity\SocietesPrestataire;
use App\Entity\ServicesPrestataire;
use App\Entity\ClassementItem;
use App\Entity\Reseaux;
use App\Services\BuzzActualiteService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
use App\Services\Util;
/**
* Portage Symfony 5.4 sans amélioration et en conservant la logique.
* Ce contrôleur étend un contrôleur général (ClassementGeneralController)
* qui fournit les helpers : getEntityManager(), get_actualites(), get_tous_reseaux(),
* get_services_prestataire(), is_service_prestataire(), get_site(), get_src_image_si_artviper_desactive(),
* get_lien_fiche(), get_seuil_max_min(), get_liste_localisation(),
* get_annee_defaut(), get_segment_defaut(), get_localisation_defaut(),
* get_roles_par_reseau(), get_roles_par_societe(), get_classement_liste_avec_change_moins_un_mois(),
* date_actuelle_moins_un_mois().
*/
class ClassementFusionAcquisitionController extends ClassementGeneralController
{
/**
* @var EntityManagerInterface
*/
public $em;
/**
* @var BuzzActualiteService
*/
public $buzzActualiteService;
public $type_role;
public $type_operation;
public $annee_operation;
public $id_localisation;
public $segment;
public $actualites;
public $conseil_banque_type_role_liste = ["5","8","11","14","17"];
public $avocat_affaire_type_role_liste = ["6","9","12","15","18"];
public $cabinet_audit_type_role_liste = ["7","10","13","16","19"];
public $parametre_conseil_banque_type_role_liste = 1;
public $parametre_avocat_affaire_type_role_liste = 2;
public $parametre_cabinet_audit_type_role_liste = 3;
public function __construct( BuzzActualiteService $buzzActualiteService,EntityManagerInterface $em)
{
$this->em = $em;
$this->buzzActualiteService = $buzzActualiteService;
}
public function banquesAffairesConseils(Request $request,$params)
{
$type_tir = 0;
$this->segment = $this->get_segment_defaut();
$this->id_localisation = $this->get_localisation_defaut();
$this->annee_operation = $this->get_annee_defaut();
if (!empty($params)) {
$params = ltrim($params, '-');
$parts = explode(',', $params);
$this->annee_operation = $parts[0] ?? $this->get_annee_defaut();
$this->id_localisation = $parts[1] ?? $this->get_localisation_defaut();
$this->segment = $parts[2] ?? $this->get_segment_defaut();
$type_tir = $parts[3] ?? 0;
}
$this->type_operation = BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION;
$this->type_role = "banques_affaires";
$liste_loc = $this->get_liste_localisation();
$nom_loc = $liste_loc[$this->id_localisation] ?? '';
if ($this->id_localisation == "00") {
$this->id_localisation = "";
}
$classementListe = $this->buzzActualiteService->getDataClassement(
$this->parametre_conseil_banque_type_role_liste,
$this->type_operation,
$this->annee_operation,
$this->id_localisation,
$this->segment,
false,
$type_tir
);
$classement_liste = $this->traiteClassementListe($classementListe, $type_tir, $this->annee_operation);
return $this->render('classement/banquesaffairesconseils.html.twig', [
"type_tir" => $type_tir,
"type_role" => $this->type_role,
"type_operation" => $this->type_operation,
"str_lien_prestations_fu_ac"=>"fusions-acquisitions",
"annee_operation" => $this->annee_operation,
"localisation" => $this->id_localisation,
"nom_loc" => $nom_loc,
"segment" => $this->segment,
"class" => $classement_liste,
"loc_liste" => $liste_loc,
]);
}
/* public function avocatsaffaires(Request $request)
{
$type_tir = $request->get('tri_type', 0);
$this->type_operation = BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION;
$this->annee_operation = ($request->get('annee') == "")
? $this->get_annee_defaut()
: $request->get('annee');
$this->type_role = "avocats_affaires";
if ($request->get('localisation') !== null && $request->get('localisation') !== "") {
$this->id_localisation = $request->get('localisation');
} else {
$this->id_localisation = "33";
}
$liste_loc = $this->get_liste_localisation();
$nom_loc = $liste_loc[$this->id_localisation] ?? '';
if ($this->id_localisation == "00") {
$this->id_localisation = "";
}
$this->segment = ($request->get('segment') !== null)
? (int)$request->get('segment')
: $this->get_segment_defaut();
$classementListe = $this->buzzActualiteService->getDataClassement(
$this->parametre_avocat_affaire_type_role_liste,
$this->type_operation,
$this->annee_operation,
$this->id_localisation,
$this->segment,
false,
$type_tir
);
$classement_liste = $this->traiteClassementListe($classementListe, $type_tir, $this->annee_operation);
return $this->render('classement/avocatsaffaires.html.twig', [
"type_tir" => $type_tir,
"type_role" => $this->type_role,
"type_operation" => $this->type_operation,
"annee_operation" => $this->annee_operation,
"localisation" => $this->id_localisation,
"nom_loc" => $nom_loc,
"segment" => $this->segment,
"class" => $classement_liste,
"loc_liste" => $liste_loc,
]);
}
public function cabinetsaudit(Request $request)
{
$type_tir = $request->get('tri_type', 0);
$this->type_operation = BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION;
$this->annee_operation = ($request->get('annee') == "")
? $this->get_annee_defaut()
: $request->get('annee');
$this->type_role = "cabinets_audit";
if ($request->get('localisation') !== null && $request->get('localisation') !== "") {
$this->id_localisation = $request->get('localisation');
} else {
$this->id_localisation = "33";
}
$liste_loc = $this->get_liste_localisation();
$nom_loc = $liste_loc[$this->id_localisation] ?? '';
if ($this->id_localisation == "00") {
$this->id_localisation = "";
}
$this->segment = ($request->get('segment') !== null)
? (int)$request->get('segment')
: $this->get_segment_defaut();
$classementListe = $this->buzzActualiteService->getDataClassement(
$this->parametre_cabinet_audit_type_role_liste,
$this->type_operation,
$this->annee_operation,
$this->id_localisation,
$this->segment,
false,
$type_tir
);
$classement_liste = $this->traiteClassementListe($classementListe, $type_tir, $this->annee_operation);
return $this->render('classement/cabinetsaudit.html.twig', [
"type_tir" => $type_tir,
"type_role" => $this->type_role,
"type_operation" => $this->type_operation,
"annee_operation" => $this->annee_operation,
"localisation" => $this->id_localisation,
"nom_loc" => $nom_loc,
"segment" => $this->segment,
"class" => $classement_liste,
"loc_liste" => $liste_loc,
]);
}
public function print(Request $request)
{
$type_tir = $request->get('tri_type', 0);
$this->type_operation = BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION;
$this->annee_operation = ($request->get('annee') == "")
? $this->get_annee_defaut()
: $request->get('annee');
if ($request->get('localisation') !== null && $request->get('localisation') !== "") {
$this->id_localisation = $request->get('localisation');
} else {
$this->id_localisation = "33";
}
$liste_loc = $this->get_liste_localisation();
$nom_loc = $liste_loc[$this->id_localisation] ?? '';
if ($this->id_localisation == "00") {
$this->id_localisation = "";
}
$this->segment = ($request->get('segment') !== null)
? (int)$request->get('segment')
: $this->get_segment_defaut();
switch ($request->get('type_classe')) {
case "banques-affaires-conseils":
$this->type_role = "banques_affaires";
$type_liste = $this->conseil_banque_type_role_liste;
$parametre_type_role_liste = $this->parametre_conseil_banque_type_role_liste;
break;
case "avocats-affaires":
$this->type_role = "avocats_affaires";
$type_liste = $this->avocat_affaire_type_role_liste;
$parametre_type_role_liste = $this->parametre_avocat_affaire_type_role_liste;
break;
case "cabinets-audit":
$this->type_role = "cabinets_audit";
$type_liste = $this->cabinet_audit_type_role_liste;
$parametre_type_role_liste = $this->parametre_cabinet_audit_type_role_liste;
break;
default:
$this->type_role = "banques_affaires";
$type_liste = $this->conseil_banque_type_role_liste;
$parametre_type_role_liste = $this->parametre_conseil_banque_type_role_liste;
break;
}
$classementListe = $this->buzzActualiteService->getDataClassement(
$parametre_type_role_liste,
$this->type_operation,
$this->annee_operation,
$this->id_localisation,
$this->segment,
false,
$type_tir
);
$classement_liste = $this->traiteClassementListe($classementListe, $type_tir, $this->annee_operation);
if ($this->annee_operation == date("Y") && date("m") != "01") {
$classementListeMoisUn = $this->buzzActualiteService->getDataClassement(
$parametre_type_role_liste,
$this->type_operation,
$this->annee_operation,
$this->id_localisation,
$this->segment,
true,
$type_tir
);
$classement_mois_moins_un = $this->traiteClassementListe($classementListeMoisUn, $type_tir, $this->annee_operation);
$classement_liste = $this->get_classement_liste_avec_change_moins_un_mois($classement_liste, $classement_mois_moins_un);
}
$role_type_liste = [
'banques_affaires'=> "Conseils / Banques d'affaires",
'cabinets_audit' => "Cabinets d'audit",
'avocats_affaires'=> "Avocats d'affaires"
];
$segment_liste = [
"5" => "ETI",
"4" => "PME-ETI",
"3" => "TPE-PME-ETI",
"2" => "TPE-PME",
"1" => "TPE"
];
// Rendu d'un template PDF (même logique que ZF2, intégration via ton moteur PDF côté Twig/bundle PDF).
return $this->render('classement/print.pdf.twig', [
"type_tir" => $type_tir,
"type_role" => $this->type_role,
"type_operation" => $this->type_operation,
"annee_operation" => $this->annee_operation,
"localisation" => $this->id_localisation,
"segment" => $this->segment,
"class" => $classement_liste,
"nom_loc" => $nom_loc,
"loc_liste" => $liste_loc,
"role_type_liste" => $role_type_liste,
"segment_liste" => $segment_liste,
]);
}*/
/**
* ====== PORTAGE INTÉGRAL ZF2 ➜ Symfony (logique originale conservée) ======
* get_classement : copie de la méthode ZF2, dépend des helpers du contrôleur général.
*/
public function get_classement(
$parametre_type_role,
$parametre_type_operation,
$parametre_annee,
$parametre_localisation,
$parametre_segment,
$pour_un_mois_avant=false,
$tri=0
) {
$util = new \App\Services\Util(); // Util identique à l'original
$liste_opearation_par_is_societe_ou_reseau = array();
$target_chiffre = null;
if ($parametre_type_operation == BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION) {
$target_chiffre = "ca_societe_achetee";
}
$societe_liste = array();
$operations_traites_liste = array();
$liste_id_operation_temp_comte = array();
$reseau_id_liste = array();
$reseau_liste = $this->get_tous_reseaux();
$classement_liste = array();
$actualites = $this->get_actualites($parametre_annee);
foreach ($actualites as $actualite) {
if (($actualite instanceof BuzzActualites)) {
$operation = $actualite->_get("id_operation");
$operation = $this->em->getRepository(BuzzOperations::class)->find($operation);
if ($operation instanceof BuzzOperations) {
if ($actualite->__get("classement_reseau") == 'oui') {
$id_op = $actualite->__get("id_reseau") . '-' . $operation->__get("id_operation");
} else {
$id_op = $actualite->__get("id_societe_prestataire") . '-' . $operation->__get("id_operation");
}
if (!in_array($id_op, $operations_traites_liste)) {
$type_oper = $operation->__get("type_operation");
$id_loc = $operation->__get("id_localisation");
$date_oper = $operation->__get("date_operation");
$date_pub = $actualite->getDateMiseEnLigne();
$rattrapage = $operation->__get("check_rattrapage");
$flag_periode = false;
$annee_maintenant = date("Y");
if ($annee_maintenant == $parametre_annee) {
if (!$pour_un_mois_avant) {
if (substr($date_pub, 0, 4) == $parametre_annee && substr($date_pub, 0, 8) <= date("Ymd") && substr($date_oper, 0, 4) == $parametre_annee) {
$flag_periode = true;
}
} else {
$date_moins_un_mois = $this->date_actuelle_moins_un_mois();
if ($rattrapage == "oui") {
if ($date_oper <= $date_moins_un_mois && substr($date_oper, 0, 4) == $parametre_annee) {
$flag_periode = true;
}
} else {
$date_moins_un_mois = $date_moins_un_mois . "235959";
if ($date_pub <= $date_moins_un_mois && substr($date_pub, 0, 4) == $parametre_annee && substr($date_oper, 0, 4) == $parametre_annee) {
$flag_periode = true;
}
}
}
} else {
$flag_periode = (substr($date_oper, 0, 4) == $parametre_annee); //anne operation
}
if ($type_oper == $parametre_type_operation //type operation
&& $flag_periode //anne operation
&& $actualite->__get("type_actualite") == BuzzActualites::TYPE_ACTUALITE_REFERENCE
&& substr($id_loc, 0, strlen($parametre_localisation)) == $parametre_localisation
) {
$id_type_role = "";
$buzz_roles = $operation->getRoles();
$flag = false;
foreach ($buzz_roles as $buzz_role) { // if it is a operation of the type we want
if ($buzz_role instanceof BuzzRoles) {
$id_acteur = $buzz_role->__get("id_acteur");
$resultatSPs = $this->getEntityManager()->getRepository('Core\Entity\ServicesPrestataire')->findBy(array("id_societe_prestataire" => $actualite->__get("id_societe_prestataire")));
foreach ($resultatSPs as $resultatSP):
if ($resultatSP instanceof ServicesPrestataire && $resultatSP->__get("id_service_prestataire") == $id_acteur) {
$id_type_role = $buzz_role->__get("id_type_role");
if ($id_type_role != "" && in_array($id_type_role, $parametre_type_role)) {
$flag = true;
}
}
endforeach;
}
}
if ($flag) {
array_push($operations_traites_liste, $id_op);
$classement_reseau = $actualite->__get("classement_reseau");
$maj_min = $operation->__get("maj_min_capital");
$pct = 1;
$seuil = array();
$seuil = $this->get_seuil_max_min($this->segment);
$temp_ca = 0;
if ($operation->__get($target_chiffre) != null) {
$temp_ca = $operation->__get($target_chiffre);
}
$fourchette_ca = 0;
if ($operation->__get("fourchette_ca") != null) {
$fourchette_ca = $operation->__get("fourchette_ca");
}
if ($classement_reseau == "oui") { //if the actuality appears in the reseau
$id_reseau = $actualite->__get("id_reseau");
$temp_reseau = $this->em->getRepository(Reseaux::class)->find($id_reseau);
//$temp_reseau = $actualite->getReseau();
if ($temp_reseau instanceof Reseaux) {
$temp_reseau_segment = $temp_reseau->__get("segments_classements_concernes");
if (!in_array($id_reseau, $reseau_id_liste) && ($temp_reseau_segment >= $this->segment || $temp_reseau_segment == 3)) { //create the reseau in the classement
if (($temp_ca != 0 && $seuil["min"] <= $temp_ca && $temp_ca <= $seuil["max"])
|| ($temp_ca == 0 && $fourchette_ca == 0 && ($this->segment == 1 || $this->segment == 2 || $this->segment == 3))
|| ($temp_ca == 0 && $fourchette_ca != 0 && $fourchette_ca <= $this->segment && ($fourchette_ca + 2) >= $this->segment)) {
array_push($reseau_id_liste, $id_reseau);
$classement = new ClassementItem();
$classement->__set("nb_operation", 0);
foreach ($buzz_roles as $buzz_role) {
if ($buzz_role instanceof BuzzRoles) {
$id_acteur = $buzz_role->__get("id_acteur");
$resultatSPs = $this->getEntityManager()->getRepository('Core\Entity\ServicesPrestataire')->findBy(array("id_societe_prestataire" => $actualite->__get("id_societe_prestataire")));
foreach ($resultatSPs as $resultatSP):
if ($resultatSP instanceof ServicesPrestataire && $resultatSP->__get("id_service_prestataire") == $id_acteur) {
$id_type_role = $buzz_role->__get("id_type_role");
if ($id_type_role != "" && in_array($id_type_role, $parametre_type_role)) {
$classement->__set("nb_operation", 1);
}
}
endforeach;
}
}
$montant = 0;
if ($operation->__get($target_chiffre) != null) {
$montant = $operation->__get($target_chiffre);
}
if ($maj_min == "0" && $parametre_type_operation == BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION) {
$pct = $operation->__get("pct_capital_achete");
$montant = round($montant * $pct / 100, 0, PHP_ROUND_HALF_DOWN);
}
$classement->__set("montant_cumule", $montant);
$classement->__set("id_reseau", $id_reseau);
$classement->__set("reseau", ClassementItem::RESEAU_OUI);
$liste_id_operation = array();
$liste_id_operation[] = $operation->__get('id_operation');
$classement->__set('liste_id_operation', $liste_id_operation);
foreach ($reseau_liste as $reseau) {
if ($reseau instanceof Reseaux) {
if ($reseau->__get("id_reseau") == $id_reseau) {
$classement->__set("nom_reseau", $reseau->__get("nom"));
$classement->__set("lien_detail_nom", 'reseau-' . $util->reecriture_pour_url($reseau->__get("nom"), "-"));
$classement->__set("site_internet", $this->get_site($id_reseau, true));
$classement->__set("src_image_si_artviper_desactive", $this->get_src_image_si_artviper_desactive($id_reseau, true));
$classement->__set("lien_fiche_expert", $this->get_lien_fiche($id_reseau, true));
}
}
}
array_push($classement_liste, $classement);
}
} else if (in_array($id_reseau, $reseau_id_liste) && ($temp_reseau_segment >= $this->segment || $temp_reseau_segment == 3)) { //update this reseau in the classement
if (($temp_ca != 0 && $seuil["min"] <= $temp_ca && $temp_ca <= $seuil["max"])
|| ($temp_ca == 0 && $fourchette_ca == 0 && ($this->segment == 1 || $this->segment == 2 || $this->segment == 3))
|| ($temp_ca == 0 && $fourchette_ca != 0 && $fourchette_ca <= $this->segment && ($fourchette_ca + 2) >= $this->segment)) {
foreach ($classement_liste as $temp_classement) {
if ($temp_classement instanceof ClassementItem) {
if ($temp_classement->__get("id_reseau") == $id_reseau) {
$temp_montant = $temp_classement->__get("montant_cumule");
$new_montant = 0;
if ($operation->__get($target_chiffre) != null) {
$new_montant = $operation->__get($target_chiffre);
}
if ($maj_min == "0" && $parametre_type_operation == BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION) {
$pct = $operation->__get("pct_capital_achete");
$new_montant = round($new_montant * $pct / 100, 0, PHP_ROUND_HALF_DOWN);
}
$montant = $temp_montant + $new_montant;
$temp_classement->__set("montant_cumule", $montant);
$temp_compter = $temp_classement->__get("nb_operation");
$pluscom = false;
foreach ($buzz_roles as $buzz_role) {
if ($buzz_role instanceof BuzzRoles) {
$id_acteur = $buzz_role->__get("id_acteur");
$resultatSPs = $this->getEntityManager()->getRepository('Core\Entity\ServicesPrestataire')->findBy(array("id_societe_prestataire" => $actualite->__get("id_societe_prestataire")));
foreach ($resultatSPs as $resultatSP):
if ($resultatSP instanceof ServicesPrestataire && $resultatSP->__get("id_service_prestataire") == $id_acteur) {
$id_type_role = $buzz_role->__get("id_type_role");
if ($id_type_role != "" && in_array($id_type_role, $parametre_type_role)) {
$pluscom = true;
}
}
endforeach;
}
}
if ($pluscom) {
$temp_compter++;
}
$temp_classement->__set("nb_operation", $temp_compter);
$liste_temp_id_operation = $temp_classement->__get('liste_id_operation');
if (!in_array($operation->__get('id_operation'), $liste_temp_id_operation)) {
$liste_temp_id_operation[] = $operation->__get('id_operation');
}
$temp_classement->__set('liste_id_operation', $liste_temp_id_operation);
}
}
}
}
}
}
} else { //if it is not part of a reseau
$temp_societe = $actualite->_get("id_societe_prestataire");
$temp_societe = $this->em->getRepository(SocietesPrestataire::class)->find($temp_societe);
if ($temp_societe instanceof SocietesPrestataire) {
$id_societe = $temp_societe->__get("id_societe_prestataire");
if ($this->is_service_prestataire($id_societe, false, $buzz_roles, $parametre_type_role)) {
$temp_societe_segment = (int)$temp_societe->__get("segments_classements_concernes");
if (!in_array($id_societe, $societe_liste) && ($temp_societe_segment >= $this->segment || $temp_societe_segment == 3)) { //create new company
if (($temp_ca != 0 && $seuil["min"] <= $temp_ca && $temp_ca <= $seuil["max"])
|| ($temp_ca == 0 && $fourchette_ca == 0 && ($this->segment == 1 || $this->segment == 2 || $this->segment == 3))
|| ($temp_ca == 0 && $fourchette_ca != 0 && $fourchette_ca <= $this->segment && ($fourchette_ca + 2) >= $this->segment)) {
array_push($societe_liste, $id_societe);
$classement = new ClassementItem();
$classement->__set("id_societe_prestataire", $id_societe);
$classement->__set("raison_sociale", $actualite->__get("service_principal")->__get("nom_commercial_societe"));
$classement->__set("lien_detail_nom", $util->reecriture_pour_url($temp_societe->__get("raison_sociale"), "-"));
$classement->__set("nb_operation", 0);
$pluscom = false;
foreach ($buzz_roles as $buzz_role) {
if ($buzz_role instanceof BuzzRoles) {
$id_acteur = $buzz_role->__get("id_acteur");
$resultatSPs = $this->getEntityManager()->getRepository('Core\Entity\ServicesPrestataire')->findBy(array("id_societe_prestataire" => $actualite->__get("id_societe_prestataire")));
foreach ($resultatSPs as $resultatSP):
if ($resultatSP instanceof ServicesPrestataire && $resultatSP->__get("id_service_prestataire") == $id_acteur) {
$id_type_role = $buzz_role->__get("id_type_role");
if ($id_type_role != "" && in_array($id_type_role, $parametre_type_role)) {
$pluscom = true;
}
}
endforeach;
}
}
if ($pluscom) {
$classement->__set("nb_operation", 1);
}
$montant = 0;
if ($operation->__get($target_chiffre) != null) {
$montant = $operation->__get($target_chiffre);
}
if ($maj_min == "0" && $parametre_type_operation == BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION) {
$pct = $operation->__get("pct_capital_achete");
$montant = round($montant * $pct / 100, 0, PHP_ROUND_HALF_DOWN);
}
$classement->__set("montant_cumule", $montant);
$classement->__set("reseau", ClassementItem::RESEAU_NON);
$classement->__set("site_internet", $this->get_site($id_societe, false));
// NOTE : ligne fidèle au code d'origine (référence $id_reseau dans ce bloc non réseau)
$classement->__set("src_image_si_artviper_desactive", $this->get_src_image_si_artviper_desactive($id_reseau, true));
$classement->__set("lien_fiche_expert", $this->get_lien_fiche($id_societe, false));
$liste_id_operation = array();
$liste_id_operation[] = $operation->__get('id_operation');
$classement->__set('liste_id_operation', $liste_id_operation);
array_push($classement_liste, $classement);
}
} else if (in_array($id_societe, $societe_liste) && ($temp_societe_segment >= $this->segment || $temp_societe_segment == 3)) { //update
if (($temp_ca != 0 && $seuil["min"] <= $temp_ca && $temp_ca <= $seuil["max"])
|| ($temp_ca == 0 && $fourchette_ca == 0 && ($this->segment == 1 || $this->segment == 2 || $this->segment == 3))
|| ($temp_ca == 0 && $fourchette_ca != 0 && $fourchette_ca <= $this->segment && ($fourchette_ca + 2) >= $this->segment)) {
foreach ($classement_liste as $temp_classement) {
if ($temp_classement instanceof ClassementItem) {
if ($temp_classement->__get("id_societe_prestataire") == $id_societe) {
$temp_montant = $temp_classement->__get("montant_cumule");
$new_montant = 0;
if ($operation->__get($target_chiffre) != null) {
$new_montant = $operation->__get($target_chiffre);
}
if ($maj_min == "0" && $parametre_type_operation == BuzzOperations::TYPE_OPERATION_FUSION_ACQUISITION) {
$pct = $operation->__get("pct_capital_achete");
$new_montant = round($new_montant * $pct / 100, 0, PHP_ROUND_HALF_DOWN);
}
$montant = $temp_montant + $new_montant;
$temp_classement->__set("montant_cumule", $montant);
$temp_compter = $temp_classement->__get("nb_operation");
$pluscom = false;
foreach ($buzz_roles as $buzz_role) {
if ($buzz_role instanceof BuzzRoles) {
$id_acteur = $buzz_role->__get("id_acteur");
$resultatSPs = $this->getEntityManager()->getRepository('Core\Entity\ServicesPrestataire')->findBy(array("id_societe_prestataire" => $actualite->__get("id_societe_prestataire")));
foreach ($resultatSPs as $resultatSP):
if ($resultatSP instanceof ServicesPrestataire && $resultatSP->__get("id_service_prestataire") == $id_acteur) {
$id_type_role = $buzz_role->__get("id_type_role");
if ($id_type_role != "" && in_array($id_type_role, $parametre_type_role)) {
$pluscom = true;
}
}
endforeach;
}
}
if ($pluscom) {
$temp_compter++;
}
$temp_classement->__set("nb_operation", $temp_compter);
$liste_temp_id_operation = $temp_classement->__get('liste_id_operation');
if (!in_array($operation->__get('id_operation'), $liste_temp_id_operation)) {
$liste_temp_id_operation[] = $operation->__get('id_operation');
}
$temp_classement->__set('liste_id_operation', $liste_temp_id_operation);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
foreach ($classement_liste as $cl) {
$liste_buzz_role = array();
if ($cl->__get('reseau') == ClassementItem::RESEAU_OUI) {
$liste_buzz_role = $this->get_roles_par_reseau($cl->__get('id_reseau'), $cl->__get('liste_id_operation'));
} else {
$liste_buzz_role = $this->get_roles_par_societe($cl->__get('id_societe_prestataire'), $cl->__get('liste_id_operation'));
}
$liste_operation_par_societe_ou_reseau = array();
$liste_operation = array();
foreach ($liste_buzz_role as $buzz_role) {
if ($buzz_role->__get('id_type_role') == '5' || $buzz_role->__get('id_type_role') == '8') {
$id_operation = $buzz_role->__get('id_operation')->__get('id_operation');
if (null !== $liste_operation_par_societe_ou_reseau[$id_operation]) {
$temp = $liste_operation_par_societe_ou_reseau[$id_operation];
if (in_array($buzz_role->__get('id_type_role'), $temp)) {
} else {
$cl->__set('nb_operation', $cl->__get('nb_operation') + 1);
$cl->__set('montant_cumule', $cl->__get('montant_cumule') + $buzz_role->__get('id_operation')->__get('ca_societe_achetee'));
$temp[] = $buzz_role->__get('id_type_role');
$liste_operation_par_societe_ou_reseau[$id_operation] = $temp;
}
} else {
$temp = array();
$temp[] = $buzz_role->__get('id_type_role');
$liste_operation_par_societe_ou_reseau[$id_operation] = $temp;
}
}
}
}
if ($tri == 1) {
usort($classement_liste, function ($a, $b) {
if ($b->__get("nb_operation") == $a->__get("nb_operation")) {
return $b->__get("montant_cumule") - $a->__get("montant_cumule");
} else {
return $b->__get("nb_operation") - $a->__get("nb_operation");
}
});
} else {
usort($classement_liste, function ($a, $b) {
if ($b->__get("montant_cumule") == $a->__get("montant_cumule")) {
return $b->__get("nb_operation") - $a->__get("nb_operation");
} else {
return $b->__get("montant_cumule") - $a->__get("montant_cumule");
}
});
}
$r = 0;
foreach ($classement_liste as $cl) {
if ($cl instanceof ClassementItem) {
$r = $r + 1;
$cl->__set("rank", $r);
}
}
return $classement_liste;
}
/**
* ====== PORTAGE INTÉGRAL ZF2 ➜ Symfony (logique originale conservée) ======
*/
public function traiteClassementListe($classement_liste, $tri, $annee)
{
if ($annee <= 2023) {
foreach ($classement_liste as $cl) {
$liste_buzz_role = array();
if ($cl->__get('reseau') == ClassementItem::RESEAU_OUI) {
$liste_buzz_role = $this->get_roles_par_reseau($cl->__get('id_reseau'), $cl->__get('liste_id_operation'));
} else {
$liste_buzz_role = $this->get_roles_par_societe($cl->__get('id_societe_prestataire'), $cl->__get('liste_id_operation'));
}
$liste_operation_par_societe_ou_reseau = array();
$liste_operation = array();
foreach ($liste_buzz_role as $buzz_role) {
if ($buzz_role->__get('id_type_role') == '5' || $buzz_role->__get('id_type_role') == '8') {
$id_operation = $buzz_role->__get('id_operation')->__get('id_operation');
if (null !== $liste_operation_par_societe_ou_reseau[$id_operation]) {
$temp = $liste_operation_par_societe_ou_reseau[$id_operation];
if (in_array($buzz_role->__get('id_type_role'), $temp)) {
} else {
$cl->__set('nb_operation', $cl->__get('nb_operation') + 1);
$cl->__set('montant_cumule', $cl->__get('montant_cumule') + $buzz_role->__get('id_operation')->__get('ca_societe_achetee'));
$temp[] = $buzz_role->__get('id_type_role');
$liste_operation_par_societe_ou_reseau[$id_operation] = $temp;
}
} else {
$temp = array();
$temp[] = $buzz_role->__get('id_type_role');
$liste_operation_par_societe_ou_reseau[$id_operation] = $temp;
}
}
}
}
}
if ($tri == 1) {
usort($classement_liste, function ($a, $b) {
if ($b->__get("nb_operation") == $a->__get("nb_operation")) {
return $b->__get("montant_cumule") - $a->__get("montant_cumule");
} else {
return $b->__get("nb_operation") - $a->__get("nb_operation");
}
});
} else {
usort($classement_liste, function ($a, $b) {
if ($b->__get("montant_cumule") == $a->__get("montant_cumule")) {
return $b->__get("nb_operation") - $a->__get("nb_operation");
} else {
return $b->__get("montant_cumule") - $a->__get("montant_cumule");
}
});
}
$r = 0;
$rCount = 0;
$nbOperationPrece = 0;
foreach ($classement_liste as $cl) {
if ($cl instanceof ClassementItem) {
if ($tri == 1) {
if ($nbOperationPrece == $cl->__get("nb_operation")) {
$rCount = $rCount + 1;
$cl->__set("rank", $r);
} else {
$rCount = $rCount + 1;
$r = $rCount;
$cl->__set("rank", $rCount);
}
$nbOperationPrece = $cl->__get("nb_operation");
} else {
$r = $r + 1;
$cl->__set("rank", $r);
}
}
}
return $classement_liste;
}
}