/** * @return ViewModel */ public function importAction() { $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form = new Import($this->getContactService(), $this->getSelectionService()); $form->setData($data); /** store the data in the session, so we can use it when we really handle the import */ $importSession = new Container('import'); $handleImport = null; if ($this->getRequest()->isPost()) { if (isset($data['upload']) && $form->isValid()) { $fileData = file_get_contents($data['file']['tmp_name'], FILE_TEXT); $importSession->active = true; $importSession->fileData = $fileData; $handleImport = $this->handleImport($fileData, null, isset($data['optIn']) ? $data['optIn'] : [], $data['selection_id'], $data['selection']); } if (isset($data['import']) && $importSession->active && isset($data['key'])) { $handleImport = $this->handleImport($importSession->fileData, $data['key'], isset($data['optIn']) ? $data['optIn'] : [], $data['selection_id'], $data['selection']); } } return new ViewModel(['form' => $form, 'handleImport' => $handleImport]); }
/** * @return ViewModel */ public function importAction() { $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form = new Import(); $form->setData($data); $handleImport = null; if ($this->getRequest()->isPost() && $form->isValid()) { $handleImport = $this->handleImport(file_get_contents($data['file']['tmp_name'])); } return new ViewModel(['form' => $form, 'handleImport' => $handleImport]); }