You are here

function ad_channel_adapi in Advertisement 6.3

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

Implement hook _adapi.

File

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

Code

function ad_channel_adapi($op, $node) {
  switch ($op) {
    case 'admin_filters':
      $channels = _ad_channel_get_channels();
      $options = array();
      $options['channel-0'] = t('<none>');
      foreach ($channels as $channel) {
        $key = 'channel-' . $channel->chid;
        $options[$key] = $channel->name;
      }
      $filters['channel'] = array(
        'title' => t('channel'),
        'options' => $options,
      );
      $options = array(
        '0' => t('false'),
        '1' => t('true'),
      );
      $filters['premiere'] = array(
        'title' => t('premiere'),
        'options' => $options,
      );
      $filters['remnant'] = array(
        'title' => t('remnant'),
        'options' => $options,
      );
      return $filters;
    case 'admin_filter_query':
      if (is_array($node)) {
        list($key, $value) = $node;
        if ($key == 'channel') {
          list($key, $value) = explode('-', $value, 2);
          if ($value == 0) {
            return array(
              'channel' => array(
                'where' => 'c.chid IS %s',
                'join' => 'LEFT JOIN {ad_channel_node} c ON n.nid = c.nid ',
                'value' => 'NULL',
              ),
            );
          }
          return array(
            'channel' => array(
              'where' => 'c.chid = %d',
              'join' => 'INNER JOIN {ad_channel_node} c ON n.nid = c.nid ',
              'value' => $value,
            ),
          );
        }
        else {
          if ($key == 'premiere') {
            return array(
              'premiere' => array(
                'where' => 'p.priority = %d',
                'join' => 'INNER JOIN {ad_priority} p ON n.nid = p.aid ',
                'value' => $value,
              ),
            );
          }
          else {
            if ($key == 'remnant') {
              return array(
                'remnant' => array(
                  'where' => 'r.remnant = %d',
                  'join' => 'INNER JOIN {ad_channel_remnant} r ON n.nid = r.aid ',
                  'value' => $value,
                ),
              );
            }
          }
        }
      }
      break;
  }
}