11
11
use HDNET \Importr \Service \ImportServiceInterface ;
12
12
use HDNET \Importr \Service \Manager ;
13
13
use Psr \Http \Message \ResponseInterface ;
14
+ use TYPO3 \CMS \Backend \Template \ModuleTemplate ;
15
+ use TYPO3 \CMS \Backend \Template \ModuleTemplateFactory ;
14
16
use TYPO3 \CMS \Core \Messaging \FlashMessage ;
15
17
use TYPO3 \CMS \Core \Messaging \FlashMessageService ;
16
18
use TYPO3 \CMS \Core \Resource \ResourceFactory ;
17
19
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
18
20
use TYPO3 \CMS \Extbase \Mvc \Controller \ActionController ;
21
+ use TYPO3 \CMS \Extbase \Utility \DebuggerUtility ;
19
22
20
23
/**
21
24
* Description of ImportrController
@@ -54,7 +57,8 @@ public function __construct(
54
57
StrategyRepository $ strategyRepository ,
55
58
ImportRepository $ importRepository ,
56
59
Manager $ importManager ,
57
- ImportServiceInterface $ importService
60
+ ImportServiceInterface $ importService ,
61
+ protected ModuleTemplateFactory $ moduleTemplateFactory
58
62
) {
59
63
$ this ->resourceFactory = $ resourceFactory ;
60
64
$ this ->strategyRepository = $ strategyRepository ;
@@ -65,6 +69,7 @@ public function __construct(
65
69
66
70
public function indexAction ():ResponseInterface
67
71
{
72
+ $ viewVariables = [];
68
73
$ combinedIdentifier = GeneralUtility::_GP ('id ' );
69
74
if (isset ($ combinedIdentifier ) && \is_string ($ combinedIdentifier )) {
70
75
$ folder = $ this ->resourceFactory ->getFolderObjectFromCombinedIdentifier ($ combinedIdentifier );
@@ -73,11 +78,13 @@ public function indexAction():ResponseInterface
73
78
$ files [$ file ->getStorage ()
74
79
->getUid () . ': ' . $ file ->getIdentifier ()] = $ file ->getName ();
75
80
}
76
- $ this -> view -> assign ( 'folder ' , $ files) ;
81
+ $ viewVariables [ 'folder ' ] = $ files ;
77
82
}
78
- $ this -> view -> assign ( 'imports ' , $ this ->importRepository ->findUserQueue () );
83
+ $ viewVariables [ 'imports ' ] = $ this ->importRepository ->findUserQueue ();
79
84
80
- return $ this ->htmlResponse ($ this ->view ->render ());
85
+ return $ this ->createModuleTemplate ()
86
+ ->assignMultiple ($ viewVariables )
87
+ ->renderResponse ('Index ' );
81
88
}
82
89
83
90
/**
@@ -86,9 +93,13 @@ public function indexAction():ResponseInterface
86
93
public function importAction ($ identifier ):ResponseInterface
87
94
{
88
95
$ file = $ this ->resourceFactory ->getObjectFromCombinedIdentifier ($ identifier );
89
- $ this ->view ->assign ('file ' , $ file );
90
- $ this ->view ->assign ('strategies ' , $ this ->strategyRepository ->findAllUser ());
91
- return $ this ->htmlResponse ($ this ->view ->render ());
96
+ $ viewVariables = [
97
+ 'file ' => $ file ,
98
+ 'strategies ' => $ this ->strategyRepository ->findAllUser (),
99
+ ];
100
+ return $ this ->createModuleTemplate ()
101
+ ->assignMultiple ($ viewVariables )
102
+ ->renderResponse ('Import ' );
92
103
}
93
104
94
105
/**
@@ -98,12 +109,19 @@ public function importAction($identifier):ResponseInterface
98
109
public function previewAction ($ identifier , Strategy $ strategy ):ResponseInterface
99
110
{
100
111
$ file = $ this ->resourceFactory ->getObjectFromCombinedIdentifier ($ identifier );
101
- $ this ->view ->assign ('filepath ' , $ file ->getPublicUrl ());
102
- $ this ->view ->assign ('strategy ' , $ strategy );
103
112
104
- $ previewData = $ this ->importManager ->getPreview ($ strategy , $ file ->getPublicUrl ());
105
- $ this ->view ->assign ('preview ' , $ previewData );
106
- return $ this ->htmlResponse ($ this ->view ->render ());
113
+ $ filePath = $ file ->getForLocalProcessing ();
114
+ // @todo check path (absolute)
115
+ $ previewData = $ this ->importManager ->getPreview ($ strategy , $ filePath );
116
+
117
+ return $ this ->createModuleTemplate ()
118
+ ->assignMultiple ([
119
+ // @todo better the file ID
120
+ 'filepath ' => $ filePath ,
121
+ 'strategy ' => $ strategy ,
122
+ 'preview ' => $ previewData ,
123
+ ])
124
+ ->renderResponse ('Preview ' );
107
125
}
108
126
109
127
/**
@@ -140,4 +158,11 @@ public function resetAction(Import $import):ResponseInterface
140
158
$ this ->importRepository ->update ($ import );
141
159
return $ this ->redirect ('index ' );
142
160
}
161
+
162
+ protected function createModuleTemplate (): ModuleTemplate
163
+ {
164
+ return $ this ->moduleTemplateFactory ->create ($ this ->request )
165
+ ->setFlashMessageQueue ($ this ->getFlashMessageQueue ())
166
+ ->setModuleClass ('tx-impotr ' );
167
+ }
143
168
}
0 commit comments