Skip to content

Instantly share code, notes, and snippets.

@joshuaadickerson
Created May 8, 2013 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaadickerson/5542380 to your computer and use it in GitHub Desktop.
Save joshuaadickerson/5542380 to your computer and use it in GitHub Desktop.
Refactor to use loadMemberGroups()
<?php
function membergroupsById($group_id, $limit = 1, $detailed = false, $assignable = false, $protected = false)
{
global $context;
if (!isset($group_id))
return false;
if (empty($context['membergroups']))
loadMemberGroups();
$group_ids = is_array($group_id) ? $group_id : array($group_id);
$groups = array();
foreach ($group_ids as $group)
{
$id = (int) $group;
if (isset($context['memmbergroups'][$id]) && (!$protected || ($protected && $context['memmbergroups'][$id]['group_type'] != 1)))
$groups[$id] = $context['memmbergroups'][$id];
}
if (is_array($group_id))
return $groups;
else
return $groups[$group_id];
}
@joshuaadickerson
Copy link
Author

  1. it needs to be refactored all around to get rid of the now extraneous parameters: $limit, $detailed, $assignable
  2. it should always return an array
  3. it should have a verb in there - getMembergroupsById()
  4. obviously with the changes it needs a new doc block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment