You are here

function lingotek_get_node_count in Lingotek Translation 7.2

Counts all the nodes of a specific language.

OLD METHOD. Replaced by: lingotek_count_node_targets() (for reporting node target counts) Not removed yet, because its still used in other places for reporting other counts.

Limits the counts to node / fields that are marked translatable.

File

./lingotek.dashboard.inc, line 301
Lingotek Dashboard.

Code

function lingotek_get_node_count($language = NULL) {
  $result = 0;
  if (isset($language)) {
    $source_language = lingotek_get_source_language();

    // if the language count we are requested to do, IS the source language.  Do a direct query against the nodes, using EntityFieldQuery.
    if ($language == $source_language) {
      $bundles = lingotek_translatable_node_types();

      // $bundles -- array ( 0 => 'page', 1 => 'article', )
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'node')
        ->propertyCondition('status', 1);

      // Published Nodes
      $query
        ->entityCondition('bundle', $bundles);

      // The Content Types we Want Translated.
      $query
        ->propertyCondition('language', $language, '=');

      // The Language to search for
      $result = $query
        ->count()
        ->execute();
    }
    else {

      // Otherwise, do a regular count, where we count field languages.
      $sum = 0;
      $type_field_mapping = lingotek_get_type_field_mapping();

      //debug( $type_field_mapping );

      // Loop though the type_field_mapping, and count this language for EACH node type and get a sum.
      foreach ($type_field_mapping as $type => $db_table) {
        $count = 0;
        $query = db_select($db_table, 'tbl')
          ->fields('tbl');
        $query
          ->condition('entity_type', 'node');
        $query
          ->condition('deleted', 0);
        $query
          ->condition('bundle', $type);
        $query
          ->condition('language', $language);
        $count = $query
          ->countQuery()
          ->execute()
          ->fetchAssoc();
        $sum += $count['expression'];

        //debug( 'Lang: ' . $language . ' Type: ' . $type . ' Count: ' . $count['expression'] );
      }
      $result = $sum;
    }

    // END:  regular count
  }

  // END:  isset $language
  return $result;
}