gestione gare pubbliche
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.
 
 
 
 
 

457 righe
20 KiB

<?php
// Classe per la gestione del Clone delle gare
Class CloneGara {
private Gara $source;
private Gara $target;
private Array $settings;
private Array $matchLotti;
private Array $matchCriteri;
private Array $matchBuste;
private myPDO $db;
public Array $errori;
public function __construct(Gara $source, Gara $target)
{
global $pdo;
$this->source = $source;
$this->target = $target;
$this->db = $pdo;
$this->matchLotti = [];
$this->matchCriteri = [];
$this->matchBuste = [];
}
public static function clonableInfo(Gara $source) : Array {
$domande = [];
if (!empty($source->getManagerIncarichi()->getIncaricati())) {
$domande["incarichi"]="Incarichi";
}
$rounds = $source->getRounds();
if (!empty($rounds)) {
$source->round = reset($rounds);
if (!empty($source->getRisposteElaborazione())) {
$domande["elaborazione"] = "Risposte elaborazione";
}
if (!empty($source->getManagerDGUE()->getRequestedCriteria())) {
$domande["dgue"] = "DGUE";
}
if ($source->info["modalita"] == "telematica") {
if (!empty($source->getRichieste())) {
$domande["buste"] = "Configurazione Buste";
}
}
if (!empty($source->getLotti())) {
foreach($source->getLotti() AS $lotto) {
$source->setLotto($lotto["codice"]);
if (!empty($source->getCriteri())) {
$domande["criteri"] = "Criteri di valutazione";
}
if (!empty($source->getSOA($lotto["codice"]))) {
$domande["soa"] = "Qualificazione lavori";
}
if (!empty($source->getProgettazione($lotto["codice"]))) {
$domande["progettazione"] = "Qualificazione progettazione";
}
if ($source->info["modalita"] != "telematica") {
if (!empty($source->getPartecipanti())) {
$domande["partecipanti"] = "Partecipanti";
}
if (!empty($source->getAggiudicatari())) {
$domande["aggiudicatari"] = "Aggiudicatari";
}
} else {
if (!empty($source->getInvitati())) {
$domande["invitati"] = "Invitati";
}
}
$source->lotto = null;
}
}
}
$domande = array_unique($domande);
return $domande;
}
private function initTargetFase() {
if (empty($this->target->getRounds())) {
$rounds = $this->source->getRounds();
if (!empty($rounds)) {
$round = reset($rounds);
$this->target->inizializzaFase($round["id"],$this->source->getProcedura()["fasi"][$round["id"]]);
$rounds = $this->target->getRounds();
$this->target->round = reset($rounds);
return true;
}
}
}
public function clone() : Bool {
$clonableInfo = ["lotti"=>"Lotti"];
$clonableInfo += self::clonableInfo($this->source);
$this->settings = $this->target->getExtraInfo()["gara"]["copyInfo"] ?? null;
if (!empty($clonableInfo)) {
foreach($clonableInfo AS $info => $label) {
if ($info == "lotti" || (isset($this->settings[$info]) && $this->settings[$info] == "S")) {
if (method_exists("CloneGara",$info)) {
if (!$this->{$info}()) {
$this->errori[] = $label;
}
}
}
}
}
$quickPanel = $this->source->getExtraInfo()["gara"]["quickPanel"] ?? null;
if (!empty($quickPanel)) {
$this->target->saveExtraInfo("quickPanel",$quickPanel);
}
return true;
}
private function setMatchLotti() {
$sourceLotti = $this->source->getLotti();
if (!empty($sourceLotti)) {
$targetLotti = $this->target->getLotti();
if (!empty($targetLotti)) {
foreach($sourceLotti AS $sLotto) {
foreach($targetLotti AS $tLotto) {
if ($sLotto["numero"] == $tLotto["numero"]) {
$this->matchLotti[$sLotto["codice"]] = $tLotto["codice"];
break;
}
}
}
}
}
}
private function incarichi() : Bool {
if (empty($this->target->getManagerIncarichi()->getIncaricati())) {
$incarichi = $this->source->getManagerIncarichi()->getIncaricati();
if (!empty($incarichi)) {
$targetManager = $this->target->getManagerIncarichi();
foreach($incarichi AS $incarico) {
$incarico["codice"] = null;
$targetManager->saveIncaricato($incarico);
}
}
}
return true;
}
private function lotti() : Bool {
if (empty($this->target->getLotti())) {
$lotti = $this->source->getLotti();
if (!empty($lotti)) {
foreach($lotti AS $lotto) {
unset($lotto["codice"]);
$lotto["cig"] = "";
$lotto["extraInfo"] = [];
unset($lotto["numero"]);
if (empty($this->settings["aggiudicatari"])) {
unset($lotto["importoAggiudicazione"]);
}
$this->target->saveLotto($lotto);
}
}
}
$this->setMatchLotti();
$this->initTargetFase();
return true;
}
private function elaborazione() : Bool {
if (empty($this->target->getExtraInfo()["round"]["elaborazione"])) {
$this->target->saveExtraInfo("elaborazione",$this->source->getExtraInfo()["round"]["elaborazione"],"round");
$this->target->validaElaborazione();
}
return true;
}
private function dgue() : Bool {
if (!empty($this->target->round["id"]) && empty($this->target->getManagerDGUE()->getRequestedCriteria())) {
$criteria = $this->source->getManagerDGUE()->getRequestedCriteria();
if (!empty($criteria)) {
$criteria = array_column($criteria,"codice");
$manager = $this->target->getManagerDGUE();
$manager->saveRequest($criteria);
}
}
return true;
}
private function soa() : Bool {
$sourceLotti = $this->source->getLotti();
foreach($sourceLotti AS $sLotto) {
$sLotto = $sLotto["codice"];
$tLotto = $this->matchLotti[$sLotto];
$soa = $this->source->getSOA($sLotto);
if (!empty($soa) && empty($this->target->getSOA($tLotto))) {
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = "b_gare_soa";
foreach($soa AS $categoria) {
$categoria["codice_lotto"] = $tLotto;
$categoria["codice"] = null;
$salva->operazione = "INSERT";
$salva->oggetto = $categoria;
$codici[] = $salva->save();
}
$this->db->go("DELETE FROM b_gare_soa WHERE codice_lotto = :lotto AND codice NOT IN (" . implode(",",$codici) . ")",[":lotto"=>$tLotto]);
}
}
return true;
}
private function progettazione() : Bool {
$sourceLotti = $this->source->getLotti();
foreach($sourceLotti AS $sLotto) {
$sLotto = $sLotto["codice"];
$tLotto = $this->matchLotti[$sLotto];
$soa = $this->source->getSOA($sLotto);
if (!empty($soa) && empty($this->target->getSOA($tLotto))) {
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = "b_gare_progettazione";
foreach($soa AS $categoria) {
$categoria["codice_lotto"] = $tLotto;
$categoria["codice"] = null;
$salva->operazione = "INSERT";
$salva->oggetto = $categoria;
$codici[] = $salva->save();
}
$this->db->go("DELETE FROM b_gare_progettazione WHERE codice_lotto = :lotto AND codice NOT IN (" . implode(",",$codici) . ")",[":lotto"=>$tLotto]);
}
}
return true;
}
private function copyCriterio(Array $criterio) : ?Int {
$newCode = $this->matchCriteri[$criterio["codice"]] ?? null;
$new = $criterio;
$sub = false;
$subCriteri = $this->source->getSubCriteri($criterio["codice"]);
$lotti = $this->source->getLottiFromCriterio($criterio["codice"]);
if (empty($newCode)) {
$new["codice"] = "i_0";
if (!empty($subCriteri)) {
$new["auto"] = null;
}
if (!empty($criterio["codice_padre"])) {
$sub = true;
$criterio["codice_padre"] = $this->matchCriteri[$criterio["codice_padre"]] ?? null;
}
$newCode = $this->target->saveCriterio($new);
if (!empty($newCode)) {
$this->matchCriteri[$criterio["codice"]] = $newCode;
}
}
if (!empty($newCode)) {
if (!empty($subCriteri)) {
foreach($subCriteri AS $sub) {
if (empty($this->matchCriteri[$sub["codice"]])) {
$this->copyCriterio($sub);
}
}
} else {
$ep = $this->source->getElencoPrezzi($criterio["codice"]);
if (!empty($ep)) {
$newEP = [];
$count = 0;
foreach($ep AS $articolo) {
$count++;
unset($articolo["codice"]);
$newEP["i_{$count}"] = $articolo;
}
$this->target->saveVociEP($newCode,$newEP);
}
$form = $this->source->getFormCriterio($criterio["codice"]);
if (!empty($form)) {
$salva_form = new salva();
$salva_form->debug = false;
$salva_form->nome_tabella = "b_gare_form";
foreach($form AS $input) {
unset($input["codice"]);
$input["codice_criterio"] = $newCode;
$salva_form->operazione = "INSERT";
$salva_form->oggetto = $input;
$salva_form->save();
}
}
}
if (!$sub) {
if (!empty($lotti)) {
$newLotti = [];
foreach($lotti AS $lotto) {
if (!empty($lotto)) {
$newLotti[] = $this->matchLotti[$lotto];
} else {
$newLotti = 0;
break;
}
}
$this->target->bindCriterio($newCode,$newLotti);
}
}
}
return $newCode;
}
private function criteri() : Bool {
$sourceLotti = $this->source->getLotti();
if (!empty($sourceLotti)) {
$targetLotti = $this->target->getLotti();
if (!empty($targetLotti)) {
foreach($sourceLotti AS $sLotto) {
$sLotto = $sLotto["codice"];
$tLotto = $this->matchLotti[$sLotto] ?? null;
$this->source->setLotto($sLotto);
$this->target->setLotto($tLotto);
$macro = $this->source->getMacroCriteri();
if (!empty($macro) && empty($this->target->getCriteri())) {
foreach($macro AS $mCriterio) {
$this->copyCriterio($mCriterio);
}
}
$this->source->lotto = $this->target->lotto = null;
}
}
}
return true;
}
private function buste() : Bool {
$sourceLotti = $this->source->getLotti();
if (!empty($sourceLotti)) {
$targetLotti = $this->target->getLotti();
if (!empty($targetLotti)) {
foreach($sourceLotti AS $sLotto) {
$sLotto = $sLotto["codice"];
$tLotto = $this->matchLotti[$sLotto] ?? null;
$this->source->setLotto($sLotto);
$this->target->setLotto($tLotto);
$richieste = $this->source->getRichieste();
if (!empty($richieste)) {
foreach($richieste AS $richiesta) {
if (empty($this->matchBuste[$richiesta["codice"]]) && $richiesta["locked"] == "N") {
$lotti = $this->source->getLottiFromRichiesta($richiesta["codice"]);
$oldCodice = $richiesta["codice"];
unset($richiesta["codice"]);
$newBusta = $this->target->saveRichiesta($richiesta);
if (!empty($newBusta)) {
$this->matchBuste[$oldCodice] = $newBusta;
$newLotti = [];
foreach($lotti AS $lotto) {
if (!empty($lotto)) {
$newLotti[] = $this->matchLotti[$lotto];
} else {
$newLotti = 0;
break;
}
}
$this->target->bindRichiesta($newBusta,$newLotti);
}
}
}
}
$this->source->lotto = $this->target->lotto = null;
}
}
}
return true;
}
private function invitati() : Bool {
if (empty($this->target->getInvitati())) {
$invitati = $this->source->getInvitati();
if (!empty($invitati)) {
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = "r_inviti_gare";
foreach($invitati AS $invitato) {
unset($invitato["id"]);
$invitato["codice_round"] = $this->target->round["codice"];
$invitato["codice_lotto"] = ($invitato["codice_lotto"] > 0) ? $this->matchLotti[$invitato["codice_lotto"]] : 0;
$salva->operazione = "INSERT";
$salva->oggetto = $invitato;
$salva->save();
}
}
}
return true;
}
private function partecipanti(Bool $onlyAggiudicatari = false) : Bool {
$sourceLotti = $this->source->getLotti();
if (!empty($sourceLotti)) {
$targetLotti = $this->target->getLotti();
if (!empty($targetLotti)) {
foreach($sourceLotti AS $sLotto) {
$sLotto = $sLotto["codice"];
$tLotto = $this->matchLotti[$sLotto] ?? null;
$this->source->setLotto($sLotto);
$this->target->setLotto($tLotto);
$partecipanti = $this->source->getPartecipanti();
$aggiudicato = false;
if (!empty($partecipanti) && empty($this->target->getPartecipanti())) {
foreach($partecipanti AS $partecipante) {
if (!$onlyAggiudicatari || $partecipante["aggiudicatario"] == "S") {
$oldCode = $partecipante["codice"];
if (!isset($this->settings["aggiudicatari"]) || $this->settings["aggiudicatari"] == "N") {
$partecipante["aggiudicatario"] = "N";
}
if ($partecipante["aggiudicatario"] == "S") {
$aggiudicato = true;
}
unset($partecipante["codice"]);
$partecipante["codice_round"] = $this->target->round["codice"];
$partecipante["codice_lotto"] = $tLotto;
$raggruppamento = $this->source->getRaggruppamento($oldCode);
if (!empty($raggruppamento)) {
$partecipante["raggruppamento"] = [];
foreach($raggruppamento AS $membro) {
unset($membro["codice"]);
$partecipante["raggruppamento"][] = $membro;
}
}
$avvalimento = $this->source->getAvvalimento($oldCode);
if (!empty($avvalimento)) {
$partecipante["avvalimento"] = [];
foreach($avvalimento AS $membro) {
unset($membro["codice"]);
$partecipante["avvalimento"][] = $membro;
}
}
$newCode = $this->target->savePartecipante($partecipante);
}
}
}
$this->target->updateStatoLotto($aggiudicato ? 30 : 21, true);
$this->source->lotto = $this->target->lotto = null;
}
}
}
return true;
}
private function aggiudicatari() : Bool {
$this->partecipanti(true);
return true;
}
}
?>