public function findAction()
 {
     // display a search field to enter a user's name
     // display an alphabetical list of users
     // @TODO implement pagination set limit per page set overal limit for results
     // @TODO implement list of alphabet to display all members whose name starts with that letter - see Packtpub.PHP.5.Social.Networking.Oct.2010
     $request = $this->getRequest();
     $form = new Application_Form_Member();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $memberMapper = new Application_Model_MemberMapper();
             try {
                 $auth = Zend_Auth::getInstance();
                 $identity = $auth->getIdentity();
                 $rows = $memberMapper->fetchAllByName($form->getValue('name'), $identity->id);
             } catch (Exception $e) {
                 throw new Exception($e->getMessage());
             }
             $this->view->rows = $rows->toArray();
         }
     }
     $this->view->form = $form;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }