function globallink_create_submission in GlobalLink Connect for Drupal 7.7
1 call to globallink_create_submission()
File
- ./
globallink_background_jobs.inc, line 1207 - To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor.
Code
function globallink_create_submission($sub_arr) {
$node_types = globallink_get_translatable_node_types_and_names('');
foreach ($sub_arr as $target_locale => $arr) {
$submission_info = $arr['globallink_submission'];
$document_info = $arr['globallink_document'];
$source_lang_name = globallink_get_drupal_locale_name($submission_info['source_lang_code']);
$target_lang_name = globallink_get_drupal_locale_name($target_locale);
$sub_rid = db_insert('globallink_submission')
->fields(array(
'submission' => $submission_info['submission'],
'pd_submission_id' => $submission_info['pd_submission_id'],
'submission_ticket' => $submission_info['submission_ticket'],
'source_lang_code' => $submission_info['source_lang_code'],
'source_lang_name' => $source_lang_name,
'sub_target_lang_code' => $target_locale,
'sub_target_lang_name' => $target_lang_name,
'project_code' => $submission_info['project_code'],
'project_name' => $submission_info['project_name'],
'due_date' => $submission_info['due_date'],
'status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
foreach ($document_info as $globallink) {
$type_name = '';
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_NODE || $globallink->metadata == GLOBALLINK_ENTITY_TYPE_ENTITY) {
if (is_array($node_types) && isset($node_types[$globallink->type])) {
$type_name = $node_types[$globallink->type];
}
$id = $globallink->nid;
$t_query = db_select('globallink_core', 'tc');
$t_query
->condition('source', $submission_info['source_lang_code'], '=');
$t_query
->condition('target', $target_locale, '=');
$t_query
->fields('tc');
$t_query
->orderBy('nid', 'ASC');
$results = $t_query
->execute()
->fetchAll();
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_NODE) {
if (count($results) > 0) {
db_delete('globallink_core')
->condition('nid', $id, '=')
->condition('source', $submission_info['source_lang_code'], '=')
->condition('target', $target_locale, '=')
->execute();
}
db_insert('globallink_core')
->fields(array(
'nid' => $id,
'vid' => $globallink->vid,
'source' => $submission_info['source_lang_code'],
'target' => $target_locale,
'last_modified' => REQUEST_TIME,
'changed' => 0,
))
->execute();
}
elseif ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_ENTITY) {
if (count($results) > 0) {
db_delete('globallink_core')
->condition('nid', $id, '=')
->condition('source', $submission_info['source_lang_code'], '=')
->condition('target', $target_locale, '=')
->execute();
}
db_insert('globallink_core')
->fields(array(
'nid' => $id,
'vid' => $globallink->vid,
'source' => $submission_info['source_lang_code'],
'target' => $target_locale,
'last_modified' => REQUEST_TIME,
'changed' => 0,
))
->execute();
}
}
else {
$id = $globallink->otherObjectId;
}
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
$titles = $globallink->title;
foreach ($titles as $key => $title) {
db_insert('globallink_document')
->fields(array(
'submission_rid' => $sub_rid,
'document_ticket' => $globallink->documentTicket,
'entity_type' => $globallink->metadata,
'entity_type_name' => globallink_get_entity_type_name($globallink->metadata),
'object_type' => $globallink->type,
'object_type_name' => $type_name,
'object_id' => $key,
'object_parent_id' => $id,
'object_version_id' => $globallink->vid,
'object_title' => $title,
'target_lang_code' => $target_locale,
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'target_last_sent' => REQUEST_TIME,
'target_last_updated' => REQUEST_TIME,
))
->execute();
}
}
else {
db_insert('globallink_document')
->fields(array(
'submission_rid' => $sub_rid,
'document_ticket' => $globallink->documentTicket,
'entity_type' => $globallink->metadata,
'entity_type_name' => globallink_get_entity_type_name($globallink->metadata),
'object_type' => $globallink->type,
'object_type_name' => $type_name,
'object_id' => $id,
'object_parent_id' => $id,
'object_version_id' => $globallink->vid,
'object_title' => $globallink->title,
'target_lang_code' => $target_locale,
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'target_last_sent' => REQUEST_TIME,
'target_last_updated' => REQUEST_TIME,
))
->execute();
}
}
}
}