You are here

function tmgmt_job_match_item in Translation Management Tool 7

Same name and namespace in other branches
  1. 8 tmgmt.module \tmgmt_job_match_item()

Returns a job which matches the requested source- and target language by user. If no job exists, a new job object will be created.

Parameters

$source_language: The source language from which should be translated.

$target_language: The target language into which should be translated.

$account: (Optional) A user object. Defaults to the currently logged in user.

Return value

TMGMTJob The job entity.

Related topics

2 calls to tmgmt_job_match_item()
TMGMTHelperTestCase::testTMGTJobMatchItem in tests/tmgmt.helper.test
Tests tmgmt_job_match_item()
TMGMTUITestCase::testCheckoutForm in ui/tmgmt_ui.test
Test the page callbacks to create jobs and check them out.

File

./tmgmt.module, line 443
Main module file for the Translation Management module.

Code

function tmgmt_job_match_item($source_language, $target_language, $account = NULL) {
  $account = isset($account) ? $account : $GLOBALS['user'];
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'tmgmt_job')
    ->propertyCondition('source_language', $source_language)
    ->propertyCondition('target_language', $target_language)
    ->propertyCondition('uid', $account->uid)
    ->propertyCondition('state', TMGMT_JOB_STATE_UNPROCESSED)
    ->execute();
  if (!empty($result['tmgmt_job'])) {
    $job = reset($result['tmgmt_job']);
    return tmgmt_job_load($job->tjid);
  }
  return tmgmt_job_create($source_language, $target_language, $account->uid);
}