public function LocalTaskItem::recalculateStatistics

Recalculates statistical word-data: pending, completed, rejected, closed.

Overrides LocalTaskItemInterface::recalculateStatistics

1 call to LocalTaskItem::recalculateStatistics()
LocalTaskItem::preSave in translators/tmgmt_local/src/Entity/LocalTaskItem.php

File

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

Class

LocalTaskItem
Entity class for the local task item entity.

Namespace

Drupal\tmgmt_local\Entity

Code

public function recalculateStatistics() {

  // Set translatable data from the current entity to calculate words.
  $this
    ->decodeData();
  if (empty($this->unserializedData)) {
    $this->unserializedData = $this
      ->getJobItem()
      ->getData();
  }

  // Consider everything accepted when the job item is accepted.
  if ($this
    ->isCompleted() || $this
    ->isClosed()) {
    $this
      ->set('count_translated', 0);
    $this
      ->set('count_completed', count(array_filter(\Drupal::service('tmgmt.data')
      ->flatten($this->unserializedData), array(
      \Drupal::service('tmgmt.data'),
      'filterData',
    ))));
    $this
      ->set('count_untranslated', 0);
  }
  else {

    // Reset counter values.
    $this
      ->set('count_translated', 0);
    $this
      ->set('count_completed', 0);
    $this
      ->set('word_count', 0);
    $this
      ->set('count_untranslated', count(array_filter(\Drupal::service('tmgmt.data')
      ->flatten($this->unserializedData), array(
      \Drupal::service('tmgmt.data'),
      'filterData',
    ))));
    $this
      ->count($this->unserializedData);
  }
}