You are here

function ad_groups_list in Advertisement 6.3

Same name and namespace in other branches
  1. 5.2 ad.module \ad_groups_list()
  2. 5 ad.module \ad_groups_list()
  3. 6 ad.module \ad_groups_list()
  4. 6.2 ad.module \ad_groups_list()
  5. 7 ad.module \ad_groups_list()

Return an array of all groups, or a specific group.

Parameters

$object: If FALSE, will return only name of group(s). If TRUE, will return full group object including ->name, ->description, and ->tid.

$tid: If set to an integer >0, will only return group info about that specific group.

5 calls to ad_groups_list()
ad_client_block in client/ad_client.module
Implementation of hook_block().
ad_embed_admin_configure_settings in embed/ad_embed.module
Module settings page.
ad_group_load in ./ad.module
Drupal menu wildcard Ad group loader
ad_report_admin in report/ad_report.module
ad_report_admin_ad_table in report/ad_report.module
Generate a table reporting on the selected advertisements. Returns an array of ad NIDs in $ads.

File

./ad.module, line 1261

Code

function ad_groups_list($object = FALSE, $tid = NULL) {
  static $groups = array();
  static $names = array();

  // Return the full group object(s).
  if ($object) {
    if (empty($groups)) {
      $tids = taxonomy_get_tree(_ad_get_vid());
      if (is_array($tids)) {
        foreach ($tids as $group) {
          $groups[$group->tid]->name = $group->name;
          $groups[$group->tid]->description = $group->description;
          $groups[$group->tid]->tid = $group->tid;
          $groups[$group->tid]->weight = $group->weight;
        }
      }

      // Hard coded "default" group with tid of 0.
      $groups[0]->name = t('default');
      $groups[0]->description = t('The default ad group is comprised of all ads not assigned to any other ad group.');
      $groups[0]->tid = 0;
      $groups[0]->weight = 0;
    }

    // Return a specific group object.
    if ((int) $tid) {
      return $groups[$tid];
    }
    else {
      return $groups;
    }
  }
  else {
    if (empty($names)) {
      $tids = taxonomy_get_tree(_ad_get_vid());
      if (is_array($tids)) {
        foreach ($tids as $group) {
          $names[$group->tid] = $group->name;
        }
      }

      // Hard coded "default" group with tid of 0.
      $names[0] = t('default');
    }

    // Return a specific group name.
    if ((int) $tid) {
      return $names[$tid];
    }
    else {
      return $names;
    }
  }
}