You are here

function legal_versions_latest_get in Legal 7

Same name and namespace in other branches
  1. 6.8 legal.admin.inc \legal_versions_latest_get()
  2. 7.2 legal.admin.inc \legal_versions_latest_get()

Get latest version for each language.

1 call to legal_versions_latest_get()
legal_languages in ./legal.admin.inc
Languages administration form.

File

./legal.admin.inc, line 501
Administration UI for the Legal module.

Code

function legal_versions_latest_get($language = NULL) {
  $conditions = array();
  $current_version = db_select('legal_conditions', 'lc')
    ->fields('lc', array(
    'version',
  ))
    ->orderBy('version', 'DESC')
    ->range(0, 1)
    ->execute()
    ->fetchField();

  // get latest version for each language
  if (empty($language)) {
    $languages = array(
      'en' => t('English'),
    );
    if (module_exists('locale')) {
      $languages = locale_language_list();
    }
    foreach ($languages as $language_id => $language_name) {
      $result = db_select('legal_conditions', 'lc')
        ->fields('lc')
        ->condition('version', $current_version)
        ->condition('language', $language_id)
        ->orderBy('revision', 'DESC')
        ->range(0, 1)
        ->addTag('legal_conditions_by_language_and_version')
        ->execute()
        ->fetchAllAssoc('tc_id');
      $row = count($result) ? (object) array_shift($result) : FALSE;
      $conditions[$language_name] = legal_versions_latest_get_data($row);
    }
  }
  else {
    $result = db_select('legal_conditions', 'lc')
      ->fields('lc')
      ->condition('language', $language)
      ->groupBy('language')
      ->orderBy('version', 'DESC')
      ->range(0, 1)
      ->addTag('legal_latest_condition_for_language')
      ->execute()
      ->fetchAllAssoc('tc_id');
    $row = count($result) ? (object) array_shift($result) : FALSE;
    $conditions[$language] = legal_versions_latest_get_data($row);
  }
  return $conditions;
}