diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-03-16 21:01:42 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-03-16 21:01:42 -0300 |
commit | 815bb3bf5a5e8da9a7962a4a532c3129f09d5735 (patch) | |
tree | 41bec5b730cc3dca936438f9e97810e7ab3ede0a /mod/subgroups/lib/subgroups.php | |
parent | c102a5c9f4e9e2f78260019ccab6098435b1df19 (diff) | |
parent | 5f6dc365a8445a48156b45912827eac39fd64fc5 (diff) | |
download | elgg-815bb3bf5a5e8da9a7962a4a532c3129f09d5735.tar.gz elgg-815bb3bf5a5e8da9a7962a4a532c3129f09d5735.tar.bz2 |
Merge commit '5f6dc365a8445a48156b45912827eac39fd64fc5' as 'mod/subgroups'
Diffstat (limited to 'mod/subgroups/lib/subgroups.php')
-rw-r--r-- | mod/subgroups/lib/subgroups.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/mod/subgroups/lib/subgroups.php b/mod/subgroups/lib/subgroups.php new file mode 100644 index 000000000..ffa531e16 --- /dev/null +++ b/mod/subgroups/lib/subgroups.php @@ -0,0 +1,84 @@ +<?php +/** + * Subgroups helper functions + * + * @package ElggSubgroups + */ + + +/** + * Gives the list of the group subgroups + * + * @param ElggGroup $group + * @return array + */ +function get_subgroups($group, $options = array()){ + if($group instanceof ElggGroup){ + + $options['type'] = 'group'; + $options['container_guid'] = $group->guid; + return elgg_get_entities($options); + + } else { + return false; + } +} + +function list_subgroups($group, $options = array()){ + + if($group instanceof ElggGroup){ + + $defaults = array( + 'full_view' => false, + 'pagination' => true, + ); + $options = array_merge($defaults, $options); + + $options['type'] = 'group'; + $options['container_guid'] = $group->guid; + + elgg_push_context('subgroups'); + $list = elgg_list_entities($options); + elgg_pop_context(); + + return $list; + + } else { + return ""; + } +} + +function subgroups_group_url_matches($url){ + $url = parse_url($url); + $pattern1 = "/groups\/profile\/(?P<group_guid>\d+)/"; + $pattern2 = "/g\/(?P<group_alias>[^\/]+)/"; + + $matches1 = array(); + $matches2 = array(); + + preg_match($pattern1, $url['path'], $matches1); + preg_match($pattern2, $url['path'], $matches2); + + if(!empty($matches1) || !empty($matches2)) { + return array_merge($matches1, $matches2); + } else { + return false; + } +} + +function subgroups_get_group_from_url($group_url){ + $matches = subgroups_group_url_matches($group_url); + $group_guid = $matches['group_guid']; + $group_alias = $matches['group_alias']; + + $group = get_entity($group_guid); + if(!$group && elgg_is_active_plugin('group_alias')) { + $group = get_group_from_group_alias($group_alias); + } + + if($group && $group->getURL() == $group_url){ + return $group; + } else { + return false; + } +} |