class Progress

Same name in this branch
  1. 8.x-1.x src/Plugin/views/field/Progress.php \Drupal\tmgmt\Plugin\views\field\Progress
  2. 8.x-1.x translators/tmgmt_local/src/Plugin/views/field/Progress.php \Drupal\tmgmt_local\Plugin\views\field\Progress

Field handler which shows the progress of a job or job item.

Plugin annotation

@ViewsField("tmgmt_progress");

Hierarchy

  • class \Drupal\tmgmt\Plugin\views\field\StatisticsBase extends \Drupal\views\Plugin\views\field\FieldPluginBase
    • class \Drupal\tmgmt\Plugin\views\field\Progress

Expanded class hierarchy of Progress

11 string references to 'Progress'
JobItemViewsData::getViewsData in src/Entity/ViewsData/JobItemViewsData.php
JobViewsData::getViewsData in src/Entity/ViewsData/JobViewsData.php
LocalTaskItemViewsData::getViewsData in translators/tmgmt_local/src/Entity/ViewsData/LocalTaskItemViewsData.php
LocalTaskViewsData::getViewsData in translators/tmgmt_local/src/Entity/ViewsData/LocalTaskViewsData.php
tmgmt_local.views.schema.yml in translators/tmgmt_local/config/schema/tmgmt_local.views.schema.yml
translators/tmgmt_local/config/schema/tmgmt_local.views.schema.yml

... See full list

File

src/Plugin/views/field/Progress.php, line 14

Namespace

Drupal\tmgmt\Plugin\views\field
View source
class Progress extends StatisticsBase {

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $entity = $this
      ->getEntity($values);

    // If job is continuous we don't show anything.
    if ($entity instanceof JobInterface && $entity
      ->isContinuous()) {
      return;
    }
    if ($entity instanceof JobInterface) {
      switch ($entity
        ->getState()) {
        case JobInterface::STATE_UNPROCESSED:
          return t('Unprocessed');
          break;
        case JobInterface::STATE_REJECTED:
          return t('Rejected');
          break;
        case JobInterface::STATE_ABORTED:
          return t('Aborted');
          break;
        case JobInterface::STATE_FINISHED:
          return t('Finished');
          break;
      }
    }
    elseif ($entity instanceof JobItemInterface) {
      switch ($entity
        ->getState()) {
        case JobItemInterface::STATE_INACTIVE:
          return t('Inactive');
          break;
        case JobItemInterface::STATE_ACCEPTED:
          return t('Accepted');
          break;
        case JobItemInterface::STATE_ABORTED:
          return t('Aborted');
          break;
      }
    }
    $counts = array(
      '@pending' => $entity
        ->getCountPending(),
      '@translated' => $entity
        ->getCountTranslated(),
      '@reviewed' => $entity
        ->getCountReviewed(),
      '@accepted' => $entity
        ->getCountAccepted(),
    );
    $title = t('Pending: @pending, translated: @translated, reviewed: @reviewed, accepted: @accepted.', $counts);
    $sum = array_sum($counts);
    if ($sum == 0) {
      return [];
    }
    $output = [
      '#theme' => 'tmgmt_progress_bar',
      '#attached' => [
        'library' => 'tmgmt/admin',
      ],
      '#title' => $title,
      '#entity' => $entity,
      '#total' => $sum,
      '#parts' => [
        'pending' => [
          'count' => $counts['@pending'],
          'width' => $counts['@pending'] / $sum * 100,
        ],
        'translated' => [
          'count' => $counts['@translated'],
          'width' => $counts['@translated'] / $sum * 100,
        ],
        'reviewed' => [
          'count' => $counts['@reviewed'],
          'width' => $counts['@reviewed'] / $sum * 100,
        ],
        'accepted' => [
          'count' => $counts['@accepted'],
          'width' => $counts['@accepted'] / $sum * 100,
        ],
      ],
    ];
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Progress::render public function
StatisticsBase::preRender public function Prefetch statistics for all jobs.