You are here

function xmlsitemap_node_views_query_alter in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_views_query_alter()

Implementation of hook_views_query_alter().

File

xmlsitemap_node/xmlsitemap_node.module, line 183
Adds nodes to the sitemap.

Code

function xmlsitemap_node_views_query_alter(&$query, &$view, $summary = NULL, $level = NULL) {
  switch ($view->page_type) {
    case 'xmlsitemap_news':
      $query
        ->add_field('created', 'node');
    case 'xmlsitemap_sitemap':
      $xn_join = array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
      );
      $ua_join = array(
        'left' => array(
          'table' => 'url_alias',
          'field' => 'pid',
        ),
        'right' => array(
          'field' => 'pid',
        ),
        'extra' => array(
          "src = CONCAT('node/', node.nid)" => NULL,
        ),
      );
      $query
        ->add_table('xmlsitemap_node', FALSE, 1, $xn_join);
      $query
        ->add_table('url_alias', FALSE, 1, $ua_join);
      if (module_exists('comment')) {
        $query
          ->add_table('node_comment_statistics');
        $query
          ->add_field('comment_count', 'node_comment_statistics');
        $query
          ->add_field('last_comment_timestamp', 'node_comment_statistics');
        $query
          ->add_field('previous_comment', 'xmlsitemap_node');
      }
      $query
        ->add_field('type', 'node');
      $query
        ->add_field('promote', 'node');
      $query
        ->add_field('changed', 'node');
      $query
        ->add_field('previously_changed', 'xmlsitemap_node');
      $query
        ->add_field('priority_override', 'xmlsitemap_node');
      $query
        ->add_field('dst', 'url_alias', 'alias');
      break;
  }
}