You are here

public static function CertificateMapping::getGlobalCertificateMappings in Certificate 4.x

Return the global certificate mappings as object

Return value

array CertificateMapping objects

1 call to CertificateMapping::getGlobalCertificateMappings()
CertificateController::certificatePage in src/Controller/CertificateController.php
Full tab

File

src/Entity/CertificateMapping.php, line 140

Class

CertificateMapping
Defines the credit mapping type entity class.

Namespace

Drupal\certificate\Entity

Code

public static function getGlobalCertificateMappings() {
  $response = [];
  $global_maps = Drupal::config('certificate.settings')
    ->get('maps');

  // filter empty global settings
  $filter = [];
  foreach ($global_maps as $key => $global) {
    $filter[$key] = array_filter($global);
  }
  $clean_array = array_filter($filter);

  // Send entities to match the course configs
  foreach ($clean_array as $map_key => $maps) {
    foreach ($maps as $map_value => $template) {
      $opts = [
        'map_key' => $map_key,
        'map_value' => $map_value,
        'cid' => $template,
      ];
      $cert_map = new CertificateMapping([], 'certificate_mapping');
      foreach ($opts as $key => $val) {
        $cert_map
          ->set($key, $val);
      }
      $response["{$map_key}.{$map_value}"] = $cert_map;
    }
  }
  return $response;
}