34 const NAME =
"admin_obligation_from_csv";
35 const KEY_UPLOAD_MAX_FILESIZE =
'upload_max_filesize';
37 function __construct()
39 parent::__construct(self::NAME, array(
40 self::TITLE =>
"Admin Obligation CSV Import",
41 self::MENU_LIST =>
"Admin::Obligation Admin::CSV Import",
42 self::REQUIRES_LOGIN =>
true,
51 protected function handle (Request $request)
55 if ($request->isMethod(
'POST')) {
56 $uploadFile = $request->files->get(
'file_input');
57 $delimiter = $request->get(
'delimiter')?:
',';
58 $enclosure = $request->get(
'enclosure')?:
'"';
59 $vars[
'message'] = $this->handleFileUpload($uploadFile,$delimiter,$enclosure);
62 $vars[self::KEY_UPLOAD_MAX_FILESIZE] = ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
63 $vars[
'baseUrl'] = $request->getBaseUrl();
65 return $this->
render(
"admin_license_from_csv.html.twig", $this->mergeWithDefault($vars));
72 protected function handleFileUpload($uploadedFile,$delimiter=
',',$enclosure=
'"')
75 if (! ($uploadedFile instanceof UploadedFile)) {
76 $errMsg = _(
"No file selected");
77 } elseif ($uploadedFile->getSize() == 0 && $uploadedFile->getError() == 0) {
78 $errMsg = _(
"Larger than upload_max_filesize ") . ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
79 } elseif ($uploadedFile->getClientOriginalExtension()!=
'csv') {
80 $errMsg = _(
'Invalid extension ') .
81 $uploadedFile->getClientOriginalExtension() .
' of file ' .
82 $uploadedFile->getClientOriginalName();
84 if (! empty($errMsg)) {
88 $obligationCsvImport = $this->
getObject(
'app.obligation_csv_import');
89 $obligationCsvImport->setDelimiter($delimiter);
90 $obligationCsvImport->setEnclosure($enclosure);
91 return $obligationCsvImport->handleFile($uploadedFile->getRealPath());
render($templateName, $vars=null, $headers=null)
Upload a file from the users computer using the UI.