Пример #1
0
 /**
  * Test forgetting.
  *
  * @return void
  */
 public function testForgetting()
 {
     $mem = new Memory();
     $url = 'http://test';
     $mem->rememberSearch($url);
     $this->assertEquals($url, $mem->retrieveSearch());
     $mem->forgetSearch();
     $this->assertEquals(null, $mem->retrieveSearch());
 }
Пример #2
0
 /**
  * Handle search history display && purge
  *
  * @return mixed
  */
 public function historyAction()
 {
     // Force login if necessary
     $user = $this->getUser();
     if ($this->params()->fromQuery('require_login', 'no') !== 'no' && !$user) {
         return $this->forceLogin();
     }
     // Retrieve search history
     $search = $this->getTable('Search');
     $searchHistory = $search->getSearches($this->getServiceLocator()->get('SessionManager')->getId(), is_object($user) ? $user->id : null);
     // Build arrays of history entries
     $saved = $unsaved = array();
     // Loop through the history
     foreach ($searchHistory as $current) {
         $minSO = unserialize($current->search_object);
         // Saved searches
         if ($current->saved == 1) {
             $saved[] = $minSO->deminify($this->getSearchManager());
         } else {
             // All the others...
             // If this was a purge request we don't need this
             if ($this->params()->fromQuery('purge') == 'true') {
                 $current->delete();
                 // We don't want to remember the last search after a purge:
                 Memory::forgetSearch();
             } else {
                 // Otherwise add to the list
                 $unsaved[] = $minSO->deminify($this->getSearchManager());
             }
         }
     }
     return $this->createViewModel(array('saved' => $saved, 'unsaved' => $unsaved));
 }