public function testEditTwoDocuments()
 {
     $model1 = new Admin_Model_DocumentEditSession(146);
     $model2 = new Admin_Model_DocumentEditSession(100);
     $namespace1 = $model1->getDocumentSessionNamespace();
     $namespace2 = $model2->getDocumentSessionNamespace();
     $this->assertNotEquals($namespace1, $namespace2);
     $model1->addPerson(array('person' => 310));
     $this->assertEquals(1, $model1->getPersonCount());
     $this->assertEquals(0, $model2->getPersonCount());
 }
 /**
  * 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);
 }
Beispiel #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);
 }
Beispiel #4
0
 /**
  * Wird nach dem Rücksprung von Add/Edit Seite für Person aufgerufen, um das Ergebnis ins Formular einzubringen.
  * 
  * @param type $request
  * @param Admin_Model_DocumentEditSession $session
  */
 public function continueEdit($request, $session = null)
 {
     $addedPersons = $session->retrievePersons();
     if (count($addedPersons) == 0) {
         $action = $request->getParam('continue', null);
         if ($action === 'addperson') {
             $personId = $request->getParam('person', null);
             if (!is_null($personId)) {
                 $addedPersons[] = array('person' => $personId, 'role' => $request->getParam('role', 'author'), 'contact' => $request->getParam('contact', 'false'), 'order' => $request->getParam('order', null));
             } else {
                 $this->getLog()->err(__METHOD__ . ' Attempt to add person without ID.');
             }
         }
     }
     foreach ($addedPersons as $person) {
         $this->addPerson($person);
     }
 }
 public function testContinueEditAddTwoPersons()
 {
     $form = new Admin_Form_Document_Persons();
     $request = $this->getRequest();
     $request->setParams(array('continue' => 'addperson'));
     $session = new Admin_Model_DocumentEditSession(100);
     $session->addPerson(array('person' => 310, 'role' => 'author'));
     $session->addPerson(array('person' => 311, 'role' => 'editor'));
     $this->assertEquals(0, count($form->getSubForm('author')->getSubForms()));
     $this->assertEquals(0, count($form->getSubForm('editor')->getSubForms()));
     $form->continueEdit($request, $session);
     $this->assertEquals(1, count($form->getSubForm('author')->getSubForms()));
     $this->assertEquals(1, count($form->getSubForm('editor')->getSubForms()));
     $author = $form->getSubForm('author')->getSubForm('PersonAuthor0');
     $this->assertNotNull($author);
     $this->assertEquals(310, $author->getElementValue('PersonId'));
     $editor = $form->getSubForm('editor')->getSubForm('PersonEditor0');
     $this->assertNotNull($editor);
     $this->assertEquals(311, $editor->getElementValue('PersonId'));
 }
Beispiel #6
0
 /**
  * Fuegt Person zu Dokument hinzu.
  * 
  * HTTP Parameter:
  * - Dokument-ID (document)
  * - Rolle (role)
  */
 public function assignAction()
 {
     $docId = $this->getRequest()->getParam('document');
     $document = $this->__documentsHelper->getDocumentForId($docId);
     if (!isset($document)) {
         return $this->_redirectTo('index', array('failure' => 'admin_document_error_novalidid'), 'documents', 'admin');
     }
     if (!$this->getRequest()->isPost()) {
         // Neues Formular anzeigen
         $form = new Admin_Form_Document_PersonAdd();
         $role = $this->getRequest()->getParam('role', 'author');
         $form->setSelectedRole($role);
         $this->view->form = $form;
     } else {
         // POST verarbeiten
         $post = $this->getRequest()->getPost();
         $form = new Admin_Form_Document_PersonAdd();
         $form->populate($post);
         $result = $form->processPost($post, $post);
         switch ($result) {
             case Admin_Form_Document_PersonAdd::RESULT_SAVE:
             case Admin_Form_Document_PersonAdd::RESULT_NEXT:
                 if ($form->isValid($post)) {
                     $person = $form->getModel();
                     $person->store();
                     $linkProps = $form->getPersonLinkProperties($person->getId());
                     $editSession = new Admin_Model_DocumentEditSession($docId);
                     if ($result == Admin_Form_Document_PersonAdd::RESULT_SAVE) {
                         // Zurück zum Metadaten-Formular springen
                         if ($editSession->getPersonCount() > 0) {
                             // Link Informationen durch Session übermitteln
                             $editSession->addPerson($linkProps);
                             return $this->_redirectToAndExit('edit', null, 'document', 'admin', array('id' => $docId, 'continue' => 'addperson'));
                         } else {
                             // Link Informationen direkt als Parameter übergeben
                             return $this->_redirectToAndExit('edit', null, 'document', 'admin', array_merge(array('id' => $docId, 'continue' => 'addperson'), $linkProps));
                         }
                     } else {
                         // Person in Session merken
                         $editSession->addPerson($linkProps);
                         // Neues Formular erzeugen
                         $role = $form->getSelectedRole();
                         $form = new Admin_Form_Document_PersonAdd();
                         $form->setSelectedRole($role);
                     }
                 } else {
                     // TODO Validierungsfehlernachricht für Formular anzeigen
                     $form->addError($this->view->translate('admin_document_error_validation'));
                 }
                 break;
             case Admin_Form_Document_PersonAdd::RESULT_CANCEL:
                 // Aktuelle Person nicht speichern, aber eventuell gemerkte Personen hinzufügen
                 return $this->_redirectToAndExit('edit', null, 'document', 'admin', array('id' => $docId, 'continue' => 'addperson'));
             default:
                 break;
         }
         $this->view->form = $form;
     }
     $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->breadcrumbsDisabled = true;
 }