/**
  * Display and manage group memberships
  *
  * @return array client, order, direction [, form (Console\Form\GroupMemberships) if groups are available]
  */
 public function groupsAction()
 {
     $vars = $this->getOrder('GroupName');
     $vars['client'] = $this->_currentClient;
     $vars['memberships'] = array();
     $groups = $this->_groupManager->getGroups(null, null, 'Name');
     if ($groups->count()) {
         $memberships = $this->_currentClient->getGroupMemberships(\Model\Client\Client::MEMBERSHIP_ANY);
         $data = array();
         // Create form data for all groups and actual membership list
         foreach ($groups as $group) {
             $id = $group['Id'];
             $name = $group['Name'];
             if (isset($memberships[$id])) {
                 $type = $memberships[$id];
                 $data['Groups'][$name] = $type;
                 if ($type != \Model\Client\Client::MEMBERSHIP_NEVER) {
                     $vars['memberships'][] = array('GroupName' => $name, 'Membership' => $type);
                 }
             } else {
                 // Default to automatic membership
                 $data['Groups'][$group['Name']] = \Model\Client\Client::MEMBERSHIP_AUTOMATIC;
             }
         }
         $form = $this->_formManager->get('Console\\Form\\GroupMemberships');
         $form->setData($data);
         $form->setAttribute('action', $this->urlFromRoute('client', 'managegroups', array('id' => $this->_currentClient['Id'])));
         $vars['form'] = $form;
     }
     return $vars;
 }
 /**
  * Show table with overview of groups
  *
  * @return array Array(groups, sorting)
  */
 public function indexAction()
 {
     $sorting = $this->getOrder('Name', 'asc');
     return array('groups' => $this->_groupManager->getGroups(null, null, $sorting['order'], $sorting['direction']), 'sorting' => $sorting);
 }