1 | <?php |
||
2 | |||
3 | declare( strict_types = 1 ); |
||
4 | |||
5 | namespace ModernTimeline; |
||
6 | |||
7 | use ModernTimeline\ResultFacade\SubjectCollection; |
||
8 | use ModernTimeline\SlidePresenter\SlidePresenter; |
||
9 | use SMWDITime; |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | class JsonBuilder { |
||
12 | |||
13 | public function __construct( |
||
14 | private SlidePresenter $slidePresenter |
||
15 | 9 | ) { |
|
16 | 9 | } |
|
17 | 9 | ||
18 | /** |
||
19 | * @param Event[] $events |
||
20 | * @return array |
||
21 | */ |
||
22 | public function eventsToTimelineJson( array $events ): array { |
||
23 | 9 | $jsonEvents = []; |
|
24 | 9 | ||
25 | foreach ( $events as $event ) { |
||
26 | 9 | if ( $event->getSubject()->getWikiPage()->getTitle() !== null ) { |
|
27 | 8 | $jsonEvents[] = $this->buildEvent( $event ); |
|
28 | } |
||
29 | } |
||
30 | 9 | ||
31 | return [ 'events' => $jsonEvents ]; |
||
32 | } |
||
33 | 8 | ||
34 | public function buildEvent( Event $event ): array { |
||
35 | $jsonEvent = [ |
||
36 | 8 | 'text' => [ |
|
37 | 8 | 'headline' => $this->newHeadline( $event->getSubject()->getWikiPage()->getTitle() ), |
|
38 | 'text' => $this->slidePresenter->getText( $event->getSubject() ) |
||
39 | 8 | ], |
|
40 | 'start_date' => $this->timeToJson( $event->getStartDate() ), |
||
41 | ]; |
||
42 | 8 | ||
43 | 6 | if ( $event->getEndDate() !== null ) { |
|
44 | $jsonEvent['end_date'] = $this->timeToJson( $event->getEndDate() ); |
||
45 | } |
||
46 | 8 | ||
47 | if ( $event->hasImage() ) { |
||
48 | $jsonEvent['media'] = [ |
||
49 | 'url' => $event->getImageUrl(), |
||
50 | 'thumbnail' => $event->getImageUrl() |
||
51 | ]; |
||
52 | } |
||
53 | 8 | ||
54 | return $jsonEvent; |
||
55 | } |
||
56 | 8 | ||
57 | 8 | private function newHeadline( \Title $title ): string { |
|
0 ignored issues
–
show
The type
Title 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 ![]() |
|||
58 | 8 | return \Html::element( |
|
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 ![]() |
|||
59 | 8 | 'a', |
|
60 | 8 | [ 'href' => $title->getFullURL() ], |
|
61 | $title->getText() |
||
62 | ); |
||
63 | |||
64 | // return DataValueFactory::getInstance()->newDataValueByItem( $subject->getWikiPage() )->getLongHTMLText( smwfGetLinker() ); |
||
65 | } |
||
66 | 8 | ||
67 | private function timeToJson( SMWDITime $time ): array { |
||
68 | 8 | return [ |
|
69 | 8 | 'year' => $time->getYear(), |
|
70 | 8 | 'month' => $time->getMonth(), |
|
71 | 8 | 'day' => $time->getDay(), |
|
72 | 8 | 'hour' => $time->getHour(), |
|
73 | 8 | 'minute' => $time->getMinute(), |
|
74 | 'second' => (int)$time->getSecond(), |
||
75 | ]; |
||
76 | } |
||
77 | |||
78 | } |
||
79 |
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