protected function JobItem::count

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 1056

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

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

      // Count words of the data item.
      if (!empty($item['#text'])) {
        $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']);
      }
      if (isset($item['#file'])) {
        $this
          ->get('file_count')->value++;
      }

      // 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]);
    }
  }
}