You are here

public function OpignoModule::getHideResults in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::getHideResults()

Get hide results setting.

File

src/Entity/OpignoModule.php, line 274

Class

OpignoModule
Defines the Module entity.

Namespace

Drupal\opigno_module\Entity

Code

public function getHideResults($answer = NULL) : bool {

  // Show results for admins.
  $account = \Drupal::currentUser();
  if ($account
    ->hasPermission('view module results')) {
    return FALSE;
  }
  $result = (bool) $this
    ->get('hide_results')->value;
  if (!$answer instanceof OpignoAnswer) {
    return $result;
  }

  // Load group.
  // Check if user has role 'student manager' in a learning_path.
  $user_module_status = $answer
    ->getUserModuleStatus();
  if ($user_module_status instanceof UserModuleStatus && $user_module_status
    ->hasField('learning_path') && !empty($group = $user_module_status
    ->get('learning_path')->target_id) && LearningPathAccess::memberHasRole('user_manager', $account, $group)) {
    return FALSE;
  }

  // Return selected value for others.
  return $result;
}