This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Создает блок для с привязкой к плану по $plan_id и $position_number для вставки в xml | |
*/ | |
use Integration\ZGR\Helper\PlanParser; | |
use Integration\ZGR\Model\ZgrExternalPlanItems; | |
use Integration\ZGR\Model\ZgrExternalPlans; | |
$plan_id = 260874; | |
$position_number = 111; | |
$zgr_external_plan = getExternalPlan($plan_id); | |
$zgr_external_plan_item = ZgrExternalPlanItems::model()->find([ | |
'parent_id' => $zgr_external_plan->id, | |
'ordinal_number' => $position_number | |
]); | |
printLotPlanInfoExternal($zgr_external_plan, $zgr_external_plan_item); | |
function getExternalPlan($plan_id) | |
{ | |
$plan_parser = new PlanParser(); | |
$plan_parser->reloadPlan($plan_id); | |
$zgr_external_plan = ZgrExternalPlans::model()->find(['plan_id' => $plan_id]); | |
if (null === $zgr_external_plan) { | |
var_dump($plan_parser->getErrors()); | |
exit; | |
} | |
return $zgr_external_plan; | |
} | |
function printLotPlanInfoExternal(ZgrExternalPlans $plan, ZgrExternalPlanItems $position) { | |
$xml = <<<XML | |
<t:lotPlanInfo> | |
<t:planRegistrationNumber>{$plan->registration_number}</t:planRegistrationNumber> | |
<t:planGuid>{$plan->data_guid}</t:planGuid> | |
<t:positionNumber>{$position->ordinal_number}</t:positionNumber> | |
<t:lotPlanPosition>COMMODITY</t:lotPlanPosition> | |
<t:positionGuid>{$position->guid}</t:positionGuid> | |
</t:lotPlanInfo> | |
XML; | |
echo '<pre>'.htmlspecialchars($xml).'</pre>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Заготовка | |
*/ | |
$string = file_get_contents('oos.xml'); | |
$string = preg_replace('~(</?)[^>:=\s]+:~', '$1', $string); | |
$xml = new \SimpleXMLElement($string); | |
$list = $xml->body->item->purchaseNoticeData->lots->lot; | |
if (!$list) { | |
echo 'Другой формат xml с ООС'; | |
die(); | |
} | |
$oos_guids = []; | |
foreach ($list as $lot) { | |
$oos_guids[] = (string)$lot->guid; | |
} | |
$string = file_get_contents('our.xml'); | |
$string = preg_replace('~(</?)[^>:=\s]+:~', '$1', $string); | |
$xml = new \SimpleXMLElement($string); | |
$list = $xml->body->item->purchaseProtocolData->lotApplicationsList->protocolLotApplications; | |
if (!$list) { | |
echo 'Другой формат xml у нас'; | |
die(); | |
} | |
$our_guids = []; | |
foreach ($list as $lot) { | |
$our_guids[] = (string)$lot->lot->guid; | |
} | |
if (count($oos_guids) != count($our_guids)) { | |
echo 'Не сошлось количество гуидов'; | |
die(); | |
} | |
$string = file_get_contents('our.xml'); | |
echo htmlspecialchars(str_replace($our_guids, $oos_guids, $string)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment