Commit d5805a3a authored by mathieso's avatar mathieso

Still refactoring...

parent a00daaed
......@@ -10,7 +10,7 @@ services:
arguments: ['@token', '@entity_type.manager', '@skilling.utilities', '@skilling.skilling_current_user', '@skilling.skilling_user_factory', '@skilling.ajax_security']
skilling.submissions:
class: Drupal\skilling\Submissions
arguments: ['@entity_type.manager', '@skilling.skilling_current_user', '@skilling.utilities', '@skilling.current_class', '@config.factory', '@skilling.nid_bag', '@skilling.skillingparser', '@skilling.filter_user_input', '@skilling.class_utilities']
arguments: ['@entity_type.manager', '@skilling.skilling_current_user', '@skilling.utilities', '@skilling.current_class', '@config.factory', '@skilling.nid_bag', '@skilling.skillingparser', '@skilling.filter_user_input']
plugin.manager.skilling.custom_tag:
class: Drupal\skilling\Plugin\SkillingCustomTagManager
parent: default_plugin_manager
......@@ -65,7 +65,7 @@ services:
arguments: ['@entity_type.manager', '@skilling.skilling_current_user', '@skilling.current_class', '@skilling.check_user_relationships', '@config.factory', '@skilling.skilling_user_factory', '@skilling.utilities', '@skilling.skillingparser', '@messenger', '@skilling.field_access_special_case_checker']
skilling.check_user_relationships:
class: Drupal\skilling\Access\SkillingCheckUserRelationships
arguments: ['@entity_type.manager', '@skilling.utilities', '@skilling.skilling_user_factory']
arguments: ['@entity_type.manager', '@skilling.utilities', '@skilling.skilling_user_factory', '@skilling.class_factory']
skilling.assessment:
class: Drupal\skilling\Assessment
arguments: ['@entity_type.manager', '@skilling.skilling_current_user', '@skilling.utilities', '@date.formatter', '@renderer']
......
......@@ -26,7 +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;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
/**
* A service to check the current user's access to entities, blocks, and fields.
......
......@@ -4,11 +4,12 @@ namespace Drupal\skilling\Access;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\skilling\SkillingClassUtilities;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingUser;
use Drupal\skilling\SkillingUserFactory;
use Drupal\skilling\Utilities as SkillingUtilities;
use Drupal\skilling\SkillingClass\SkillingClass;
use Drupal\skilling\SkillingClass\SkillingClassFactory;
/**
* Check relationships between users.
......@@ -42,6 +43,9 @@ class SkillingCheckUserRelationships {
*/
protected $userFactory;
/** @var SkillingClassFactory */
protected $classFactory;
/**
* SkillingCheckUserRelationships constructor.
*
......@@ -55,11 +59,13 @@ class SkillingCheckUserRelationships {
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
SkillingUtilities $skillingUtilities,
SkillingUserFactory $userFactory
SkillingUserFactory $userFactory,
SkillingClassFactory $classFactory
) {
$this->entityTypeManager = $entityTypeManager;
$this->skillingUtilities = $skillingUtilities;
$this->userFactory = $userFactory;
$this->classFactory = $classFactory;
}
/**
......@@ -165,13 +171,13 @@ class SkillingCheckUserRelationships {
/**
* @param \Drupal\skilling\SkillingUser $user
* @param \Drupal\node\EntityInterface $class
* @param SkillingClass $class
*
* @return bool
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function isInstructorOfClass(SkillingUser $user, EntityInterface $class) {
public function isInstructorOfClass(SkillingUser $user, SkillingClass $class) {
$userClasseIds = $this->getInstructorClassIds($user);
$classId = $class->id();
$result = in_array($classId, $userClasseIds);
......@@ -192,8 +198,7 @@ class SkillingCheckUserRelationships {
if (!$user) {
return FALSE;
}
$class = $this->entityTypeManager->getStorage('node')
->load($classId);
$class = $this->classFactory->makeSkillingClass($classId);
if (!$class) {
return FALSE;
}
......
......@@ -12,7 +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;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
/**
* Completion score service.
......
......@@ -3,7 +3,7 @@
namespace Drupal\skilling\Controller;
use Drupal\Core\Controller\ControllerBase;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
......
......@@ -6,12 +6,12 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\skilling\Access\FilterUserInputInterface;
use Drupal\skilling\Access\SkillingAjaxSecurityInterface;
use Drupal\skilling\SkillingClassUtilities;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling_history\History;
use Drupal\skilling\SkillingClass\SkillingClassFactory;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\skilling\CurrentClassOld;
use Drupal\skilling\SkillingCurrentUser;
use Drupal\skilling\Utilities;
......@@ -30,7 +30,7 @@ class YourClassController extends ControllerBase {
/**
* The Skilling current class service.
*
* @var \Drupal\skilling\CurrentClassOld
* @var SkillingCurrentClass
*/
protected $skillingCurrentClass;
......@@ -69,13 +69,6 @@ class YourClassController extends ControllerBase {
*/
protected $filterInputService;
/**
* The Skilling class service.
*
* @var \Drupal\skilling\SkillingClassUtilities
*/
protected $skillingClassUtilities;
/**
* Module handler service.
*
......@@ -83,12 +76,17 @@ class YourClassController extends ControllerBase {
*/
protected $moduleHandler;
/**
* @var \Drupal\skilling\SkillingClass\SkillingClassFactory
*/
protected $skillingClassFactory;
/**
* Constructs a new MyClassController object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\skilling\CurrentClassOld $skilling_current_class
* @param SkillingCurrentClass $skilling_current_class
* The Skilling current class service.
* @param \Drupal\skilling\SkillingCurrentUser $skilling_current_user
* The Skilling current user service.
......@@ -99,19 +97,17 @@ class YourClassController extends ControllerBase {
* @param \Drupal\skilling\Access\SkillingAjaxSecurityInterface $ajaxSecurityService
* AJAX security checking service.
* @param \Drupal\skilling\Access\FilterUserInputInterface $filterInputService
* @param \Drupal\skilling\SkillingClassUtilities $skillingClassUtilities
* The current class service.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
CurrentClassOld $skilling_current_class,
SkillingCurrentClass $skilling_current_class,
SkillingCurrentUser $skilling_current_user,
Utilities $skilling_utilities,
History $historyService,
SkillingAjaxSecurityInterface $ajaxSecurityService,
FilterUserInputInterface $filterInputService,
SkillingClassUtilities $skillingClassUtilities,
ModuleHandlerInterface $moduleHandler
ModuleHandlerInterface $moduleHandler,
SkillingClassFactory $skillingClassFactory
) {
$this->entityTypeManager = $entity_type_manager;
$this->skillingCurrentClass = $skilling_current_class;
......@@ -120,8 +116,8 @@ class YourClassController extends ControllerBase {
$this->historyService = $historyService;
$this->ajaxSecurityService = $ajaxSecurityService;
$this->filterInputService = $filterInputService;
$this->skillingClassUtilities = $skillingClassUtilities;
$this->moduleHandler = $moduleHandler;
$this->skillingClassFactory = $skillingClassFactory;
}
/**
......@@ -137,8 +133,8 @@ class YourClassController extends ControllerBase {
$container->get('skilling_history.history'),
$container->get('skilling.ajax_security'),
$container->get('skilling.filter_user_input'),
$container->get('skilling.class_utilities'),
$container->get('module_handler')
$container->get('module_handler'),
$container->get('skilling.class_factory')
);
}
......@@ -152,11 +148,11 @@ class YourClassController extends ControllerBase {
* Renderable array.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\skilling\Exception\SkillingInvalidValueException
* @throws \Drupal\skilling\Exception\SkillingNotFoundException
* @throws \Drupal\skilling\Exception\SkillingUnknownValueException
* @throws \Drupal\skilling\Exception\SkillingValueMissingException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
public function yourClass() {
......@@ -183,9 +179,9 @@ class YourClassController extends ControllerBase {
}
// Find instructors for classes.
$instructors = [];
/** @var \Drupal\node\Entity\Node $class */
/** @var \Drupal\skilling\SkillingClass\SkillingClass $class */
foreach ($classes as $class) {
$instructorsForClass = $this->skillingClassUtilities->getInstructorsForClass($class);
$instructorsForClass = $class->getInstructors();
foreach ($instructorsForClass as $instructor) {
if (!isset($instructors[$instructor->id()])) {
$instructors[$instructor->id()] = $instructor;
......
<?php
<?php /** @noinspection PhpUnusedParameterInspection */
namespace Drupal\skilling\EventSubscriber;
use Drupal;
use Drupal\skilling\SkillingConstants;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Drupal\Core\Config\ConfigFactoryInterface;
/**
* Watch events.
......@@ -24,30 +24,32 @@ class SkillingSubscriber implements EventSubscriberInterface {
/**
* This method is called when the routing.route_finished event is dispatched.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* What happened.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\skilling\Exception\SkillingValueMissingException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
public function routingRouteFinished(GetResponseEvent $event) {
/** @var \Drupal\skilling\BookUpdateTracker $bookUpdateTracker */
$bookUpdateTracker = \Drupal::service('skilling.book_update_tracker');
$bookUpdateTracker = Drupal::service('skilling.book_update_tracker');
$bookUpdateTracker->runScheduledBookOrderUpdates();
/** @var \Drupal\skilling\RecomputeClassRoles $recomputeClassRoles */
$recomputeClassRoles = \Drupal::service('skilling.recompute_class_roles');
$recomputeClassRoles = Drupal::service('skilling.recompute_class_roles');
$recomputeClassRoles->runScheduledClassRoleUpdates();
// Recompute completion score if needed.
/** @var \Drupal\skilling\SkillingCurrentUser $currentUser */
$currentUser = \Drupal::service('skilling.skilling_current_user');
$currentUser = Drupal::service('skilling.skilling_current_user');
if ($currentUser->isStudent()) {
/** @var \Drupal\skilling\CurrentClassOld $currentClass */
$currentClass = \Drupal::service('skilling.current_class');
/** @var \Drupal\skilling\SkillingClass\SkillingCurrentClass $currentClass */
$currentClass = Drupal::service('skilling.current_class');
if ($currentClass) {
/** @var \Drupal\skilling\CompletionScore $completionScoreService */
$completionScoreService = \Drupal::service('skilling.completion_score');
$completionScoreService = Drupal::service('skilling.completion_score');
$completionScoreService->getCompletionScoreForCurrentEnrollment();
}
}
......@@ -59,7 +61,7 @@ class SkillingSubscriber implements EventSubscriberInterface {
*/
protected function runScheduledCacheClear() {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
$configFactory = \Drupal::service('config.factory');
$configFactory = Drupal::service('config.factory');
$settings = $configFactory->getEditable(SkillingConstants::SETTINGS_MAIN_KEY);
$cacheClearScheduled = $settings->get(SkillingConstants::SETTING_KEY_SCHEDULE_CLEAR_CACHE);
if ($cacheClearScheduled) {
......
<?php
namespace src;
//namespace src;
namespace Drupal\skilling;
use Drupal;
use Drupal\Core\Entity\EntityTypeManager;
......
......@@ -9,7 +9,7 @@ use DateTime;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingNotFoundException;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
/**
* Class Exercises.
......@@ -56,7 +56,7 @@ class Exercises {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
* Entity type manager service.
* @param \src\SkillingClass\SkillingCurrentClass $skillingCurrentClassIn
* @param \Drupal\skilling\SkillingClass\SkillingCurrentClass $skillingCurrentClassIn
* Current class service.
* @param \Drupal\skilling\SkillingCurrentUser $skillingCurrentUserIn
* Skilling current user service.
......
......@@ -4,7 +4,7 @@ namespace Drupal\skilling\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\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 \src\SkillingClass\SkillingCurrentClass
* @var \Drupal\skilling\SkillingClass\SkillingCurrentClass
*/
protected $currentClass;
......@@ -53,7 +53,7 @@ class ClassSelector extends BlockBase implements ContainerFactoryPluginInterface
* @param \Drupal\skilling\Utilities $skillingUtilitiesIn
* The Skilling utilities service
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* @param \src\SkillingClass\SkillingCurrentClass $currentClass
* @param \Drupal\skilling\SkillingClass\SkillingCurrentClass $currentClass
* Current class service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition,
......
......@@ -6,7 +6,7 @@ use DateInterval;
use DateTime;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use src\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingCurrentUser;
......
This diff is collapsed.
<?php
namespace src\SkillingClass;
namespace Drupal\skilling\SkillingClass;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
......@@ -9,12 +9,12 @@ use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingWrongTypeException;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingUserFactory;
use src\ExerciseDueRecord;
use Drupal\skilling\ExerciseDueRecord;
/**
* Class SkillingClass
*
* @package src\SkillingClass
* @package Drupal\skilling\SkillingClass
*
* Represents a class that a student can take.
*
......
<?php
namespace src\SkillingClass;
//namespace src\SkillingClass;
namespace Drupal\skilling\SkillingClass;
use Drupal;
......@@ -32,7 +33,7 @@ class SkillingClassFactory {
/**
* @param $thingToWrap
*
* @return \src\SkillingClass\SkillingClass
* @return \Drupal\skilling\SkillingClass\SkillingClass
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\skilling\Exception\SkillingNotFoundException
......
<?php
namespace Drupal\skilling;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\Exception\SkillingWrongTypeException;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Class SkillingClassUtilities.
*
* Some useful functions for working with class nodes.
*/
class SkillingClassUtilities {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Utilities service.
*
* @var \Drupal\skilling\Utilities
*/
protected $skillingUtilities;
/**
* The Skilling current user service.
*
* @var \Drupal\skilling\SkillingCurrentUser
*/
protected $skillingSkillingCurrentUser;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs a new SkillingClassUtilities object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager service.
* @param \Drupal\skilling\Utilities $skillingUtilities
* Utilities service.
* @param \Drupal\skilling\SkillingCurrentUser $skillingCurrentUser
* The Skilling current user service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
Utilities $skillingUtilities,
SkillingCurrentUser $skillingCurrentUser,
MessengerInterface $messenger
) {
$this->entityTypeManager = $entityTypeManager;
$this->skillingUtilities = $skillingUtilities;
$this->skillingSkillingCurrentUser = $skillingCurrentUser;
$this->messenger = $messenger;
}
/**
* Get the instructors for a class.
*
* @param \Drupal\node\NodeInterface $class
* The class.
*
* @return \Drupal\user\Entity\User[]
* User objects.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
// public function getInstructorsForClass(NodeInterface $class) {
// if ($class->bundle() !== SkillingConstants::CLASS_CONTENT_TYPE) {
// throw new SkillingWrongTypeException(
// 'Expected class node, got ' . $class->bundle(),
// __FILE__, __LINE__
// );
// }
// // Find enrollments for the class, with instructor role.
// $enrollmentIds = $this->entityTypeManager
// ->getStorage('node')
// ->getQuery()
// ->condition('type', SkillingConstants::ENROLLMENT_CONTENT_TYPE)
// // Enrollment is published.
// ->condition('status', TRUE)
// // For the class.
// ->condition('field_class', $class->id())
// // Class is published.
// ->condition('field_class.entity.status', 1)
// // Is an instructor.
// ->condition('field_class_roles', [SkillingConstants::CLASS_ROLE_INSTRUCTOR], 'IN')
// ->execute();
// $enrollments = $this->entityTypeManager
// ->getStorage('node')
// ->loadMultiple($enrollmentIds);
// $instructorIds = [];
// /** @var \Drupal\node\Entity\Node $enrollment */
// foreach ($enrollments as $enrollment) {
// $instructorIds[] = $enrollment->get('field_user')->target_id;
// }
// // Load instructor's user objects.
// /** @var \Drupal\user\Entity\User[] $instructors */
// $instructors = $this->entityTypeManager
// ->getStorage('user')
// ->loadMultiple($instructorIds);
// return $instructors;
// }
/**
* Get the exercise due paragraph items for a class.
* Published exercises only.
*
* @param NodeInterface $class
* The class to get exercise dues for.
*
* @return array
* The exercise dues paragraph items, and exercise nids.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
// public function getExerciseDues(NodeInterface $class) {
// if (!$class) {
// throw new SkillingException(
// Html::escape('No class given.'), __FILE__, __LINE__
// );
// }
// $exerciseDues = [];
// $exerciseNids = [];
// $exerciseDueParaRefs = $class->get(SkillingConstants::FIELD_EXERCISES_DUE)->getValue();
// foreach ($exerciseDueParaRefs as $exerciseDueParaRef) {
// $exerciseDueParagraph = $this->entityTypeManager->getStorage('paragraph')
// ->load($exerciseDueParaRef['target_id']);
// if (!$exerciseDueParagraph) {
// // In case the para does not exist.
// continue;
// }
// $exerciseId = (int)$exerciseDueParagraph->get(SkillingConstants::FIELD_EXERCISE)
// ->getValue()[0]['target_id'];
// /** @var NodeInterface $exercise */
// $exercise = $this->entityTypeManager->getStorage('node')
// ->load($exerciseId);
// if (!$exercise) {
// // In case the exercise does not exist.
// $exerciseDueParagraph->delete();
// continue;
// }
// if ($exercise->isPublished()) {
// // Check that something exists.
// $dayDataieThing = $exerciseDueParagraph->get(SkillingConstants::FIELD_DAY)
// ->getValue();
// if (isset($dayDataieThing[0])) {
// $day = (int) $exerciseDueParagraph->get(SkillingConstants::FIELD_DAY)
// ->getValue()[0]['value'];
// $required = FALSE;
// if (isset($exerciseDueParagraph->get(SkillingConstants::FIELD_REQUIRED)
// ->getValue()[0]['value'])) {
// $required = (boolean) $exerciseDueParagraph->get(SkillingConstants::FIELD_REQUIRED)
// ->getValue()[0]['value'];
// // Convert from truthy/falsey to real bool.
// $required = !(!$required);
// }
// // Compute max subs allowed for exercise.
// // Start with value from class.
// $exerMaxSubs = (integer)$class->get(SkillingConstants::FIELD_DEFAULT_MAX_SUBMISSIONS)
// ->getValue()[0]['value'];
// if (isset($exerciseDueParagraph->get(SkillingConstants::FIELD_MAX_SUBMISSIONS)
// ->getValue()[0]['value'])) {
// $exerMaxSubs = $exerciseDueParagraph->get(SkillingConstants::FIELD_MAX_SUBMISSIONS)
// ->getValue()[0]['value'];
// if (!$exerMaxSubs) {
// $exerMaxSubs = 0;
// }
// else {
// $exerMaxSubs = (integer) $exerMaxSubs;
// }
// }
// $exerciseDue = [
// 'exerciseId' => $exerciseId,
// 'day' => $day,
// 'required' => $required,
// 'maxSubs' => $exerMaxSubs,
// ];
// $exerciseDues[] = $exerciseDue;
// $exerciseNids[] = $exerciseId;
// }
// }
// }
// return [$exerciseDues, $exerciseNids];
// }
// /**
// * Get exercise due record for an exercise for the current class.
// * Return null if there is no record for the exercise.
// *
// * @param \Drupal\node\NodeInterface $class
// * @param int $exerciseId
// * Exercise id.
// *
// * @return NodeInterface|null
// * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
// * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
// * @throws \Drupal\Core\Entity\EntityStorageException
// * @throws \Drupal\skilling\Exception\SkillingException
// */
// public function getExerciseDueRecordForExercise(NodeInterface $class, $exerciseId) {
// if (!$class) {
// throw new SkillingException(
// Html::escape('No class.'), __FILE__, __LINE__
// );
// }
// list($classExerciseDues, $classExerciseNids) = $this->getExerciseDues($class);
// // Find the exercise due data for the exercise.
// $exerciseDue = NULL;
// foreach ($classExerciseDues as $record) {
// if ($record['exerciseId'] == $exerciseId) {
// $exerciseDue = $record;
// break;
// }
// }
// return $exerciseDue;
// }
// /**
// * Get the default max submissions for a class.
// *
// * @param \Drupal\node\NodeInterface $class
// *
// * @return int|NULL
// * @throws \Drupal\skilling\Exception\SkillingException
// */
// public function getDefaultMaxSubmissions(NodeInterface $class) {
// if (!$class) {
// throw new SkillingException(
// Html::escape('No current class.'), __FILE__, __LINE__
// );
// }
// $exerciseMaxSubs = $class
// ->get(SkillingConstants::FIELD_DEFAULT_MAX_SUBMISSIONS)
// ->getValue()[0]['value'];
// if (is_numeric($exerciseMaxSubs)) {
// $exerciseMaxSubs = (int)$exerciseMaxSubs;
// }
// return $exerciseMaxSubs;
// }
//
// /**
// * @param \Drupal\node\NodeInterface $class
// * @param $exerciseId
// *
// * @return int|NULL
// * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
// * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
// * @throws \Drupal\Core\Entity\EntityStorageException
// * @throws \Drupal\skilling\Exception\SkillingException
// */
// public function getMaxSubmissionsAllowedForExercise(NodeInterface $class, $exerciseId) {
// if (!$class) {
// throw new SkillingException(
// Html::escape('No class.'), __FILE__, __LINE__
// );
// }
// $exerciseDueRecord = $this->getExerciseDueRecordForExercise($class, $exerciseId);
// if ($exerciseDueRecord) {
// $maxSubs = $exerciseDueRecord['maxSubs'];
// }
// else {
// $maxSubs = $this->getDefaultMaxSubmissions($class);
// }
// return $maxSubs;
// }