diff options
author | Christian Weiske <cweiske@cweiske.de> | 2011-03-25 07:44:07 +0100 |
---|---|---|
committer | Christian Weiske <cweiske@cweiske.de> | 2011-03-25 07:44:07 +0100 |
commit | e667feb0ca9ff30a063149a2ce20b3398585dd4f (patch) | |
tree | 18a17453d4615a5683425f99b5d98d562a927d33 | |
parent | d761abb05e28ef4f345acef739e3b371b462f9fe (diff) | |
download | semanticscuttle-e667feb0ca9ff30a063149a2ce20b3398585dd4f.tar.gz semanticscuttle-e667feb0ca9ff30a063149a2ce20b3398585dd4f.tar.bz2 |
beginsWith-parameter for getPopulartags, getContactTags and getAdminTags
-rw-r--r-- | src/SemanticScuttle/Service/Bookmark2Tag.php | 25 | ||||
-rw-r--r-- | tests/Bookmark2TagTest.php | 64 |
2 files changed, 84 insertions, 5 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index beb4185..1dc0ffe 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -466,6 +466,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * returned. * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -473,14 +474,16 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getPopularTags() */ public function getAdminTags( - $limit = 30, $logged_on_user = null, $days = null + $limit = 30, $logged_on_user = null, $days = null, $beginsWith = null ) { // look for admin ids $userservice = SemanticScuttle_Service_Factory::get('User'); $adminIds = $userservice->getAdminIds(); // ask for their tags - return $this->getPopularTags($adminIds, $limit, $logged_on_user, $days); + return $this->getPopularTags( + $adminIds, $limit, $logged_on_user, $days, $beginsWith + ); } @@ -497,6 +500,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * people to get the tags from * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -504,7 +508,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getPopularTags() */ public function getContactTags( - $user, $limit = 30, $logged_on_user = null, $days = null + $user, $limit = 30, $logged_on_user = null, $days = null, + $beginsWith = null ) { // look for contact ids $userservice = SemanticScuttle_Service_Factory::get('User'); @@ -516,7 +521,9 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService } // ask for their tags - return $this->getPopularTags($contacts, $limit, $logged_on_user, $days); + return $this->getPopularTags( + $contacts, $limit, $logged_on_user, $days, $beginsWith + ); } @@ -533,6 +540,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * returned. * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -541,7 +549,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getContactTags() */ public function getPopularTags( - $user = null, $limit = 30, $logged_on_user = null, $days = null + $user = null, $limit = 30, $logged_on_user = null, $days = null, + $beginsWith = null ) { // Only count the tags that are visible to the current user. if (($user != $logged_on_user) || is_null($user) || ($user === false)) { @@ -577,6 +586,12 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService . '"'; } + if (!is_null($beginsWith)) { + $query .= ' AND T.tag LIKE \'' + . $this->db->sql_escape($beginsWith) + . '%\''; + } + $query .= ' AND LEFT(T.tag, 7) <> "system:"' . ' GROUP BY T.tag' . ' ORDER BY bCount DESC, tag'; diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index e2020dc..ffd83c3 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -334,6 +334,31 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'thr', 'bCount' => '2'), $arTags); } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsBeginsWith() + { + $user = $this->addUser(); + $this->addTagBookmark($user, array('one', 'two')); + $this->addTagBookmark($user, array('one', 'thr')); + $this->addTagBookmark($user, array('one', 'two')); + $this->addTagBookmark($user, array('one', 'thr')); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 'o'); + $this->assertEquals(1, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '4'), $arTags); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 'tw'); + $this->assertEquals(1, count($arTags)); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 't'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '2'), $arTags); + } + /** @@ -500,6 +525,23 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags); } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getAdminTags + */ + public function testGetAdminTagsBeginsWith() + { + $admin1 = $this->addUser('admin1'); + $this->addBookmark($admin1, null, 0, array('admintag', 'admintag1')); + $this->addBookmark($admin1, null, 0, array('tester', 'testos')); + + $GLOBALS['admin_users'] = array('admin1'); + + $arTags = $this->b2ts->getAdminTags(4, null, null, 'test'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'tester', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'testos', 'bCount' => '1'), $arTags); + } + /** @@ -546,6 +588,28 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags); } + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags + */ + public function testGetContactTagsBeginsWith() + { + $user1 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('usertag', 'usertag1')); + $this->addBookmark($user1, null, 0, array('usable', 'undefined')); + $this->addBookmark($user1, null, 0, array('fußbad', 'usable')); + + $arTags = $this->b2ts->getContactTags($user1, 10, $user1, null, 'user'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); + + $arTags = $this->b2ts->getContactTags($user1, 10, $user1, null, 'us'); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { |