You are here

function og_menu_get_group_menus in Organic Groups Menu (OG Menu) 7.3

Same name and namespace in other branches
  1. 6.2 og_menu.module \og_menu_get_group_menus()
  2. 7.2 og_menu.module \og_menu_get_group_menus()

Returns accessible menus for a given user or gids in a structured array.

Parameters

array $groups: An optional array of groups as returned by og_get_entity_groups().

StdClass $user: An optional array of the user object.

Return value

array A structured array with menus list.

4 calls to og_menu_get_group_menus()
og_menu_block_view in ./og_menu.module
Implements hook_block_view().
og_menu_edit_item_form in ./og_menu.pages.inc
Form callback; Build the menu link editing form.
og_menu_node_prepare in ./og_menu.module
Implements hook_node_prepare().
og_menu_node_update in ./og_menu.module
Implements hook_node_update().

File

./og_menu.module, line 954
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function og_menu_get_group_menus($groups = NULL, $user = NULL) {
  if (!isset($groups)) {
    $groups = og_get_entity_groups('user', $user);
  }
  $menus = array();
  $query = db_select('og_menu', 'om');
  $query
    ->join('menu_custom', 'm', 'om.menu_name = m.menu_name');
  $query
    ->fields('om', array(
    'gid',
    'group_type',
    'menu_name',
  ))
    ->fields('m', array(
    'title',
  ));
  $gids_condition = db_or();
  foreach ($groups as $group_type => $group_gids) {
    if (!empty($group_gids)) {

      // This should never be empty?
      $group_gids_condition = db_and()
        ->condition('om.gid', $group_gids, 'IN')
        ->condition('om.group_type', $group_type, '=');
      $gids_condition
        ->condition($group_gids_condition);
    }
  }
  if ($gids_condition
    ->count() > 0) {
    $query
      ->condition($gids_condition);
  }
  $query
    ->orderBy('weight', 'asc');
  $result = $query
    ->execute();
  while ($record = $result
    ->fetchAssoc()) {
    $menus[] = $record;
  }
  return $menus;
}