You are here

function opigno_learning_path_completed_on in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 opigno_learning_path.module \opigno_learning_path_completed_on()

Calculates learning path completion date.

Parameters

int $group_id: Group ID.

int $uid: User ID.

Return value

int Completion time.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

6 calls to opigno_learning_path_completed_on()
LPStatus::getCertificateExpireTimestamp in src/Entity/LPStatus.php
Returns training certificate expire timestamp.
opigno_learning_path_group_access in ./opigno_learning_path.module
Restricts user access to Learning Path and it's content.
opigno_learning_path_save_achievements in ./opigno_learning_path.module
Stores training achievements data.
Progress::getProgressBuildAchievementsPage in src/Progress.php
Get get progress for achievements page.
Progress::getProgressBuildGroupPage in src/Progress.php
Get get progress for group page.

... See full list

File

./opigno_learning_path.module, line 3096
Contains opigno_learning_path.module.

Code

function opigno_learning_path_completed_on($group_id, $uid, $only_mandatory = FALSE) {

  // Get all mandatory steps.
  $steps = opigno_learning_path_get_steps($group_id, $uid);
  $mandatory_steps = array_filter($steps, function ($step) {
    return $step['mandatory'];
  });
  $completed_on = 0;

  // If has mandatory steps.
  if (!empty($mandatory_steps)) {
    $completed_steps = array_filter($mandatory_steps, function ($step) {
      return $step['completed on'] > 0;
    });

    // If all mandatory steps completed.
    if (count($completed_steps) === count($mandatory_steps)) {

      // Get completion time of the last step.
      if (!$only_mandatory) {
        $completed_on = max(array_map(function ($step) {
          return $step['completed on'];
        }, $steps));
      }
      else {
        $completed_on = max(array_map(function ($step) {
          return $step['completed on'];
        }, $mandatory_steps));
      }
    }
  }
  return $completed_on;
}