Esempio n. 1
0
 /**
  * Für ein leeres Dokument werden fast alle Unterformulare entfernt. Weiterhin angezeigt werden die ActionBox, und
  * die InfoBox,
  */
 public function testPrepareRenderingAsViewForEmptyDocument()
 {
     $form = new Admin_Form_Document();
     $document = $this->createTestDocument();
     $form->populateFromModel($document);
     $form->prepareRenderingAsView();
     $this->verifySubForms($form, array('ActionBox', 'InfoBox', 'Bibliographic'));
 }
Esempio n. 2
0
 /**
  * Konstruiert Formular mit Unterformularen basierend auf POST Daten.
  * @param array $data
  */
 public static function getInstanceFromPost($data, $document = null)
 {
     $form = new Admin_Form_Document();
     $subforms = $form->getSubForms();
     foreach ($subforms as $name => $subform) {
         if (array_key_exists($name, $data)) {
             $subform->constructFromPost($data[$name], $document);
         } else {
             // ActionBox und InfoBox haben keine Element die im POST enthalten wären, müssen aber nach POST wieder
             // neu initialisiert werden
             $subform->constructFromPost(array(), $document);
         }
     }
     return $form;
 }
Esempio n. 3
0
 /**
  * Zeigt Metadaten-Formular an bzw. verarbeitet POST Requests vom Formular.
  * 
  * TODO prüfen ob Form DocID mit URL DocID übereinstimmt
  */
 public function editAction()
 {
     $docId = $this->getRequest()->getParam('id');
     $document = $this->documentsHelper->getDocumentForId($docId);
     if (!isset($document)) {
         return $this->_redirectTo('index', array('failure' => $this->view->translate('admin_document_error_novalidid')), 'documents', 'admin');
     } else {
         $editSession = new Admin_Model_DocumentEditSession($docId);
         if ($this->getRequest()->isPost()) {
             $data = $this->getRequest()->getPost();
             $data = $data['Document'];
             // 'Document' Form wraps actual metadata form
             $form = Admin_Form_Document::getInstanceFromPost($data, $document);
             $form->populate($data);
             // Use return value for decision how to continue
             $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_Document::RESULT_SAVE:
                     if ($form->isValid($data)) {
                         // Formular ist korrekt; aktualisiere Dokument
                         $form->updateModel($document);
                         try {
                             $document->store();
                             // TODO redirect to Übersicht/Browsing/???
                             $message = $this->view->translate('admin_document_update_success');
                             return $this->_redirectTo('index', $message, 'document', 'admin', array('id' => $docId));
                         } catch (Exception $ex) {
                             $message = $this->view->translate('admin_document_error_exception_storing');
                             $message = sprintf($message, $ex->getMessage());
                             $form->setMessage($message);
                         }
                     } else {
                         $form->setMessage($this->view->translate('admin_document_error_validation'));
                     }
                     break;
                 case Admin_Form_Document::RESULT_SAVE_AND_CONTINUE:
                     if ($form->isValid($data)) {
                         // Formular ist korrekt; aktualisiere Dokument
                         $form->updateModel($document);
                         // TODO handle exceptions
                         $document->store();
                     } else {
                         // Zend_Debug::dump($form->getErrors());
                         $form->setMessage($this->view->translate('admin_document_error_validation'));
                     }
                     break;
                 case Admin_Form_Document::RESULT_CANCEL:
                     // TODO redirect to origin page (Store in Session oder Form?)
                     // Possible Rücksprungziele: Frontdoor, Metadaten-Übersicht, Suchergebnisse (Documents, ?)
                     return $this->_redirectTo('index', null, 'document', 'admin', array('id' => $docId));
                     break;
                 case Admin_Form_Document::RESULT_SWITCH_TO:
                     $editSession->storePost($data, $docId);
                     // TODO Parameter in Unterarray 'params' => array() verlagern?
                     $target['document'] = $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;
                 default:
                     // Zurueck zum Formular
                     break;
             }
         } else {
             // GET zeige neues oder gespeichertes Formular an
             // Hole gespeicherten POST aus Session
             $post = $editSession->retrievePost($docId);
             $continue = $this->getRequest()->getParam('continue', null);
             if ($post && !is_null($continue)) {
                 // Initialisiere Formular vom gespeicherten POST
                 $form = Admin_Form_Document::getInstanceFromPost($post, $document);
                 $form->populate($post);
                 // Führe Rücksprung aus
                 $form->continueEdit($this->getRequest(), $editSession);
             } else {
                 // Initialisiere Formular vom Dokument
                 $form = new Admin_Form_Document();
                 $form->populateFromModel($document);
             }
         }
         $wrappedForm = new Admin_Form_Wrapper($form);
         $wrappedForm->setAction('#current');
         $this->view->form = $wrappedForm;
     }
     $this->view->document = $document;
     $this->view->documentAdapter = new Util_DocumentAdapter($this->view, $document);
     // Beim wechseln der Sprache würden Änderungen in editierten Felder verloren gehen
     $this->view->languageSelectorDisabled = true;
     $this->view->contentWrapperDisabled = true;
     $this->_helper->breadcrumbs()->setDocumentBreadcrumb($document);
     $this->renderForm($this->view->form);
 }