Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
409 righe
16 KiB
409 righe
16 KiB
<?php |
|
|
|
trait eFormsManager_suggestions |
|
{ |
|
|
|
/** |
|
* Integrazioni passate da altri moduli |
|
* |
|
* @var null|array |
|
*/ |
|
protected $suggestions; |
|
|
|
/** |
|
* Abilita i suggerimenti forzati |
|
* |
|
* @var bool |
|
*/ |
|
public $enable_forced_suggestions = true; |
|
|
|
/** |
|
* Dati relativi agli helper di integrazione correntemente visibili |
|
* Struttura intesa (WIP) |
|
* - sezione v |
|
* - ripetizione v |
|
* array |
|
* - modulo => modulo di integrazione |
|
* - sottomodulo => sottomodulo di integrazione |
|
* - data => dati del modulo |
|
* - title => titolo dell'helper |
|
* |
|
* @var array |
|
*/ |
|
protected $integrationHelperData = []; |
|
|
|
|
|
public function appendIntegrationHelper(string $modulo, string $sottomodulo, array $data, string $title, string $section, int $subsection = 0, string $position = "floating", bool $data_is_array = false) |
|
{ |
|
$target = &$this->integrationHelperData[$section][$subsection][$title]; |
|
|
|
// Se lo slot è vuoto lo creiamo |
|
if(empty($target)) { |
|
$target["modulo"] = $modulo; |
|
$target["sottomodulo"] = $sottomodulo; |
|
|
|
$target["title"] = $title; |
|
$target["position"] = $position; |
|
// Flag per gestire aggiunte |
|
$target["is_array"] = $data_is_array; |
|
$target["data"] = $data_is_array ? [$data] : $data; |
|
} |
|
// Altrimenti appendiamo i dati |
|
else { |
|
// Se stiamo aggiungendo, rendiamo i dati un array in modo da passarli come lista |
|
// al renderer |
|
if(!$target["is_array"]) { |
|
$target["is_array"] = true; |
|
$target["data"] = [$target["data"]]; |
|
} |
|
$target["data"][] = $data; |
|
} |
|
|
|
} |
|
|
|
/** |
|
* Carica i suggerimenti dall'integrazione |
|
* |
|
* @return void |
|
*/ |
|
public function setSuggestions() |
|
{ |
|
$this->loadSuggestions(); |
|
// Verifichiamo che il form attuale abbia una sezione risultati |
|
$hasResults = false; |
|
foreach ($this->sections as $section) { |
|
if ($section["id"] === "GR-Result") { |
|
$hasResults = true; |
|
break; |
|
} |
|
} |
|
|
|
// Importazione prima organizzazione che è sempre il CONTRACTING BODY |
|
if (isset($this->suggestions["CONTRACTING_BODY"])) { |
|
$contracting_body = $this->suggestions["CONTRACTING_BODY"]; |
|
|
|
// Verifichiamo che in values sia vuota in modo da riempire e obbligare l'autocompilazione |
|
$empty = (empty($this->info["valori"]["eforms2"]["GR-Organisations-Section"]["values"]["GR-Organisations"][0])); |
|
if ($empty) { |
|
$this->info["valori"]["eforms2"]["GR-Organisations-Section"]["values"]["GR-Organisations"][0] = []; |
|
} |
|
// Puntatore alla prima organizzazione negli integration_values |
|
$first_organization = &$this->info["valori"]["eforms2"]["GR-Organisations-Section"]["integration_values"]["GR-Organisations"][0]; |
|
// ID GUUE |
|
$first_organization["OPT-200-Organization-Company"] = ["forced" => true, "value" => "ORG-0001"]; |
|
// Nome |
|
$first_organization["BT-500-Organization-Company"] = ["forced" => true, "value" => $contracting_body["OFFICIALNAME"]]; |
|
// Codice fiscale[0] |
|
$first_organization["GR-Organisation-Identifier"][0]["BT-501-Organization-Company"] = ["forced" => true, "value" => $contracting_body["IDENTIFIER_NUM"]]; |
|
// URL |
|
$first_organization["BT-505-Organization-Company"] = ["forced" => false, "value" => $contracting_body["URL_GENERAL"]]; |
|
// Località (TODO -> dizionario per le altre nazioni) |
|
if ($contracting_body["COUNTRY"] === "IT") { |
|
$first_organization["BT-514-Organization-Company"] = ["forced" => true, "value" => "ITA"]; |
|
} |
|
// Codice postale |
|
$first_organization["BT-512-Organization-Company"] = ["forced" => false, "value" => $contracting_body["POSTAL_CODE"]]; |
|
// Telefono |
|
$first_organization["BT-503-Organization-Company"] = ["forced" => false, "value" => $contracting_body["PHONE"]]; |
|
// Email |
|
$first_organization["BT-506-Organization-Company"] = ["forced" => false, "value" => $contracting_body["E_MAIL"]]; |
|
// FAX |
|
$first_organization["BT-739-Organization-Company"] = ["forced" => false, "value" => $contracting_body["FAX"]]; |
|
// Indirizzo |
|
$first_organization["BT-510(a)-Organization-Company"] = ["forced" => false, "value" => $contracting_body["ADDRESS"]]; |
|
// Città |
|
$first_organization["BT-513-Organization-Company"] = ["forced" => false, "value" => $contracting_body["TOWN"]]; |
|
|
|
|
|
|
|
// Importiamo ORG-0001 come buyer |
|
|
|
$buyer_values_path = "valori.eforms2.GR-Buyer.values.GR-ContractingAuthority.0.GR-ContractingAuthority-Buyer"; |
|
$buyer_ivalues_path = "valori.eforms2.GR-Buyer.integration_values.GR-ContractingAuthority.0.GR-ContractingAuthority-Buyer.OPT-300-Procedure-Buyer"; |
|
|
|
$empty = empty(self::get($this->info, $buyer_values_path)); |
|
if ($empty) { |
|
self::set($this->info, $buyer_values_path, []); |
|
} |
|
self::set($this->info, $buyer_ivalues_path, ["forced" => false, "value" => "ORG-0001"]); |
|
} |
|
|
|
|
|
|
|
// Importazione altre organizzazioni partecipanti. |
|
// Avviene solo se il form corrente prevede risultati, quindi a offerte presentate |
|
if (isset($this->suggestions["PARTECIPANTI"])) { |
|
// Aggiungiamo il modulo da renderizzare |
|
$this->appendIntegrationHelper( |
|
$this->suggestions["MODULO"], |
|
"organizzazioni", |
|
$this->suggestions["PARTECIPANTI"], |
|
__guue("Organizzazioni menzionate"), |
|
"GR-Organisations-Section", |
|
0, |
|
"GR-Organisations", |
|
); |
|
} |
|
|
|
// Importazione info sulla gara su GR-Procedure |
|
if (isset($this->suggestions["GENERAL"])) { |
|
$gara = &$this->suggestions["GENERAL"]; |
|
|
|
// Popoliamo GR-Procedure se è vuota |
|
$empty = (empty($this->info["valori"]["eforms2"]["GR-Procedure"]["values"])); |
|
if ($empty) { |
|
$this->info["valori"]["eforms2"]["GR-Procedure"]["values"] = []; |
|
} |
|
|
|
// Creiamo i valori di integrazione |
|
$procedure = &$this->info["valori"]["eforms2"]["GR-Procedure"]["integration_values"]; |
|
// Oggetto della gara |
|
$procedure["BT-21-Procedure"] = ["forced" => true, "value" => $gara["oggetto"]]; |
|
if(isset($gara["prezzoRiferimento"])) { |
|
// Valore della gara |
|
$procedure["BT-27-Procedure"] = [ |
|
"forced" => true, |
|
"value" => [ |
|
"value" => round($gara["prezzoRiferimento"], 2), |
|
"type" => "EUR", |
|
], |
|
]; |
|
} |
|
|
|
if (!empty($gara["CPV_CODES"])) { |
|
// CPV |
|
$procedure["BT-26(m)-Procedure"] = ["forced" => true, "value" => "cpv"]; |
|
$procedure["BT-262-Procedure"] = ["forced" => true, "value" => $gara["CPV_CODES"][0]]; |
|
} |
|
if (isset($this->suggestions["LOT"])) { |
|
if($this->info["lotto_riferimento"] > 0) { |
|
$codice_lotto = $this->info["lotto_riferimento"]; |
|
$this->suggestions["LOT"] = array_filter($this->suggestions["LOT"], function ($value) use ($codice_lotto) { |
|
return $value["codice"] == $codice_lotto; |
|
}); |
|
$this->suggestions["LOT"] = array_values($this->suggestions["LOT"]); |
|
} |
|
} |
|
$codiceAppalto = $this->suggestions["GENERAL"]["codiceAppalto"]; |
|
if (!empty($this->npa->fascicolo["revisione_fascicolo"])) { |
|
$codiceAppalto .= "_v{$this->npa->fascicolo['revisione_fascicolo']}"; |
|
} |
|
|
|
$procedure["BT-22-Procedure"] = ["forced" => true, "value" => $codiceAppalto]; |
|
|
|
|
|
|
|
// Tipologia della gara |
|
$tipologia_gara = $gara["tipologia"] ?? null; |
|
if ($tipologia_gara) { |
|
// Passiamo la tipologia della gara anche ai lotti |
|
if (isset($this->suggestions["LOT"])) { |
|
foreach ($this->suggestions["LOT"] as $index => $lot) { |
|
$this->suggestions["LOT"][$index]["tipologia"] = $tipologia_gara; |
|
} |
|
} |
|
// Popoliamo il campo |
|
$procedure["BT-23-Procedure"] = [ |
|
"forced" => true, |
|
"value" => $tipologia_gara, |
|
]; |
|
} |
|
} |
|
|
|
// Importazione lotti |
|
if (isset($this->suggestions["LOT"])) { |
|
|
|
if ($this->enable_forced_suggestions) { |
|
// Forziamo il numero di ripetizione dei lotti |
|
$this->info["valori"]["settings"]["reps"]["GR-Lot"] = count($this->suggestions["LOT"]); |
|
// Impediamo all'utente di modificarlo |
|
$this->info["valori"]["settings"]["reps_locked"]["GR-Lot"] = true; |
|
// Forziamo il numero di ripetizione dei gruppi di lotti a 0 |
|
$this->info["valori"]["settings"]["reps"]["GR-LotsGroup"] = 0; |
|
// Impediamo all'utente di modificarlo |
|
$this->info["valori"]["settings"]["reps_locked"]["GR-LotsGroup"] = true; |
|
} |
|
|
|
// Autopopolazione dei lotti |
|
foreach ($this->suggestions["LOT"] as $index => $lot) { |
|
// Puntatore ai valori di integrazione |
|
$lot_integration = &$this->info["valori"]["eforms2"]["GR-Lot"]["integration_values"][$index]; |
|
|
|
// Se questo lotto è vuoto creiamo un valore dummy per popolarlo forzatamente |
|
$empty = (empty($this->info["valori"]["eforms2"]["GR-Lot"]["values"][$index])); |
|
if ($empty) { |
|
$this->info["valori"]["eforms2"]["GR-Lot"]["values"][$index] = []; |
|
} |
|
$lotReference = &$this->info["valori"]["eforms2"]["GR-Lot"]["values"][$index]; |
|
|
|
|
|
|
|
if (!empty($lot["CRITERI"])) { |
|
|
|
$this->appendIntegrationHelper( |
|
$this->suggestions["MODULO"], |
|
"criteri", |
|
$lot["CRITERI"], |
|
__guue("Criteri per il lotto ") . "\"{$lot['oggetto']}\"", |
|
"GR-Lot", |
|
$index, |
|
"floating" |
|
); |
|
} |
|
if (!empty($this->suggestions["GENERAL"]["round"])) { |
|
$this->appendIntegrationHelper( |
|
$this->suggestions["MODULO"], |
|
"round_scadenze", |
|
$this->suggestions["GENERAL"]["round"], |
|
__guue("Riepilogo delle scadenze"), |
|
"GR-Lot", |
|
$index, |
|
"GR-Lot-PlannedDuration", |
|
true, |
|
); |
|
} |
|
|
|
if ($hasResults) { |
|
|
|
if (!empty($lot["VINCITORI"])) { |
|
|
|
$this->appendIntegrationHelper( |
|
$this->suggestions["MODULO"], |
|
"vincitori", |
|
$lot, |
|
__guue("Aggiudicatari della gara"), |
|
"GR-Result", |
|
0, |
|
"floating", |
|
true |
|
); |
|
} |
|
} |
|
// Identificativo |
|
$lotIdentifier = "LOT-" . str_pad($lot["numero"], 4, "0", STR_PAD_LEFT); |
|
//$lotIdentifierLocal = "LOT-" . str_pad($index+1, 4, "0", STR_PAD_LEFT); |
|
$lot_integration["BT-137-Lot"] = ["forced" => true, "value" => $lotIdentifier]; |
|
$lotReference["BT-137-Lot"] = $lotIdentifier; |
|
// Titolo e descrizione |
|
$lot_integration["BT-21-Lot"] = ["forced" => true, "value" => $lot["oggetto"]]; |
|
$lot_integration["BT-22-Lot"] = ["forced" => true, "value" => "$codiceAppalto/$lotIdentifier"]; |
|
|
|
$lot_integration["BT-24-Lot"] = ["forced" => true, "value" => $lot["descrizione"]]; |
|
// CPV |
|
$lot_integration["BT-26(m)-Lot"] = ["forced" => true, "value" => "cpv"]; |
|
$lot_integration["BT-262-Lot"] = ["forced" => true, "value" => $lot["cpv"]]; |
|
// Italia ? |
|
$lot_integration["BT-5141-Lot"] = ["forced" => false, "value" => "ITA"]; |
|
// URL Documenti |
|
$lot_integration["BT-15-Lot"] = ["forced" => false, "value" => $this->suggestions["PUBLIC_URL"]]; |
|
$lot_integration["OPT-301-Lot-AddInfo"] = ["forced" => false, "value" => "ORG-0001"]; |
|
// Tipologia |
|
$tipologia_gara = $lot["tipologia"] ?? null; |
|
|
|
if ($tipologia_gara) { |
|
$lot_integration["BT-23-Lot"] = [ |
|
"forced" => false, |
|
"value" => $tipologia_gara, |
|
]; |
|
} |
|
// Importo |
|
$lot_integration["BT-27-Lot"] = |
|
[ |
|
"forced" => false, |
|
"value" => [ |
|
"value" => round($lot["importoBase"] + $lot["importoManodopera"] + $lot["oneriNoRibasso"] + $lot["importoOpzioni"], 2), |
|
"type" => "EUR", |
|
], |
|
]; |
|
|
|
/*// Importazione risultati relativi ai lotti |
|
if ($hasResults) { |
|
$result_integration = &$this->info["valori"]["eforms2"]["GR-Result"]["integration_values"]["GR-LotResult-Section"]["GR-LotResult"][$index]; |
|
|
|
// Se questo risultato è vuoto creiamo un valore dummy per popolarlo forzatamente |
|
$empty = (empty($this->info["valori"]["eforms2"]["GR-Result"]["values"]["GR-LotResult-Section"]["GR-LotResult"][$index])); |
|
if ($empty) { |
|
$this->info["valori"]["eforms2"]["GR-Result"]["values"]["GR-LotResult-Section"]["GR-LotResult"][$index] = []; |
|
} |
|
|
|
// Identificativo |
|
$result_integration["OPT-322-LotResult"] = ["forced" => true, "value" => "RES-" . str_pad($index + 1, 4, "0", STR_PAD_LEFT)]; |
|
// Identificativo del lotto |
|
$result_integration["BT-13713-LotResult"] = ["forced" => true, "value" => "LOT-" . str_pad($index + 1, 4, "0", STR_PAD_LEFT)]; |
|
|
|
// Se c'è almeno un vincitore |
|
if (!empty($lot["VINCITORI"])) { |
|
$result_integration["BT-142-LotResult"] = ["forced" => true, "value" => "selec-w"]; |
|
} |
|
}*/ |
|
} |
|
} elseif($this->info["modulo"] == "albo_fornitori") { |
|
$lot_integration = &$this->info["valori"]["eforms2"]["GR-Lot"]["integration_values"][0]; |
|
$lot_integration["BT-137-Lot"] = ["forced" => true, "value" => "LOT-0001"]; |
|
} |
|
} |
|
|
|
public function loadSuggestions() |
|
{ |
|
|
|
|
|
if (empty($this->suggestions)) { |
|
|
|
$suggestions = []; |
|
|
|
if (!empty($this->info["modulo"]) && !empty($this->info["codice_elemento"])) { |
|
global $beRoot; |
|
$path = self::moduliCollegati()[$this->info["modulo"]] ?? false; |
|
if ($path) { |
|
$path = $beRoot . $path; |
|
} |
|
|
|
if (file_exists($path)) { |
|
// Wrappo in una funzione perchè PHP non capisce il concetto di scope |
|
// delle variabili |
|
$callIntegration = function ($path) use (&$suggestions) { |
|
$contents = require($path); |
|
if (is_array($contents)) { |
|
$suggestions += $contents; |
|
} |
|
}; |
|
$callIntegration($path); |
|
} |
|
} |
|
if (empty($this->info["codice"])) { |
|
if (!empty($suggestions["GENERAL"]["codice_ente"])) { |
|
$this->info["codice_ente"] = $suggestions["GENERAL"]["codice_ente"]; |
|
} |
|
if (!empty($suggestions["__titolo"])) { |
|
$this->info["titolo"] = $suggestions["__titolo"]; |
|
} |
|
} |
|
if (!empty($suggestions["PARTECIPANTI"])) { |
|
foreach ($suggestions["PARTECIPANTI"] as $index => $partecipante) { |
|
if (($partecipante["codice_operatore"] ?? 0) > 0) { |
|
$operatore = oeManager::getOE($partecipante["codice_operatore"]); |
|
if ($operatore) { |
|
$suggestions["PARTECIPANTI"][$index] = $partecipante + $operatore; |
|
} |
|
} |
|
} |
|
} |
|
$codice_ente = (!empty($this->info["codice_ente"])) ? $this->info["codice_ente"] : $_SESSION["ente"]->codice; |
|
$ente = $suggestions["STAZIONEAPPALTANTE"] ?? (ente::getInfoFromID($codice_ente)[0] ?? null); |
|
if (!empty($ente) && is_array($ente)) { |
|
$suggestions["CONTRACTING_BODY"]["OFFICIALNAME"] = $ente["denominazione"]; |
|
$suggestions["CONTRACTING_BODY"]["ADDRESS"] = $ente["indirizzo"]; |
|
$suggestions["CONTRACTING_BODY"]["TOWN"] = $ente["citta"]; |
|
$suggestions["CONTRACTING_BODY"]["POSTAL_CODE"] = $ente["cap"]; |
|
$suggestions["CONTRACTING_BODY"]["COUNTRY"] = "IT"; |
|
$suggestions["CONTRACTING_BODY"]["PHONE"] = $ente["telefono"]; |
|
$suggestions["CONTRACTING_BODY"]["FAX"] = $ente["fax"]; |
|
$suggestions["CONTRACTING_BODY"]["E_MAIL"] = $ente["pec"]; |
|
$suggestions["CONTRACTING_BODY"]["URL_GENERAL"] = $ente["url"]; |
|
$suggestions["CONTRACTING_BODY"]["IDENTIFIER_NUM"] = $ente["cf"]; |
|
$suggestions["CONTRACTING_BODY"]["URL_BUYER"] = "https://" . $_SESSION["ente"]->getInfo()["dominio"]; |
|
} |
|
$this->suggestions = $suggestions; |
|
} |
|
} |
|
}
|
|
|