public function Progress::render

Same name in this branch
  1. 8.x-1.x src/Plugin/views/field/Progress.php \Drupal\tmgmt\Plugin\views\field\Progress::render()
  2. 8.x-1.x translators/tmgmt_local/src/Plugin/views/field/Progress.php \Drupal\tmgmt_local\Plugin\views\field\Progress::render()

File

translators/tmgmt_local/src/Plugin/views/field/Progress.php, line 20

Class

Progress
Field handler which shows the progress of a job or job item.

Namespace

Drupal\tmgmt_local\Plugin\views\field

Code

public function render(ResultRow $values) {
  $entity = $values->_entity;
  if ($entity
    ->getEntityTypeId() == 'tmgmt_local_task' && $entity
    ->getStatus() == LocalTaskInterface::STATUS_CLOSED || $entity
    ->getEntityTypeId() == 'tmgmt_local_task_item' && $entity
    ->getStatus() == LocalTaskItemInterface::STATUS_CLOSED) {
    return t('Closed');
  }
  $counts = array(
    '@untranslated' => $entity
      ->getCountUntranslated(),
    '@translated' => $entity
      ->getCountTranslated(),
    '@completed' => $entity
      ->getCountCompleted(),
  );
  $title = t('Untranslated: @untranslated, translated: @translated, completed: @completed.', $counts);
  $one_hundred_percent = array_sum($counts);
  if ($one_hundred_percent == 0) {
    return [];
  }
  $output = array(
    '#theme' => 'tmgmt_local_progress_bar',
    '#attached' => array(
      'library' => 'tmgmt/admin',
    ),
    '#title' => $title,
    '#count_untranslated' => $counts['@untranslated'],
    '#count_translated' => $counts['@translated'],
    '#count_completed' => $counts['@completed'],
    '#width_untranslated' => $counts['@untranslated'] / $one_hundred_percent * 100,
    '#width_translated' => $counts['@translated'] / $one_hundred_percent * 100,
    '#width_completed' => $counts['@completed'] / $one_hundred_percent * 100,
  );
  return $output;
}