You are here

public function OpignoModule::insertResultsOptions in Opigno module 8

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

Insert feedback results options.

1 call to OpignoModule::insertResultsOptions()
OpignoModule::updateResultsOptions in src/Entity/OpignoModule.php
Update feedback results options.

File

src/Entity/OpignoModule.php, line 310

Class

OpignoModule
Defines the Module entity.

Namespace

Drupal\opigno_module\Entity

Code

public function insertResultsOptions(FormStateInterface $form_state) {

  /* @var $connection \Drupal\Core\Database\Connection */
  $connection = \Drupal::service('database');
  $insert_query = $connection
    ->insert('opigno_module_result_options')
    ->fields([
    'module_id',
    'module_vid',
    'option_name',
    'option_summary',
    'option_summary_format',
    'option_start',
    'option_end',
  ]);
  $form_values = $form_state
    ->getValues();
  foreach ($form_values['results_options'] as $option) {
    if (!empty($option['option_name'])) {
      if (is_array($option['option_summary'])) {
        $option['option_summary_format'] = $option['option_summary']['format'];
        $option['option_summary'] = $option['option_summary']['value'];
      }
      $insert_query
        ->values([
        'module_id' => $this
          ->id(),
        'module_vid' => $this
          ->getRevisionId(),
        'option_name' => $option['option_name'],
        'option_summary' => $option['option_summary'],
        'option_summary_format' => $option['option_summary_format'],
        'option_start' => $option['option_start'],
        'option_end' => $option['option_end'],
      ]);
    }
  }
  $insert_query
    ->execute();
}