ILTResult.php in Opigno Instructor-led Trainings 8
File
src/Entity/ILTResult.php
View source
<?php
namespace Drupal\opigno_ilt\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\opigno_ilt\ILTInterface;
use Drupal\opigno_ilt\ILTResultInterface;
use Drupal\user\UserInterface;
class ILTResult extends ContentEntityBase implements ILTResultInterface {
public function getILT() {
return $this
->get('opigno_ilt')->entity;
}
public function setILT(ILTInterface $opigno_ilt) {
$this
->set('opigno_ilt', $opigno_ilt
->id());
return $this;
}
public function getILTId() {
return $this
->get('opigno_ilt')->target_id;
}
public function setILTId($id) {
$this
->set('opigno_ilt', $id);
return $this;
}
public function getUser() {
return $this
->get('user_id')->entity;
}
public function setUser(UserInterface $account) {
$this
->set('user_id', $account
->id());
return $this;
}
public function getUserId() {
return $this
->get('user_id')->target_id;
}
public function setUserId($uid) {
$this
->set('user_id', $uid);
return $this;
}
public function getStatus() {
return $this
->get('status')->value;
}
public function getStatusString() {
return $this
->get('status')->value == 1 ? t('Attended') : t('Absent');
}
public function setStatus($value) {
$this
->set('status', $value);
return $this;
}
public function getScore() {
return $this
->get('score')->value;
}
public function setScore($value) {
$this
->set('score', $value);
return $this;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the ILT Result entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the ILT Result entity.'))
->setReadOnly(TRUE);
$fields['opigno_ilt'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('ILT'))
->setDescription(t('The ILT of the ILT Result entity.'))
->setSettings([
'handler' => 'default',
'target_type' => 'opigno_ilt',
])
->setRequired(TRUE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User'))
->setDescription(t('The User of the ILT Result entity.'))
->setSettings([
'handler' => 'default',
'target_type' => 'user',
])
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Status'))
->setDescription(t('The Status of the ILT Result entity.'));
$fields['score'] = BaseFieldDefinition::create('integer')
->setLabel(t('Score'))
->setDescription(t('The Score of the ILT Result entity.'));
return $fields;
}
}