Commit a00daaed authored by mathieso's avatar mathieso

Still refactoring.

parent 58c5265c
......@@ -2607,6 +2607,8 @@ function _skilling_validate_lesson_form(&$form, FormStateInterface $form_state)
/**
* Implements hook_entity_presave().
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function skilling_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
global $dueData;
......
......@@ -3,8 +3,8 @@ services:
class: Drupal\skilling\Utilities
arguments: [ '@entity_type.manager', '@date.formatter', '@module_handler', '@user.data', '@path.current', '@current_route_match', '@messenger']
skilling.current_class:
class: Drupal\skilling\CurrentClass
arguments: [ '@entity_type.manager', '@user.data', '@skilling.utilities', '@skilling.skilling_current_user', '@skilling.class_utilities']
class: Drupal\skilling\SkillingClass\CurrentClass
arguments: [ '@entity_type.manager', '@user.data', '@skilling.utilities', '@skilling.skilling_current_user']
skilling.skillingparser:
class: Drupal\skilling\SkillingParser\SkillingParser
arguments: ['@token', '@entity_type.manager', '@skilling.utilities', '@skilling.skilling_current_user', '@skilling.skilling_user_factory', '@skilling.ajax_security']
......@@ -120,9 +120,9 @@ services:
skilling.field_access_special_case_checker:
class: Drupal\skilling\Access\FieldAccessSpecialCaseChecker
arguments: ['@path.validator', '@path.current', '@skilling.skilling_current_user', '@request_stack', '@skilling.utilities']
skilling.class_utilities:
class: Drupal\skilling\SkillingClassUtilities
arguments: ['@entity_type.manager', '@skilling.utilities', '@skilling.skilling_current_user', '@messenger']
skilling.class_factory:
class: Drupal\skilling\SkillingClass\SkillingClassFactory
arguments: ['@entity_type.manager', '@skilling.skilling_user_factory']
skilling.notice:
class: Drupal\skilling\Notice
arguments: ['@entity_type.manager', '@skilling.skilling_current_user', '@skilling.utilities', '@skilling.access_checker']
......
......@@ -16,7 +16,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\file\Entity\File;
use Drupal\node\NodeInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\skilling\CurrentClassOld;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\Exception\SkillingInvalidValueException;
use Drupal\skilling\Exception\SkillingNotFoundException;
......@@ -27,6 +26,7 @@ use Drupal\skilling\SkillingParser\SkillingParser;
use Drupal\skilling\SkillingUser;
use Drupal\skilling\SkillingUserFactory;
use Drupal\skilling\Utilities as SkillingUtilities;
use src\SkillingClass\SkillingCurrentClass;
/**
* A service to check the current user's access to entities, blocks, and fields.
......@@ -57,7 +57,7 @@ class SkillingAccessChecker {
* If the current user is enrolled in more than one class, s/he chooses
* one of them to be the context for the site.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -117,7 +117,7 @@ class SkillingAccessChecker {
* The entity type manager service.
* @param \Drupal\skilling\SkillingCurrentUser $currentUser
* The current user service.
* @param \Drupal\skilling\CurrentClassOld $currentClass
* @param SkillingCurrentClass $currentClass
* The current class service.
* @param \Drupal\skilling\Access\SkillingCheckUserRelationships $checkUserRelationshipsService
* Service to check relationships between users.
......@@ -140,7 +140,7 @@ class SkillingAccessChecker {
public function __construct(
EntityTypeManagerInterface $entityTypeTanager,
SkillingCurrentUser $currentUser,
CurrentClassOld $currentClass,
SkillingCurrentClass $currentClass,
SkillingCheckUserRelationships $checkUserRelationshipsService,
ConfigFactory $configFactory,
SkillingUserFactory $skillingUserFactory,
......
......@@ -12,6 +12,7 @@ use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\Utilities as SkillingUtilities;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use src\SkillingClass\SkillingCurrentClass;
/**
* Completion score service.
......@@ -80,7 +81,7 @@ class CompletionScore {
/**
* The current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -109,7 +110,7 @@ class CompletionScore {
* User factory service.
* @param \Drupal\skilling\SkillingCurrentUser $skilling_current_user
* The Skilling current user service.
* @param \Drupal\Skilling\CurrentClassOld $current_class
* @param SkillingCurrentClass $current_class
* The current class service.
* @param \Drupal\skilling\Enrollment $enrollmentService
* The enrollment service.
......@@ -121,7 +122,7 @@ class CompletionScore {
SkillingUtilities $skillingUtilities,
SkillingUserFactory $skillingUserFactory,
SkillingCurrentUser $skilling_current_user,
CurrentClassOld $current_class,
SkillingCurrentClass $current_class,
Enrollment $enrollmentService,
MessengerInterface $messenger
) {
......@@ -546,23 +547,6 @@ class CompletionScore {
return $completionScore;
}
// /**
// * Get whether progress score for current enrollment is based on
// * required exercises only.
// *
// * @return bool
// * True if progress score for current enrollment is based on
// * required exercises only.
// */
// public function getIsProgressScoreBasedOnRequiredOnlyForCurrentEnrollment() {
// $enrollment = $this->currentClass->getCurrentEnrollment();
// $baseOnRequired = $enrollment
// ->get(SkillingConstants::FIELD_BASE_PROGRESS_ON_REQUIRED_ONLY)
// ->getValue()[0]['value'];
// $baseOnRequired = $baseOnRequired === "1";
// return $baseOnRequired;
// }
/**
* Get emotional interpretation of score.
*
......@@ -593,7 +577,6 @@ class CompletionScore {
$fileName = 'very-sad.svg';
$text = $this->t("Argh! You're way behind.");
}
// $text .= ' ' . $this->t('Completion score: @cs', ['@cs' => $completionScore]);
return [$fileName, $text];
}
......
......@@ -3,7 +3,7 @@
namespace Drupal\skilling\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\skilling\CurrentClassOld;
use src\SkillingClass\SkillingCurrentClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
......@@ -15,9 +15,9 @@ use Drupal\Core\Messenger\MessengerInterface;
class ClassSelectionController extends ControllerBase {
/**
* The current class service.
* The current class.
*
* @var \Drupal]skilling\CurrentClass
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -31,12 +31,12 @@ class ClassSelectionController extends ControllerBase {
/**
* Constructs a new ClassSelectionController object.
*
* @param \Drupal\skilling\CurrentClassOld $currentClass
* @param SkillingCurrentClass $currentClass
* The current class service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(CurrentClassOld $currentClass, MessengerInterface $messenger) {
public function __construct(SkillingCurrentClass $currentClass, MessengerInterface $messenger) {
$this->currentClass = $currentClass;
$this->messenger = $messenger;
}
......
......@@ -9,6 +9,7 @@ use DateTime;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingNotFoundException;
use src\SkillingClass\SkillingCurrentClass;
/**
* Class Exercises.
......@@ -27,7 +28,7 @@ class Exercises {
/**
* Current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -53,28 +54,28 @@ class Exercises {
/**
* Constructs a new Exercise object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
* Entity type manager service.
* @param \Drupal\skilling\CurrentClassOld $skilling_current_class
* @param \src\SkillingClass\SkillingCurrentClass $skillingCurrentClassIn
* Current class service.
* @param \Drupal\skilling\SkillingCurrentUser $skilling_skilling_current_user
* @param \Drupal\skilling\SkillingCurrentUser $skillingCurrentUserIn
* Skilling current user service.
* @param \Drupal\skilling\Submissions $submissionsService
* @param \Drupal\skilling\Submissions $submissionsServiceIn
* Submissions service.
* @param \Drupal\skilling\Timeline $timelineService
* @param \Drupal\skilling\Timeline $timelineServiceIn
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
CurrentClassOld $skilling_current_class,
SkillingCurrentUser $skilling_skilling_current_user,
Submissions $submissionsService,
Timeline $timelineService
EntityTypeManagerInterface $entityTypeManagerIn,
SkillingCurrentClass $skillingCurrentClassIn,
SkillingCurrentUser $skillingCurrentUserIn,
Submissions $submissionsServiceIn,
Timeline $timelineServiceIn
) {
$this->entityTypeManager = $entity_type_manager;
$this->currentClass = $skilling_current_class;
$this->currentUser = $skilling_skilling_current_user;
$this->submissionsService = $submissionsService;
$this->timelineService = $timelineService;
$this->entityTypeManager = $entityTypeManagerIn;
$this->currentClass = $skillingCurrentClassIn;
$this->currentUser = $skillingCurrentUserIn;
$this->submissionsService = $submissionsServiceIn;
$this->timelineService = $timelineServiceIn;
}
/**
......@@ -90,16 +91,8 @@ class Exercises {
$result['problem_message'] = $this->t('Calendar only available when logged in.');
return $result;
}
// Get the class.
/** @var \Drupal\node\Entity\Node $class */
$class = $this->currentClass->getWrappedDrupalClassNode();
if (!$class) {
$result['problem_message'] = $this->t('No current class.');
return $result;
}
// Get the exercise due paragraph items for the class.
list($exerciseDuesForClass, $publishedExerciseNidsForClass)
= $this->currentClass->getExerciseDues();
$exerciseDuesForClass = $this->currentClass->getExerciseDueRecords();
// Load all published exercises.
$allPublishedExerciseNids = $this->entityTypeManager->getStorage('node')
->getQuery()
......@@ -128,6 +121,7 @@ class Exercises {
// Find the exercise nids for completed submissions.
$exerciseNidsComplete = [];
foreach ($submissions as $submission) {
// TODO: replace
$complete = $submission->field_complete->value;
if ($complete) {
$exerciseNidsComplete[] = $submission->field_exercise->target_id;
......@@ -157,7 +151,7 @@ class Exercises {
// Find due data for the exercise
$dueDataForExercise = NULL;
foreach ($exerciseDuesForClass as $exerciseDue) {
if ($exerciseDue['exerciseId'] == $exerciseNid) {
if ($exerciseDue->getExerciseId() == $exerciseNid) {
$dueDataForExercise = $exerciseDue;
break;
}
......
......@@ -4,7 +4,7 @@ namespace Drupal\skilling\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\skilling\CurrentClassOld;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\SkillingConstants;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\skilling\Utilities;
......@@ -37,7 +37,7 @@ class ClassSelector extends BlockBase implements ContainerFactoryPluginInterface
/**
* Current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var \src\SkillingClass\SkillingCurrentClass
*/
protected $currentClass;
......@@ -50,17 +50,20 @@ class ClassSelector extends BlockBase implements ContainerFactoryPluginInterface
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
* @param \Drupal\skilling\Utilities $skilling_utilities
* @param \Drupal\skilling\Utilities $skillingUtilitiesIn
* The Skilling utilities service
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\skilling\CurrentClassOld $current_class
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* @param \src\SkillingClass\SkillingCurrentClass $currentClass
* Current class service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Utilities $skilling_utilities, EntityTypeManagerInterface $entity_type_manager, CurrentClassOld $current_class) {
public function __construct(array $configuration, $plugin_id, $plugin_definition,
Utilities $skillingUtilitiesIn,
EntityTypeManagerInterface $entityTypeManagerIn,
SkillingCurrentClass $currentClassIn) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->skillingUtilities = $skilling_utilities;
$this->entityTypeManager = $entity_type_manager;
$this->currentClass = $current_class;
$this->skillingUtilities = $skillingUtilitiesIn;
$this->entityTypeManager = $entityTypeManagerIn;
$this->currentClass = $currentClassIn;
}
/**
......@@ -100,7 +103,7 @@ class ClassSelector extends BlockBase implements ContainerFactoryPluginInterface
$build['class_selector'] = [
'#theme' => 'class_selector',
'#class_list' => $renderData,
'#current_class_nid' => $this->currentClass->getCurrentClassId(),
'#current_class_nid' => $this->currentClass->id(),
'#return_url' => $returnPath,
'#cache' => [
'tags' => [SkillingConstants::BLOCK_CURRENT_CLASS_CACHE_TAG],
......
......@@ -6,7 +6,7 @@ use DateInterval;
use DateTime;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\skilling\CurrentClassOld;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingCurrentUser;
......@@ -63,7 +63,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
/**
* Skilling current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -98,7 +98,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
* Submissions service.
* @param \Drupal\Core\Render\Renderer $renderer
* The renderer service.
* @param \Drupal\skilling\CurrentClassOld $currentClass
* @param SkillingCurrentClass $currentClass
*/
public function __construct(
array $configuration,
......@@ -108,7 +108,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
SkillingCurrentUser $skillingCurrentUser,
Submissions $submissionsService,
Renderer $renderer,
CurrentClassOld $currentClass
SkillingCurrentClass $currentClass
) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->entityTypeManager = $entityTypeManager;
......@@ -226,7 +226,8 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
$exerciseNids = $this->submissionsService->extractExerciseNidsFromSubmissions($submissions);
$exercises = $this->entityTypeManager->getStorage('node')
->loadMultiple($exerciseNids);
list($classExerciseDues, $classExerciseNids) = $this->currentClass->getExerciseDues();
// Get exercise due records for the current class.
$classExerciseDues = $this->currentClass->getExerciseDueRecords();
if (isset($this->where)) {
foreach ($this->where as $where_group => $where) {
foreach ($where['conditions'] as $condition) {
......@@ -257,7 +258,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
// Find the exercise due data for the exercise.
$exerciseDue = NULL;
foreach ($classExerciseDues as $record) {
if ($record['exerciseId'] == $exercise->id()) {
if ($record->getExerciseId() == $exercise->id()) {
$exerciseDue = $record;
break;
}
......@@ -266,7 +267,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
->getSubmissionStatusForStudentExercise(
$this->skillingCurrentUser,
$exercise->id(),
$this->currentClass->getWrappedDrupalClassNode()
$this->currentClass
);
if (isset($filters['status'])) {
$valueToFilterFor = $filters['status'][0];
......@@ -275,7 +276,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
}
}
// Compute max submissions allowed.
$exerciseMaxSubs = $exerciseDue['maxSubs'];
$exerciseMaxSubs = $exerciseDue->getMaximumSubmissions();
if (is_null($exerciseMaxSubs)) {
$exerciseMaxSubs = $this->currentClass->getDefaultMaxSubmissions();
}
......@@ -294,7 +295,9 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
}
else {
$classStartDate = new DateTime($this->currentClass->getStartDate());
$dueDaysInterval = new DateInterval('P' . ($exerciseDue['day'] - 1) . 'D');
$dueDaysInterval = new DateInterval(
'P' . ($exerciseDue->getDay() - 1) . 'D'
);
$exerciseDueDate = clone $classStartDate;
$exerciseDueDate->add($dueDaysInterval);
$row['exercise_due_date'] = $exerciseDueDate->getTimestamp();
......
This diff is collapsed.
......@@ -46,32 +46,37 @@ class SkillingClass {
protected $skillingUserFactory;
/**
* Constructor.
*
* @param \Drupal\Core\Entity\EntityInterface $wrappedDrupalClassIn
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
*
* @param \Drupal\skilling\SkillingUserFactory $skillingUserFactoryIn
* * @param \Drupal\skilling\SkillingUserFactory $skillingUserFactoryIn
*
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
public function __construct(
EntityInterface $wrappedDrupalClassIn,
EntityTypeManagerInterface $entityTypeManagerIn,
SkillingUserFactory $skillingUserFactoryIn
) {
if ($wrappedDrupalClassIn->bundle() !== SkillingConstants::CLASS_CONTENT_TYPE) {
// Remember services.
$this->entityTypeManager = $entityTypeManagerIn;
$this->skillingUserFactory = $skillingUserFactoryIn;
}
/**
* @param \Drupal\node\NodeInterface $classNode
*
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
public function setWrappedClassNode(NodeInterface $classNode) {
if ($classNode->bundle() !== SkillingConstants::CLASS_CONTENT_TYPE) {
throw new SkillingWrongTypeException(
'Expected class node, got ' . $wrappedDrupalClassIn->bundle(),
'Expected class node, got ' . $classNode->bundle(),
__FILE__, __LINE__
);
}
$this->wrappedDrupalClassNode = $wrappedDrupalClassIn;
// Remember services.
$this->entityTypeManager = $entityTypeManagerIn;
$this->skillingUserFactory = $skillingUserFactoryIn;
$this->wrappedDrupalClassNode = $classNode;
}
/**
......@@ -88,6 +93,10 @@ class SkillingClass {
return $this->wrappedDrupalClassNode->id();
}
public function getTitle() {
return $this->wrappedDrupalClassNode->getTitle();
}
/**
* Get the current class' cache tags.
*
......@@ -171,7 +180,7 @@ class SkillingClass {
* Get the exercise due paragraph items for the class.
* Published exercises only.
*
* @return array
* @return ExerciseDueRecord[]
* The exercise dues paragraph items, and exercise nids.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
......@@ -182,8 +191,9 @@ class SkillingClass {
* @throws \Drupal\skilling\Exception\SkillingValueMissingException
*/
public function getExerciseDueRecords() {
/** @var ExerciseDueRecord[] $exerciseDues */
$exerciseDues = [];
$exerciseNids = [];
// $exerciseNids = [];
$exerciseDueParaRefs = $this->wrappedDrupalClassNode->get(SkillingConstants::FIELD_EXERCISES_DUE)->getValue();
foreach ($exerciseDueParaRefs as $exerciseDueParaRef) {
/** @var \Drupal\paragraphs\ParagraphInterface $exerciseDueParagraph */
......@@ -241,11 +251,12 @@ class SkillingClass {
// 'maxSubs' => $exerMaxSubs,
// ];
$exerciseDues[] = $exerciseDueRecord;
$exerciseNids[] = $exerciseId;
// $exerciseNids[] = $exerciseId;
}
}
}
return [$exerciseDues, $exerciseNids];
return $exerciseDues;
// return [$exerciseDues, $exerciseNids];
}
......@@ -264,7 +275,7 @@ class SkillingClass {
* @throws \Drupal\skilling\Exception\SkillingException
*/
public function getExerciseDueRecordForExercise($exerciseId) {
list($classExerciseDues, $classExerciseNids) = $this->getExerciseDueRecords();
$classExerciseDues = $this->getExerciseDueRecords();
// Find the exercise due data for the exercise.
$exerciseDue = NULL;
/** @var ExerciseDueRecord $record */
......
......@@ -20,9 +20,6 @@ class SkillingClassFactory {
*/
protected $entityTypeManager;
protected $skillingUserFactory;
public function __construct(
EntityTypeManagerInterface $entityTypeManagerIn,
SkillingUserFactory $skillingUserFactoryIn
......@@ -81,10 +78,10 @@ class SkillingClassFactory {
}
$skillingClass = new SkillingClass(
$class,
$this->entityTypeManager,
$this->skillingUserFactory
);
$skillingClass->setWrappedClassNode($class);
return $skillingClass;
}
}
This diff is collapsed.
......@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Utility\Token;
use \Drupal\Core\Render\BubbleableMetadata;
use Drupal\skilling\Exception\SkillingException;
use src\SkillingClass\SkillingCurrentClass;
/**
* Class SkillingTokens.
......@@ -31,10 +32,11 @@ class SkillingTokens implements SkillingTokensInterface {
* @var \Drupal\skilling\SkillingCurrentUser
*/
protected $skillingCurrentUser;
/**
* Drupal\skilling\CurrentClass definition.
* Current class.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
/**
......@@ -59,8 +61,22 @@ class SkillingTokens implements SkillingTokensInterface {
/**
* Constructs a new SkillingTokens object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\skilling\SkillingCurrentUser $skillingCurrentUser
* @param \src\SkillingClass\SkillingCurrentClass $currentClass
* @param \Drupal\skilling\Submissions $skilling_submissions
* @param \Drupal\skilling\Utilities $skilling_utilities
* @param \Drupal\Core\Utility\Token $token
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, SkillingCurrentUser $skillingCurrentUser, CurrentClassOld $currentClass, Submissions $skilling_submissions, Utilities $skilling_utilities, Token $token) {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
SkillingCurrentUser $skillingCurrentUser,
SkillingCurrentClass $currentClass,
Submissions $skilling_submissions,
Utilities $skilling_utilities,
Token $token
) {
$this->entityTypeManager = $entity_type_manager;
$this->skillingCurrentUser = $skillingCurrentUser;
$this->currentClass = $currentClass;
......@@ -369,6 +385,10 @@ class SkillingTokens implements SkillingTokensInterface {
/**
* Get an attribute of the current user's instructor.
*
* NB: gets the first instructor only.
*
* TODO: multi instrutor thing. Field to mark main one?
*
* Return a not-available value when appropriate.
*
* @param string $attributeName
......@@ -379,11 +399,14 @@ class SkillingTokens implements SkillingTokensInterface {
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\skilling\Exception\SkillingInvalidValueException
* @throws \Drupal\skilling\Exception\SkillingNotFoundException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
protected function getInstructorAttribute($attributeName) {
$result = self::NOT_AVAILABLE_VALUE;
$instructor = $this->currentClass->getCurrentInstructor();
$instructor = $this->currentClass->getInstructor();
if ($instructor) {
switch ($attributeName) {
case 'first name':
......@@ -422,6 +445,7 @@ class SkillingTokens implements SkillingTokensInterface {
* Associative array of replacement values.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\skilling\Exception\SkillingNotFoundException
* @throws \Drupal\skilling\Exception\SkillingUnknownValueException
......
This diff is collapsed.
......@@ -9,6 +9,7 @@ use DateTime;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\skilling_history\SkillingHistoryConstants;
use src\SkillingClass\SkillingCurrentClass;
/**
* Class Timeline.
......@@ -27,7 +28,7 @@ class Timeline {
/**
* Current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $currentClass;
......@@ -50,14 +51,19 @@ class Timeline {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager service.
* @param \Drupal\skilling\CurrentClassOld $skilling_current_class
* @param SkillingCurrentClass $skilling_current_class
* Current class service.
* @param \Drupal\skilling\SkillingCurrentUser $skilling_skilling_current_user
* Skilling current user service.
* @param \Drupal\skilling\Submissions $submissionsService
* Submissions service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, CurrentClassOld $skilling_current_class, SkillingCurrentUser $skilling_skilling_current_user, Submissions $submissionsService) {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
SkillingCurrentClass $skilling_current_class,
SkillingCurrentUser $skilling_skilling_current_user,
Submissions $submissionsService
) {
$this->entityTypeManager = $entity_type_manager;
$this->currentClass = $skilling_current_class;
$this->currentUser = $skilling_skilling_current_user;
......@@ -93,8 +99,11 @@ class Timeline {
return [$problemMessage, $eventsForTemplate];
}
// Get the exercise due paragraph items for the class.
list($exerciseDues, $exerciseDuesNids)
= $this->currentClass->getExerciseDues();
$exerciseDueRecords = $this->currentClass->getExerciseDueRecords();
$exerciseDuesNids = [];
foreach ($exerciseDueRecords as $exerciseDueRecord) {
$exerciseDuesNids = $exerciseDueRecord->getExerciseId();
}
$exerciseRecords = [];
$exerciseNids = [];
// Keep published exercises, adding data about the exercises.
......@@ -111,18 +120,19 @@ class Timeline {
if ($exercise->isPublished()) {
$exerciseNids[] = $exerciseDuesNid;
// Keep exercise due for the exercise.
foreach ($exerciseDues as $rawExerciseDue) {
if ($rawExerciseDue['exerciseId'] === $exerciseDuesNid) {
/** @var \src\ExerciseDueRecord $rawExerciseDue */
foreach ($exerciseDueRecords as $rawExerciseDue) {
if ($rawExerciseDue->getExerciseId() === $exerciseDuesNid) {
// Compute max submissions for the exercise.
// Exercise-specific, or use the class value.
// $maxSubsForExercise = $rawExerciseDue
$exerciseRecord = [];
$exerciseRecord['exercise_nid'] = $exercise->id();
$exerciseRecord['title'] = $exercise->getTitle();
$exerciseRecord['day'] = $rawExerciseDue['day'];
$exerciseRecord['max_subs'] = $rawExerciseDue['maxSubs'];
$exerciseRecord['day'] = $rawExerciseDue->getDay();
$exerciseRecord['max_subs'] = $rawExerciseDue->getMaximumSubmissions();
$exerciseRecord['exercise_internal_name'] = $exercise->field_internal_name->value;
$exerciseRecord['exercise_required'] = $rawExerciseDue['required'];
$exerciseRecord['exercise_required'] = $rawExerciseDue->getRequired();
$exerciseRecord['exercise_challenge'] = $exercise->field_challenge->value;
$exerciseRecord['exercise_submission_status'] = '';
$exerciseRecords[] = $exerciseRecord;
......@@ -164,14 +174,18 @@ class Timeline {
// Exercise is published. Extra check.
->condition('field_exercise.entity.status', 1)
->execute();
$submissions = $this->entityTypeManager->getStorage('node')
->loadMultiple($submissionIds);
// $submissions = $this->entityTypeManager->getStorage('node')
// ->loadMultiple($submissionIds);
}
// Find out the submission status of each exercise.
// Returns array indexed by exercise nid.
$exercisesSubmissionSummary = $this->submissionsService
->getSubmissionStatusForStudentExercisesSubmissions(