示例#1
0
 public function newsendefilestep1Action()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if ((int) $id > 0) {
         $file = $this->fighterService->getDb()->find('Application\\Entity\\SendeFile', (int) $id);
         if (!$file) {
             $this->flashMessenger()->addMessage('Sende-Datei ist nicht gefunden!');
             return $this->redirect()->toRoute('sendefile', array('action' => 'newarchivefilestep1'));
         } else {
             return new ViewModel(array('file' => $file));
         }
     }
     if ($this->request->isPost()) {
         $postData = $this->getRequest()->getPost();
         $file = new \Application\Entity\SendeFile();
         $file->setCreatedAt(new \DateTime());
         $fileIndex = new \Application\Entity\FileIndex();
         $fileIndex->setType('sende');
         $fileIndex->setStatus('New');
         $fileIndex->setSendeFile($file);
         $this->fileService->getDb()->persist($fileIndex);
         $this->fileService->getDb()->flush();
         $file->setFileIndex($fileIndex);
         if (!empty($postData->title)) {
             $file->setTitle($postData->title);
         }
         if (!empty($postData->product_year)) {
             $file->setProductYear($postData->product_year);
         }
         $this->fileService->getDb()->persist($file);
         $this->fileService->getDb()->flush($file);
         $file = $this->fighterService->getDb()->find('Application\\Entity\\SendeFile', $file->getId());
         $file->setName($file->getId() . '_' . $file->getCreatedAt()->format('Ymd'));
         $file->setStorage($this->fileService->getAvailableStorage());
         $this->fileService->getDb()->persist($file);
         $this->fileService->getDb()->flush();
         return $this->redirect()->toRoute('sendefile', array('action' => 'newsendefilestep1', 'id' => $file->getId()));
     }
     return $this->redirect()->toRoute('sendefile', array('action' => 'newsendefilestep1', 'id' => $file->getId()));
 }