function globallink_content_preview_content in GlobalLink Connect for Drupal 7.7
Helper function
1 string reference to 'globallink_content_preview_content'
- globallink_preview in ./
globallink_workbench_all_active_submissions.inc - Helper function
File
- ./
globallink_workbench_all_active_submissions.inc, line 1160
Code
function globallink_content_preview_content() {
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
module_load_include('inc', 'globallink', 'globallink');
module_load_include('inc', 'globallink', 'globallink_settings');
$pd4 = globallink_get_project_director_details();
$type = '';
$name = '';
$doc_id = arg(7);
$sub_rid = arg(4);
$target_locale = arg(5);
$output = "";
$output .= "<table><tr><th>Fields</th><th>Translated Contents</th></tr>";
$sub_sql = db_select('globallink_submission', 'gs');
$sub_sql
->condition('rid', $sub_rid, '=');
$sub_sql
->fields('gs');
$sub_sql_result = $sub_sql
->execute()
->fetchAll();
$submission_row = $sub_sql_result[0];
$submission_ticket = $submission_row->submission_ticket;
if (!check_if_submission_cancelled_or_deleted($pd4, $submission_ticket)) {
$sql = db_select('globallink_document', 'gd');
$sql
->fields('gd');
$sql
->condition('gd.rid', $doc_id, '=');
$sql_results = $sql
->execute()
->fetchAll();
foreach ($sql_results as $row) {
$document_tickets[] = $row->document_ticket;
}
$globallink_arr = globallink_get_ready_translations_for_documents($pd4, $document_tickets);
if (count($globallink_arr) == 0) {
drupal_set_message("No completed targets were found. Please try again after some time.");
return;
}
foreach ($globallink_arr as $globallink) {
if ($globallink->targetLocale == $target_locale) {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
$xml = new SimpleXMLElement($globallink->targetXML);
$entity_type = $globallink->type;
$name = 'name';
$type = 'field';
$metatag = 'metatag';
$title = 'title';
$image = 'field_image';
switch ($entity_type) {
case GLOBALLINK_ENTITY_TYPE_WEBFORM:
$type = 'webform';
break;
case GLOBALLINK_ENTITY_TYPE_MENU:
$type = 'menu';
break;
case GLOBALLINK_ENTITY_TYPE_INTERFACE:
$type = 'interface';
break;
case GLOBALLINK_ENTITY_TYPE_BLOCK:
$type = 'block';
break;
case GLOBALLINK_ENTITY_TYPE_FPP:
$name = 'field';
break;
case GLOBALLINK_ENTITY_TYPE_BEAN:
$name = 'field_name';
break;
case GLOBALLINK_ENTITY_TYPE_FILE_ENTITY:
$name = 'field';
break;
case GLOBALLINK_ENTITY_TYPE_COM:
$name = 'field_name';
break;
default:
$name = 'label';
break;
}
$title_cnt = $xml->{$title}
->count();
if ($title_cnt > 0) {
foreach ($xml->title as $e) {
$title_value = (string) $e;
$title_label = 'title';
$output .= "<tr><td><strong>" . ucfirst($title_label) . "</strong></td><td>" . $title_value . "</td></tr>";
}
}
$elem = $xml->{$type}
->count();
if ($elem > 0) {
foreach ($xml->{$type} as $element) {
$value = (string) $element;
$label = (string) $element
->attributes()->{$name};
$output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
}
}
$metatag_cnt = $xml->{$metatag}
->count();
if ($metatag_cnt > 0) {
foreach ($xml->{$metatag} as $element) {
$name = 'label';
$value = (string) $element;
$label = (string) $element
->attributes()->{$name};
$output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
}
}
if ($metatag_cnt == 0 && $elem == 0) {
drupal_set_message("No content available");
}
$image_cnt = $xml->{$image}
->count();
if ($image_cnt > 0) {
foreach ($xml->{$image} as $element) {
$type = (string) $element
->attributes()->type;
$value = (string) $element;
if ($type == 'alt') {
$type = 'alternate text';
}
$name = (string) $element
->attributes()->field_name;
$label = $name . '-' . $type;
$output .= "<tr><td><strong>" . ucfirst($label) . "</strong></td><td>" . $value . "</td></tr>";
}
}
}
}
}
$output .= "</table>";
$form['preview'] = array(
'#markup' => $output,
);
return $form;
}