public function fetchByDestination($destination, $isPartial) { //For debugging $this->_logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream('sample.log'); $this->_logger->addWriter($writer); $this->_logger->log('Ajax fetch idea by destination start', Zend_Log::INFO); $ideas = array(); try { $select = $this->getDbTable()->select()->from(array('i' => 'ideas'))->join(array('m' => 'members'), 'i.author_id = m.member_id'); if ($isPartial == 'true') { $destination = "%" . $destination . "%"; $select->where('i.destination like ?', $destination); $this->_logger->log('Ajax fetch idea by destination partial, isPartial=' . $isPartial, Zend_Log::INFO); } else { $select->where('i.destination = ?', $destination); $this->_logger->log('Ajax fetch idea by destination NOT partial, isPartial=' . $isPartial, Zend_Log::INFO); } $select->setIntegrityCheck(false); $resultSet = $this->getDbTable()->fetchAll($select); foreach ($resultSet as $row) { $author = new Application_Model_Member(); $author->setId($row->member_id)->setMemberLogin($row->member_login)->setEmail($row->email)->setFirstName($row->first_name)->setLastName($row->last_name); $idea = new Application_Model_Idea(); $idea->setId($row->idea_id)->setDestination($row->destination)->setTitle($row->title)->setStartDate($row->start_date)->setEndDate($row->end_date)->setAuthor($author)->setCreateDatetime($row->create_datetime)->setLastUpdateDatetime($row->last_update_datetime); $ideas[] = $idea; } $this->_logger->log('Ajax fetch idea by destination end. no. of result=' . count($ideas), Zend_Log::INFO); } catch (Exception $ex) { $this->_logger->log($ex->getMessage(), Zend_Log::ERROR); } return $ideas; }
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; }