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.
323 righe
17 KiB
323 righe
17 KiB
<?php |
|
Class DGUEModel extends DGUEModelBase { |
|
|
|
private $ecertis; |
|
|
|
public function generateUUID() { |
|
return true; |
|
} |
|
|
|
public static function legislation() { |
|
return "c753a2c5-59e6-4970-b6eb-27224e96bf76"; |
|
} |
|
|
|
private function getEcertisInfo(String $uuid,Bool $returnAllResult = true, Bool $searchParent = true) { |
|
if (empty($this->ecertis)) { |
|
$this->ecertis = jsonToArray(__DIR__ . DIRECTORY_SEPARATOR . "ecertis.json"); |
|
} |
|
$founds = []; |
|
if (!empty($this->ecertis)) { |
|
foreach($this->ecertis AS $criterio) { |
|
if (($criterio["id"] === $uuid && !$searchParent) || ($criterio["parentId"] === $uuid && $searchParent)) { |
|
$founds[] = $criterio; |
|
} |
|
} |
|
} else { |
|
Throw new Exception("Configurazione ecertis Mancante"); |
|
} |
|
if (!empty($founds)) { |
|
if (!$returnAllResult) { |
|
if (count($founds) > 1) { |
|
usort($founds,function($a,$b) { |
|
if (isset($a["versionId"]) && isset($b["versionId"])) { |
|
return $a["versionId"] < $b["versionId"]; |
|
} else { |
|
return true; |
|
} |
|
}); |
|
} |
|
return reset($founds); |
|
} else { |
|
return $founds; |
|
} |
|
} |
|
} |
|
|
|
private static function matchGroupPropertiesWithInputs(Array $properties, Array $inputs) : Bool { |
|
$available = array_column($properties,"valueDataTypeCode"); |
|
$selected = []; |
|
foreach($inputs AS $input) { |
|
$selected[] = self::getInputResponseType($input); |
|
} |
|
$matches = array_intersect($available,$selected); |
|
return (count($matches) > 1 || (!empty($matches) && count($selected) === 1)); |
|
} |
|
|
|
private static function getInputResponseType(Array $input) : String { |
|
$responseType = reset($input["index"]); |
|
$responseType = explode(":",$responseType); |
|
$responseType = strtoupper(end($responseType)); |
|
if ($responseType == "EVIDENCE") { |
|
$responseType .= "_IDENTIFIER"; |
|
} |
|
return $responseType; |
|
} |
|
|
|
private static function checkEcertisGroup(Array $group,Array $inputs,Array $chain = [],Bool $appendChain = false) : Array { |
|
if ($appendChain) { |
|
$chain[] = $group["id"]; |
|
} |
|
if (!empty($group["properties"])) { |
|
$check = self::matchGroupPropertiesWithInputs($group["properties"],$inputs); |
|
if ($check) { |
|
return $chain; |
|
} |
|
} |
|
if (!empty($group["propertiesGroups"])) { |
|
foreach($group["propertiesGroups"] AS $sub) { |
|
$tmp = self::checkEcertisGroup($sub,$inputs,$chain,true); |
|
if (!empty($tmp)) { |
|
return $tmp; |
|
} |
|
} |
|
} |
|
if (!empty($group["subsidiaryPropertiesGroups"])) { |
|
foreach($group["subsidiaryPropertiesGroups"] AS $sub) { |
|
$tmp = self::checkEcertisGroup($sub,$inputs,$chain, true); |
|
if (!empty($tmp)) { |
|
return $tmp; |
|
} |
|
} |
|
} |
|
return []; |
|
} |
|
|
|
private function findPropertyChain(Array $ecertis, Array $inputs) : Array { |
|
foreach($ecertis AS $info) { |
|
$check = self::checkEcertisGroup($info,$inputs); |
|
if (!empty($check)) { |
|
return $check; |
|
} |
|
} |
|
return []; |
|
} |
|
|
|
public function getRequestArray(Array $criteria) : Array { |
|
$dgue = array(); |
|
$dgue["@xmlns"] = "urn:oasis:names:specification:ubl:schema:xsd:QualificationApplicationRequest-2"; |
|
$dgue["@xmlns:cac"]="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" ; |
|
$dgue["@xmlns:cbc"]="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"; |
|
// $dgue["@xmlns:xsi"]="http://www.w3.org/2001/XMLSchema-instance"; |
|
// $dgue["@xsi:schemaLocation"]="http://www.w3.org/2001/XMLSchema-instance"; |
|
$dgue["cbc:UBLVersionID"]["$"] = "2.2"; |
|
$dgue["cbc:UBLVersionID"]["@schemeAgencyID"] = "OASIS-UBL-TC"; |
|
$dgue["cbc:ProfileID"]["$"] = "41"; |
|
$dgue["cbc:ProfileID"]["@schemeAgencyID"] = "CEN-BII"; |
|
$dgue["cbc:ProfileID"]["@schemeVersionID"] = "2.1.1"; |
|
$dgue["cbc:ProfileExecutionID"]["$"] = "ESPD-EDMv2.1.1-EXTENDED"; |
|
$dgue["cbc:ProfileExecutionID"]["@SchemeAgencyID"] = "EU-COM-GROW"; |
|
$dgue["cbc:CustomizationID"]["$"] = "urn:www.cenbii.eu:transaction:biitrdm070:ver3.0"; |
|
$dgue["cbc:CustomizationID"]["@SchemeAgencyID"] = "CEN-BII"; |
|
$dgue["cbc:CustomizationID"]["@schemeVersionID"] = "2.1.1"; |
|
|
|
$dgue["cbc:ID"]["$"] = hash("sha256","{$this->dgue->modulo}{$this->dgue->oggetto}"); |
|
$dgue["cbc:ID"]["@schemeAgencyID"] = $this->dgue->codice_fiscale_ente ?? $_SESSION["ente"]->getInfo()["cf"]; |
|
$dgue["cbc:UUID"]["$"] = hash("sha256","{$this->dgue->modulo}{$this->dgue->oggetto}"); |
|
$dgue["cbc:UUID"]["@schemeAgencyID"] = $this->dgue->codice_fiscale_ente ?? $_SESSION["ente"]->getInfo()["cf"]; |
|
$dgue["cbc:CopyIndicator"] = "false"; |
|
$dgue["cbc:ContractFolderID"]["$"] = $this->dgue->id_appalto; |
|
$dgue["cbc:UUID"]["@schemeAgencyID"] = $this->dgue->codice_fiscale_ente ?? $_SESSION["ente"]->getInfo()["cf"]; |
|
$dgue["cbc:IssueDate"] = date('Y-m-d'); |
|
$dgue["cbc:IssueTime"] = date('H:i:s'); |
|
$dgue["cbc:VersionID"] = "1.0"; |
|
$dgue["cbc:QualificationApplicationTypeCode"]["$"] = "EXTENDED"; |
|
$dgue["cbc:QualificationApplicationTypeCode"]["@listID"] = "QualificationApplicationType"; |
|
$dgue["cbc:QualificationApplicationTypeCode"]["@listAgencyName"] = "EU-COM-GROW"; |
|
$dgue["cbc:QualificationApplicationTypeCode"]["@listVersionID"] = "2.1.1"; |
|
|
|
|
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PartyIdentification"]["cbc:ID"] = $this->dgue->codice_fiscale_ente; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cbc:WebsiteURI"] = "https://{$_SESSION["ente"]->getInfo()["dominio"]}"; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cbc:EndPointID"] = "https://{$_SESSION["ente"]->getInfo()["dominio"]}"; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PartyName"]["cbc:Name"] = $this->dgue->ente; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PostalAddress"]["cac:Country"]["cbc:IdentificationCode"]["$"] = "IT"; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PostalAddress"]["cac:Country"]["cbc:IdentificationCode"]["@listID"] = "CountryCodeIdentifier"; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PostalAddress"]["cac:Country"]["cbc:IdentificationCode"]["@listAgencyName"] = "ISO"; |
|
$dgue["cac:ContractingParty"]["cac:Party"]["cac:PostalAddress"]["cac:Country"]["cbc:IdentificationCode"]["@listVersionID"] = "1.0"; |
|
|
|
$dgue["cac:ProcurementProject"]["cac:ProcurementProject"]["cbc:Name"] = strip_tags($this->dgue->oggetto); |
|
$dgue["cac:ProcurementProject"]["cac:ProcurementProject"]["cbc:Description"] = strip_tags($this->dgue->descrizione); |
|
if (!empty($this->dgue->lotti) && count($this->dgue->lotti) > 1) { |
|
$dgue["cac:ProcurementProject"] = []; |
|
foreach($this->dgue->lotti AS $lotto) { |
|
$dgue["cac:ProcurementProject"][] = ["cbc:ID" => "LOTTO{$lotto["numero"]}"]; |
|
} |
|
} |
|
$dgue["cac:TenderingCriterion"] = array(); |
|
$tmp = []; |
|
$nationals = []; |
|
$i = 0; |
|
$nationalI = null; |
|
foreach($criteria AS $criterio) { |
|
$i++; |
|
if ($criterio["taxa"] == "CRITERION.EXCLUSION.NATIONAL") { |
|
$nationalI = $i; |
|
$tmp[$i] = $criterio; |
|
} else if (strpos($criterio["taxa"],".NATIONAL")) { |
|
$nationals[] = $criterio; |
|
} else { |
|
$tmp[$i] = $criterio; |
|
} |
|
} |
|
$criteria = $tmp; |
|
foreach($criteria AS $i => $criterio) { |
|
$ecertis = $this->getEcertisInfo($criterio["uuid"]); |
|
$definitions = []; |
|
$captions = []; |
|
if ($i !== $nationalI) { |
|
$national = false; |
|
$definitions = [DGUE::getCriteriaTemplateDefinition($criterio["template"])]; |
|
} else { |
|
$national = true; |
|
foreach($nationals AS $n) { |
|
$definitions[$n["codice"]] = DGUE::getCriteriaTemplateDefinition($n["template"]); |
|
$captions[$n["codice"]] = $n["nome"]; |
|
} |
|
} |
|
$uuid = $criterio["uuid"]; |
|
$subCriterion = []; |
|
if (!empty($ecertis)) { |
|
$uuid = $ecertis[0]["parentId"]; |
|
$subCriterion["cbc:ID"]["@schemeID"]="CriteriaTaxonomy"; |
|
$subCriterion["cbc:ID"]["@schemeAgencyID"]="EU-COM-GROW"; |
|
$subCriterion["cbc:ID"]["$"] = $criterio["uuid"]; |
|
} |
|
$criterion = array(); |
|
$criterion["cbc:ID"]["@schemeID"]="CriteriaTaxonomy"; |
|
$criterion["cbc:ID"]["@schemeAgencyID"]="EU-COM-GROW"; |
|
$criterion["cbc:ID"]["$"] = $uuid; |
|
$criterion["cbc:CriterionTypeCode"]["@listID"] = "CriteriaTypeCode"; |
|
$criterion["cbc:CriterionTypeCode"]["@listAgencyID"] = "EU-COM-GROW"; |
|
$criterion["cbc:CriterionTypeCode"]["@listVersionID"] = "2.0.2"; |
|
$criterion["cbc:CriterionTypeCode"]["$"] = $criterio["taxa"]; |
|
$criterion["cbc:Name"] = $criterio["nome"]; |
|
$criterion["cbc:Description"] = strip_tags($criterio["descrizione"]); |
|
$criterion["cac:Legislation"]["cbc:ID"]["$"] = self::legislation(); |
|
$criterion["cac:Legislation"]["cbc:ID"]["@schemeID"] = "CriteriaTaxonomy"; |
|
$criterion["cac:Legislation"]["cbc:ID"]["@schemeAgencyID"] = "EU-COM-GROW"; |
|
$criterion["cac:Legislation"]["cbc:ID"]["@schemeVersionID"] = "2.1.1"; |
|
$criterion["cac:Legislation"]["cbc:Title"] = "D.lgs {$this->dgue->version}"; |
|
$criterion["cac:Legislation"]["@LanguageID"] = "it"; |
|
if (!empty($definitions)) { |
|
foreach($definitions AS $kd => $definition) { |
|
if (!empty($definition) && is_array($definition)) { |
|
foreach($definition AS $group_id => $inputs) { |
|
if ($national) { |
|
$propertiesGroupChain = ["8d79d5f7-dc21-45e9-b188-e02008b854e0","IT-cbb135d8-a0ca-43b1-ba9f-c80e17def684"]; |
|
} else if (!empty($ecertis)) { |
|
$propertiesGroupChain = $this->findPropertyChain($ecertis,$inputs); |
|
} else { |
|
$propertiesGroupChain = []; |
|
} |
|
$properties = $this->getGroupProperties($inputs,$criterio["codice"],$group_id); |
|
if ($national) { |
|
$properties[] = [ |
|
"cbc:TypeCode" => [ |
|
"@listID" => "CriterionElementType", |
|
"@listAgencyID" => "EU-COM-GROW", |
|
"@listVersionID" => "2.1.1", |
|
"$" => "CAPTION" |
|
], |
|
"cbc:Name" => $captions[$kd], |
|
]; |
|
} |
|
$criterionVariableName = "criterion"; |
|
if (!empty($subCriterion)) { |
|
$criterionVariableName = "subCriterion"; |
|
} |
|
if (empty($propertiesGroupChain)) { |
|
$$criterionVariableName["cac:TenderingCriterionPropertyGroup"][] = ["cac:TenderingCriterionProperty"=>$properties]; |
|
} else { |
|
$first = true; |
|
foreach($propertiesGroupChain AS $criterionPropertiesGroupID) { |
|
if ($first) { |
|
$group = [ |
|
"cbc:ID" => [ |
|
"$" => $criterionPropertiesGroupID, |
|
"@schemeID" => "CriteriaTaxonomy", |
|
"@schemeAgencyID" => "EU-COM-GROW", |
|
"@schemeVersionID" => "2.1.1", |
|
] |
|
]; |
|
$lastGroup = &$group; |
|
$first = false; |
|
} else { |
|
self::aggiungiSottoGruppo($lastGroup,$criterionPropertiesGroupID); |
|
$lastGroup = &$lastGroup["cac:SubsidiaryTenderingCriterionPropertyGroup"]; |
|
|
|
} |
|
} |
|
$lastGroup["cac:TenderingCriterionProperty"] = $properties; |
|
$$criterionVariableName["cac:TenderingCriterionPropertyGroup"][] = $group; |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
if (!empty($subCriterion)) { |
|
if ($national) { |
|
$subCriterion["cbc:ID"] = [ |
|
"$" => "41a62578-d8ef-48c7-82e6-16779b32f434", |
|
"@schemeID" => "CriteriaTaxonomy", |
|
]; |
|
} |
|
$criterion["cac:SubTenderingCriterion"] = $subCriterion; |
|
} |
|
$dgue["cac:TenderingCriterion"][] = $criterion; |
|
} |
|
$dgue = array("QualificationApplicationRequest"=>$dgue); |
|
return $dgue; |
|
} |
|
|
|
private function getGroupProperties(Array $inputs,Int $codiceCriterio, String $group_id) { |
|
$properties = []; |
|
foreach($inputs AS $input) { |
|
$responseType = $this->getInputResponseType($input); |
|
$properties[] = [ |
|
"cbc:ID" => [ |
|
"@schemeID" => "CriteriaTaxonomy", |
|
"@schemeAgencyID" => "EU-COM-GROW", |
|
"@schemeVersionID" => "2.1.1", |
|
"$" => $this->dgue->getUUIDMatches($codiceCriterio)[$group_id][$input["id"]] ?? null |
|
], |
|
"cbc:TypeCode" => [ |
|
"@listID" => "CriterionElementType", |
|
"@listAgencyID" => "EU-COM-GROW", |
|
"@listVersionID" => "2.1.1", |
|
"$" => "QUESTION" |
|
], |
|
"cbc:ValueDataTypeCode" => [ |
|
"@listID" => "ResponseDataType", |
|
"@listAgencyID" => "EU-COM-GROW", |
|
"@listVersionID" => "2.1.1", |
|
"$" => $responseType |
|
] |
|
]; |
|
} |
|
return $properties; |
|
} |
|
|
|
private static function aggiungiSottoGruppo(Array &$group,String $id) { |
|
$element = [ |
|
"cbc:ID" => [ |
|
"$" => $id, |
|
"@schemeID" => "CriteriaTaxonomy", |
|
"@schemeAgencyID" => "EU-COM-GROW", |
|
"@schemeVersionID" => "2.1.1", |
|
] |
|
]; |
|
$group["cac:SubsidiaryTenderingCriterionPropertyGroup"] = $element; |
|
return $group; |
|
} |
|
} |