/** * Switches the status of a document to target state. */ public function changestateAction() { $docId = $this->getRequest()->getParam('docId'); $targetState = $this->getRequest()->getParam('targetState'); $document = $this->__documentsHelper->getDocumentForId($docId); // Check if document identifier is valid if (!isset($document)) { return $this->_redirectTo('index', array('failure' => $this->view->translate('admin_document_error_novalidid')), 'documents', 'admin'); } // Check if valid target state if (!$this->__workflowHelper->isValidState($targetState)) { return $this->_redirectTo('index', array('failure' => $this->view->translate('admin_workflow_error_invalidstate')), 'document', 'admin', array('id' => $docId)); } // Check if allowed target state if (!$this->__workflowHelper->isTransitionAllowed($document, $targetState)) { return $this->_redirectTo('index', array('failure' => $this->view->translate('admin_workflow_error_illegal_transition', $targetState)), 'document', 'admin', array('id' => $docId)); } // Check if document is already in target state if ($document->getServerState() === $targetState) { // if defined used custom message for state, other use common key $key = 'admin_workflow_error_already_' . $targetState; if (!$this->view->translate()->getTranslator()->isTranslated($key)) { $key = 'admin_workflow_error_alreadyinstate'; } return $this->_redirectTo('index', array('failure' => $this->view->translate($key, $targetState)), 'document', 'admin', array('id' => $docId)); } if ($this->__confirmChanges) { if ($this->getRequest()->isPost()) { $form = $this->_getConfirmationForm($document, $targetState); $sureyes = $this->getRequest()->getPost('sureyes'); if ($form->isValid($this->getRequest()->getPost()) && isset($sureyes) === true) { return $this->_changeState($document, $targetState, $form); } return $this->_redirectTo('index', null, 'document', 'admin', array('id' => $docId)); } // show confirmation page $this->view->documentAdapter = new Util_DocumentAdapter($this->view, $document); $this->view->title = $this->view->translate('admin_workflow_' . $targetState); $this->view->text = $this->view->translate('admin_workflow_' . $targetState . '_sure', $docId); $this->view->form = $this->_getConfirmationForm($document, $targetState); } else { return $this->_changeState($document, $targetState); } }
/** * 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); }