From 19eaeb4f4e3200c068d9b8b7642ea70a9243d87e Mon Sep 17 00:00:00 2001 From: Bellord Date: Tue, 7 Jul 2026 17:09:04 +0300 Subject: [PATCH] init --- .gitignore | 10 ++ .module.json | 9 ++ admin/main/config.php | 23 ++++ admin/main/index.php | 9 ++ admin/main/lang/ru/config.php | 2 + admin/main/menu.php | 11 ++ admin/main/submenu/settings/config.php | 43 +++++++ .../main/submenu/settings/include/config.php | 49 ++++++++ .../settings/include/documentation.php | 1 + admin/main/submenu/settings/index.php | 9 ++ admin/main/submenu/settings/lang/ru/index.php | 2 + admin/main/submenu/settings/menu.php | 11 ++ default_config.php | 21 ++++ functions/app.php | 11 ++ include.php | 9 ++ install/index.php | 117 ++++++++++++++++++ lang/ru/install/index.php | 5 + lib/AbstractFactory/MainAbstractFactory.php | 11 ++ lib/App/App.php | 51 ++++++++ lib/Collection/CatalogCollection.php | 78 ++++++++++++ lib/Entity/CatalogEntity.php | 26 ++++ lib/Facade/DefaultDefines.php | 10 ++ lib/Facade/DefaultFactoryFacade.php | 18 +++ lib/Facade/DefaultServiceFacade.php | 10 ++ lib/Factory/CatalogFactory.php | 75 +++++++++++ lib/Handlers/Autoloader.php | 11 ++ lib/IFields/CatalogFields.php | 10 ++ lib/Interfaces/ITest.php | 8 ++ lib/ORM/CatalogTable.php | 92 ++++++++++++++ lib/Providers/DefaultFactoryProvider.php | 23 ++++ lib/Providers/DefaultServiceProvider.php | 19 +++ src/.env.example | 1 + src/config.php.example | 7 ++ 33 files changed, 792 insertions(+) create mode 100644 .gitignore create mode 100644 .module.json create mode 100644 admin/main/config.php create mode 100644 admin/main/index.php create mode 100644 admin/main/lang/ru/config.php create mode 100644 admin/main/menu.php create mode 100644 admin/main/submenu/settings/config.php create mode 100644 admin/main/submenu/settings/include/config.php create mode 100644 admin/main/submenu/settings/include/documentation.php create mode 100644 admin/main/submenu/settings/index.php create mode 100644 admin/main/submenu/settings/lang/ru/index.php create mode 100644 admin/main/submenu/settings/menu.php create mode 100644 default_config.php create mode 100644 functions/app.php create mode 100644 include.php create mode 100644 install/index.php create mode 100644 lang/ru/install/index.php create mode 100644 lib/AbstractFactory/MainAbstractFactory.php create mode 100644 lib/App/App.php create mode 100644 lib/Collection/CatalogCollection.php create mode 100644 lib/Entity/CatalogEntity.php create mode 100644 lib/Facade/DefaultDefines.php create mode 100644 lib/Facade/DefaultFactoryFacade.php create mode 100644 lib/Facade/DefaultServiceFacade.php create mode 100644 lib/Factory/CatalogFactory.php create mode 100644 lib/Handlers/Autoloader.php create mode 100644 lib/IFields/CatalogFields.php create mode 100644 lib/Interfaces/ITest.php create mode 100644 lib/ORM/CatalogTable.php create mode 100644 lib/Providers/DefaultFactoryProvider.php create mode 100644 lib/Providers/DefaultServiceProvider.php create mode 100644 src/.env.example create mode 100644 src/config.php.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2597961 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.env +src/config.php +*_config.php +!default_config.php +src/Defines.php +src/*Defines.php +src/*Facade.php +!*.example +!.example +_utils \ No newline at end of file diff --git a/.module.json b/.module.json new file mode 100644 index 0000000..17f59d8 --- /dev/null +++ b/.module.json @@ -0,0 +1,9 @@ +{ + "id": "ixrs.catalog", + "prefix": "ixrs_catalog", + "namespace": "Ixrs\\Catalog", + "gitUrl": "https://bitbucket.org/bellord13/ixrs.catalog/", + "version": "1.0.0", + "date": "2026-07-07 00:00:00", + "deps": ["wt.core"] +} \ No newline at end of file diff --git a/admin/main/config.php b/admin/main/config.php new file mode 100644 index 0000000..7972348 --- /dev/null +++ b/admin/main/config.php @@ -0,0 +1,23 @@ + [ + 'TITLE' => GetMessage('MAIN_OPTIONS_PARAMETERS'), + 'THEME' => 'Y', + 'OPTIONS' => [ + + ], + ], + 'TEST' => [ + 'TITLE' => 'test', + 'OPTIONS' => [ + 'TEST' => [ + 'TITLE' => 'test_setting', + 'TYPE' => 'text', + 'DEFAULT' => '', + ], + ], + ], +]; \ No newline at end of file diff --git a/admin/main/index.php b/admin/main/index.php new file mode 100644 index 0000000..bed785f --- /dev/null +++ b/admin/main/index.php @@ -0,0 +1,9 @@ +render(); + +require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php'); \ No newline at end of file diff --git a/admin/main/lang/ru/config.php b/admin/main/lang/ru/config.php new file mode 100644 index 0000000..9532459 --- /dev/null +++ b/admin/main/lang/ru/config.php @@ -0,0 +1,2 @@ +setSort(10) + ->setTitle('Catalog Main'); \ No newline at end of file diff --git a/admin/main/submenu/settings/config.php b/admin/main/submenu/settings/config.php new file mode 100644 index 0000000..490744c --- /dev/null +++ b/admin/main/submenu/settings/config.php @@ -0,0 +1,43 @@ + [ + 'TITLE' => 'Общие сведения', + 'OPTIONS' => [ + //'ENABLE' => [ + // 'TITLE' => 'Enable module', + // 'TYPE' => 'checkbox', + // 'DEFAULT' => 'N', + // 'HINT' => '', + //], + 'CONFIG' => [ + 'TITLE' => 'Конфигурационные данные', + 'HINT' => '', + 'TYPE' => 'content', + 'INCLUDEFILE' => \Wt\Core\Tools::removeDocRoot(__DIR__ . '/include/config.php'), + 'SHOW_EDIT_BUTTON' => 'N', + 'DEFAULT' => '', + ], + ], + ], + 'DOCS' => [ + 'TITLE' => 'Docs', + 'OPTIONS' => [ + 'DOCUMENTATION' => [ + 'TITLE' => 'Documentation', + 'TYPE' => 'content', + 'INCLUDEFILE' => \Wt\Core\Tools::removeDocRoot(__DIR__ . '/include/documentation.php'), + 'SHOW_EDIT_BUTTON' => 'N', + 'DEFAULT' => '', + ], + ], + ], +]; \ No newline at end of file diff --git a/admin/main/submenu/settings/include/config.php b/admin/main/submenu/settings/include/config.php new file mode 100644 index 0000000..3cfe04b --- /dev/null +++ b/admin/main/submenu/settings/include/config.php @@ -0,0 +1,49 @@ +getAdminPage()->getModuleId(); +$app = app()::getInstance($moduleId); +$data = []; +$data['env'] = $app->env(); + + +?> + + $value) { + ?>
+
+ + module()->getSrc(); + $html = "
if(file_exists(\$_SERVER['DOCUMENT_ROOT'] . '$src/init.php')) + include_once \$_SERVER['DOCUMENT_ROOT'] . '$src/init.php';
"; + ?> + + + + +
+ getCheckTemplate($app->isIncludeFileToInitPhp())?> + + Модуль подключен в init.php + + + + init.php отсутствует +
+ +
+
\ No newline at end of file diff --git a/admin/main/submenu/settings/include/documentation.php b/admin/main/submenu/settings/include/documentation.php new file mode 100644 index 0000000..45d092e --- /dev/null +++ b/admin/main/submenu/settings/include/documentation.php @@ -0,0 +1 @@ +Документация \ No newline at end of file diff --git a/admin/main/submenu/settings/index.php b/admin/main/submenu/settings/index.php new file mode 100644 index 0000000..c6684b5 --- /dev/null +++ b/admin/main/submenu/settings/index.php @@ -0,0 +1,9 @@ +render(); + +require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php'); \ No newline at end of file diff --git a/admin/main/submenu/settings/lang/ru/index.php b/admin/main/submenu/settings/lang/ru/index.php new file mode 100644 index 0000000..bd9dc32 --- /dev/null +++ b/admin/main/submenu/settings/lang/ru/index.php @@ -0,0 +1,2 @@ +setSort(5) + ->setTitle('Settings') + ->setUrl(); \ No newline at end of file diff --git a/default_config.php b/default_config.php new file mode 100644 index 0000000..eda1147 --- /dev/null +++ b/default_config.php @@ -0,0 +1,21 @@ + [ + 'Ixrs\Catalog\Factory\CatalogFactory' => ['cache' => ['hit'], 'is_collection_query' => true], + ], + 'events' => [ + 'main:OnPageStart' => [ + ['Ixrs\Catalog\Handlers\Autoloader', 'onPageStart'], + ], + 'main:OnProlog' => [ + ['Ixrs\Catalog\Handlers\Autoloader', 'onProlog'], + ], + 'main:OnEpilog' => [ + ['Ixrs\Catalog\Handlers\Autoloader', 'onEpilog'], + ], + 'main:OnBeforeProlog' => [ + ['Ixrs\Catalog\Handlers\Autoloader', 'onBeforeProlog'], + ], + ], +]; \ No newline at end of file diff --git a/functions/app.php b/functions/app.php new file mode 100644 index 0000000..a5e75e6 --- /dev/null +++ b/functions/app.php @@ -0,0 +1,11 @@ +container())); \ No newline at end of file diff --git a/install/index.php b/install/index.php new file mode 100644 index 0000000..4ade06a --- /dev/null +++ b/install/index.php @@ -0,0 +1,117 @@ +module = $module; + + $this->MODULE_ID = $module['id']; + $this->MODULE_VERSION = $module['version']; + $this->MODULE_VERSION_DATE = $module['date']; + + $langPrefix = $module['prefix']; + + $this->PARTNER_NAME = GetMessage("{$langPrefix}_partner_name"); + $this->PARTNER_URI = GetMessage("{$langPrefix}_partner_uri"); + $this->MODULE_NAME = GetMessage("{$langPrefix}_module_name"); + $this->MODULE_DESCRIPTION = GetMessage("{$langPrefix}_module_description"); + } + + + public function DoInstall() + { + global $APPLICATION; + + if (is_array($this->module['deps'])) { + foreach ($this->module['deps'] as $moduleId) { + if (!Loader::includeModule($moduleId)) { + $APPLICATION->ThrowException("Module {$moduleId} not installed!"); + return false; + } + } + } + + if (!(version_compare(PHP_VERSION, '8.0.0') >= 0)) { + $APPLICATION->ThrowException('Php version required more 8.0.0'); + return false; + } + + RegisterModule($this->MODULE_ID); + RegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID); + $this->InstallEvents(); + $this->InstallCatalogExport(); + + + return true; + } + + public function DoUninstall() + { + global $APPLICATION; + UnRegisterModule($this->MODULE_ID); + UnRegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID, '', ''); + $this->UnInstallEvents(); + $this->UnInstallCatalogExport(); + return true; + } + + public function InstallCatalogExport() + { + if (is_dir(__DIR__ . '/catalog_export') && Loader::includeModule('catalog')) { + CopyDirFiles(__DIR__ . '/catalog_export', $_SERVER['DOCUMENT_ROOT'] . CATALOG_PATH2EXPORTS, true, true); + } + return true; + } + + public function UnInstallCatalogExport() + { + return true; + } + + + public function InstallEvents() + { + if (class_exists('\Bitrix\Main\EventManager')) { + $eventManager = EventManager::getInstance(); + // $eventManager->registerEventHandler( + // 'main', + // 'OnPageStart', + // $this->MODULE_ID, + // 'Ixrs\Catalog\Handler\Handler', + // 'exec', + // 100 + // ); + } + return true; + } + + public function UnInstallEvents() + { + if (class_exists('\Bitrix\Main\EventManager')) { + $eventManager = \Bitrix\Main\EventManager::getInstance(); + // $eventManager->unRegisterEventHandler( + // 'main', + // 'OnPageStart', + // $this->MODULE_ID, + // 'Ixrs\Catalog\Handler\Handler', + // 'exec' + // ); + } + + return true; + } +} \ No newline at end of file diff --git a/lang/ru/install/index.php b/lang/ru/install/index.php new file mode 100644 index 0000000..f628194 --- /dev/null +++ b/lang/ru/install/index.php @@ -0,0 +1,5 @@ +includeFileToInitPhp; + } + $this->includeFileToInitPhp = $value; + return $this; + } +} \ No newline at end of file diff --git a/lib/Collection/CatalogCollection.php b/lib/Collection/CatalogCollection.php new file mode 100644 index 0000000..c2b769f --- /dev/null +++ b/lib/Collection/CatalogCollection.php @@ -0,0 +1,78 @@ +app->container()->make($this->app->module()->getId().':mainAbstractFactory'); + } +} \ No newline at end of file diff --git a/lib/Facade/DefaultServiceFacade.php b/lib/Facade/DefaultServiceFacade.php new file mode 100644 index 0000000..c699265 --- /dev/null +++ b/lib/Facade/DefaultServiceFacade.php @@ -0,0 +1,10 @@ + new \Bitrix\Main\Entity\IntegerField('ID', [ + 'primary' => true, + 'autocomplete' => true, + 'title' => 'Id', + ]), + 'CREATED_AT' => new \Bitrix\Main\Entity\DatetimeField('CREATED_AT', [ + 'title' => 'CreatedAt', + 'user_edit' => false, + ]), + 'UPDATED_AT' => new \Bitrix\Main\Entity\DatetimeField('UPDATED_AT', [ + 'title' => 'UpdatedAt', + 'user_edit' => false, + ]), + ]; + } + + /** + * @param $primary + * @param array $data + * @return \Bitrix\Main\ORM\Data\UpdateResult + * @throws \Bitrix\Main\ObjectException + * @throws Exception + */ + public static function update($primary, array $data) + { + foreach (static::getEntity()->getFields() as $field){ + if(is_a($field, DatetimeField::class)){ + if(isset($data[$field->getName()]) && !is_a($data[$field->getName()], DateTime::class)) { + $data[$field->getName()] = new \Bitrix\Main\Type\DateTime($data[$field->getName()]); + } + } + } + + $data = array_merge($data, [ + 'UPDATED_AT' => new \Bitrix\Main\Type\DateTime(), // date(CDatabase::DateFormatToPHP(FORMAT_DATETIME)) + ]); + unset($data['CREATED_AT']); + + return parent::update($primary, $data); + } + + /** + * @param array $fields + * @return \Bitrix\Main\ORM\Data\AddResult + * @throws \Bitrix\Main\ObjectException + * @throws Exception + */ + public static function add(array $fields) + { + $fields = array_merge($fields, [ + 'CREATED_AT' => new \Bitrix\Main\Type\DateTime(), + 'UPDATED_AT' => new \Bitrix\Main\Type\DateTime(), + ]); + + return parent::add($fields); + } +} \ No newline at end of file diff --git a/lib/Providers/DefaultFactoryProvider.php b/lib/Providers/DefaultFactoryProvider.php new file mode 100644 index 0000000..e31c372 --- /dev/null +++ b/lib/Providers/DefaultFactoryProvider.php @@ -0,0 +1,23 @@ +config(); + $serviceContainer = $app->container(); + + /** + * @var MainAbstractFactory $mainAbstractFactory + */ + $mainAbstractFactory = $serviceContainer->make(MainAbstractFactory::class, [$config->get('MainAbstractFactory', [])]); + $serviceContainer->singleton($app->module()->getId().':mainAbstractFactory', $mainAbstractFactory); + + } +} \ No newline at end of file diff --git a/lib/Providers/DefaultServiceProvider.php b/lib/Providers/DefaultServiceProvider.php new file mode 100644 index 0000000..d961d88 --- /dev/null +++ b/lib/Providers/DefaultServiceProvider.php @@ -0,0 +1,19 @@ +app->container(); + $config = $this->app->config(); + + } +} \ No newline at end of file diff --git a/src/.env.example b/src/.env.example new file mode 100644 index 0000000..c2c027f --- /dev/null +++ b/src/.env.example @@ -0,0 +1 @@ +local \ No newline at end of file diff --git a/src/config.php.example b/src/config.php.example new file mode 100644 index 0000000..ec8c5aa --- /dev/null +++ b/src/config.php.example @@ -0,0 +1,7 @@ + [], +];