public function JobItem::recalculateStatistics

Recalculate statistical word-data: pending, translated, reviewed, accepted.

Overrides JobItemInterface::recalculateStatistics

1 call to JobItem::recalculateStatistics()

File

src/Entity/JobItem.php, line 1021

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public function recalculateStatistics() {

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

  // Consider everything accepted when the job item is accepted.
  if ($this
    ->isAccepted()) {
    $this->count_pending = 0;
    $this->count_translated = 0;
    $this->count_reviewed = 0;
    $this->count_accepted = count(array_filter(\Drupal::service('tmgmt.data')
      ->flatten($this->unserializedData), array(
      \Drupal::service('tmgmt.data'),
      'filterData',
    )));
  }
  else {

    // Reset counter values.
    $this->count_pending = 0;
    $this->count_translated = 0;
    $this->count_reviewed = 0;
    $this->count_accepted = 0;
    $this->word_count = 0;
    $this->tags_count = 0;
    $this->file_count = 0;
    $this
      ->count($this->unserializedData);
  }
}