/** * Add into the search table (history) * * @access protected */ protected function addToHistory() { global $user; // Get the list of all old searches for this session and/or user $s = new SearchEntry(); /** @var SearchEntry[] $searchHistory */ $searchHistory = $s->getSearches(session_id(), is_object($user) ? $user->id : null); // Duplicate elimination $dupSaved = false; foreach ($searchHistory as $oldSearch) { // Deminify the old search $minSO = unserialize($oldSearch->search_object); $dupSearch = SearchObjectFactory::deminify($minSO); // See if the classes and urls match if (get_class($dupSearch) && get_class($this) && $dupSearch->renderSearchUrl() == $this->renderSearchUrl()) { // Is the older search saved? if ($oldSearch->saved) { // Flag for later $dupSaved = true; // Record the details $this->searchId = $oldSearch->id; $this->savedSearch = true; } else { // Delete this search $oldSearch->delete(); } } } // Save this search unless we found a 'saved' duplicate if (!$dupSaved) { $search = new SearchEntry(); $search->session_id = session_id(); $search->created = date('Y-m-d'); $search->search_object = serialize($this->minify()); $search->insert(); // Record the details $this->searchId = $search->id; $this->savedSearch = false; // Chicken and egg... We didn't know the id before insert $search->search_object = serialize($this->minify()); $search->update(); } }