/**
  * sets up the display groups
  * 
  * first, attempts to get the list from the shortcode, then uses the defined as 
  * visible list from the database
  *
  * if the shortcode "groups" attribute is used, it overrides the gobal group 
  * visibility settings
  *
  * @global object $wpdb
  * @param  bool $public_only if true, include only public groups, if false, include all groups
  * @return null
  */
 protected function _set_display_groups($public_only = true)
 {
     global $wpdb;
     $groups = array();
     if (!empty($this->shortcode_atts['fields'])) {
         foreach ($this->display_columns as $column) {
             $column = $this->fields[$column];
             $groups[$column->group] = true;
         }
         $groups = array_keys($groups);
     } elseif (!empty($this->shortcode_atts['groups'])) {
         /*
          * process the shortcode groups attribute and get the list of groups defined
          */
         $group_list = array();
         $groups_attribute = explode(',', str_replace(array(' '), '', $this->shortcode_atts['groups']));
         foreach ($groups_attribute as $item) {
             if (Participants_Db::is_group($item)) {
                 $group_list[] = trim($item);
             }
         }
         if (count($group_list) !== 0) {
             /*
              * get a list of all defined groups
              */
             $sql = 'SELECT g.name 
             FROM ' . Participants_Db::$groups_table . ' g ORDER BY FIELD( g.name, "' . implode('","', $group_list) . '")';
             $result = $wpdb->get_results($sql, ARRAY_N);
             foreach ($result as $group) {
                 if (in_array(current($group), $group_list) || $public_only === false) {
                     $groups[] = current($group);
                 }
             }
         }
     }
     if (count($groups) === 0) {
         $orderby = empty($this->shortcode_atts['fields']) ? 'g.order ASC' : 'FIELD( g.name, "' . implode('","', $groups) . '")';
         if ($this->module === 'signup') {
             $sql = 'SELECT DISTINCT g.name 
             FROM ' . Participants_Db::$groups_table . ' g 
             JOIN ' . Participants_Db::$fields_table . ' f ON f.group = g.name 
             WHERE f.signup = "1" ' . ($public_only ? 'AND g.display = "1"' : '') . ' AND f.form_element <> "hidden" ORDER BY ' . $orderby;
         } else {
             $sql = 'SELECT g.name 
           FROM ' . Participants_Db::$groups_table . ' g
             WHERE 1=1 ' . ($public_only ? 'AND g.display = "1"' : '') . ' ORDER BY ' . $orderby;
         }
         $result = $wpdb->get_results($sql, ARRAY_N);
         foreach ($result as $group) {
             $groups[] = current($group);
         }
     }
     $this->display_groups = $groups;
 }
 /**
  * gets only display-enabled groups
  * 
  * first, attempts to get the list from the shortcode, then uses the defined as 
  * visible list from the database
  *
  * @global object $wpdb
  * @param  bool $logic true to get display-enabled groups, false to get non-enabled groups
  * @return array of group names
  */
 protected function _get_display_groups($logic = true)
 {
     global $wpdb;
     $return = array();
     if (!empty($this->shortcode_atts['groups'])) {
         /*
          * process the shortcode groups attribute and get the list of groups defined
          */
         $list = array();
         $groups_attribute = explode(',', $this->shortcode_atts['groups']);
         foreach ($groups_attribute as $item) {
             if (Participants_Db::is_group($item)) {
                 $list[] = trim($item);
             }
         }
         if (count($list) !== 0) {
             /*
              * get a list of all defined groups
              */
             $sql = 'SELECT g.name 
           FROM ' . Participants_Db::$groups_table . ' g';
             $result = $wpdb->get_results($sql, ARRAY_N);
             foreach ($result as $group) {
                 if (in_array(current($group), $list) === $logic) {
                     $return[] = current($group);
                 }
             }
         }
     }
     if (count($return) === 0) {
         $sql = 'SELECT g.name 
           FROM ' . Participants_Db::$groups_table . ' g
           WHERE g.display = ' . ($logic ? 1 : 0);
         $result = $wpdb->get_results($sql, ARRAY_N);
         foreach ($result as $group) {
             $return[] = current($group);
         }
     }
     return $return;
 }