You are here

protected function StatisticsPageTrait::getGroupContentStatisticsCertificated in Opigno statistics 3.x

Same name and namespace in other branches
  1. 8 src/StatisticsPageTrait.php \Drupal\opigno_statistics\StatisticsPageTrait::getGroupContentStatisticsCertificated()

Returns group content average statistics for certificated training.

Parameters

\Drupal\group\Entity\Group $group: Group object.

mixed $users: Users IDs array.

\Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent $content: Group content object.

Return value

array Group content average statistics for certificated training.

Throws

\Exception

1 call to StatisticsPageTrait::getGroupContentStatisticsCertificated()
TrainingForm::buildTrainingContent in src/Form/TrainingForm.php
Builds training content.

File

src/StatisticsPageTrait.php, line 372

Class

StatisticsPageTrait
Common helper methods for a statistics pages.

Namespace

Drupal\opigno_statistics

Code

protected function getGroupContentStatisticsCertificated(Group $group, $users, OpignoGroupManagedContent $content) {
  $gid = $group
    ->id();
  $entity_type_manager = \Drupal::entityTypeManager();
  $name = '';
  $completed = 0;
  $score = 0;
  $time = 0;
  foreach ($users as $user) {
    $uid = $user->uid;
    $id = $content
      ->getEntityId();
    $type = $content
      ->getGroupContentTypeId();
    $latest_cert_date = LPStatus::getTrainingStartDate($group, $uid);
    switch ($type) {
      case 'ContentTypeModule':
        if ($opigno_module = OpignoModule::load($id)) {
          $name = $opigno_module
            ->getName();
          $step_info = opigno_learning_path_get_module_step($gid, $uid, $opigno_module, $latest_cert_date);
          $step_score = $opigno_module
            ->getKeepResultsOption() == 'newest' ? $step_info["current attempt score"] : $step_info["best score"];
        }
        break;
      case 'ContentTypeCourse':
        if ($course = Group::load($id)) {
          $name = $course
            ->label();
          $step_info = opigno_learning_path_get_course_step($gid, $uid, $course, $latest_cert_date);
          $step_score = $step_info["best score"];
        }
        break;
      case 'ContentTypeMeeting':
        if ($meeting = $entity_type_manager
          ->getStorage('opigno_moxtra_meeting')
          ->load($id)) {
          $step_info = opigno_learning_path_get_meeting_step($gid, $uid, $meeting);
          $step_score = $step_info["best score"];
        }
        break;
      case 'ContentTypeILT':
        if ($ilt = $entity_type_manager
          ->getStorage('opigno_ilt')
          ->load($id)) {
          $name = $ilt
            ->label();
          $step_info = opigno_learning_path_get_ilt_step($gid, $uid, $ilt);
          $step_score = $step_info["best score"];
        }
        break;
    }
    if (!empty($step_info["completed on"])) {
      $completed++;
    }
    if (!empty($step_score)) {
      $score = $score + $step_score;
    }
    if (!empty($step_info["time spent"])) {
      $time = $time + $step_info["time spent"];
    }
  }
  return [
    'name' => $name,
    'completed' => $completed,
    'score' => $score,
    'time' => $time,
  ];
}