1 | <?php |
||
2 | |||
3 | declare( strict_types = 1 ); |
||
4 | |||
5 | namespace ModernTimeline; |
||
6 | |||
7 | use ModernTimeline\ResultFacade\SimpleQueryResult; |
||
8 | use ModernTimeline\ResultFacade\ResultPresenter; |
||
9 | use ModernTimeline\SlidePresenter\SimpleSlidePresenter; |
||
10 | use ModernTimeline\SlidePresenter\SlidePresenter; |
||
11 | use ModernTimeline\SlidePresenter\TemplateSlidePresenter; |
||
12 | use SMWOutputs; |
||
0 ignored issues
–
show
|
|||
13 | |||
14 | class TimelinePresenter implements ResultPresenter { |
||
15 | |||
16 | private string $id; |
||
17 | |||
18 | 4 | public function __construct() { |
|
19 | 4 | $this->id = $this->newTimelineId(); |
|
20 | 4 | } |
|
21 | |||
22 | 4 | private function newTimelineId(): string { |
|
23 | 4 | static $timelineNumber = 0; |
|
24 | 4 | return 'modern_timeline_' . ++$timelineNumber; |
|
25 | } |
||
26 | |||
27 | 4 | public function presentResult( SimpleQueryResult $result ): string { |
|
28 | 4 | SMWOutputs::requireResource( 'ext.modern.timeline' ); |
|
29 | |||
30 | 4 | SMWOutputs::requireHeadItem( |
|
31 | 4 | $this->id, |
|
32 | 4 | $this->createJs( $this->createJsonString( $result ) ) |
|
33 | ); |
||
34 | |||
35 | 4 | return $this->createDiv( $result->getParameters() ); |
|
36 | } |
||
37 | |||
38 | 4 | private function createJsonString( SimpleQueryResult $result ): string { |
|
39 | 4 | $preJson = $this->newJsonBuilder( $result ) |
|
40 | 4 | ->eventsToTimelineJson( ( new EventExtractor( $result->getParameters() ) )->extractEvents( $result->getSubjects() ) ); |
|
41 | |||
42 | 4 | $preJson['options'] = TimelineOptions::processedParamsToJson( $result->getParameters() ); |
|
43 | |||
44 | 4 | return json_encode( $preJson ); |
|
45 | } |
||
46 | |||
47 | 4 | private function newJsonBuilder( SimpleQueryResult $result ): JsonBuilder { |
|
48 | 4 | return new JsonBuilder( |
|
49 | 4 | $this->getSlidePresenter( $result ) |
|
50 | ); |
||
51 | } |
||
52 | |||
53 | 4 | private function getSlidePresenter( SimpleQueryResult $result ): SlidePresenter { |
|
54 | 4 | $templateName = $result->getParameters()['template']; |
|
55 | |||
56 | 4 | if ( $templateName === '' ) { |
|
57 | 3 | return new SimpleSlidePresenter( $result->getProcessingResult()->getParameterArray() ); |
|
58 | } |
||
59 | |||
60 | 1 | return new TemplateSlidePresenter( $templateName ); |
|
61 | } |
||
62 | |||
63 | 4 | private function createJs( string $json ): string { |
|
64 | 4 | return \Html::rawElement( |
|
0 ignored issues
–
show
The type
Html was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
65 | 4 | 'script', |
|
66 | [ |
||
67 | 4 | 'type' => 'text/javascript' |
|
68 | ], |
||
69 | "if (!window.hasOwnProperty('modernTimeline')) {window.modernTimeline = {};}" |
||
70 | 4 | . "\n window.modernTimeline.{$this->id} = $json;" |
|
71 | ); |
||
72 | } |
||
73 | |||
74 | 4 | private function createDiv( array $parameters ): string { |
|
75 | 4 | $width = $parameters[TimelineOptions::PARAM_WIDTH]; |
|
76 | 4 | $height = $parameters[TimelineOptions::PARAM_HEIGHT]; |
|
77 | |||
78 | 4 | return \Html::rawElement( |
|
79 | 4 | 'div', |
|
80 | [ |
||
81 | 4 | 'id' => $this->id, |
|
82 | 4 | 'style' => "width: $width; height: $height", |
|
83 | 4 | 'class' => 'modern_timeline_outer_div' |
|
84 | ], |
||
85 | 4 | \Html::element( |
|
86 | 4 | 'div', |
|
87 | [ |
||
88 | 4 | 'class' => 'modern_timeline_inner_div', |
|
89 | 'style' => 'width: 100%; height: calc(100% - 10px); background-color: rgba(0, 0, 0, 0.05); margin-top: 5px; margin-bottom: 5px;' |
||
90 | ] |
||
91 | ) |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | } |
||
96 |
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