setData((prev) => prev.map((it, i) => {
return index !== i ? it : {
...it, [key]: value
}
}))
const changeDT: ChangeDateTime = (type, value, index) => {
setData((prev) => {
return [
...prev,
[index]: { ...prev[type]: value }
]
})
}
$path = 'http://example.loc/data/sovremennye-torshery.json';
$data = json_decode(file_get_contents($path), true);
$tablePrefix = "configs";
$withPrefix = function (string $key) use ($tablePrefix) {
return "{$tablePrefix}_" . strtolower($key);
};
/* Основа */
$userId = 4;
$user = R::load('users', $userId);
/** @var null|OODBBean|OODBBean[] $config */
$config = R::xdispense($tablePrefix);
$user["ownConfigList"][] = $config;
$config["name"] = "Sovremennye torshery";
$config["description"] = null;
$config["file"] = "sovremennye-torshery";
$config["added"] = "2022-11-07T00:46:15+03:00";
$config["modified"] = "2022-12-14T18:03:32+03:00";
$config["author"] = $user["login"];
/* Модули => metaInfo */
$dataKey = "metaInfo";
$cSiteMetrics = R::xdispense($withPrefix($dataKey));
$cSiteMetrics[$tablePrefix] = $config;
$cSiteMetrics["title"] = $data[$dataKey]["title"];
$cSiteMetrics["description"] = $data[$dataKey]["description"];
$cSiteMetrics["keywords"] = $data[$dataKey]["keywords"];
/* Модули => siteMetrics */
$dataKey = "siteMetrics";
$cMetaInfo = R::xdispense($withPrefix($dataKey));
$cMetaInfo[$tablePrefix] = $config;
$cMetaInfo["head"] = $data[$dataKey]["head"];
$cMetaInfo["footer"] = $data[$dataKey]["footer"];
/* Модули => siteInfo */
$dataKey = "siteInfo";
$cSiteInfo = R::xdispense($withPrefix($dataKey));
$cSiteInfo[$tablePrefix] = $config;
$cSiteInfo["description"] = $data[$dataKey]["description"];
$cSiteInfo["phone"] = json_encode($data[$dataKey]["phone"]);
$cSiteInfo["currencySymbol"] = $data[$dataKey]["currencySymbol"];
/* Модули => preview */
$dataKey = new KeyStruct("preview", [
new KeyStruct("listPreview"),
new KeyStruct("linksToOtherProducts")
]);
// configs
$LPKey = $dataKey->bound[0]->key;
$LTOPKey = $dataKey->bound[1]->key;
$cPreview = R::xdispense($withPrefix($dataKey->getKey()));
$cPreview[$tablePrefix] = $config;
$cPreview["titleForm"] = $data[$dataKey->key]["titleForm"];
$cPreview["titlePreview"] = $data[$dataKey->key]["titlePreview"];
$cPreview["listImage"] = $data[$dataKey->key]["listImage"];
$cPreview["imageRight"] = $data[$dataKey->key]["imageRight"];
$cPreview["backgroundImage"] = $data[$dataKey->key]["backgroundImage"];
// bound tables
foreach ($data[$dataKey->key][$LPKey] as $item) {
$cPreviewLP = R::xdispense($withPrefix($dataKey->getBoundKey(0)));
$cPreview["ownListPreviewList"][] = $cPreviewLP;
$cPreviewLP["text"] = $item["text"];
}
foreach ($data[$dataKey->key][$LTOPKey] as $item) {
$cPreviewLTOP = R::xdispense($withPrefix($dataKey->getBoundKey(1)));
$cPreview["ownLinksToOtherProductsList"][] = $cPreviewLTOP;
$cPreviewLTOP["text"] = $item["text"];
$cPreviewLTOP["link"] = $item["link"];
}
/* Модули => why */
$dataKey = "why";
foreach ($data[$dataKey] as $item) {
$cWhy = R::xdispense($withPrefix($dataKey));
$config["ownWhyList"][] = $cWhy;
$cWhy["text"] = $item["text"];
$cWhy["image"] = $item["image"];
}
/* Модули => catalog */
$dataKey = "catalog";
$cCatalog = R::xdispense($withPrefix($dataKey));
$cCatalog[$tablePrefix] = $config;
$cCatalog["title"] = $data[$dataKey]["title"];
$cCatalog["productsFile"] = $data[$dataKey]["productsFile"];
$cCatalog["filterSticky"] = $data[$dataKey]["filterSticky"];
$cCatalog["loadingModeNewProducts"] = $data[$dataKey]["loadingModeNewProducts"];
/* Модули => discount */
$dataKey = "discount";
$cDiscount = R::xdispense($withPrefix($dataKey));
$cDiscount[$tablePrefix] = $config;
$cDiscount["title"] = $data[$dataKey]["title"];
$cDiscount["subtitle"] = $data[$dataKey]["subtitle"];
$cDiscount["image"] = $data[$dataKey]["image"];
/* Модули => lider */
$dataKey = new KeyStruct("lider", [
new KeyStruct("blocks"),
]);
// configs
$blocksKey = $dataKey->bound[0]->key;
$cLider = R::xdispense($withPrefix($dataKey->getKey()));
$cLider[$tablePrefix] = $config;
$cLider["title"] = $data[$dataKey->key]["title"];
$cLider["subtitle"] = $data[$dataKey->key]["subtitle"];
// bound table
foreach ($data[$dataKey->key][$blocksKey] as $item) {
$cLiderBlock = R::xdispense($withPrefix($dataKey->getBoundKey(0)));
$cLider["ownBlocksList"][] = $cLiderBlock;
$cLiderBlock["image"] = $item["image"];
$cLiderBlock["text"] = $item["text"];
$cLiderBlock["title"] = $item["title"];
}
/* Модули => footer */
$dataKey = "footer";
$cFooter = R::xdispense($withPrefix($dataKey));
$cFooter[$tablePrefix] = $config;
$cFooter["copyright"] = $data[$dataKey]["copyright"];
/* Модули => options */
$baseOption = [
"useCatalogSection",
"manualHTMLStructure",
"orderManualStructure",
"bodyClass"
];
$dataKey = "landOptions";
foreach ($baseOption as $key) {
$value = $data[$dataKey][$key];
$cOptions = R::xdispense($withPrefix("options"));
$config["ownOptionList"][] = $cOptions;
$cOptions["name"] = $key;
$cOptions["value"] = $value;
}
/* Модули => options => rootCategories */
foreach ($data[$dataKey]["rootCategories"] as $cat) {
$cProductCats = R::xdispense($withPrefix("categories"));
$config["ownCategoriesList"][] = $cProductCats;
$cProductCats["slug"] = $cat["slug"];
$cProductCats["image"] = $cat["image"];
$cProductCats["title"] = $cat["title"];
$cProductCats["url"] = $cat["url"];
}
/* Модули => options => rootAttributes */
foreach ($data[$dataKey]["rootSubCategories"] as $category) {
$cProductAttrs = R::xdispense($withPrefix("attributes"));
$config["ownAttributesList"][] = $cProductAttrs;
$cProductAttrs["title"] = $category["title"];
$cProductAttrs["count"] = count($category["subCategories"]);
foreach ($category["subCategories"] as $property) {
$cProductAttrProps = R::xdispense($withPrefix("attribute_props"));
$cProductAttrs["ownPropsList"][] = $cProductAttrProps;
$cProductAttrProps["slug"] = $property["slug"];
$cProductAttrProps["title"] = $property["title"];
$cProductAttrProps["revers"] = (bool) $property["revers"];
}
}
/* */
R::storeAll([
$cSiteMetrics,
$cMetaInfo,
$cPreview,
$cCatalog,
$cDiscount,
$cLider,
$cFooter,
$config,
$user
]);
if (empty($cookie)) {]
И придется использовать такой