You are here

function _ad_channel_validate_nodes in Advertisement 5.2

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

Be sure that the enabled channels actually can be enabled.

1 call to _ad_channel_validate_nodes()
ad_channel_nodeapi in channel/ad_channel.module
Implementation of hook_nodeapi().

File

channel/ad_channel.module, line 308
Ad Channel

Code

function _ad_channel_validate_nodes($node) {
  $channels = _ad_channel_get_enabled($node);
  foreach ($channels as $chid) {
    $channel = _ad_channel_get_channels($chid);
    $taxonomy = is_array($node->taxonomy) ? $node->taxonomy : array();
    $groups = unserialize($channel->groups);
    if (!empty($groups)) {
      $enabled = FALSE;
      foreach ($groups as $group) {
        if ($group) {
          $enabled = TRUE;
          break;
        }
      }
      if ($enabled) {
        $ad_groups = taxonomy_get_tree(_ad_get_vid());
        foreach ($ad_groups as $ad_group) {
          if (is_array($taxonomy[$ad_group->vid]) && isset($taxonomy[$ad_group->vid][$ad_group->tid]) && isset($groups[$ad_group->tid]) && !$groups[$ad_group->tid] && !isset($groups[''])) {
            form_set_error("channel[{$channel->conid}][channel-{$chid}]", t('The %channel channel does not allow advertisements from the %group group.', array(
              '%channel' => $channel->name,
              '%group' => $ad_group->name,
            )));
          }
        }
      }
    }
  }
}