예제 #1
0
 public function processAction()
 {
     if (!$this->request->isPost()) {
         return $this->redirect()->toRoute(NULL, array('controller' => 'upload', 'action' => 'index'));
     }
     //$post = $this->request->getPost();
     //$request = $this->getRequest();
     //Création du formulaire
     $form = new UploadForm();
     //récupération de l'objet de travail
     //$uploadFile = new File();
     $uploadFile = $this->params()->fromFiles('fileupload');
     $form->setData($this->{$request}->getPost());
     if ($form->isValid()) {
         // Fetch Configuration from Module Config
         $uploadPath = $this->getFileUploadLocation();
         // Save Uploaded file
         $adapter = new \Zend\File\Transfer\Adapter\Http();
         $adapter->setDestination($uploadPath);
         if ($adapter->receive($uploadFile['name'])) {
             // File upload sucessfull
             $exchange_data = array();
             $exchange_data['label'] = $request->getPost()->get('label');
             $exchange_data['filename'] = $uploadFile['name'];
             $exchange_data['user_id'] = $user->id;
             $upload->exchangeArray($exchange_data);
             $uploadTable = $this->getServiceLocator()->get('UploadTable');
             $uploadTable->saveUpload($upload);
             return $this->redirect()->toRoute('users/upload-manager', array('action' => 'index'));
         }
         /*
                     $post = $this->request->getPost();
                     $form = new UploadForm();
                     // to get Login Form
                   // $form = $this->getServiceLocator()->get('LoginForm');
         
                     
                     $inputFilter = new UploadFilter();
                     $form->setInputFilter($inputFilter);
                     $form->setData($post);
                         if (!$form->isValid()) {
           $model = new ViewModel(array(
             'error' => true,
              'form' => $form,
                    ));
         
                      $model->setTemplate('users/upload/index');
                  return $model;
          }
          
          // Créer l'utisateur avant la page de  confirmation  
           $this->createUpload($form->getData());
         
            return $this->redirect()->toRoute(NULL , array(
            'controller' => 'upload',
                'action' => 'confirm'
                          ));
         */
     }
 }
 public function processAction()
 {
     $userEmail = $this->getAuthService()->getStorage()->read();
     if (!$userEmail) {
         $this->flashMessenger()->addErrorMessage("not authorized");
         return $this->redirect()->toRoute('media', array('action' => 'index'));
     }
     $request = $this->getRequest();
     $form = new UploadForm();
     $uploadFile = $this->params()->fromFiles('fileupload');
     $form->setData($request->getPost());
     if ($form->isValid()) {
         // Получение конфигурации из конфигурационных данных модуля
         $uploadPath = $this->getFileUploadLocation();
         // Сохранение выгруженного файла
         $adapter = new \Zend\File\Transfer\Adapter\Http();
         $adapter->setDestination($uploadPath);
         if ($adapter->receive($uploadFile['name'])) {
             $userTable = $this->getServiceLocator()->get('UserTable');
             $user = $userTable->getUserByEmail($userEmail);
             //                // Успешная выгрузка файла
             $exchange_data = array();
             $exchange_data['label'] = $request->getPost()->get('label');
             $exchange_data['filename'] = $uploadFile['name'];
             $exchange_data['user_id'] = $user->getId();
             $imageUpload = new \Users\Model\ImageUpload();
             $thumbnailFileName = $this->generateThumbnail($uploadFile['name']);
             $thumbnail_data = $exchange_data;
             $thumbnail_data['thumbnail'] = $thumbnailFileName;
             $imageUpload->exchangeArray($thumbnail_data);
             $imageUploadTable = $this->getServiceLocator()->get('ImageUploadTable');
             $imageUploadTable->save($imageUpload);
         }
     }
     return $this->redirect()->toRoute('media', array('action' => 'index'));
 }
 public function processAction()
 {
     $userEmail = $this->getAuthService()->getStorage()->read();
     if (!$userEmail) {
         $this->flashMessenger()->addErrorMessage("not authorized");
         return $this->getResponse()->setContent("not authorized");
     }
     $request = $this->getRequest();
     $form = new UploadForm();
     $uploadFile = $this->params()->fromFiles('fileupload');
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Получение конфигурации из конфигурационных данных модуля
             $uploadPath = $this->getFileUploadLocation();
             // Сохранение выгруженного файла
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setDestination($uploadPath);
             if ($adapter->receive($uploadFile['name'])) {
                 $userTable = $this->getServiceLocator()->get('UserTable');
                 $user = $userTable->getUserByEmail($userEmail);
                 $upload = new \Users\Model\Upload();
                 // Успешная выгрузка файла
                 $exchange_data = array();
                 $exchange_data['label'] = $request->getPost()->get('label');
                 $exchange_data['filename'] = $uploadFile['name'];
                 $exchange_data['user_id'] = $user->getId();
                 $upload->exchangeArray($exchange_data);
                 $uploadTable = $this->getServiceLocator()->get('UploadTable');
                 $uploadTable->save($upload);
                 $upload->setId($uploadTable->getLastInsertValue());
                 //добавить в Lucene
                 $searchIndexLocation = $this->getIndexLocation();
                 $index = Lucene\Lucene::create($searchIndexLocation);
                 // создание полей lucene
                 $fileUploadId = Document\Field::unIndexed('upload_id', $upload->getId());
                 $label = Document\Field::Text('label', $upload->getLabel());
                 $owner = Document\Field::Text('owner', $user->getName());
                 $uploadPath = $this->getFileUploadLocation();
                 $fileName = $upload->getFilename();
                 $filePath = $uploadPath . DIRECTORY_SEPARATOR . $fileName;
                 if (substr_compare($fileName, ".xlsx", strlen($fileName) - strlen(".xlsx"), strlen(".xlsx")) === 0) {
                     // Индексирование таблицы excel
                     $indexDoc = Lucene\Document\Xlsx::loadXlsxFile($filePath);
                 } else {
                     if (substr_compare($fileName, ".docx", strlen($fileName) - strlen(".docx"), strlen(".docx")) === 0) {
                         // Индексирование документа Word
                         $indexDoc = Lucene\Document\Docx::loadDocxFile($filePath);
                     } else {
                         $indexDoc = new Lucene\Document();
                     }
                 }
                 // создание нового документа и добавление всех полей
                 $indexDoc = new Lucene\Document();
                 $indexDoc->addField($label);
                 $indexDoc->addField($owner);
                 $indexDoc->addField($fileUploadId);
                 $index->addDocument($indexDoc);
                 $index->commit();
             }
         }
     }
     return $this->redirect()->toRoute('uploads', array('action' => 'index'));
 }
예제 #4
0
 public function getServiceConfig()
 {
     return array('abstract_factories' => array(), 'aliases' => array(), 'factories' => array('UserTable' => function ($sm) {
         $tableGateway = $sm->get('UserTableGateway');
         $table = new Model\UserTable($tableGateway);
         return $table;
     }, 'UserTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new Model\User());
         return new TableGateway('myuser', $dbAdapter, null, $resultSetPrototype);
     }, 'UploadTable' => function ($sm) {
         $tableGateway = $sm->get('UploadTableGateway');
         $uploadSharingTableGateway = $sm->get('UploadSharingTableGateway');
         $table = new Model\UploadTable($tableGateway, $uploadSharingTableGateway);
         return $table;
     }, 'UploadTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new Model\Upload());
         return new TableGateway('uploads', $dbAdapter, null, $resultSetPrototype);
     }, 'ImageUploadTable' => function ($sm) {
         $tableGateway = $sm->get('ImageUploadTableGateway');
         $table = new Model\ImageUploadTable($tableGateway);
         return $table;
     }, 'ImageUploadTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new Model\ImageUpload());
         return new TableGateway('image_uploads', $dbAdapter, null, $resultSetPrototype);
     }, 'LoginForm' => function ($sm) {
         $form = new \Users\Form\LoginForm();
         $form->setInputFilter($sm->get('LoginFilter'));
         return $form;
     }, 'RegisterForm' => function ($sm) {
         $form = new \Users\Form\RegisterForm();
         $form->setInputFilter($sm->get('RegisterFilter'));
         return $form;
     }, 'UserEditForm' => function ($sm) {
         $form = new \Users\Form\UserEditForm();
         return $form;
     }, 'LoginFilter' => function ($sm) {
         return new \Users\Form\Filter\LoginFilter();
     }, 'RegisterFilter' => function ($sm) {
         return new \Users\Form\Filter\RegisterFilter();
     }, 'UploadForm' => function ($sm) {
         $form = new Form\UploadForm();
         $uploadTable = $sm->get('UploadTable');
         $userTable = $sm->get('UserTable');
         $form->setUploadTable($uploadTable);
         $form->setUserTable($userTable);
         return $form;
     }, 'SendMailForm' => function ($sm) {
         $form = new Form\SendMailForm();
         $userTable = $sm->get('UserTable');
         $form->setUserTable($userTable);
         return $form;
     }, 'AuthStorageUsers' => function ($sm) {
         return new Model\AuthStorage();
     }, 'AuthServiceUsers' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'myuser', 'email', 'password', 'MD5(?)');
         $authService = new AuthenticationService();
         $authService->setAdapter($dbTableAuthAdapter);
         $authService->setStorage($sm->get('AuthStorageUsers'));
         return $authService;
     }, 'UploadSharingTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         return new TableGateway('uploads_sharing', $dbAdapter);
     }, 'ChatMessagesTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         return new TableGateway('chat_messages', $dbAdapter);
     }), 'invokables' => array(), 'services' => array(), 'shared' => array());
 }