CourseCreditCertificateMapper.php in Certificate 4.x
File
src/Plugin/certificate/CertificateMapper/CourseCreditCertificateMapper.php
View source
<?php
namespace Drupal\certificate\Plugin\certificate\CertificateMapper;
use Drupal;
use Drupal\certificate\Plugin\CertificateMapperBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\course_credit\Entity\CourseCreditType;
class CourseCreditCertificateMapper extends CertificateMapperBase {
public function getMapKeys() {
$options = [];
$credits = CourseCreditType::loadMultiple();
$credit_types = Drupal::entityTypeManager()
->getStorage('course_credit_type')
->loadByProperties([
'status' => 1,
]);
foreach ($credit_types as $key => $type) {
$options[$key] = $type
->label();
}
return $options;
}
public function processMapping(ContentEntityInterface $entity, AccountInterface $account) {
if (Drupal::moduleHandler()
->moduleExists('course_credit')) {
$options = [];
$enrollment = $entity
->getEnrollment($account);
$awarded = $enrollment
->get('course_credit_awarded')
->referencedEntities();
foreach ($awarded as $credit) {
$credit_type = $credit
->get('type')
->referencedEntities()[0];
$options[] = $credit_type
->id();
}
return $options;
}
}
}
Classes
Name |
Description |
CourseCreditCertificateMapper |
Plugin annotation
@CertificateMapper(
id = "course_credit_awarded",
label = @Translation("Awarded course credit"),
description = @Translation("Using this mapping will award a certificate based on the credit type the user claimed after completing a… |