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->getAlbumTable()->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->getAlbumTable()->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 2
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     try {
         $album = $this->getAlbumTable()->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->getAlbumTable()->saveAlbum($album);
             return $this->redirect()->toRoute('album');
         }
     }
     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'));
     }
     $album = $this->getEntityManager()->find('Album\\Entity\\Album', $id);
     if (!$album) {
         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->getEntityManager()->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
 /**
  * Edit Action
  * <br/> Used to Edit Exists Album
  * @return ViewModel edit view
  */
 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 connot be found, in which case go to index page
     try {
         $album = $this->getAlbumTable()->getAlbum($id);
     } catch (\Exception $e) {
         return $this->redirect()->toRoute('album', array('action' => 'index'));
     }
     $form = new AlbumForm();
     $form->bind($album);
     $form->get('submit')->setAttribute('value', 'Edit');
     // Or also can change Submit button value using setValue() method like into AddAction
     // $form->get('submit')->setValue('Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getAlbumTable()->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return new ViewModel(array('id' => $id, 'form' => $form));
 }
Exemplo n.º 5
0
 public function addAction()
 {
     $form = new AlbumForm();
     $form->get('submit')->setValue('add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $album = new Album();
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $album->exchangeArray($form->getData());
             $this->getAlbumTable()->saveAlbum($album);
             return $this->redirect()->toRoute('album');
         }
     }
     return array('form' => $form);
 }
Exemplo n.º 6
0
 public function editAction()
 {
     $id = (int) $this->params('id');
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     $album = $this->getAlbumTable()->getAlbum($id);
     $form = new AlbumForm();
     $form->bind($album);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getAlbumTable()->saveAlbum($album);
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 7
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     //Get the id from url parmas
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
         //Wheather id is null then redirect to add function
     }
     try {
         $album = $this->getAlbumTable()->getAlbum($id);
         //get the album data of that particular id
     } catch (Exception $e) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     $form = new AlbumForm();
     //Create a Instance of AlbumForm
     $form->bind($album);
     //Bind the album data to the form
     $form->get('submit')->setAttribute('value', 'Edit');
     //Change submit to Edit Button
     $request = $this->getRequest();
     //Generate Request
     if ($request->isPost()) {
         //check wheather request is POST or Not
         $album = new Album();
         //create a instance of Album Model
         $form->setInputFilter($album->getInputFilter());
         //Validation filter set of type album on form
         $form->setData($request->getPost());
         //set data on form
         if ($form->isValid()) {
             //Check wheather form data is valid or not
             $this->getAlbumTable()->saveAlbum($form->getData());
             //Save updated data from form
             //Redirect to list of album
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 8
0
 public function editAction()
 {
     $id = (int) $this->getEvent()->getRouteMatch()->getParam('id');
     if (!$id) {
         return $this->redirect()->toRoute('dalbum', array('action' => 'add'));
     }
     $album = $this->getEntityManager()->find('Album\\Entity\\Album', $id);
     $form = new AlbumForm();
     $form->setBindOnValidate(false);
     $form->bind($album);
     $form->get('submit')->setAttribute('label', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $form->bindValues();
             $this->getEntityManager()->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('dalbum');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 9
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     $album = $this->getAlbumTable()->getAlbum($id);
     //var_dump($album); die;
     $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->getAlbumTable()->saveAlbum($this->getRequest()->getPost()->toArray());
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     return array('id' => $id, 'form' => $form, 'role' => $this->zfcUserAuthentication()->getIdentity()->getRole());
 }
Exemplo n.º 10
0
 public function editAction()
 {
     $auth = new AuthenticationService();
     $acl = $this->getAcl();
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toRoute('album', array('action' => 'login'));
     }
     if (!$acl->isAllowed($this->getRole(), null, 'edit')) {
         return $this->redirect()->toRoute('album', array('action' => 'index'));
     }
     $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->getAlbumTable()->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()) {
         if ($request->getPost('submit2')) {
             return $this->redirect()->toRoute('album');
         }
         $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getAlbumTable()->saveAlbum($album);
             $form->get('title')->setAttribute('value', $request->getPost('title'));
             $form->get('artist')->setAttribute('value', $request->getPost('artist'));
             $notification = array('title' => $request->getPost('title'), 'artist' => $request->getPost('artist'));
         }
     }
     return array('id' => $id, 'form' => $form, 'notification' => $notification);
 }
Exemplo n.º 11
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('album', array('action' => 'add'));
     }
     $resp = $this->getRestResponse(sprintf($this->domain . "/album-rest/%s", $id));
     $respData = Json::decode($resp->getBody());
     $album = new Album();
     $album->exchangeArray(get_object_vars($respData->album));
     $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()) {
             $resp = $this->getRestResponse(sprintf($this->domain . "/album-rest/%s", $id), "POST", get_object_vars($form->getData()));
             // Redirect to list of albums
             return $this->redirect()->toRoute('album');
         }
     }
     $model = new ViewModel(array('id' => $id, 'form' => $form));
     //         $model->setTemplate("album/album/edit.phtml");
     return $model;
 }