You are here

public function UserModuleStatus::getCompletionTime in Opigno module 3.x

Get the time (in seconds) that the user spent to complete the module.

Return value

int The time (in seconds) that the user spent to complete the module.

Overrides UserModuleStatusInterface::getCompletionTime

File

src/Entity/UserModuleStatus.php, line 176

Class

UserModuleStatus
Defines the User module status entity.

Namespace

Drupal\opigno_module\Entity

Code

public function getCompletionTime() : int {
  if (!$this
    ->isFinished()) {
    return 0;
  }

  // We'll consider that the max time that the user can spend on the module
  // is 8h.
  $max = 28800;
  $time = $this
    ->getFinishedTime() - $this
    ->getCreatedTime();
  return $time < $max ? $time : $max;
}