Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_jobs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_jobs
Commits
e8a773d4
Commit
e8a773d4
authored
7 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Started work on file upload
parent
3beef7ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Classes/Controller/JoblistController.php
+79
-2
79 additions, 2 deletions
Classes/Controller/JoblistController.php
Resources/Private/Templates/Joblist/ApplyForm.html
+2
-2
2 additions, 2 deletions
Resources/Private/Templates/Joblist/ApplyForm.html
ext_localconf.php
+1
-1
1 addition, 1 deletion
ext_localconf.php
with
82 additions
and
5 deletions
Classes/Controller/JoblistController.php
+
79
−
2
View file @
e8a773d4
...
...
@@ -28,10 +28,11 @@ namespace SGalinski\SgJobs\Controller;
use
SGalinski\SgJobs\Service\BackendService
;
use
SGalinski\SgMail\Service\MailTemplateService
;
use
TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
;
use
TYPO3\CMS\Core\Exception
;
use
TYPO3\CMS\Core\Resource\ResourceFactory
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Mvc\Controller\ActionController
;
use
TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
;
/**
* The joblist plugin controller
...
...
@@ -80,8 +81,17 @@ class JoblistController extends ActionController {
/**
* @param array $applyData
* @return void
* @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
* @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
* @throws \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException
* @throws \Exception
* @throws \InvalidArgumentException
*/
public
function
applyAction
(
array
$applyData
=
[])
{
$this
->
handleFileUpload
(
'coverLetter'
);
$this
->
handleFileUpload
(
'cv'
);
$this
->
handleFileUpload
(
'certificates'
);
// get an instance of the mail service
/** @var MailTemplateService $mailService */
$mailService
=
$this
->
objectManager
->
get
(
...
...
@@ -100,7 +110,7 @@ class JoblistController extends ActionController {
* @param array $applyData
* @return array
*/
private
function
getApplicationMailMarkers
(
array
$applyData
=
[])
{
private
function
getApplicationMailMarkers
(
array
$applyData
=
[])
:
array
{
return
[
'jobtitle'
=>
$applyData
[
'jobTitle'
],
'salutation'
=>
$applyData
[
'salutation'
],
...
...
@@ -115,4 +125,71 @@ class JoblistController extends ActionController {
'message'
=>
$applyData
[
'message'
]
];
}
/**
* Registers an uploaded file for TYPO3 native upload handling.
*
* @param array &$data
* @param string $namespace
* @param string $fieldName
* @param string $targetDirectory
* @return void
*/
private
function
registerUploadField
(
array
&
$data
,
$namespace
,
$fieldName
,
$targetDirectory
=
'1:/_temp_/'
)
{
if
(
!
isset
(
$data
[
'upload'
]))
{
$data
[
'upload'
]
=
[];
}
$counter
=
count
(
$data
[
'upload'
])
+
1
;
$keys
=
array_keys
(
$_FILES
[
$namespace
]);
foreach
(
$keys
as
$key
)
{
$_FILES
[
'upload_'
.
$counter
][
$key
]
=
$_FILES
[
$namespace
][
$key
][
$fieldName
];
}
$data
[
'upload'
][
$counter
]
=
[
'data'
=>
$counter
,
'target'
=>
$targetDirectory
,
];
}
/**
* @param string $fieldName
*/
private
function
handleFileUpload
(
$fieldName
=
''
)
{
$data
=
[];
$namespace
=
key
(
$_FILES
);
$applicationId
=
md5
(
uniqid
(
'sg'
,
TRUE
));
$resourceFactory
=
GeneralUtility
::
makeInstance
(
ResourceFactory
::
class
);
$storage
=
$resourceFactory
->
getStorageObject
(
1
);
if
(
!
$storage
->
hasFolder
(
'/Applications/'
.
$applicationId
.
'/'
))
{
$storage
->
createFolder
(
'/Applications/'
.
$applicationId
.
'/'
);
}
$targetFalDirectory
=
'1:/Applications/'
.
$applicationId
.
'/'
;
// Register every upload field from the form:
$this
->
registerUploadField
(
$data
,
$namespace
,
$fieldName
,
$targetFalDirectory
);
// Initializing:
/** @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility $fileProcessor */
$fileProcessor
=
GeneralUtility
::
makeInstance
(
ExtendedFileUtility
::
class
);
$fileProcessor
->
setActionPermissions
([
'addFile'
=>
TRUE
]);
// Actual upload
$fileProcessor
->
start
(
$data
);
$result
=
$fileProcessor
->
processData
();
debug
(
$result
);
// Do whatever you want with $result (array of File objects)
foreach
(
$result
[
'upload'
]
as
$files
)
{
/** @var \TYPO3\CMS\Core\Resource\File $file */
$file
=
$files
[
0
];
// Single element array due to the way we registered upload fields
}
}
}
This diff is collapsed.
Click to expand it.
Resources/Private/Templates/Joblist/ApplyForm.html
+
2
−
2
View file @
e8a773d4
...
...
@@ -42,11 +42,11 @@
<f:form.upload
property=
"cv"
id=
"apply-cv"
/>
<br
/>
<label
for=
"apply-certificates"
><f:translate
key=
"frontend.apply.certificates"
/></label>
<
f:form.upload
property=
"certificates"
id=
"apply-
certificates
"
/>
<
input
id=
"apply-certificates"
type=
"file"
name=
"tx_sgjobs_joblist[applyData][
certificates
]"
multiple
/>
<br
/>
<label
for=
"apply-message"
><f:translate
key=
"frontend.apply.message"
/></label>
<f:form.textarea
property=
"message"
id=
"apply-message"
data=
"{}"
class=
""
/>
<br
/>
<br
/>
-
<f:form.submit
value=
"{f:translate(key:'frontend.applyNow')}"
/>
</f:form>
</f:section>
This diff is collapsed.
Click to expand it.
ext_localconf.php
+
1
−
1
View file @
e8a773d4
...
...
@@ -10,7 +10,7 @@
],
[
// Uncacheable actions
'Joblist'
=>
'apply'
'Joblist'
=>
'
applyForm,
apply'
]
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment