/** * 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; }
public function testGetSelectedRole() { $form = new Admin_Form_Document_PersonAdd(); $form->getSubForm(Admin_Form_Document_PersonAdd::SUBFORM_DOCUMENT)->getElement(Admin_Form_PersonLink::ELEMENT_ROLE)->setValue('contributor'); $this->assertEquals('contributor', $form->getSelectedRole()); }