class ContentTypeILT in Opigno Instructor-led Trainings 8
Same name and namespace in other branches
- 3.x src/Plugin/OpignoGroupManagerContentType/ContentTypeILT.php \Drupal\opigno_ilt\Plugin\OpignoGroupManagerContentType\ContentTypeILT
Class ContentTypeILT.
Plugin annotation
@OpignoGroupManagerContentType(
id = "ContentTypeILT",
entity_type = "opigno_ilt",
readable_name = "Instructor-Led Training",
description = "Contains the Instructor-Led Trainings",
allowed_group_types = {
"learning_path"
},
group_content_plugin_id = "opigno_ilt_group"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\opigno_group_manager\ContentTypeBase implements ContentTypeInterface
- class \Drupal\opigno_ilt\Plugin\OpignoGroupManagerContentType\ContentTypeILT
- class \Drupal\opigno_group_manager\ContentTypeBase implements ContentTypeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ContentTypeILT
File
- src/
Plugin/ OpignoGroupManagerContentType/ ContentTypeILT.php, line 26
Namespace
Drupal\opigno_ilt\Plugin\OpignoGroupManagerContentTypeView source
class ContentTypeILT extends ContentTypeBase {
/**
* {@inheritdoc}
*/
public function shouldShowNext() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getUserScore($user_id, $entity_id) {
/** @var \Drupal\opigno_ilt\ILTResultInterface[] $results */
$results = \Drupal::entityTypeManager()
->getStorage('opigno_ilt_result')
->loadByProperties([
'user_id' => $user_id,
'opigno_ilt' => $entity_id,
]);
$best_score = 0;
foreach ($results as $result) {
$score = $result
->getScore();
if ($score > $best_score) {
$best_score = $score;
}
}
return $best_score / 100;
}
/**
* {@inheritdoc}
*/
public function getViewContentUrl($entity_id) {
return Url::fromRoute('entity.opigno_ilt.canonical', [
'opigno_ilt' => $entity_id,
]);
}
/**
* {@inheritdoc}
*/
public function getStartContentUrl($content_id, $group_id = NULL) {
return Url::fromRoute('entity.opigno_ilt.canonical', [
'opigno_ilt' => $content_id,
]);
}
/**
* {@inheritdoc}
*
* @param int|\Drupal\opigno_ilt\ILTInterface $entity
* The entity ID or entity instance.
*/
public function getContent($entity) {
// If the value is the ILT ID, load the ILT.
if (is_numeric($entity) || is_string($entity)) {
/** @var \Drupal\opigno_ilt\ILTInterface $entity */
$entity = ILT::load($entity);
}
if ($entity === NULL || $entity === FALSE) {
return FALSE;
}
return new OpignoGroupContent($this
->getPluginId(), $this
->getEntityType(), $entity
->id(), $entity
->label(), $this
->getDefaultModuleImageUrl(), t('Default image'));
}
/**
* Returns default image url.
*/
public function getDefaultModuleImageUrl() {
$request = \Drupal::request();
$path = \Drupal::service('module_handler')
->getModule('opigno_module')
->getPath();
return $request
->getBasePath() . '/' . $path . '/img/img_module.svg';
}
/**
* {@inheritdoc}
*/
public function getContentFromRequest(Request $request) {
$entity = $request
->get('opigno_ilt');
if ($entity === NULL || $entity === FALSE) {
return FALSE;
}
return $this
->getContent($entity);
}
/**
* {@inheritdoc}
*/
public function getFormObject($entity_id = NULL) {
if (empty($entity_id)) {
$form = \Drupal::entityTypeManager()
->getFormObject($this
->getEntityType(), 'add');
$entity = ILT::create();
}
else {
$form = \Drupal::entityTypeManager()
->getFormObject($this
->getEntityType(), 'edit');
$entity = ILT::load($entity_id);
}
$form
->setEntity($entity);
return $form;
}
/**
* {@inheritdoc}
*/
public function getAllContents() {
try {
/** @var \Drupal\opigno_ilt\ILTInterface[] $entities */
$entities = \Drupal::entityTypeManager()
->getStorage('opigno_ilt')
->loadMultiple();
} catch (InvalidPluginDefinitionException $e) {
// TODO: Log the error.
return FALSE;
}
$contents = [];
foreach ($entities as $entity) {
$contents[] = $this
->getContent($entity);
}
return $contents;
}
/**
* {@inheritdoc}
*/
public function getAvailableContents() {
return $this
->getAllContents();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentTypeBase:: |
public | function | Returns allowed group types. | |
ContentTypeBase:: |
public | function | Returns description. | |
ContentTypeBase:: |
public | function | Returns entity type. | |
ContentTypeBase:: |
public | function | Returns plugin id. | |
ContentTypeBase:: |
public | function | Returns ID. | |
ContentTypeBase:: |
public | function | Returns readable name. | |
ContentTypeBase:: |
public | function | Answer if the current page should show the "finish" button. | |
ContentTypeILT:: |
public | function |
Get all the entities in an array of LearningPathContent. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Get all the published entities in an array of LearningPathContent. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Try to get the content from a Request object. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function | Returns default image url. | |
ContentTypeILT:: |
public | function |
Get the form object based on the entity ID. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Get the URL object for starting the quiz. Overrides ContentTypeBase:: |
|
ContentTypeILT:: |
public | function |
Get the score of the user for a specific entity. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Get the URL object of the main view page of a specific entity. Overrides ContentTypeInterface:: |
|
ContentTypeILT:: |
public | function |
Return TRUE if the page should show the "next" action button. Overrides ContentTypeInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |