public function editAction()
 {
     $request = $this->getRequest();
     $authns = new Zend_Session_Namespace('AuthNameSpace');
     if (!isset($authns->userId)) {
         return;
     }
     $form = new Application_Form_Signup();
     $mapper = new Application_Model_MemberMapper();
     $member = new Application_Model_Member();
     $mapper->find($authns->userId, $member);
     //reuse member_id in post
     $id = $member->getId();
     //handle changes to member info
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             //get the newly updated form value
             $member = new Application_Model_Member($form->getValues());
             //set the id of the form in order to make changes to the same member in database
             $member->setId($id);
             //Verify user password before updating user information
             $oldPassword = $form->getValue('oldPassword');
             if ($mapper->verifyPassword($member, $oldPassword)) {
                 $mapper->save($member);
                 $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Update Successful!');
                 $this->_logger->log('Update: Password Verified!', Zend_Log::INFO);
                 return $this->_redirect('/');
             } else {
                 $this->_helper->FlashMessenger()->setNamespace('error')->addMessage('Incorrect password. Failed to save changes.');
                 $this->_logger->log('Update: Incorrect Password!', Zend_Log::INFO);
                 return $this->_redirect('/members/edit');
             }
         }
     }
     //form data array to populate signup form with existing data
     $data = array('memberLogin' => $member->getMemberLogin(), 'memberPassword' => $member->getMemberPassword(), 'firstName' => $member->getFirstName(), 'lastName' => $member->getLastName(), 'email' => $member->getEmail());
     $form->populate($data);
     $this->view->form = $form;
 }
 public function editAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam("id");
     // Get the idea information from the database
     $form = new Application_Form_Idea();
     $mapper = new Application_Model_IdeaMapper();
     $idea = new Application_Model_Idea();
     $mapper->find($id, $idea);
     // Get the tag information from the database
     $mapper = new Application_Model_TagMapper();
     $tags = $mapper->fetchByIdea($idea);
     // formulate the tag string for the idea
     $tagString = "";
     foreach ($tags as $tag) {
         $tagString = $tagString . $tag->getTag() . ";";
     }
     $idea->setTagString($tagString);
     //handle changes to travel idea
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             //get the newly updated form value
             $idea = new Application_Model_Idea($form->getValues());
             //set the id of the idea in order to make changes to the same idea in database
             $idea->setId($id);
             // Get idea author information
             $author = new Application_Model_Member();
             $authns = new Zend_Session_Namespace('AuthNameSpace');
             $mapper = new Application_Model_MemberMapper();
             $mapper->find($authns->userId, $author);
             $idea->setAuthor($author);
             // save the idea in the database
             $mapper = new Application_Model_IdeaMapper();
             $mapper->save($idea);
             // Delete all the tag related to this idea
             $mapper = new Application_Model_TagMapper();
             $mapper->deleteByIdeaId($id);
             $this->_logger->log('after update idea, tag String =' . $idea->tagString, Zend_Log::INFO);
             // Extract the updated tag
             $tags = explode(";", $idea->tagString);
             foreach ($tags as $temp) {
                 if (strlen($temp) > 0) {
                     $tag = new Application_Model_Tag();
                     $tag->setTag($temp);
                     $tag->setIdeaId($id);
                     $this->_logger->log('tag = ' . $temp, Zend_Log::INFO);
                     // Save the tag in the database
                     $mapper->save($tag);
                 }
             }
             $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Update Successful!');
             $this->_logger->log('Update Idea successfully! ID =' . $id, Zend_Log::INFO);
             $this->_redirector->gotoSimple('detail', 'ideas', null, array('id' => $id));
             return;
         }
     }
     //form data array to populate idea creation form with existing data
     $data = array('title' => $idea->getTitle(), 'destination' => $idea->getDestination(), 'startDate' => $idea->getStartDate(), 'endDate' => $idea->getEndDate(), 'tagString' => $idea->getTagString());
     $form->populate($data);
     $this->view->form = $form;
 }