You are here

protected function ImportTrainingForm::setMaxScore in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/ImportTrainingForm.php \Drupal\opigno_module\Form\ImportTrainingForm::setMaxScore()

Build Array of settings to create entity.

Parameters

OpignoActivity $activity: OpignoActivity entity.

OpignoModule $module: OpignoModule entity.

array $activity_content: List of values from imported file.

File

src/Form/ImportTrainingForm.php, line 586

Class

ImportTrainingForm
Import Course form.

Namespace

Drupal\opigno_module\Form

Code

protected function setMaxScore($activity, $module, $activity_content) {

  // Set max score.
  if (!empty($activity_content['max_score'])) {
    $db_connection = \Drupal::service('database');
    unset($activity_content['max_score']['omr_id']);
    $max_score = $activity_content['max_score'];
    $max_score['parent_id'] = $module
      ->id();
    $max_score['child_id'] = $activity
      ->id();
    $max_score['parent_vid'] = $module
      ->get('vid')
      ->getValue()[0]['value'];
    $max_score['child_vid'] = $activity
      ->get('vid')
      ->getValue()[0]['value'];
    try {
      $db_connection
        ->insert('opigno_module_relationship')
        ->fields($max_score)
        ->execute();
    } catch (\Exception $e) {
      \Drupal::logger('opigno_groups_migration')
        ->error($e
        ->getMessage());
    }
  }
}