You are here

function tmgmt_local_tmgmt_job_item_update in Translation Management Tool 8

Same name and namespace in other branches
  1. 7 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 411
Main module file for the local translation module.

Code

function tmgmt_local_tmgmt_job_item_update(JobItemInterface $job_item) {
  if ($job_item
    ->isAccepted() && !$job_item->original
    ->isAccepted() || $job_item
    ->isAborted() && !$job_item->original
    ->isAborted()) {
    $tltiid = \Drupal::database()
      ->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
        ->getJobId(),
      ':tjiid' => $job_item
        ->id(),
    ))
      ->fetchField();
    if ($tltiid) {
      $task_item = LocalTaskItem::load($tltiid);
      $task_item
        ->closed();
      $task_item
        ->save();

      // Check if the task can be marked as closed as well.
      $unclosed_tasks = \Drupal::entityQuery('tmgmt_local_task_item')
        ->condition('tltid', $task_item
        ->id())
        ->condition('status', LocalTaskItemInterface::STATUS_CLOSED, '<>')
        ->count()
        ->execute();
      if ($unclosed_tasks == 0) {
        $task = $task_item
          ->getTask();
        $task
          ->setStatus(LocalTaskInterface::STATUS_CLOSED);
        $task
          ->save();
      }
    }
  }
}