From 8d9d7c25af42eb6e89c87e153c0069147c94df69 Mon Sep 17 00:00:00 2001 From: samerton Date: Mon, 11 Jul 2022 21:40:26 +0100 Subject: [PATCH] Add clone group permissions hook --- .../hooks/CloneGroupResourcesHook.php | 31 +++++++++++++++++++ upload/modules/Resources/init.php | 1 + upload/modules/Resources/module.php | 1 + 3 files changed, 33 insertions(+) create mode 100644 upload/modules/Resources/hooks/CloneGroupResourcesHook.php diff --git a/upload/modules/Resources/hooks/CloneGroupResourcesHook.php b/upload/modules/Resources/hooks/CloneGroupResourcesHook.php new file mode 100644 index 0000000..037ff1d --- /dev/null +++ b/upload/modules/Resources/hooks/CloneGroupResourcesHook.php @@ -0,0 +1,31 @@ +query('SELECT * FROM nl2_resources_categories_permissions WHERE group_id = ?', [$params['cloned_group_id']]); + if ($permissions->count()) { + $permissions = $permissions->results(); + + $inserts = []; + foreach ($permissions as $permission) { + $inserts[] = '(' .$new_group_id . ',' . $permission->category_id . ',' . $permission->view . ',' . $permission->post . ',' . $permission->move_resource . ',' . $permission->edit_resource . ',' . $permission->delete_resource . ',' . $permission->edit_review . ',' . $permission->delete_review . ',' . $permission->download . ',' . $permission->premium . ')'; + } + + $query = 'INSERT INTO nl2_resources_categories_permissions (group_id, category_id, `view`, post, move_resource, edit_resource, delete_resource, edit_review, delete_review, download, premium) VALUES '; + $query .= implode(',', $inserts); + + DB::getInstance()->query($query); + } + } +} diff --git a/upload/modules/Resources/init.php b/upload/modules/Resources/init.php index 786c186..ccd61c3 100644 --- a/upload/modules/Resources/init.php +++ b/upload/modules/Resources/init.php @@ -13,6 +13,7 @@ $resource_language = new Language(ROOT_PATH . '/modules/Resources/language', LANGUAGE); require_once ROOT_PATH . '/modules/Resources/classes/Resources_Sitemap.php'; +require_once ROOT_PATH . '/modules/Resources/hooks/CloneGroupResourcesHook.php'; require_once ROOT_PATH . '/modules/Resources/hooks/DeleteUserResourcesHook.php'; require_once ROOT_PATH . '/modules/Resources/module.php'; diff --git a/upload/modules/Resources/module.php b/upload/modules/Resources/module.php index edfbab4..bf83da7 100644 --- a/upload/modules/Resources/module.php +++ b/upload/modules/Resources/module.php @@ -43,6 +43,7 @@ public function __construct($pages, $language, $resource_language){ $pages->add('Resources', '/user/resources/licenses', 'pages/user/licenses.php'); EventHandler::registerListener('deleteUser', 'DeleteUserResourcesHook::execute'); + EventHandler::registerListener('cloneGroup', 'CloneGroupResourcesHook::execute'); }