Commit 5666aa97 authored by mathieso's avatar mathieso

Still refactoring......

parent d5805a3a
......@@ -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\SkillingClass\CurrentClass
arguments: [ '@entity_type.manager', '@user.data', '@skilling.utilities', '@skilling.skilling_current_user']
class: Drupal\skilling\SkillingClass\SkillingCurrentClass
arguments: [ '@entity_type.manager', '@skilling.skilling_user_factory', '@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']
......
......@@ -18,7 +18,6 @@ use Drupal\node\NodeInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\Exception\SkillingInvalidValueException;
use Drupal\skilling\Exception\SkillingNotFoundException;
use Drupal\skilling\Exception\SkillingValueMissingException;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingCurrentUser;
......
......@@ -2,6 +2,7 @@
namespace Drupal\skilling\Controller;
use Drupal;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\skilling\Access\FilterUserInputInterface;
......@@ -10,6 +11,7 @@ use Drupal\skilling\SkillingConstants;
use Drupal\skilling_history\History;
use Drupal\skilling\SkillingClass\SkillingClassFactory;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\skilling\SkillingCurrentUser;
......@@ -97,6 +99,8 @@ class YourClassController extends ControllerBase {
* @param \Drupal\skilling\Access\SkillingAjaxSecurityInterface $ajaxSecurityService
* AJAX security checking service.
* @param \Drupal\skilling\Access\FilterUserInputInterface $filterInputService
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* @param \Drupal\skilling\SkillingClass\SkillingClassFactory $skillingClassFactory
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
......@@ -152,7 +156,6 @@ class YourClassController extends ControllerBase {
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\skilling\Exception\SkillingInvalidValueException
* @throws \Drupal\skilling\Exception\SkillingNotFoundException
* @throws \Drupal\skilling\Exception\SkillingValueMissingException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
*/
public function yourClass() {
......@@ -227,10 +230,10 @@ class YourClassController extends ControllerBase {
// Store the event.
$this->historyService->recordYourClassView();
}
catch (\Exception $e) {
catch (Exception $e) {
$message = 'Exception view your class: '
. $e->getMessage();
\Drupal::logger(SkillingConstants::HISTORY_MODULE_NAME)->error($message);
Drupal::logger(SkillingConstants::HISTORY_MODULE_NAME)->error($message);
}
}
return [
......
......@@ -52,9 +52,8 @@ class ClassSelector extends BlockBase implements ContainerFactoryPluginInterface
* The plugin implementation definition.
* @param \Drupal\skilling\Utilities $skillingUtilitiesIn
* The Skilling utilities service
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* @param \Drupal\skilling\SkillingClass\SkillingCurrentClass $currentClass
* Current class service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
* @param \Drupal\skilling\SkillingClass\SkillingCurrentClass $currentClassIn
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition,
Utilities $skillingUtilitiesIn,
......
<?php
<?php /** @noinspection PhpUnusedParameterInspection */
namespace Drupal\skilling\Plugin\views\query;
use DateInterval;
use DateTime;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
use Drupal\skilling\Exception\SkillingException;
......@@ -17,6 +16,7 @@ use Drupal\views\ViewExecutable;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Render\Renderer;
use Drupal\Core\Url;
/**
* Student's submissions views query plugin.
*
......@@ -202,6 +202,7 @@ class StudentSubmissionsDataSource extends QueryPluginBase {
if (!isset($this->where[$group])) {
$this->setWhereGroup('AND', $group);
}
/** @noinspection PhpUndefinedFieldInspection */
$this->where[$group]['conditions'][] = [
'field' => $field,
'value' => $value,
......
<?php
namespace Drupal\skilling\SkillingClass;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingWrongTypeException;
......@@ -50,9 +48,7 @@ class SkillingClass {
* Constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
* * @param \Drupal\skilling\SkillingUserFactory $skillingUserFactoryIn
*
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
* @param \Drupal\skilling\SkillingUserFactory $skillingUserFactoryIn
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManagerIn,
......@@ -215,9 +211,9 @@ class SkillingClass {
}
if ($exercise->isPublished()) {
// Check that something exists.
$dayDataieThing = $exerciseDueParagraph->get(SkillingConstants::FIELD_DAY)
$dayDataThing = $exerciseDueParagraph->get(SkillingConstants::FIELD_DAY)
->getValue();
if (isset($dayDataieThing[0])) {
if (isset($dayDataThing[0])) {
$day = (int) $exerciseDueParagraph->get(SkillingConstants::FIELD_DAY)
->getValue()[0]['value'];
$required = FALSE;
......@@ -230,25 +226,25 @@ class SkillingClass {
}
// Compute max subs allowed for exercise.
// Start with value from class.
$exerMaxSubs = (integer)$this->wrappedDrupalClassNode->get(SkillingConstants::FIELD_DEFAULT_MAX_SUBMISSIONS)
$exerciseMaxSubs = (integer)$this->wrappedDrupalClassNode->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)
$exerciseMaxSubs = $exerciseDueParagraph->get(SkillingConstants::FIELD_MAX_SUBMISSIONS)
->getValue()[0]['value'];
if (!$exerMaxSubs) {
$exerMaxSubs = 0;
if (!$exerciseMaxSubs) {
$exerciseMaxSubs = 0;
}
else {
$exerMaxSubs = (integer) $exerMaxSubs;
$exerciseMaxSubs = (integer) $exerciseMaxSubs;
}
}
$exerciseDueRecord = new ExerciseDueRecord($exerciseId, $day, $required, $exerMaxSubs);
$exerciseDueRecord = new ExerciseDueRecord($exerciseId, $day, $required, $exerciseMaxSubs);
// [
// 'exerciseId' => $exerciseId,
// 'day' => $day,
// 'required' => $required,
// 'maxSubs' => $exerMaxSubs,
// 'maxSubs' => $exerciseMaxSubs,
// ];
$exerciseDues[] = $exerciseDueRecord;
// $exerciseNids[] = $exerciseId;
......@@ -291,8 +287,6 @@ class SkillingClass {
/**
* Get the default max submissions for a class.
*
* @param \Drupal\node\NodeInterface $class
*
* @return int|NULL
*/
public function getDefaultMaxSubmissions() {
......@@ -307,7 +301,6 @@ class SkillingClass {
}
/**
* @param \Drupal\node\NodeInterface $class
* @param $exerciseId
*
* @return int|NULL
......
<?php
//namespace src\SkillingClass;
namespace Drupal\skilling\SkillingClass;
use Drupal;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Drupal\skilling\Exception\SkillingNotFoundException;
use Drupal\skilling\Exception\SkillingValueMissingException;
use Drupal\skilling\Exception\SkillingWrongTypeException;
use Drupal\skilling\SkillingConstants;
use Drupal\skilling\SkillingUserFactory;
/**
......@@ -21,6 +22,13 @@ class SkillingClassFactory {
*/
protected $entityTypeManager;
/**
* The user factory service.
*
* @var \Drupal\skilling\SkillingUserFactory
*/
protected $skillingUserFactory;
public function __construct(
EntityTypeManagerInterface $entityTypeManagerIn,
SkillingUserFactory $skillingUserFactoryIn
......@@ -55,7 +63,7 @@ class SkillingClassFactory {
$class = $this->entityTypeManager->getStorage('node')
->load($classId);
if (!$class) {
throw new Drupal\skilling\Exception\SkillingNotFoundException(
throw new SkillingNotFoundException(
'Class with id not found. Id: ' . $classId,
__FILE__, __LINE__
);
......@@ -63,16 +71,16 @@ class SkillingClassFactory {
} // end is numeric
// If node, should have bundle() method.
if (method_exists($thingToWrap, 'bundle')) {
if ($class->bundle() !== Drupal\skilling\SkillingConstants::CLASS_CONTENT_TYPE) {
throw new Drupal\skilling\Exception\SkillingWrongTypeException(
'Need class id: ' . $classId,
if ($class->bundle() !== SkillingConstants::CLASS_CONTENT_TYPE) {
throw new SkillingWrongTypeException(
'Wrong bundle: ' . $class->bundle(),
__FILE__, __LINE__
);
}
}
// Still found nothing?
if (is_null($class)) {
throw new Drupal\skilling\Exception\SkillingNotFoundException(
throw new SkillingNotFoundException(
'Class making failed. Thing: ' . $thingToWrap,
__FILE__, __LINE__
);
......@@ -82,7 +90,9 @@ class SkillingClassFactory {
$this->entityTypeManager,
$this->skillingUserFactory
);
$skillingClass->setWrappedClassNode($class);
/** @var NodeInterface $node */
$node = $class;
$skillingClass->setWrappedClassNode($node);
return $skillingClass;
}
}
......@@ -117,6 +117,7 @@ class SkillingCurrentClass extends SkillingClass {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManagerIn
* The entity type manager service.
* @param \Drupal\skilling\SkillingUserFactory $skillingUserFactoryIn
* @param \Drupal\user\UserDataInterface $userData
* The user data service.
* @param \Drupal\skilling\Utilities $skillingUtilities
......@@ -225,7 +226,7 @@ class SkillingCurrentClass extends SkillingClass {
// class list. Use the first class instead.
reset($this->currentEnrollments);
$this->currentEnrollment = current($this->currentEnrollments);
$this->$skillingClass = $this->currentEnrollment->field_class->entity;
$this->wrappedSkillingClassNode = $this->currentEnrollment->field_class->entity;
}
}
// Current class is set. Remember its id.
......@@ -233,7 +234,7 @@ class SkillingCurrentClass extends SkillingClass {
SkillingConstants::MODULE_NAME,
$this->skillingCurrentUser->id(),
self::CURRENT_CLASS_KEY,
$this->$skillingClass->id()
$this->wrappedSkillingClassNode->id()
);
} //End there is more than one enrollment.
} //End there are enrollments.
......@@ -315,7 +316,6 @@ class SkillingCurrentClass extends SkillingClass {
* required exercises only.
*/
public function getIsProgressScoreBasedOnRequiredOnlyForCurrentEnrollment() {
$enrollment = $this->getCurrentEnrollment();
$baseOnRequired = $this->currentEnrollment
->get(SkillingConstants::FIELD_BASE_PROGRESS_ON_REQUIRED_ONLY)
->getValue()[0]['value'];
......
......@@ -2,14 +2,13 @@
namespace Drupal\skilling;
use Drupal;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\node\NodeInterface;
use Drupal\skilling\Access\FilterUserInputInterface;
use Drupal\skilling\Exception\SkillingClassRoleException;
use Drupal\skilling\Exception\SkillingException;
use Drupal\skilling\Exception\SkillingInvalidValueException;
use Drupal\skilling\Exception\SkillingNotFoundException;
use Drupal\skilling\Exception\SkillingValueMissingException;
use Drupal\skilling\Exception\SkillingWrongTypeException;
use Drupal\skilling\SkillingParser\SkillingParser;
......@@ -149,7 +148,7 @@ class Submissions {
public function changeFloatingSubmissionForm(array &$form) {
// Is the form request from a floating submission form?
$floater = FALSE;
$request = \Drupal::request();
$request = Drupal::request();
$query = $request->query;
if ($query->has('floater')) {
$floater = $query->getBoolean('floater');
......@@ -204,6 +203,7 @@ class Submissions {
$moduleUrl = $this->skillingUtilities->getModuleUrlPath();
$challengeImageUrl = $moduleUrl . 'images/challenge.png';
// Separate out the Challenge label for translation.
/** @noinspection HtmlUnknownTarget */
$formTitle = $this->t(
"Exercise: @e <img src='@challengeUrl' alt='@challengeLabel'> (attempt: @v)",
[
......@@ -407,7 +407,7 @@ class Submissions {
// Make an entity type manager.
// Load current user service.
/* @var \Drupal\skilling\Utilities $utilities */
$utilities = \Drupal::service('skilling.utilities');
$utilities = Drupal::service('skilling.utilities');
// Add must specify exercise.
if (!$queryParams->has('exercisename')) {
throw new SkillingValueMissingException(
......
......@@ -6,10 +6,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use DateInterval;
use DateTime;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\skilling\SkillingClass\ExerciseDueRecord;
use Drupal\skilling_history\SkillingHistoryConstants;
use Drupal\skilling\SkillingClass\SkillingCurrentClass;
/**
......@@ -160,24 +157,24 @@ class Timeline {
}
else {
// Load the submissions for the exercises.
$submissionIds = [];
$submissions = [];
if (count($exerciseNids) > 0) {
$submissionIds = $this->entityTypeManager->getStorage('node')
->getQuery()
->condition('type', 'submission')
// For the current user.
->condition('field_user', $this->currentUser->id())
// Published submissions.
->condition('status', 1)
// One of the exercises in question.
->condition('field_exercise.target_id', $exerciseNids, 'IN')
// Exercise is published. Extra check.
->condition('field_exercise.entity.status', 1)
->execute();
// $submissionIds = [];
// $submissions = [];
// if (count($exerciseNids) > 0) {
// $submissionIds = $this->entityTypeManager->getStorage('node')
// ->getQuery()
// ->condition('type', 'submission')
// // For the current user.
// ->condition('field_user', $this->currentUser->id())
// // Published submissions.
// ->condition('status', 1)
// // One of the exercises in question.
// ->condition('field_exercise.target_id', $exerciseNids, 'IN')
// // Exercise is published. Extra check.
// ->condition('field_exercise.entity.status', 1)
// ->execute();
// $submissions = $this->entityTypeManager->getStorage('node')
// ->loadMultiple($submissionIds);
}
// }
// Find out the submission status of each exercise.
// Returns array indexed by exercise nid.
$exercisesSubmissionSummary = $this->submissionsService
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment