Skip to content

Commit

Permalink
Add clone group permissions hook
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Jul 11, 2022
1 parent df64607 commit 8d9d7c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions upload/modules/Resources/hooks/CloneGroupResourcesHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/*
* Made by Partydragen + Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-pr13
*
* Clone group event listener handler class
*/

class CloneGroupResourcesHook {

public static function execute(array $params = []): void {

// Clone group permissions for resource categories
$new_group_id = $params['group_id'];
$permissions = DB::getInstance()->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);
}
}
}
1 change: 1 addition & 0 deletions upload/modules/Resources/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions upload/modules/Resources/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

}

Expand Down

0 comments on commit 8d9d7c2

Please sign in to comment.