Пример #1
0
 public function createArchiveFile($data)
 {
     try {
         $archiveFileEntity = new \Application\Entity\ArchiveFile();
         if (!is_array($data)) {
             $data = $data->toArray();
         }
         $fighterA = $this->getFighterService()->getFighter($data['fighter_a']);
         $fighterB = $this->getFighterService()->getFighter($data['fighter_b']);
         unset($data['fighter_b']);
         unset($data['fighter_a']);
         $data['status'] = 'New';
         $archiveFileEntity->setFighterA($fighterA);
         $archiveFileEntity->setFighterB($fighterB);
         $archiveFileEntity->setRawData($data);
         $archiveFileEntity->validateData();
         $fileIndex = new \Application\Entity\FileIndex();
         $fileIndex->setStatus($archiveFileEntity->getStatus());
         $fileIndex->setType('archive');
         $this->db->persist($fileIndex);
         $this->db->flush($fileIndex);
         $archiveFileEntity->setFileIndex($fileIndex);
         $archiveFileEntity->setStorage($this->getAvailableStorage());
         $this->db->persist($archiveFileEntity);
         $this->db->flush();
         /*
                     $fileName = 'AF' . sprintf('%010d', (int)$archiveFileEntity->getId());
                     $archiveFileEntity->setName($fileName);
                     $archiveFileEntity->setPath('examplePath/' . $fileName);
                     $this->db->persist($archiveFileEntity);
         * 
         */
         $archiveFileId = $archiveFileEntity->getId();
         $fileName = $archiveFileEntity->getId() . '_' . $archiveFileEntity->getSource() . '_' . $fighterA->getLastnameShortcut() . '_' . $fighterB->getLastnameShortcut();
         $fileName = strtolower($fileName);
         $archiveFileEntity->setName($fileName);
         if (isset($data['actions'])) {
             foreach ($data['actions'] as $action) {
                 $actionObj = new \Application\Entity\Tape();
                 $actionObj->setFkId($archiveFileId);
                 $actionObj->setAction($action['action']);
                 $actionObj->setActionFrom($action['action_from']);
                 $actionObj->setArchiveFile($archiveFileEntity);
                 $this->db->persist($actionObj);
             }
         }
         if (isset($data['interviews'])) {
             foreach ($data['interviews'] as $interview) {
                 $interviewObj = new \Application\Entity\Interview();
                 $interviewObj->setActionIn($interview['action_in']);
                 $interviewObj->setArchivFile($archiveFileEntity);
                 $interviewObj->setFighter($interview['fighter']);
                 $interviewObj->setLanguage($interview['language']);
                 $this->db->persist($interviewObj);
             }
         }
         $this->db->flush();
         return $archiveFileEntity;
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         return false;
     }
     return true;
 }
Пример #2
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()));
 }