Example #1
0
 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 testUpdateModel()
 {
     $form = new Admin_Form_Collection();
     $form->getElement('Id')->setValue(99);
     $form->getElement('Name')->setValue('TestName');
     $form->getElement('Number')->setValue('50');
     $form->getElement('Visible')->setValue('1');
     $form->getElement('VisiblePublish')->setValue('1');
     $form->getElement('OaiSubset')->setValue('TestSubset');
     $form->getElement('Theme')->setValue('plain');
     $model = new Opus_Collection();
     $form->updateModel($model);
     $this->assertNull($model->getId());
     $this->assertEquals('TestName', $model->getName());
     $this->assertEquals('50', $model->getNumber());
     $this->assertEquals('1', $model->getVisible());
     $this->assertEquals('1', $model->getVisiblePublish());
     $this->assertEquals('TestSubset', $model->getOaiSubset());
     $this->assertEquals('plain', $model->getTheme());
 }