public function createAction() { if (!$this->getRequest()->isPost()) { return $this->_redirectToAndExit('index', '', 'collectionroles'); } $data = $this->getRequest()->getPost(); $collectionModel = new Admin_Model_Collection($this->getRequest()->getParam('oid')); $collection = $collectionModel->getObject(); $form = new Admin_Form_Collection(); if (!$form->isValid($data)) { if ($collection->isNewRecord()) { $form->setAction($this->view->url(array('action' => 'create', 'id' => $this->getRequest()->getParam('id'), 'type' => $this->getRequest()->getParam('type')))); $this->view->title = 'admin_collections_collection_new'; } else { $form->setAction($this->view->url(array('action' => 'create', 'oid' => $collection->getId(), 'id' => $this->getRequest()->getParam('id'), 'type' => $this->getRequest()->getParam('type')))); $this->view->title = 'admin_collections_collection_edit'; } $form->populate($data); $this->view->form = $form; return; } $form->updateModel($collection); if (true === $collection->isNewRecord()) { $id = $this->getRequest()->getParam('id'); if (is_null($id)) { return $this->_redirectToAndExit('index', array('failure' => 'id parameter is missing'), 'collectionroles'); } $type = $this->getRequest()->getParam('type'); if (is_null($type)) { return $this->_redirectToAndExit('index', array('failure' => 'type parameter is missing'), 'collectionroles'); } switch ($type) { case 'child': $refCollection = new Opus_Collection($id); $refCollection->addFirstChild($collection); $refCollection->store(); $message = $this->view->translate('admin_collections_add', $collectionModel->getName()); break; case 'sibling': $refCollection = new Opus_Collection($id); $refCollection->addNextSibling($collection); $refCollection->store(); $message = $this->view->translate('admin_collections_add', $collectionModel->getName()); break; default: return $this->_redirectToAndExit('index', array('failure' => 'type paramter invalid'), 'collectionroles'); } return $this->_redirectTo('show', $message, 'collection', 'admin', array('id' => $collection->getId())); } // nur Änderungen $collection->store(); $message = $this->view->translate('admin_collections_edit', $collectionModel->getName()); $parents = $collection->getParents(); if (count($parents) === 1) { return $this->_redirectTo('show', $message, 'collection', 'admin', array('id' => $collection->getRoleId())); } return $this->_redirectTo('show', $message, 'collection', 'admin', array('id' => $parents[1]->getId())); }
public function testValidationFailure() { $form = new Admin_Form_Collection(); $this->assertFalse($form->isValid(array())); $errors = $form->getErrors('Name'); $this->assertNotNull($errors); $this->assertContains('allElementsEmpty', $errors); $errors = $form->getErrors('Number'); $this->assertNotNull($errors); $this->assertContains('allElementsEmpty', $errors); }