aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-03-14 10:32:00 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-03-14 10:32:00 +0000
commit219888d4899fa1704452ed7169b718f6766aaa07 (patch)
tree5584dabf3b28af36af08ebbb55878fdf06103a29
parent6ab15b1c291b35bcb2564ae5a20e10ef19a208e9 (diff)
downloadsemanticscuttle-219888d4899fa1704452ed7169b718f6766aaa07.tar.gz
semanticscuttle-219888d4899fa1704452ed7169b718f6766aaa07.tar.bz2
New Feature: save searches (and display a searchhistory box)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@80 b3834d28-1941-0410-a4f8-b48e95affb8f
-rw-r--r--config.inc.php.example6
-rw-r--r--index.php2
-rw-r--r--locales/fr_FR/LC_MESSAGES/messages.mobin18568 -> 18840 bytes
-rw-r--r--locales/fr_FR/LC_MESSAGES/messages.po57
-rw-r--r--locales/messages.po48
-rw-r--r--search.php6
-rw-r--r--services/searchhistoryservice.php108
-rw-r--r--tables.sql16
-rw-r--r--templates/sidebar.block.search.php35
-rw-r--r--tests/LAUNCH_TESTS2
-rw-r--r--tests/searchTest.php80
11 files changed, 312 insertions, 48 deletions
diff --git a/config.inc.php.example b/config.inc.php.example
index 55b1c24..1059bba 100644
--- a/config.inc.php.example
+++ b/config.inc.php.example
@@ -95,6 +95,10 @@ $dbname = 'scuttle';
#
# enableWebsiteThumbnails : true or false. According to artviper.net license, buy a license if you gain profit with your pages. (see http://www.websitethumbnail.de/)
#
+# sizeSearchHistory : the number of users' searches that are saved
+# 10 [Default]
+# -1 Unlimited
+#
######################################################################
$sitename = 'SemanticScuttle';
@@ -137,6 +141,8 @@ $enableCommonBookmarkDescription = true;
$enableWebsiteThumbnails = true; // see above, if you gain profit with your pages
+$sizeSearchHistory = 10;
+
include_once('debug.inc.php');
?>
diff --git a/index.php b/index.php
index f70f72b..e3125aa 100644
--- a/index.php
+++ b/index.php
@@ -67,7 +67,7 @@ $dtend = date('Y-m-d H:i:s', strtotime('tomorrow'));
$tplVars['page'] = $page;
$tplVars['start'] = $start;
$tplVars['popCount'] = 30;
-$tplVars['sidebar_blocks'] = array('users', 'linked', 'recent');
+$tplVars['sidebar_blocks'] = array('search', 'users', 'linked', 'recent');
$tplVars['range'] = 'all';
$tplVars['pagetitle'] = T_('Store, share and tag your favourite links');
$tplVars['subtitle'] = T_('Recent Bookmarks');
diff --git a/locales/fr_FR/LC_MESSAGES/messages.mo b/locales/fr_FR/LC_MESSAGES/messages.mo
index 820aea1..e6ab4ae 100644
--- a/locales/fr_FR/LC_MESSAGES/messages.mo
+++ b/locales/fr_FR/LC_MESSAGES/messages.mo
Binary files differ
diff --git a/locales/fr_FR/LC_MESSAGES/messages.po b/locales/fr_FR/LC_MESSAGES/messages.po
index e3879f3..3dcaf1c 100644
--- a/locales/fr_FR/LC_MESSAGES/messages.po
+++ b/locales/fr_FR/LC_MESSAGES/messages.po
@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Scuttle\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-03-12 18:05+0100\n"
-"PO-Revision-Date: 2008-03-12 18:09+0100\n"
+"POT-Creation-Date: 2008-03-14 11:27+0100\n"
+"PO-Revision-Date: 2008-03-14 11:29+0100\n"
"Last-Translator: BenjaminHKB <benjamin.huynh-kim-bang@loria.fr>\n"
"Language-Team: fr-FR <toony.sf@chezouam.net>\n"
"MIME-Version: 1.0\n"
@@ -27,7 +27,7 @@ msgstr "À propos"
#: ../../../ajaxDelete.php:30
msgid "You are not allowed to delete this bookmark"
-msgstr "Vous ne pouvez pas supprimer ce signet."
+msgstr "Vous n'êtes pas autorisés à supprimer ce signet"
#: ../../../ajaxDelete.php:34
#: ../../../edit.php:78
@@ -43,7 +43,7 @@ msgstr "Tous les tags"
#: ../../../populartags.php:58
#: ../../../profile.php:44
#: ../../../rss.php:62
-#: ../../../search.php:87
+#: ../../../search.php:88
#: ../../../watch.php:34
#: ../../../watchlist.php:61
#, php-format
@@ -419,12 +419,12 @@ msgstr "tous les signets"
msgid "for"
msgstr "pour"
-#: ../../../search.php:58
-#: ../../../search.php:104
+#: ../../../search.php:59
+#: ../../../search.php:108
msgid "Search Bookmarks"
msgstr "Recherche de signets"
-#: ../../../search.php:64
+#: ../../../search.php:65
msgid "Search Results"
msgstr "Résultats de recherche"
@@ -463,9 +463,8 @@ msgid "Tag common description updated"
msgstr "Editer la description commune du tag"
#: ../../../tagcommondescriptionedit.php:48
-#, fuzzy
msgid "Failed to update the tag common description"
-msgstr "Impossible d'effacer le tag"
+msgstr "Impossible de mettre à jour la description commune du tag"
#: ../../../tagcommondescriptionedit.php:55
#: ../../../templates/sidebar.block.tagactions.php:25
@@ -652,32 +651,32 @@ msgstr " et les autres %s"
msgid "Copy"
msgstr "Copier"
-#: ../../../templates/bookmarks.tpl.php:201
-#: ../../../templates/bookmarks.tpl.php:207
+#: ../../../templates/bookmarks.tpl.php:202
+#: ../../../templates/bookmarks.tpl.php:208
msgid "First"
msgstr "Première"
-#: ../../../templates/bookmarks.tpl.php:202
-#: ../../../templates/bookmarks.tpl.php:208
+#: ../../../templates/bookmarks.tpl.php:203
+#: ../../../templates/bookmarks.tpl.php:209
msgid "Previous"
msgstr "Précédent"
-#: ../../../templates/bookmarks.tpl.php:215
-#: ../../../templates/bookmarks.tpl.php:218
+#: ../../../templates/bookmarks.tpl.php:216
+#: ../../../templates/bookmarks.tpl.php:219
msgid "Next"
msgstr "Suivant"
-#: ../../../templates/bookmarks.tpl.php:216
-#: ../../../templates/bookmarks.tpl.php:219
+#: ../../../templates/bookmarks.tpl.php:217
+#: ../../../templates/bookmarks.tpl.php:220
msgid "Last"
msgstr "Dernière"
-#: ../../../templates/bookmarks.tpl.php:221
+#: ../../../templates/bookmarks.tpl.php:222
#, php-format
msgid "Page %d of %d"
msgstr "Page %d de %d"
-#: ../../../templates/bookmarks.tpl.php:225
+#: ../../../templates/bookmarks.tpl.php:226
msgid "No bookmarks available"
msgstr "Pas de signets disponibles."
@@ -942,27 +941,27 @@ msgstr "Enregistrez-vous ici pour créer un compte gratuit %s. Toutes les inform
msgid "Antispam question"
msgstr "Question antispam"
-#: ../../../templates/sidebar.block.linked.php:16
+#: ../../../templates/sidebar.block.linked.php:17
msgid "Edit link"
msgstr "Editer un lien"
-#: ../../../templates/sidebar.block.linked.php:40
+#: ../../../templates/sidebar.block.linked.php:44
msgid "Synonyms:"
msgstr "Synonymes :"
-#: ../../../templates/sidebar.block.linked.php:101
+#: ../../../templates/sidebar.block.linked.php:105
msgid "Linked Tags"
msgstr "Tags structurés"
-#: ../../../templates/sidebar.block.linked.php:104
+#: ../../../templates/sidebar.block.linked.php:108
msgid "plus"
msgstr "plus"
-#: ../../../templates/sidebar.block.linked.php:122
+#: ../../../templates/sidebar.block.linked.php:126
msgid "Add new link"
msgstr "Créer un lien"
-#: ../../../templates/sidebar.block.linked.php:123
+#: ../../../templates/sidebar.block.linked.php:127
msgid "Delete link"
msgstr "Supprimer un lien"
@@ -974,6 +973,14 @@ msgstr "Tags récents"
msgid "Related Tags"
msgstr "Tags en relation"
+#: ../../../templates/sidebar.block.search.php:16
+msgid "Last Searches"
+msgstr "Dernières recherches"
+
+#: ../../../templates/sidebar.block.search.php:25
+msgid "Number of bookmarks for this query"
+msgstr "Nombre de signets pour cette recherche"
+
#: ../../../templates/sidebar.block.tagactions.php:17
#: ../../../templates/sidebar.block.watchstatus.php:17
#, fuzzy
diff --git a/locales/messages.po b/locales/messages.po
index e7be482..4a1c074 100644
--- a/locales/messages.po
+++ b/locales/messages.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-03-12 18:05+0100\n"
+"POT-Creation-Date: 2008-03-14 11:27+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -36,7 +36,7 @@ msgstr ""
#: ../../../alltags.php:57 ../../../bookmarks.php:72
#: ../../../populartags.php:58 ../../../profile.php:44 ../../../rss.php:62
-#: ../../../search.php:87 ../../../watch.php:34 ../../../watchlist.php:61
+#: ../../../search.php:88 ../../../watch.php:34 ../../../watchlist.php:61
#, php-format
msgid "User with username %s was not found"
msgstr ""
@@ -397,11 +397,11 @@ msgstr ""
msgid "for"
msgstr ""
-#: ../../../search.php:58 ../../../search.php:104
+#: ../../../search.php:59 ../../../search.php:108
msgid "Search Bookmarks"
msgstr ""
-#: ../../../search.php:64
+#: ../../../search.php:65
msgid "Search Results"
msgstr ""
@@ -633,32 +633,32 @@ msgstr ""
msgid "Copy"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:201
-#: ../../../templates/bookmarks.tpl.php:207
+#: ../../../templates/bookmarks.tpl.php:202
+#: ../../../templates/bookmarks.tpl.php:208
msgid "First"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:202
-#: ../../../templates/bookmarks.tpl.php:208
+#: ../../../templates/bookmarks.tpl.php:203
+#: ../../../templates/bookmarks.tpl.php:209
msgid "Previous"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:215
-#: ../../../templates/bookmarks.tpl.php:218
+#: ../../../templates/bookmarks.tpl.php:216
+#: ../../../templates/bookmarks.tpl.php:219
msgid "Next"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:216
-#: ../../../templates/bookmarks.tpl.php:219
+#: ../../../templates/bookmarks.tpl.php:217
+#: ../../../templates/bookmarks.tpl.php:220
msgid "Last"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:221
+#: ../../../templates/bookmarks.tpl.php:222
#, php-format
msgid "Page %d of %d"
msgstr ""
-#: ../../../templates/bookmarks.tpl.php:225
+#: ../../../templates/bookmarks.tpl.php:226
msgid "No bookmarks available"
msgstr ""
@@ -938,27 +938,27 @@ msgstr ""
msgid "Antispam question"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:16
+#: ../../../templates/sidebar.block.linked.php:17
msgid "Edit link"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:40
+#: ../../../templates/sidebar.block.linked.php:44
msgid "Synonyms:"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:101
+#: ../../../templates/sidebar.block.linked.php:105
msgid "Linked Tags"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:104
+#: ../../../templates/sidebar.block.linked.php:108
msgid "plus"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:122
+#: ../../../templates/sidebar.block.linked.php:126
msgid "Add new link"
msgstr ""
-#: ../../../templates/sidebar.block.linked.php:123
+#: ../../../templates/sidebar.block.linked.php:127
msgid "Delete link"
msgstr ""
@@ -970,6 +970,14 @@ msgstr ""
msgid "Related Tags"
msgstr ""
+#: ../../../templates/sidebar.block.search.php:16
+msgid "Last Searches"
+msgstr ""
+
+#: ../../../templates/sidebar.block.search.php:25
+msgid "Number of bookmarks for this query"
+msgstr ""
+
#: ../../../templates/sidebar.block.tagactions.php:17
#: ../../../templates/sidebar.block.watchstatus.php:17
msgid "Actions"
diff --git a/search.php b/search.php
index 2c88f91..6e002bb 100644
--- a/search.php
+++ b/search.php
@@ -31,6 +31,7 @@ if (isset($_POST['terms'])) {
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
$templateservice =& ServiceFactory::getServiceInstance('TemplateService');
$userservice =& ServiceFactory::getServiceInstance('UserService');
+ $searchhistoryservice =& ServiceFactory::getServiceInstance('SearchHistoryService');
$logged_on_userid = $userservice->getCurrentUserId();
list($url, $range, $terms, $page) = explode('/', $_SERVER['PATH_INFO']);
@@ -94,11 +95,14 @@ if (isset($_POST['terms'])) {
}
}
$bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
+
+ // Save search
+ $searchhistoryservice->addSearch($terms, $range, $bookmarks['total'], $logged_on_userid);
$tplVars['page'] = $page;
$tplVars['start'] = $start;
$tplVars['popCount'] = 25;
- $tplVars['sidebar_blocks'] = array('recent');
+ $tplVars['sidebar_blocks'] = array('search', 'recent');
$tplVars['range'] = $range;
$tplVars['terms'] = $terms;
$tplVars['pagetitle'] = T_('Search Bookmarks');
diff --git a/services/searchhistoryservice.php b/services/searchhistoryservice.php
new file mode 100644
index 0000000..7389906
--- /dev/null
+++ b/services/searchhistoryservice.php
@@ -0,0 +1,108 @@
+<?php
+class SearchHistoryService {
+ var $db;
+ var $tablename;
+ var $sizeSearchHistory;
+
+ function &getInstance(&$db) {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new SearchHistoryService($db);
+ return $instance;
+ }
+
+ function SearchHistoryService(& $db) {
+ $this->db =& $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'searchhistory';
+ if(isset($GLOBALS['sizeSearchHistory'])) {
+ $this->sizeSearchHistory = $GLOBALS['sizeSearchHistory'];
+ } else {
+ $this->sizeSearchHistory = 10;
+ }
+ }
+
+ function addSearch($terms, $range, $nbResults, $uId=0) {
+ if(strlen($terms) == 0) {
+ return false;
+ }
+ $datetime = gmdate('Y-m-d H:i:s', time());
+
+ //Insert values
+ $values = array('shTerms'=>$terms, 'shRange'=>$range, 'shDatetime'=>$datetime, 'shNbResults'=>$nbResults, 'uId'=>$uId);
+ $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+ $this->db->sql_transaction('begin');
+ if (!($dbresult = & $this->db->sql_query($sql))) {
+ $this->db->sql_transaction('rollback');
+ message_die(GENERAL_ERROR, 'Could not insert search history', '', __LINE__, __FILE__, $sql, $this->db);
+ return false;
+ }
+
+ if($this->sizeSearchHistory != -1 &&
+ $this->countSearches() > $this->sizeSearchHistory) {
+ $this->deleteOldestSearch();
+ }
+ }
+
+ function getAllSearches($range = NULL, $uId = NULL, $nb = NULL, $start = NULL, $distinct = false) {
+ $sql = 'SELECT DISTINCT(shTerms), shId, shRange, shNbResults, shDatetime, uId';
+ $sql.= ' FROM '. $this->getTableName();
+ $sql.= ' WHERE 1=1';
+ if($range != NULL) {
+ $sql.= ' AND shRange = "'.$range.'"';
+ } else {
+ $sql.= ' AND shRange = "all"';
+ }
+ if($uId != NULL) {
+ $sql.= ' AND uId = '.$uId;
+ }
+ if($distinct) {
+ $sql.= ' GROUP BY shTerms';
+ }
+ $sql.= ' ORDER BY shId DESC';
+
+ if (!($dbresult = & $this->db->sql_query_limit($sql, $nb, $start))) {
+ message_die(GENERAL_ERROR, 'Could not get searches', '', __LINE__, __FILE__, $sql, $this->db);
+ return false;
+ }
+
+ $searches = array();
+ while ($row = & $this->db->sql_fetchrow($dbresult)) {
+ $searches[] = $row;
+ }
+ return $searches;
+ }
+
+ function countSearches() {
+ $sql = 'SELECT COUNT(*) AS `total` FROM '. $this->getTableName();
+ if (!($result = & $this->db->sql_query($sql)) || (!($row = & $this->db->sql_fetchrow($result)))) {
+ message_die(GENERAL_ERROR, 'Could not get total searches', '', __LINE__, __FILE__, $sql, $this->db);
+ return false;
+ }
+
+ return $row['total'];
+ }
+
+ /* This function allows to limit the number of saved searches
+ by deleting the oldest one */
+ function deleteOldestSearch() {
+ $sql = 'DELETE FROM '.$this->getTableName();
+ $sql.= ' ORDER BY shId ASC LIMIT 1'; // warning: here the limit is important
+
+ $this->db->sql_transaction('begin');
+ if (!($dbresult = & $this->db->sql_query($sql))) {
+ $this->db->sql_transaction('rollback');
+ message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+ }
+
+ function deleteAll() {
+ $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+ $this->db->sql_query($query);
+ }
+
+ // Properties
+ function getTableName() { return $this->tablename; }
+ function setTableName($value) { $this->tablename = $value; }
+}
+?>
diff --git a/tables.sql b/tables.sql
index 64a7ec9..92c42c7 100644
--- a/tables.sql
+++ b/tables.sql
@@ -121,3 +121,19 @@ CREATE TABLE `sc_commondescription` (
UNIQUE KEY `sc_commondescription_tag_datetime` (`tag`,`cdDatetime`),
UNIQUE KEY `sc_commondescription_bookmark_datetime` (`bHash`,`cdDatetime`)
);
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `sc_searchhistory`
+--
+
+CREATE TABLE `sc_searchhistory` (
+ `shId` int(11) NOT NULL auto_increment,
+ `shTerms` varchar(255) NOT NULL default '',
+ `shRange` varchar(32) NOT NULL default '',
+ `shDatetime` datetime NOT NULL default '0000-00-00 00:00:00',
+ `shNbResults` int(6) NOT NULL default '0',
+ `uId` int(11) NOT NULL default '0',
+ PRIMARY KEY (`shId`)
+);
diff --git a/templates/sidebar.block.search.php b/templates/sidebar.block.search.php
new file mode 100644
index 0000000..e9638d2
--- /dev/null
+++ b/templates/sidebar.block.search.php
@@ -0,0 +1,35 @@
+<?php
+$tagservice =& ServiceFactory::getServiceInstance('TagService');
+$userservice =& ServiceFactory::getServiceInstance('UserService');
+$searchhistoryservice =& ServiceFactory::getServiceInstance('SearchHistoryService');
+
+$logged_on_userid = $userservice->getCurrentUserId();
+if ($logged_on_userid === false) {
+ $logged_on_userid = NULL;
+}
+
+$lastSearches = $searchhistoryservice->getAllSearches('all', NULL, 3, NULL, true);
+
+if ($lastSearches && count($lastSearches) > 0) {
+?>
+
+<h2><?php echo T_('Last Searches'); ?></h2>
+<div id="searches">
+<table>
+<?php
+foreach ($lastSearches as $row) {
+ echo '<tr><td>';
+ echo '<a href="'.createURL('search', $range.'/'.$row['shTerms']).'">';
+ echo $row['shTerms'];
+ echo '</a>';
+ echo ' <span title="'.T_('Number of bookmarks for this query').'">('.$row['shNbResults'].')</span>';
+ echo '</td></tr>';
+}
+//echo '<tr><td><a href="'.createURL('users').'">...</a></td></tr>';
+?>
+
+</table>
+</div>
+<?php
+}
+?>
diff --git a/tests/LAUNCH_TESTS b/tests/LAUNCH_TESTS
index dc8bdf4..52d4ba5 100644
--- a/tests/LAUNCH_TESTS
+++ b/tests/LAUNCH_TESTS
@@ -4,4 +4,4 @@ Then
To launch the tests, put in a console situated in the root of the SEMANTICSCUTTLE project (where is the SEMANTICSCUTTLE config file):
-phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php
+phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php ; phpunit SearchTest tests/searchTest.php
diff --git a/tests/searchTest.php b/tests/searchTest.php
new file mode 100644
index 0000000..ecdc6ad
--- /dev/null
+++ b/tests/searchTest.php
@@ -0,0 +1,80 @@
+<?php
+require_once 'PHPUnit/Framework.php';
+
+/*
+To launch this test, type the following line into a shell
+at the root of the scuttlePlus directory :
+ phpunit SearchTest tests/searchTest.php
+*/
+
+class SearchTest extends PHPUnit_Framework_TestCase
+{
+ protected $us;
+ protected $bs;
+ protected $ts;
+ protected $tts;
+ protected $shs;
+
+ protected function setUp()
+ {
+ global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype, $tableprefix;
+ require_once('./header.inc.php');
+
+ $this->us =& ServiceFactory::getServiceInstance('UserService');
+ $this->bs =& ServiceFactory::getServiceInstance('BookmarkService');
+ $this->bs->deleteAll();
+ $this->ts =& ServiceFactory::getServiceInstance('TagService');
+ $this->ts->deleteAll();
+ $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService');
+ $this->tts->deleteAll();
+ $this->tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $this->tsts->deleteAll();
+ $this->shs =& ServiceFactory::getServiceInstance('SearchHistoryService');
+ $this->shs->deleteAll();
+ }
+
+ public function testSearchHistory()
+ {
+ $shs = $this->shs;
+
+ $terms = 'bbqsdkbb;,:,:q;,qddds&é"\'\\\\\(-è_çà)';
+ $terms2 = '~#{|`]';
+ $range = 'all';
+ $nbResults = 10908;
+ $uId = 10;
+
+ $shs->addSearch($terms, $range, $nbResults, $uId);
+ $shs->addSearch($terms2, $range, $nbResults, $uId);
+ $shs->addSearch('', $range, $nbResults, $uId); // A void search must not be saved
+
+ $searches = $shs->getAllSearches();
+ $this->assertSame(2, count($searches));
+ $searches = $shs->getAllSearches($range, $uId);
+ $this->assertEquals(2, count($searches));
+ $searches = $shs->getAllSearches($range, 20); // fake userid
+ $this->assertEquals(0, count($searches));
+ $searches = $shs->getAllSearches($range, $uId, 1);
+ $this->assertEquals(1, count($searches));
+ $searches = $shs->getAllSearches($range, null, 1, 1);
+ $this->assertEquals(1, count($searches));
+
+ //test content of results
+ $searches = $shs->getAllSearches();
+ $this->assertSame($terms2, $searches[0]['shTerms']);
+ $this->assertSame($range, $searches[0]['shRange']);
+ $this->assertEquals($nbResults, $searches[0]['shNbResults']);
+ $this->assertEquals($uId, $searches[0]['uId']);
+ $this->assertSame($terms, $searches[1]['shTerms']);
+ $this->assertSame($range, $searches[1]['shRange']);
+ $this->assertEquals($nbResults, $searches[1]['shNbResults']);
+ $this->assertEquals($uId, $searches[1]['uId']);
+
+ //test distinct parameter
+ $shs->addSearch($terms, $range, $nbResults, 30); // we repeat a search (same terms)
+ $searches = $shs->getAllSearches();
+ $this->assertSame(3, count($searches));
+ $searches = $shs->getAllSearches(NULL, NULL, NULL, NULL, true);
+ $this->assertSame(2, count($searches));
+ }
+}
+?>