Exemplo n.º 1
0
 /**
  * Upload a meeting document.
  *
  * @param array|Traversable $post
  * @param array|Traversable $files
  *
  * @return boolean If uploading was a success
  */
 public function uploadDocument($post, $files)
 {
     $form = $this->getDocumentForm();
     $data = array_merge_recursive($post->toArray(), $files->toArray());
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     $data = $form->getData();
     $path = $this->getFileStorageService()->storeUploadedFile($data['upload']);
     $meeting = explode('/', $data['meeting']);
     $meeting = $this->getMeeting($meeting[0], $meeting[1]);
     $document = new MeetingDocument();
     $document->setPath($path);
     $document->setName($data['name']);
     $document->setMeeting($meeting);
     $this->getMeetingMapper()->persistDocument($document);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Upload a meeting document.
  *
  * @param array|Traversable $post
  * @param array|Traversable $files
  *
  * @return boolean If uploading was a success
  */
 public function uploadDocument($post, $files)
 {
     $form = $this->getDocumentForm();
     $data = array_merge_recursive($post->toArray(), $files->toArray());
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     $data = $form->getData();
     $config = $this->getServiceManager()->get('config');
     $config = $config['meeting-documents'];
     $filename = $data['meeting'] . '/' . $data['upload']['name'];
     $path = $config['upload_dir'] . '/' . $filename;
     if (file_exists($path)) {
         $form->setError(Notes::ERROR_FILE_EXISTS);
         return false;
     }
     $meeting = explode('/', $data['meeting']);
     $meeting = $this->getMeeting($meeting[0], $meeting[1]);
     $document = new MeetingDocument();
     $document->setPath($data['upload']['name']);
     $document->setName($data['name']);
     $document->setMeeting($meeting);
     // finish upload and save in the database
     if (!is_dir(dirname($path))) {
         mkdir(dirname($path), $config['dir_mode'], true);
     }
     move_uploaded_file($data['upload']['tmp_name'], $path);
     $this->getMeetingMapper()->persistDocument($document);
     return true;
 }