public function testConstructForm() { $form = new Admin_Form_FileManager(); $this->assertEquals(3, count($form->getElements())); $this->assertNotNull($form->getElement('Id')); $this->assertNotNull($form->getElement('Save')); $this->assertNotNull($form->getElement('Cancel')); $this->assertEquals(3, count($form->getSubForms())); $this->assertNotNull($form->getSubForm('Action')); $this->assertNotNull($form->getSubForm('Info')); $this->assertNotNull($form->getSubForm('Files')); $this->assertEquals(3, count($form->getDecorators())); $this->assertNotNull($form->getDecorator('FormElements')); $this->assertNotNull($form->getDecorator('HtmlTag')); $this->assertNotNull($form->getDecorator('Form')); $this->assertEquals('FileManager', $form->getName()); }
/** * 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); }