129 lines
4.1 KiB
PHP
129 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
/**
|
|
* Импорт центров из материализованного представления (Bitrix view).
|
|
*
|
|
* См. MedicalCenterController + CrudResponder для CRUD; этот сервис — только syncFromView*.
|
|
*/
|
|
final class MedicalCenterCrudService
|
|
{
|
|
public function __construct(
|
|
private EntityManagerInterface $em,
|
|
) {
|
|
}
|
|
|
|
public function syncFromViewCenters(string $viewName = 'public.view_centers'): int
|
|
{
|
|
if (!preg_match('/^[A-Za-z0-9_\.]+$/', $viewName)) {
|
|
throw new \InvalidArgumentException('Invalid view name');
|
|
}
|
|
|
|
$sql = sprintf(
|
|
'INSERT INTO medical_center (
|
|
id,
|
|
name,
|
|
active,
|
|
region_id,
|
|
alias,
|
|
anons,
|
|
content,
|
|
update_at,
|
|
kod_uslug,
|
|
doctors,
|
|
services,
|
|
articles,
|
|
txt_up,
|
|
main_link_staff,
|
|
contraindications,
|
|
hide_picture,
|
|
indications,
|
|
link_sale,
|
|
plus_list,
|
|
plus_text,
|
|
plus_title,
|
|
process_text,
|
|
process_title,
|
|
services_list,
|
|
services_photos,
|
|
services_title,
|
|
sort_staff,
|
|
training_text,
|
|
training_text_title,
|
|
why_text,
|
|
why_title
|
|
)
|
|
SELECT
|
|
id,
|
|
name,
|
|
active,
|
|
region_id,
|
|
alias,
|
|
anons,
|
|
content,
|
|
update_at,
|
|
kod_uslug,
|
|
doctors,
|
|
services,
|
|
articles,
|
|
txt_up,
|
|
main_link_staff,
|
|
contraindications,
|
|
hide_picture,
|
|
indications,
|
|
link_sale,
|
|
plus_list,
|
|
plus_text,
|
|
plus_title,
|
|
process_text,
|
|
process_title,
|
|
services_list,
|
|
services_photos,
|
|
services_title,
|
|
sort_staff,
|
|
training_text,
|
|
training_text_title,
|
|
why_text,
|
|
why_title
|
|
FROM %s
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
active = EXCLUDED.active,
|
|
region_id = EXCLUDED.region_id,
|
|
alias = EXCLUDED.alias,
|
|
anons = EXCLUDED.anons,
|
|
content = EXCLUDED.content,
|
|
update_at = EXCLUDED.update_at,
|
|
kod_uslug = EXCLUDED.kod_uslug,
|
|
doctors = EXCLUDED.doctors,
|
|
services = EXCLUDED.services,
|
|
articles = EXCLUDED.articles,
|
|
txt_up = EXCLUDED.txt_up,
|
|
main_link_staff = EXCLUDED.main_link_staff,
|
|
contraindications = EXCLUDED.contraindications,
|
|
hide_picture = EXCLUDED.hide_picture,
|
|
indications = EXCLUDED.indications,
|
|
link_sale = EXCLUDED.link_sale,
|
|
plus_list = EXCLUDED.plus_list,
|
|
plus_text = EXCLUDED.plus_text,
|
|
plus_title = EXCLUDED.plus_title,
|
|
process_text = EXCLUDED.process_text,
|
|
process_title = EXCLUDED.process_title,
|
|
services_list = EXCLUDED.services_list,
|
|
services_photos = EXCLUDED.services_photos,
|
|
services_title = EXCLUDED.services_title,
|
|
sort_staff = EXCLUDED.sort_staff,
|
|
training_text = EXCLUDED.training_text,
|
|
training_text_title = EXCLUDED.training_text_title,
|
|
why_text = EXCLUDED.why_text,
|
|
why_title = EXCLUDED.why_title',
|
|
$viewName
|
|
);
|
|
|
|
return (int) $this->em->getConnection()->executeStatement($sql);
|
|
}
|
|
}
|