You are here

public static function LPResult::learningPathUserProgress in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/Entity/LPResult.php \Drupal\opigno_learning_path\Entity\LPResult::learningPathUserProgress()

Returns LP user progress.

1 call to LPResult::learningPathUserProgress()
OpignoLearningPathTakeLink::render in src/Plugin/views/field/OpignoLearningPathTakeLink.php
Renders the field.

File

src/Entity/LPResult.php, line 147

Class

LPResult
Defines the Learning Path Content entity.

Namespace

Drupal\opigno_learning_path\Entity

Code

public static function learningPathUserProgress(Group $group, $uid) {
  $progress = 0;
  $contents = LPManagedContent::loadByLearningPathId($group
    ->id());
  if (!empty($contents)) {
    $content_count = count($contents);
    foreach ($contents as $content) {
      $content_type = $content
        ->getLearningPathContentType();
      $user_score = $content_type
        ->getUserScore($uid, $content
        ->getEntityId());
      $progress += $user_score;
    }
    $progress = round($progress / $content_count * 100);
  }
  return $progress;
}