10
10
/** ActionController of Core */
11
11
namespace Cv \Controller ;
12
12
13
+ use Core \Repository \RepositoryService ;
13
14
use Cv \Entity \CvInterface ;
15
+ use Cv \Service \UploadHandler ;
14
16
use Geo \Form \GeoSelect ;
15
17
use Geo \Form \GeoText ;
16
18
use Interop \Container \ContainerInterface ;
19
+ use Laminas \Form \FormElementManager \FormElementManagerV3Polyfill ;
17
20
use Laminas \Mvc \Controller \AbstractActionController ;
21
+ use Laminas \View \HelperPluginManager ;
18
22
use Laminas \View \Model \JsonModel ;
19
23
use Core \Form \SummaryFormInterface ;
20
24
use Auth \Entity \User ;
21
25
use Cv \Entity \Cv ;
22
26
use Cv \Entity \Contact ;
27
+ use PHPUnit \Util \Json ;
23
28
24
29
/**
25
30
* Main Action Controller for the application.
@@ -33,21 +38,32 @@ class ManageController extends AbstractActionController
33
38
private $ formElements ;
34
39
35
40
private $ viewHelper ;
36
-
37
- public static function factory (ContainerInterface $ container )
41
+
42
+ private $ uploadHandler ;
43
+
44
+ public function __construct (
45
+ RepositoryService $ repositories ,
46
+ FormElementManagerV3Polyfill $ formElements ,
47
+ HelperPluginManager $ viewHelper ,
48
+ UploadHandler $ uploadHandler
49
+ )
38
50
{
39
- $ controller = new static ();
40
- $ controller ->init ($ container );
41
- return $ controller ;
51
+ $ this ->repositories = $ repositories ;
52
+ $ this ->formElements = $ formElements ;
53
+ $ this ->viewHelper = $ viewHelper ;
54
+ $ this ->uploadHandler = $ uploadHandler ;
42
55
}
43
-
44
- public function init (ContainerInterface $ container )
56
+
57
+ public static function factory (ContainerInterface $ container )
45
58
{
46
- $ this ->repositories = $ container ->get ('repositories ' );
47
- $ this ->formElements = $ container ->get ('FormElementManager ' );
48
- $ this ->viewHelper = $ container ->get ('ViewHelperManager ' );
59
+ $ repositories = $ container ->get ('repositories ' );
60
+ $ formElements = $ container ->get ('FormElementManager ' );
61
+ $ viewHelper = $ container ->get ('ViewHelperManager ' );
62
+ $ uploadHandler = $ container ->get (UploadHandler::class);
63
+
64
+ return new self ($ repositories , $ formElements , $ viewHelper , $ uploadHandler );
49
65
}
50
-
66
+
51
67
public function formAction ()
52
68
{
53
69
$ repositories = $ this ->repositories ;
@@ -86,18 +102,25 @@ public function formAction()
86
102
$ params ->fromPost (),
87
103
$ params ->fromFiles ()
88
104
));
89
-
90
- if (!$ form ->isValid ()) {
91
- return new JsonModel ([
92
- 'valid ' => false ,
93
- 'errors ' => $ form ->getMessages ()
94
- ]);
95
- }
96
- /*
97
- * @todo This is a workaround for GeoJSON data insertion
98
- * until we figured out, what we really want it to be.
99
- */
100
105
$ formId = $ params ->fromQuery ('form ' );
106
+ $ viewHelperManager = $ this ->viewHelper ;
107
+
108
+ if ('image ' === $ formId ){
109
+ $ uploadHandler = $ this ->uploadHandler ;
110
+ $ uploadHandler ->handleUpload ($ cv , $ _FILES ['image ' ]);
111
+ }else {
112
+ if (!$ form ->isValid ()) {
113
+ return new JsonModel ([
114
+ 'valid ' => false ,
115
+ 'errors ' => $ form ->getMessages ()
116
+ ]);
117
+ };
118
+
119
+ /*
120
+ * @todo This is a workaround for GeoJSON data insertion
121
+ * until we figured out, what we really want it to be.
122
+ */
123
+
101
124
// if ('preferredJob' == $formId) {
102
125
// $locElem = $form->getBaseFieldset()->get('geo-location');
103
126
// if ($locElem instanceof GeoText) {
@@ -110,11 +133,11 @@ public function formAction()
110
133
// $cv->getPreferredJob()->setDesiredLocation($locElem->getValue());
111
134
// }
112
135
// }
136
+ $ this ->validateCv ($ cv );
137
+ $ repositories ->store ($ cv );
138
+ }
113
139
114
- $ this ->validateCv ($ cv );
115
140
116
- $ repositories ->store ($ cv );
117
- $ viewHelperManager = $ this ->viewHelper ;
118
141
119
142
if ('file-uri ' === $ params ->fromPost ('return ' )) {
120
143
$ content = $ viewHelperManager ->get ('basepath ' )
0 commit comments