public function testGetInstanceFromPost()
 {
     $document = new Opus_Document(146);
     $post = array('Files' => array('File0' => array('Id' => 126)));
     $form = Admin_Form_FileManager::getInstanceFromPost($post, $document);
     $this->assertInstanceOf('Admin_Form_FileManager', $form);
     $this->assertEquals(1, count($form->getSubForm('Files')->getSubForms()));
     $fileForm = $form->getSubForm('Files')->getSubForm('File0');
     $this->assertNotNull($fileForm);
     $this->assertNull($fileForm->getElementValue('Id'));
     // Formular noch nicht befüllt
 }
Esempio n. 2
0
 public static function getInstanceFromPost($post, $document)
 {
     $form = new Admin_Form_FileManager();
     $form->constructFromPost($post, $document);
     return $form;
 }
Esempio n. 3
0
 /**
  * Zeigt Upload-Formular und Formulare fuer Dateien an.
  */
 public function indexAction()
 {
     $docId = $this->getRequest()->getParam(self::PARAM_DOCUMENT_ID);
     $document = $this->getHelper('documents')->getDocumentForId($docId);
     $form = null;
     if (isset($document)) {
         $editSession = new Admin_Model_DocumentEditSession($docId);
         if ($this->getRequest()->isPost()) {
             $post = $this->getRequest()->getPost();
             $form = new Admin_Form_FileManager();
             $data = $post[$form->getName()];
             // TODO
             $form->constructFromPost($data, $document);
             $form->populate($post);
             $result = $form->processPost($data, $data);
             if (is_array($result)) {
                 $target = $result['target'];
                 // TODO check if present
                 $result = $result['result'];
                 // TODO check if present
             }
             switch ($result) {
                 case Admin_Form_FileManager::RESULT_SAVE:
                     if ($form->isValid($post)) {
                         $form->updateModel($document);
                         try {
                             $document->store();
                         } catch (Opus_Mode_Exception $ome) {
                             $this->getLogger()->err(__METHOD__ . ' Error saving file metadata: ' . $ome->getMessage());
                             return $this->_redirectTo('index', 'admin_filemanager_save_failure', 'document', 'admin', array('id' => $docId));
                         }
                         return $this->_redirectTo('index', 'admin_filemanager_save_success', 'document', 'admin', array('id' => $docId));
                     } else {
                         $form->setMessage($this->view->translate('admin_filemanager_error_validation'));
                     }
                     break;
                 case Admin_Form_FileManager::RESULT_CANCEL:
                     // TODO Rücksprung zur Ursprungsseite
                     return $this->_redirectTo('index', null, 'document', 'admin', array('id' => $docId));
                     break;
                 case Admin_Form_Document::RESULT_SWITCH_TO:
                     $editSession->storePost($data, 'files');
                     // TODO Parameter in Unterarray 'params' => array() verlagern?
                     $target[self::PARAM_DOCUMENT_ID] = $docId;
                     $action = $target['action'];
                     unset($target['action']);
                     $controller = $target['controller'];
                     unset($target['controller']);
                     $module = $target['module'];
                     unset($target['module']);
                     return $this->_redirectTo($action, null, $controller, $module, $target);
                     break;
                 case Admin_Form_Document::RESULT_SHOW:
                 default:
                     // $form->populate($post);
                     break;
             }
         } else {
             // GET-Request; Neues Formular anzeigen bzw. Editieren fortsetzen
             $form = new Admin_Form_FileManager();
             $form->populateFromModel($document);
             $post = $editSession->retrievePost('files');
             if ($this->getRequest()->getParam('continue') && !is_null($post)) {
                 $form->continueEdit($this->getRequest(), $post);
             }
         }
     } else {
         // missing or bad parameter => go back to main page
         return $this->_redirectTo('index', array('failure' => 'admin_document_error_novalidid'), 'documents', 'admin');
     }
     // Set dynamic breadcrumb
     $this->_breadcrumbs->setDocumentBreadcrumb($document);
     $this->view->languageSelectorDisabled = true;
     $this->view->contentWrapperDisabled = true;
     // wrapper wird innerhalb des Formulars gerendert
     $form->setAction($this->view->url(array('module' => 'admin', 'controller' => 'filemanager', 'action' => 'index', self::PARAM_DOCUMENT_ID => $document->getId()), null, true));
     $this->renderForm($form);
 }