summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-04 07:46:45 -0500
committerPeter Kozak <spag@golwen.net>2013-03-04 07:46:45 -0500
commitedb0e6cae9d39610739da9bf9c428468d9a53617 (patch)
tree408d938384121301ca5304ff37941e39cd9fb0e4
parentb0118a229516766c22ee8268c182c91c3c15b1cd (diff)
set theory
-rw-r--r--misc/freeswitch/scripts/common/group.lua46
1 files changed, 41 insertions, 5 deletions
diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua
index ac2f542..db56129 100644
--- a/misc/freeswitch/scripts/common/group.lua
+++ b/misc/freeswitch/scripts/common/group.lua
@@ -87,6 +87,7 @@ function Group.name_id_by_member(self, member_id, member_type)
return group_names, group_ids;
end
+
function Group.permission_targets(self, group_ids, permission)
if not group_ids or not permission then
return {};
@@ -100,18 +101,36 @@ function Group.permission_targets(self, group_ids, permission)
AND `b`.`active` IS TRUE \
GROUP BY `a`.`target_group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS;
-
- local groups = {};
+ local group_names = {};
+ local group_ids = {};
self.database:query(sql_query, function(account_entry)
- groups[account_entry.id] = account_entry.name;
+ table.insert(group_names, account_entry.name);
+ table.insert(group_ids, tonumber(account_entry.id));
end);
- return groups;
+ return group_names, group_ids;
+end
+
+
+function Group.is_target(self, group_id, permission)
+ if not group_id or not permission then
+ return nil;
+ end
+
+ local sql_query = 'SELECT `b`.`name` \
+ FROM `group_permissions` `a` \
+ JOIN `groups` `b` ON `b`.`id` = `a`.`target_group_id` \
+ WHERE `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \
+ AND `a`.`group_id` = ' .. tonumber(group_id) .. ' \
+ AND `b`.`active` IS TRUE \
+ LIMIT 1';
+
+ return self.database:query_return_value(sql_query);
end
-function Group.combine(self, ...)
+function Group.union(self, ...)
local groups = {};
local group_sets = {...};
for set_index=1, #group_sets do
@@ -130,3 +149,20 @@ function Group.combine(self, ...)
return group_ids;
end
+
+
+function Group.intersection(self, set_one, set_two)
+ local basic_set = {};
+ for index=1, #set_one do
+ basic_set[set_one[index]] = true;
+ end
+
+ local final_set = {};
+ for index=1, #set_two do
+ if basic_set[set_two[index]] then
+ table.insert(final_set, set_two[index]);
+ end
+ end
+
+ return final_set;
+end