You are here

protected function JobItem::count in Translation Management Tool 8

Sums up the counters for accepted, translated and pending items.

Parameters

array $item: The current data item.

1 call to JobItem::count()
JobItem::recalculateStatistics in src/Entity/JobItem.php
Recalculate statistical word-data: pending, translated, reviewed, accepted.

File

src/Entity/JobItem.php, line 1035

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

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

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

      // Count HTML tags of the data item.
      $this->tags_count->value += \Drupal::service('tmgmt.data')
        ->tagsCount($item['#text']);

      // Set default states if no state is set.
      if (!isset($item['#status'])) {

        // Translation is present.
        if (!empty($item['#translation'])) {
          $item['#status'] = TMGMT_DATA_ITEM_STATE_TRANSLATED;
        }
        else {
          $item['#status'] = TMGMT_DATA_ITEM_STATE_PENDING;
        }
      }
      switch ($item['#status']) {
        case TMGMT_DATA_ITEM_STATE_REVIEWED:
          $this->count_reviewed->value++;
          break;
        case TMGMT_DATA_ITEM_STATE_TRANSLATED:
          $this->count_translated->value++;
          break;
        default:
          $this->count_pending->value++;
          break;
      }
    }
  }
  elseif (is_array($item)) {
    foreach (Element::children($item) as $key) {
      $this
        ->count($item[$key]);
    }
  }
}