summaryrefslogtreecommitdiffstats
path: root/modules-available/permissionmanager/inc/dbupdate.inc.php
blob: 20ff746a37de5a58fc507bd4af757783d3bec742 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

class DbUpdate {

	// insert new userXrole to database. "ignore" to ignore duplicate entry try
	public static function addRoleToUser($users, $roles) {
		foreach($users AS $user) {
			foreach ($roles AS $role) {
				$query = "INSERT IGNORE INTO userXrole (userid, roleid) VALUES ($user, $role)";
				Database::exec($query);
			}
		}
	}

	// remove userXrole entry from database
	public static function removeRoleFromUser($users, $roles) {
		foreach($users AS $user) {
			foreach ($roles AS $role) {
				$query = "DELETE FROM userXrole WHERE userid = $user AND roleid = $role";
				Database::exec($query);
			}
		}
	}

	// delete role, delete userXrole relationships, delete roleXlocation relationships, delete roleXpermission relationships
	public static function deleteRole($id) {
		$query = "DELETE FROM role WHERE id = $id";
		Database::exec($query);
		$query = "DELETE FROM userXrole WHERE roleid = $id";
		Database::exec($query);
		$query = "DELETE FROM roleXlocation WHERE roleid = $id";
		Database::exec($query);
		$query = "DELETE FROM roleXpermission WHERE roleid = $id";
		Database::exec($query);
	}

}