/** Save a search * @access public * @return void */ public function saveAction() { $form = new SaveSearchForm(); $form->submit->setLabel('Save search'); $this->view->form = $form; // Clean up the parameters that are to be parsed. $params = $this->cleanParams($this->getAllParams(), array('searchDescription', 'public', 'title')); $this->view->params = $params; if ($this->getRequest()->isPost() && $form->isValid($this->_request->getPost())) { $insertData = $form->getValues(); //Serialize the search string $insertData['searchString'] = serialize($params); $saved = new SavedSearches(); $saved->add($insertData); // Redirect back to that search $this->_helper->Redirector->gotoSimple('results', 'search', 'database', $params); } else { // Error in submission of the form $this->getFlash()->addMessage('There are problems with your submission.'); //Populate with the error $form->populate($params); } }
public function saveAction() { $form = new SaveSearchForm(); $form->submit->setLabel('Save search'); $this->view->form = $form; $searches = new Searches(); $lastsearch = $searches->fetchRow($searches->select()->where('userid = ?', $this->getIdentityForForms())->order('id DESC')); $querystring = unserialize($lastsearch->searchString); $params = array(); $query = ''; foreach ($querystring as $key => $value) { $query .= $key . '/' . $value . '/'; $params[$key] = $value; } $this->view->params = $params; if ($this->_request->isPost()) { $data = $this->_getAllParams(); if ($form->isValid($data)) { $insertData = array(); $insertData['created'] = $this->getTimeForForms(); $insertData['createdBy'] = $this->getIdentityForForms(); $insertData['title'] = $form->getValue('title'); $insertData['description'] = $form->getValue('description'); $insertData['searchString'] = $lastsearch->searchString; $insertData['public'] = $form->getValue('public'); $saved = new SavedSearches(); $insert = $saved->insert($insertData); $this->_redirect(self::REDIRECT . $query); } else { $this->_flashMessenger->addMessage('There are problems with your submission.'); $form->populate($data); } } }