You are here

function ad_channel_adreport in Advertisement 6.3

Same name and namespace in other branches
  1. 6.2 channel/ad_channel.module \ad_channel_adreport()
  2. 7 channel/ad_channel.module \ad_channel_adreport()

Filter reports by selected channel.

File

channel/ad_channel.module, line 417
Ad Channel module.

Code

function ad_channel_adreport($join, $where, $args, $select) {
  if (isset($_SESSION['ad_report_channel']) && is_array($_SESSION['ad_report_channel']) && !empty($_SESSION['ad_report_channel'])) {

    // Check if we're filtering by <none>
    if (isset($_SESSION['ad_report_channel'][-1])) {
      $join = array(
        'LEFT JOIN {ad_channel_node} acn ON acn.nid = a.aid',
      );
      $channels = $_SESSION['ad_report_channel'];
      unset($channels[-1]);

      // Check if we're filtering on <none> and one or more channels
      $list = array();
      $list[] = 'none';
      if (count($channels)) {
        foreach ($channels as $chid) {
          $channel = _ad_channel_get_channels($chid);
          $list[] = $channel->name;
        }
        $where = array(
          '(ISNULL(acn.chid) OR acn.chid IN (%s))',
        );
        $args = array(
          implode(',', $channels),
        );
      }
      else {
        $where = array(
          'ISNULL(acn.chid)',
        );
      }
      drupal_set_message(t('Ad channels: !channels', array(
        '!channels' => implode(', ', $list),
      )));
      return array(
        'join' => $join,
        'where' => $where,
        'args' => $args,
      );
    }
    else {
      $channels = $_SESSION['ad_report_channel'];
      $list = array();
      foreach ($channels as $chid) {
        $channel = _ad_channel_get_channels($chid);
        $list[] = $channel->name;
      }
      drupal_set_message(t('Ad channels: !channels', array(
        '!channels' => implode(', ', $list),
      )));
      $join = array(
        'LEFT JOIN {ad_channel_node} acn ON acn.nid = a.aid',
      );
      $where = array(
        'acn.chid IN (%s)',
      );
      $args = array(
        implode(',', $_SESSION['ad_report_channel']),
      );
      return array(
        'join' => $join,
        'where' => $where,
        'args' => $args,
      );
    }
  }
  else {
    drupal_set_message(t('Ad channels: all'));
  }
}