Ejemplo n.º 1
0
 public function editAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Save');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $artist = $form->getValue('artist');
             $title = $form->getValue('title');
             $id = (int) $form->getValue('id');
             $albums = new Application_Model_DbTable_Albums();
             $albums->updateAlbum($id, $artist, $title);
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $albums = new Application_Model_DbTable_Albums();
             $form->populate($albums->getAlbum($id));
         }
     }
 }
 public function modifierAction()
 {
     $form = new Application_Form_Album();
     $form->envoyer->setLabel('Sauvegarder');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $id = $form->getValue('id');
             $artiste = $form->getValue('artiste');
             $titre = $form->getValue('titre');
             $albums = new Application_Model_DbTable_Albums();
             $albums->modifierAlbum($id, $artiste, $titre);
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $albums = new Application_Model_DbTable_Albums();
             $form->populate($albums->obtenirAlbum($id));
         }
     }
 }
Ejemplo n.º 3
0
 public function addAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Add');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         // form validation
         if ($form->isValid($formData)) {
             // collecting the data from user intput
             $dataArray = array('artist' => $form->getValue('artist'), 'title' => $form->getValue('title'), 'price' => $form->getValue('price'));
             //commented after passing
             //$artist = $form->getValue('artist');
             //$title = $form->getValue('title');
             //$albums = new Model_Albums();
             // some db related stuff
             $albums = new Application_Model_DbTable_Albums();
             $albums->addAlbum($dataArray);
             // after success redirect to index action
             $this->_helper->redirector('index');
         } else {
             // if any validation erros,
             // populate the form with previouis data
             $form->populate($formData);
         }
     }
 }
Ejemplo n.º 4
0
 public function editAlbumAction()
 {
     $id = $this->_getParam('id');
     $model1 = new Application_Model_Album();
     $model = $model1->find($id);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/gallery/albums'));
     }
     $options['title'] = $model->getTitle();
     $options['description'] = $model->getDescription();
     $options['coverImage'] = $model->getCoverImage();
     $options['status'] = $model->getStatus();
     $request = $this->getRequest();
     $form = new Application_Form_Album();
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         /*---- title validation ----*/
         if ($options['title'] != $model->getTitle()) {
             $form->getElement('title')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'album', 'field' => 'title', 'messages' => 'Album with the same title is already exists, Please choose another title.'))));
         }
         /*-------------------------*/
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             /*---------  Upload image START -------------------------*/
             $model->uploadCoverImage($id, $options);
             /*---------  Upload image END -------------------------*/
             $this->_flashMessenger->addMessage(array('success' => 'Album has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/gallery/edit-album/id/' . $id));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.'));
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->cover_image_thumb = $model->getCoverImageThumb();
     $this->view->form = $form;
 }