public function fetchByIdea($idea) { $logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream('sample.log'); $logger->addWriter($writer); $logger->log('Fetch Tag by Idea start...', Zend_Log::INFO); $select = $this->getDbTable()->select(); $select->where('idea_id = ?', $idea->id); $resultSet = $this->getDbTable()->fetchAll($select); $entries = array(); foreach ($resultSet as $row) { $entry = new Application_Model_Tag(); $entry->setTag($row->tag)->setIdeaId($row->idea_id)->setCreateDatetime($row->create_datetime)->setLastUpdateDatetime($row->last_update_datetime); $entries[] = $entry; } $logger->log('Fetch Tag by Idea end, result size = ' . count($entries), Zend_Log::INFO); return $entries; }
public function fetchRecord($text, $search_type, $is_partial) { //For debugging $this->_logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream('sample.log'); $this->_logger->addWriter($writer); //Array to hold the final search results $entries = array(); //Search by destination name //Formulate SQL query for partial or full search if ($search_type == "Destination") { $select = $this->getDbTable()->select(); if ($is_partial == "true") { $filteredText = "%" . $text . "%"; $select->where('destination like ?', $filteredText); $this->_logger->log($select, Zend_Log::INFO); } else { $select->where('destination = ?', $text); $this->_logger->log($select, Zend_Log::INFO); } $resultSet = $this->getDbTable()->fetchAll($select); } else { if ($search_type == "Tags") { //Access tag's mapper function $tagMapper = new Application_Model_TagMapper(); $selectTag = $tagMapper->getDbTable()->select(); $selectTag->where('tag = ?', $text); $this->_logger->log($selectTag, Zend_Log::INFO); $tagResultSet = $tagMapper->getDbTable()->fetchAll($selectTag); //Array to store matching ideas object $temp_entries = array(); //Parse return results foreach ($tagResultSet as $row) { $entry = new Application_Model_Tag(); $entry->setTag($row->tag)->setIdeaId($row->idea_id)->setCreateDatetime($row->create_datetime)->setLastUpdateDatetime($row->last_update_datetime); //Retrive ideas object by idea_id which has a matching tag $select = $this->getDbTable()->select(); $select->where('idea_id = ?', $row->idea_id); $tempResultSet = $this->getDbTable()->fetchRow($select); //Aggregate the matching ideas to the same array array_push($temp_entries, $tempResultSet); } //Assign result for parsing $resultSet = $temp_entries; } } //Parse return results foreach ($resultSet as $row) { $author = new Application_Model_Member(); $author->setId($row->author_id); $entry = new Application_Model_Idea(); $entry->setId($row->idea_id)->setDestination($row->destination)->setTitle($row->title)->setStartDate($row->start_date)->setEndDate($row->end_date)->setAuthor($row->author)->setCreateDatetime($row->create_datetime)->setLastUpdateDatetime($row->last_update_datetime); $entries[] = $entry; } return $entries; }
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; }