function globallink_block_get_translated_blocks in GlobalLink Connect for Drupal 7.6
Same name and namespace in other branches
- 7.5 globallink_block/globallink_block.inc \globallink_block_get_translated_blocks()
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.
2 calls to globallink_block_get_translated_blocks()
- globallink_auto_receive in ./
globallink.module - Automatically receives translated contents.
- globallink_block_receive_form_submit in globallink_block/
globallink_block_receive.inc - Handles block form submission.
File
- globallink_block/
globallink_block.inc, line 474
Code
function globallink_block_get_translated_blocks($pd4, &$globallink_arr) {
module_load_include('inc', 'globallink', 'globallink');
$count = 0;
$source_link = array(
'link_title' => 'No Title',
);
$strings = globallink_block_get_strings(NULL, 'blocks');
foreach ($globallink_arr as $globallink) {
$target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
if ($globallink->sourceDeleted) {
continue;
}
if (!isset($target_xml)) {
continue;
}
$count++;
$language = globallink_get_drupal_locale_code($globallink->targetLocale);
$translated_arr = globallink_block_get_translated_items($target_xml);
try {
$bid = $translated_arr['bid'];
foreach ($translated_arr as $attribute => $translations) {
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);
}
globallink_block_update_status($globallink);
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
} catch (SoapFault $se) {
$count--;
globallink_block_update_status($globallink, 'Error');
watchdog('GlobalLink', 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
form_set_error('', t('Web Services Error: @faultcode - @faultstring', array(
'@faultcode' => $se->faultcode,
'@faultstring' => $se->faultstring,
)));
} catch (Exception $e) {
$count--;
globallink_block_update_status($globallink, 'Error');
watchdog('GlobalLink', '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);
form_set_error('', t('Error: @message', array(
'@message' => $e
->getMessage(),
)));
}
}
return $count;
}