You are here

function globallink_block_import in GlobalLink Connect for Drupal 7.7

Gets number of translated blocks.

Parameters

string $pd4: The project director details.

array $globallink_arr: Array of GlobalLink objects.

Return value

int The number of translated blocks.

1 call to globallink_block_import()
globallink_background_import in ./globallink_background_jobs.inc
Imports the documents

File

globallink_block/globallink_block.inc, line 205

Code

function globallink_block_import(&$globallink) {
  module_load_include('inc', 'globallink', 'globallink');
  $strings = globallink_block_get_strings(NULL, 'blocks');
  $target_xml = $globallink->targetXML;
  if (!isset($target_xml)) {
    $globallink->status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
    return;
  }
  $language = globallink_get_drupal_locale_code($globallink->targetLocale);
  $translated_arr = globallink_block_get_translated_items($target_xml);
  $bid = $translated_arr['bid'];
  foreach ($translated_arr as $attribute => $translations) {
    try {
      if ($attribute == 'bid') {
        continue;
      }
      $source = '';
      switch ($attribute) {
        case 'title':
          $title_string_arr = isset($strings['blocks:block:' . $bid . ':title']) ? $strings['blocks:block:' . $bid . ':title'] : FALSE;
          if (!$title_string_arr) {
            continue;
          }
          $source = $title_string_arr['source'];
          break;
        case 'body':
          $body_string_arr = isset($strings['blocks:block:' . $bid . ':body']) ? $strings['blocks:block:' . $bid . ':body'] : FALSE;
          if (!$body_string_arr) {
            throw new Exception('Source string not found for block id ' . $bid . ' and field name ' . $attribute);
          }
          $source = $body_string_arr['source'];
          break;
      }
      $report =& drupal_static(__FUNCTION__, array(
        'additions' => 0,
        'updates' => 0,
        'deletes' => 0,
        'skips' => 0,
      ));
      _locale_import_one_string_db($report, $language, $translations['context'], $source, $translations['translation'], 'blocks', $translations['location'], LOCALE_IMPORT_OVERWRITE);
    } catch (Exception $e) {
      $globallink->status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
      watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
        '%function' => __FUNCTION__,
        '%file' => $e
          ->getFile(),
        '%line' => $e
          ->getLine(),
        '%code' => $e
          ->getCode(),
        '%message' => $e
          ->getMessage(),
      ), WATCHDOG_ERROR);
    }
  }
  if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
    $globallink->status = GLOBALLINK_STATUS_TRANSLATION_IMPORTED;
  }
  return;
}