You are here

protected function LocalTaskItem::count in Translation Management Tool 8

Counts accepted, translated and pending items.

Parse all data items recursively and sums up the counters for accepted, translated and pending items.

Parameters

array $item: The current data item.

1 call to LocalTaskItem::count()
LocalTaskItem::recalculateStatistics in translators/tmgmt_local/src/Entity/LocalTaskItem.php
Recalculates statistical word-data: pending, completed, rejected, closed.

File

translators/tmgmt_local/src/Entity/LocalTaskItem.php, line 302

Class

LocalTaskItem
Entity class for the local task item entity.

Namespace

Drupal\tmgmt_local\Entity

Code

protected function count(array &$item) {
  if (!empty($item['#text'])) {
    if (\Drupal::service('tmgmt.data')
      ->filterData($item)) {

      // Count words of the data item.
      $text = is_array($item['#text']) ? $item['#text']['value'] : $item['#text'];
      $this
        ->set('word_count', $this
        ->get('word_count')->value + \Drupal::service('tmgmt.data')
        ->wordCount($text));

      // Set default states if no state is set.
      if (!isset($item['#status'])) {
        $item['#status'] = TMGMT_DATA_ITEM_STATE_UNTRANSLATED;
      }
      switch ($item['#status']) {
        case TMGMT_DATA_ITEM_STATE_TRANSLATED:
          $this
            ->set('count_untranslated', $this
            ->get('count_untranslated')->value - 1);
          $this
            ->set('count_translated', $this
            ->get('count_translated')->value + 1);
          break;
      }
    }
  }
  else {
    foreach (Element::children($item) as $key) {
      $this
        ->count($item[$key]);
    }
  }
}