You are here

function tmgmt_local_tmgmt_job_item_update in Translation Management Tool 7

Same name and namespace in other branches
  1. 8 translators/tmgmt_local/tmgmt_local.module \tmgmt_local_tmgmt_job_item_update()

Implements hook_tmgmt_job_item_update().

@todo: Move this to the translator plugin API.

File

translators/tmgmt_local/tmgmt_local.module, line 607
Main module file for the local translation module.

Code

function tmgmt_local_tmgmt_job_item_update(TMGMTJobItem $job_item) {
  if ($job_item
    ->isAccepted() && !$job_item->original
    ->isAccepted()) {
    $tltiid = db_query('SELECT tltiid FROM {tmgmt_local_task_item} ti INNER JOIN {tmgmt_local_task} t ON ti.tltid = t.tltid WHERE t.tjid = :tjid AND ti.tjiid = :tjiid', array(
      ':tjid' => $job_item->tjid,
      ':tjiid' => $job_item->tjiid,
    ))
      ->fetchField();
    if ($tltiid) {
      $task_item = tmgmt_local_task_item_load($tltiid);
      $task_item
        ->closed();
      $task_item
        ->save();

      // Check if the task can be marked as closed as well.
      $query = new EntityFieldQuery();
      $unclosed_tasks = $query
        ->entityCondition('entity_type', 'tmgmt_local_task_item')
        ->propertyCondition('tltid', $task_item->tltid)
        ->propertyCondition('status', TMGMT_LOCAL_TASK_ITEM_STATUS_CLOSED, '<>')
        ->count()
        ->execute();
      if ($unclosed_tasks == 0) {
        $task = $task_item
          ->getTask();
        $task
          ->setStatus(TMGMT_LOCAL_TASK_STATUS_CLOSED);
        $task
          ->save();
      }
    }
  }
}