From 8146646a0e1c7535e62aeebab049f7b1740c86ae Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 17 Mar 2011 08:46:15 +0100 Subject: prepare jquery autocomplete (does not work yet) --- www/ajax/getcontacttags.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'www/ajax/getcontacttags.php') diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 89d6a3a..5f1edb3 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -27,18 +27,20 @@ require_once '../www-header.php'; $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $bookmarkservice =SemanticScuttle_Service_Factory::get('Tag'); +$listTags = $b2tservice->getContactTags( + $userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId() +); +$tags = array(); +foreach($listTags as $t) { + $tags[] = array( + 'caption' => $t['tag'], + 'value' => $t['tag'], + ); +} + +echo json_encode($tags); ?> -{identifier:"tag", -items: [ -getContactTags($userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId()); - foreach($listTags as $t) { - echo "{tag: \"".$t['tag']."\"},"; - } -?> -]} - -- cgit v1.2.3 From 6d49b0622df0ea44975e99b585781f55fe9ac671 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 25 Mar 2011 19:26:42 +0100 Subject: begin modifying ajax/getcontacttags --- data/templates/editbookmark.tpl.php | 5 +++ www/ajax/getcontacttags.php | 69 +++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 34 deletions(-) (limited to 'www/ajax/getcontacttags.php') diff --git a/data/templates/editbookmark.tpl.php b/data/templates/editbookmark.tpl.php index 727ee1a..6ce10b3 100644 --- a/data/templates/editbookmark.tpl.php +++ b/data/templates/editbookmark.tpl.php @@ -150,6 +150,11 @@ jQuery(document).ready(function() { $.ui.autocomplete.filter( availableTags, extractLast(request.term) ) + /* + $.getJSON( "search.php", { + term: extractLast( request.term ) + }, response ); + */ ); }, diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 5f1edb3..1377fea 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -1,46 +1,47 @@ + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -***************************************************************************/ - -/* Return a json file with list of tags according to current user and sort by popularity*/ $httpContentType = 'application/json'; require_once '../www-header.php'; -/* Service creation: only useful services are created */ -$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); -$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag'); +$limit = 30; +$beginsWith = null; +$currentUserId = $userservice->getCurrentUserId(); + +if (isset($_GET['limit']) && is_numeric($_GET['limit'])) { + $limit = (int)$_GET['limit']; +} +if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) { + $beginsWith = trim($_GET['beginsWith']); +} -$listTags = $b2tservice->getContactTags( - $userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId() +$listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags( + $currentUserId, $limit, $currentUserId, $beginsWith ); $tags = array(); -foreach($listTags as $t) { - $tags[] = array( - 'caption' => $t['tag'], - 'value' => $t['tag'], - ); +foreach ($listTags as $t) { + $tags[] = $t['tag']; } echo json_encode($tags); ?> - - - - -- cgit v1.2.3 From 78654369e918126c137b5aa4ba709a7bc0a27b43 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 11:54:47 +0100 Subject: test for beginsWith parameter and a bugfix :) --- tests/ajax/GetContactTagsTest.php | 17 +++++++++++++++++ www/ajax/getcontacttags.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'www/ajax/getcontacttags.php') diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 757dce9..6e40444 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -71,6 +71,23 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertContains('public2', $data); $this->assertContains('user2tag', $data); } + + public function testParameterBeginsWith() + { + list($req, $uId) = $this->getLoggedInRequest('?beginsWith=bar'); + $this->addBookmark($uId, null, 0, array('foobar', 'barmann')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(1, count($data)); + $this->assertContains('barmann', $data); + } } diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 1377fea..d353226 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -36,7 +36,7 @@ if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) { } $listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags( - $currentUserId, $limit, $currentUserId, $beginsWith + $currentUserId, $limit, $currentUserId, null, $beginsWith ); $tags = array(); foreach ($listTags as $t) { -- cgit v1.2.3