1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Game\Lib; |
4
|
|
|
|
5
|
|
|
use Stu\Component\Game\GameEnum; |
|
|
|
|
6
|
|
|
use Stu\Module\Control\GameControllerInterface; |
7
|
|
|
use Stu\Module\Control\ViewContext; |
8
|
|
|
use Stu\Orm\Repository\TutorialStepRepositoryInterface; |
9
|
|
|
use Stu\Orm\Repository\UserTutorialRepositoryInterface; |
10
|
|
|
|
11
|
|
|
final class TutorialProvider |
12
|
|
|
{ |
13
|
4 |
|
public function __construct( |
14
|
|
|
private TutorialStepRepositoryInterface $tutorialStepRepository, |
15
|
|
|
private UserTutorialRepositoryInterface $userTutorialRepository |
16
|
4 |
|
) {} |
17
|
|
|
|
18
|
|
|
public function setTemplateVariables( |
19
|
|
|
ViewContext $viewContext, |
20
|
|
|
GameControllerInterface $game |
21
|
|
|
): void { |
22
|
|
|
|
23
|
|
|
$user = $game->getUser(); |
24
|
|
|
if ($user->getTutorials()->isEmpty()) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$tutorialSteps = $this->tutorialStepRepository->findByUserAndViewContext( |
29
|
|
|
$game->getUser(), |
30
|
|
|
$viewContext |
31
|
|
|
); |
32
|
|
|
if (!$tutorialSteps) { |
|
|
|
|
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$userTutorial = $this->userTutorialRepository->findUserTutorialByUserAndViewContext( |
37
|
|
|
$game->getUser(), |
38
|
|
|
$viewContext |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
if (!$userTutorial) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
$currentStep = $userTutorial->getTutorialStep(); |
47
|
|
|
$currentStepId = $currentStep->getId(); |
48
|
|
|
|
49
|
|
|
$payloadArray = []; |
50
|
|
|
foreach ($tutorialSteps as $tutorialStep) { |
51
|
|
|
$result = []; |
52
|
|
|
|
53
|
|
|
if ($tutorialStep->getElementIds() !== null) { |
54
|
|
|
$result['elementIds'] = array_map('trim', explode(',', $tutorialStep->getElementIds())); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($tutorialStep->getTitle() !== null) { |
58
|
|
|
$result['title'] = trim((string)json_encode($tutorialStep->getTitle()), '"'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($tutorialStep->getText() !== null) { |
62
|
|
|
$result['text'] = trim((string)json_encode($tutorialStep->getText()), '"'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($tutorialStep->getInnerUpdate() !== null) { |
66
|
|
|
$result['innerUpdate'] = $tutorialStep->getInnerUpdate(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($tutorialStep->getFallbackIndex() !== null) { |
70
|
|
|
$result['fallbackIndex'] = $tutorialStep->getFallbackIndex(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$result['previousid'] = $tutorialStep->getPreviousStepId(); |
74
|
|
|
$result['nextid'] = $tutorialStep->getNextStepId(); |
75
|
|
|
|
76
|
|
|
$payloadArray[$tutorialStep->getId()] = $result; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$game->addExecuteJS(sprintf( |
80
|
|
|
"initTutorialSteps('%s', %d);", |
81
|
|
|
json_encode($payloadArray), |
82
|
|
|
$currentStepId |
83
|
|
|
), GameEnum::JS_EXECUTION_AFTER_RENDER); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths