You are here

function ad_groups_list in Advertisement 5.2

Same name and namespace in other branches
  1. 5 ad.module \ad_groups_list()
  2. 6.3 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.

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

Parameters

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

6 calls to ad_groups_list()
ad_block in ./ad.module
Drupal _block hook.
ad_embed_admin_configure_settings in embed/ad_embed.module
Module settings page.
ad_report_admin in report/ad_report.module
ad_report_admin_ad_table in report/ad_report.module
ad_report_generate_bargraph in report/ad_report.module
Page that utilizes gd to generate a bargraph.

... See full list

File

./ad.module, line 1996
An advertising system for Drupal powered websites.

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;
        }
      }

      // 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;
    }

    // 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;
    }
  }
}