public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     // id that we editing, defaults to zero
     $form = new AlbumForm();
     // form used for the edit
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $album = $em->getRepository('Application\\Entity\\Album')->find($id);
     // if we do not have an entry for the album, i.e id not found or not defined
     // send them to add
     if (!$album) {
         return $this->redirect()->toRoute('admin/album', array('action' => 'add'));
     }
     // setup form
     // (validation, data and button)
     $form->setInputFilter($album->getInputFilter())->setData($album->toArray())->get('submit')->setAttribute('value', 'Edit');
     // process a submission
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         // set the form with the submitted values
         // is valid?
         if ($form->isValid()) {
             $album->setOptions($form->getData());
             // set the data
             $album->id = $id;
             $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
             // entity manager
             $em->persist($album);
             // set data
             $em->flush();
             // save
             // set messages
             //$this->flashMessenger()->addMessage('You must do something.');
             //$this->flashMessenger()->addMessage(array('alert-info'=>'Soon this changes.'));
             $this->flashMessenger()->addMessage(array('alert-success' => 'Updated!'));
             //$this->flashMessenger()->addMessage(array('alert-error'=>'Sorry, Error.'));
             // Redirect to list of albums
             return $this->redirect()->toRoute('admin/album');
         } else {
             //$this->flashMessenger()->addMessage(array('alert-error'=>'Form error'));
         }
     }
     return array('id' => $id, 'form' => $form);
 }
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     // Get the Album with the specified id.  An exception is thrown
     // if it cannot be found, in which case go to the index page.
     try {
         $album = $this->getServiceLocator()->get('Album\\Model\\AlbumTable')->getAlbum($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('album', array('action' => 'index'));
     }
     $form = new AlbumForm();
     $form->bind($album);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getServiceLocator()->get('Album\\Model\\AlbumTable')->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemple #3
0
 public function update($id, $data)
 {
     // identical to create, the only change is the id is manually added after
     // getting the form data, this is becuase the form does not have the id
     $form = new AlbumForm();
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $album = $em->getRepository('Application\\Entity\\Album')->find($id);
     $form->setInputFilter($album->getInputFilter());
     $form->setData($data);
     // album was found, add the form data, and reinstate the id
     if ($album && $form->isValid()) {
         $album->setOptions($form->getData());
         // set the data
         $album->id = $id;
         $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         // entity manager
         $em->persist($album);
         // set data
         $em->flush();
         // save
     }
     return new JsonModel(array('data' => $album->toArray()));
 }
Exemple #4
0
 public function editimageAction()
 {
     $auth = new AuthenticationService();
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $id = (int) $this->params('id');
     if (!$id) {
         return $this->redirect()->toRoute('addalbum');
     }
     $form = new AlbumForm($this->getRequest()->getBaseUrl() . '/application/album/edit/');
     $album = new Album();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $file = $this->params()->fromFiles('image');
         $albumss = $this->getAdminTable()->getAlbum($id);
         //print_r($albumss); die;
         $data = array('id' => $albumss->id, 'name' => $albumss->name, 'title' => $albumss->title, 'email' => $albumss->email, 'mob' => $albumss->mob, 'address' => $albumss->address, 'short_description' => $albumss->short_description, 'description' => $albumss->description, 'image' => $file['name']);
         $form->setData($data);
         if ($form->isValid()) {
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setDestination(getcwd() . '/public/adminModule/img/AlbumImage/');
             unlink(getcwd() . '/public/adminModule/img/AlbumImage/' . $albumss->image);
             if ($adapter->receive($file['name'])) {
                 //echo $file['name']; die;
                 $album->exchangeArray($form->getData());
                 $this->getAdminTable()->saveAlbum($album);
                 return $this->redirect()->toRoute('album');
             }
         }
     }
     $viewModel = new ViewModel(array('form' => $form, 'id' => $id));
     $viewModel->setTerminal(true);
     return $viewModel;
 }