]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
beginsWith-parameter for getPopulartags, getContactTags and getAdminTags
authorChristian Weiske <cweiske@cweiske.de>
Fri, 25 Mar 2011 06:44:07 +0000 (07:44 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 25 Mar 2011 06:44:07 +0000 (07:44 +0100)
src/SemanticScuttle/Service/Bookmark2Tag.php
tests/Bookmark2TagTest.php

index beb4185382cd8d8f190b9e710b0efecbc825eb13..1dc0ffe4164e0ec890dc2e0eb2aa97e1b7415b86 100644 (file)
@@ -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';
index e2020dc5d36dcf435db297142540278bd8195246..ffd83c38476ed6313b4f9712fa48c4359dfe1ce6 100644 (file)
@@ -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') {