From 3ef7b27643328861ab47bc1cfd8596bc747b5a09 Mon Sep 17 00:00:00 2001 From: mensonge Date: Mon, 28 Jan 2008 14:55:07 +0000 Subject: [PATCH] new feature: structured tags, add synonym link git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@29 b3834d28-1941-0410-a4f8-b48e95affb8f --- locales/fr_FR/LC_MESSAGES/messages.mo | Bin 17339 -> 17488 bytes locales/fr_FR/LC_MESSAGES/messages.po | 38 +++++++------- locales/messages.po | 36 ++++++++------ services/tag2tagservice.php | 18 +++---- services/tagservice.php | 43 ++++++++++------ templates/editbookmark.tpl.php | 4 ++ templates/sidebar.block.linked.php | 69 +++++++++++++++++++++----- tests/tag2TagTest.php | 47 ++++++++++++++---- 8 files changed, 177 insertions(+), 78 deletions(-) diff --git a/locales/fr_FR/LC_MESSAGES/messages.mo b/locales/fr_FR/LC_MESSAGES/messages.mo index c068266ec7a1559d42925a94a73832707778d04e..c075f597b1e8258ac97407a3a6ff8e047452d753 100644 GIT binary patch delta 4083 zcmXxme^6Fc9>?*6_ygsah~*DNFC;>!C?X4iPqFkvEwz+c$)Zg00Y&A(=K+GR+^>iA?=)Peh%v-(1C04Eei_RTt`8E8SrcWBp#%U&KwQoAjb))Rwhk4jw>td;zrrm(al#1)lU&>=C@n#v6i7$=0Q|{OHnK4 zhA1#NgW8Hu(1+(S3x}n9r=b|N_cb^RPvb2Z z%RbG(J8=N-H=8Idr(r8b;}s+w%&+L+u<U)sFpeCn||wKn-9& zW??sKOFp-LgZ-)hgvybt=&IxYQ0R(cnaRL*>L+U>|zX4DwRv_iNF z7veXli4;uo26i0vDegn<`RAw=`_{Jq57`ZqIGM*Zl4+B@b6ctEx{#vZBBkAUv z^AzH^;WuO#%-}y5^Cv7s4X7P&z@0b%-$1?S80xwAP!sqJAI6IqkGB-?Ey0~8?nN+hfptYQ3GwU^>);f zccNBmH|qJrsI7a~)-R(wk%pfr=*Cf;EuG73R0nfyeIe>aji@DTLM2lh*5E2lJPN z?KZhsjmxd)P+L*RQIU_La_1Dfcp9~(r6trffV)b(|01nLb$k$$@Ej^BzeNosiQZCi zEUJSU*n}mh=lXCe{$T5)OT7iG+(6^y#WTfunL?=w(amyKgF7o+eg;sBx5i2V6wOH3zGtpVa=NCJZ!1dXmxvw2qr}@`U&569{gk?hgG4ToLX;3eLf2uB$YED8jc5w*O-OOu zDUphi>v4YGM({l}hY01Vu64wE;t_&$jQr;bBKi6X@)sv^y~fWuw!8v|5HHyJ0$gd! zVxw191{%}jRU$u+@N>4UFUDO&oUQM*idv$PNG2X4%7`Lj7O|aphe#maB6QtJR1y_L zE3uR?89gTxCnOa3(w+K%vwF!&zY}V#4b(QScIwv!ocblzp&ZAbQ=L=fR0WsRR{DKa zL4R%K^2$I%ZGEt@=X`46;6a5>Zhlc-K{z=x%`4|m?ISutIR;>v6gHAfH rs0%a%9iCqn^gGM^4eKNQUw@%LNm< zVH=F&DA9_zbdA~H_+C>^91SsM4}_Qdx_Euo->SD+f&gu1aF)zjBdJwJ|B_zUVq72K>T ztHh4@B&y-JQ5kp_)A2LR!z-u^=5UgIIe9AF&57Tv(iuQCv>!Ehb;$JEVfXuSR0qF9 zz36Au2>(G%LGvVk3Nug{$VN?J4?KjuQ3JS=WS+IA5Rz<`ff=ZJDQb~SMa}J89Ef{R z9s3Q{fy=Jmh%_iu;i!h=QEMm}%P|Ah-h3R2%Uu0bEAp>~&T&BvUqr3uKd}+^PVpZs zMNPqQ)P0p0iXO5YtO_-Nji`*giduZ{VqZLoYOhtQ|9d(rBON^oSrodVR`Xa?s#l>F z(Kb}i51=~ws`D7Kv+M+_p>wDa|Khytv@|~>;i&dvP?<_c`ea@X1vStg+u<b6HlY=zcJl^VKHhA48famEUKLv9L4+XB?@XVhKau( zTcUbcg6i=g=U8`rCTa>6;7zy~+vDq~UGM{H&J)_0^}`w19UHI+FQOK8C+2Gk@3#U9 znwuJA+HEJMK_5a@3S8a<0ZO>YGq& zWE-m8z3A-=VNp?7!-dH_tqlBu>$o0A_qDHgcVOP|2v%Ss!yAFCQ3E)G>ez%FfB#QM z&G{l!#@4#)&m!5kS5O`KD#z{rb6n5}BXa$eC!iiIL}g|K7UDM42j((7Z=*2%GA2SQU~kG zxD1=&1k{V?ptkQyRLW~mnc0QvU@fZsH?SFg?om)rf5LqH3lCv#p8w)ANOtW47Gpve z|9Uy9ficJR}aXu2&(;!FFIY9>ZAt z6!qYFRAwT(`l)Y+>PVim1V5oZ48yTQf!|)fb2MggeKAIA`Rt=W_U#bfj%QIFD!jo@ zX&=0X`W>hjjYA%^Sr{Avj-g(SQTRQM$4jWpmUr_zdJk%sOvlkU3!7;9zE2^Z3nx(@ ziu1uANZ*bA139SFbw)OT4Mb(;LDUN##WH*h8{^lgj+{ev^mkOdp`4fvE5byafpOYC z%PHvZ|5j9kwWtP;;C1+pyZ$BW1?N#C|JBw1LZ#Yz_!){oJ)eY{vi7dtAGMZ7qB6M@ zJ?+O06x2Wis{RJ*MQ2dk>jDP93wST}IQF9MUx>c|32!R4q1_TnOZ4)t6PZ`Jl2j;cR` z8CdJCe}uiMhnD#N@#u?MLr9x5Y6s0MnWQaBBj z!FlfYb*QP^fT_3zLvSUrhtM&KAkp?XF>x}dtH(A9?Fo%!1TlrsL6&VQkx1+&78Cu6 zg~VDy$9+Ttq3qQW(}u2UWYuBUdjvH=vTSix};$W#gm7P=XxWe1c^e{Cl?)1B8wwidj)9nfoY@BgPP= zL<>R(pEFxR3?W_$OpQuTsid@m*i7hn!6*2&oDtX&73Uq|N+>al*iUGpb=3L\n" "Language-Team: fr-FR \n" "MIME-Version: 1.0\n" @@ -633,66 +633,70 @@ msgstr "Séparés par des virgules" msgid "Note: use \">\" to include one tag in another. e.g.: europe>france>paris" msgstr "Note: utiliser \">\" pour inclure un tag dans un autre. ex: europe>france>paris" -#: ../../../templates/editbookmark.tpl.php:53 +#: ../../../templates/editbookmark.tpl.php:54 +msgid "Note: use \"=\" to make synonym two tags. e.g.: france=frenchcountry" +msgstr "Note : utiliser \"=\" pour rendre deux tags synonymes ex: europe=eu" + +#: ../../../templates/editbookmark.tpl.php:57 #: ../../../templates/importDelicious.tpl.php:15 #: ../../../templates/importNetscape.tpl.php:16 msgid "Privacy" msgstr "Vision" -#: ../../../templates/editbookmark.tpl.php:56 +#: ../../../templates/editbookmark.tpl.php:60 #: ../../../templates/importDelicious.tpl.php:18 #: ../../../templates/importNetscape.tpl.php:19 msgid "Public" msgstr "Publique" -#: ../../../templates/editbookmark.tpl.php:57 +#: ../../../templates/editbookmark.tpl.php:61 msgid "Shared with Watch List" msgstr "Partagé avec liste d'accès" -#: ../../../templates/editbookmark.tpl.php:58 +#: ../../../templates/editbookmark.tpl.php:62 #: ../../../templates/importDelicious.tpl.php:20 #: ../../../templates/importNetscape.tpl.php:21 msgid "Private" msgstr "Privée" -#: ../../../templates/editbookmark.tpl.php:70 +#: ../../../templates/editbookmark.tpl.php:74 msgid "Delete Bookmark" msgstr "Supprimer le signet" -#: ../../../templates/editbookmark.tpl.php:97 +#: ../../../templates/editbookmark.tpl.php:101 msgid "Bookmarklet" msgstr "Bookmarklet" -#: ../../../templates/editbookmark.tpl.php:98 +#: ../../../templates/editbookmark.tpl.php:102 #, php-format msgid "Drag one of the following bookmarklets to your browser's bookmarks and click it whenever you want to add the page you are on to %s" msgstr "Déplacez l'un des 'bookmarklet' suivants dans les marques-pages de votre navigateur et cliquez dessus chaque fois que vous souhaitez ajouter un signet pour la page courante dans %s " -#: ../../../templates/editbookmark.tpl.php:110 +#: ../../../templates/editbookmark.tpl.php:114 #, php-format msgid "Post to %s" msgstr "Ajouter à %s" -#: ../../../templates/editbookmark.tpl.php:111 +#: ../../../templates/editbookmark.tpl.php:115 #, php-format msgid "Post to %s (Pop-up)" msgstr "Ajouter à %s (Pop-up)" -#: ../../../templates/editbookmark.tpl.php:115 +#: ../../../templates/editbookmark.tpl.php:119 #: ../../../templates/importDelicious.tpl.php:26 #: ../../../templates/importNetscape.tpl.php:27 msgid "Import" msgstr "Importer" -#: ../../../templates/editbookmark.tpl.php:117 +#: ../../../templates/editbookmark.tpl.php:121 msgid "Import bookmarks from bookmark file" msgstr "Importer les signets depuis un fichier" -#: ../../../templates/editbookmark.tpl.php:117 +#: ../../../templates/editbookmark.tpl.php:121 msgid "Internet Explorer, Mozilla Firefox and Netscape" msgstr "Internet Explorer, Mozilla Firefox et Netscape" -#: ../../../templates/editbookmark.tpl.php:118 +#: ../../../templates/editbookmark.tpl.php:122 msgid "Import bookmarks from del.icio.us" msgstr "Importer les signets depuis del.icio.us" @@ -851,11 +855,11 @@ 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:72 +#: ../../../templates/sidebar.block.linked.php:97 msgid "Linked Tags" msgstr "Tags structurés" -#: ../../../templates/sidebar.block.linked.php:75 +#: ../../../templates/sidebar.block.linked.php:100 msgid "plus" msgstr "plus" diff --git a/locales/messages.po b/locales/messages.po index a5301eb..acd7574 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-01-22 16:54+0100\n" +"POT-Creation-Date: 2008-01-28 15:37+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -620,68 +620,72 @@ msgid "" "Note: use \">\" to include one tag in another. e.g.: europe>france>paris" msgstr "" -#: ../../../templates/editbookmark.tpl.php:53 +#: ../../../templates/editbookmark.tpl.php:54 +msgid "Note: use \"=\" to make synonym two tags. e.g.: france=frenchcountry" +msgstr "" + +#: ../../../templates/editbookmark.tpl.php:57 #: ../../../templates/importDelicious.tpl.php:15 #: ../../../templates/importNetscape.tpl.php:16 msgid "Privacy" msgstr "" -#: ../../../templates/editbookmark.tpl.php:56 +#: ../../../templates/editbookmark.tpl.php:60 #: ../../../templates/importDelicious.tpl.php:18 #: ../../../templates/importNetscape.tpl.php:19 msgid "Public" msgstr "" -#: ../../../templates/editbookmark.tpl.php:57 +#: ../../../templates/editbookmark.tpl.php:61 msgid "Shared with Watch List" msgstr "" -#: ../../../templates/editbookmark.tpl.php:58 +#: ../../../templates/editbookmark.tpl.php:62 #: ../../../templates/importDelicious.tpl.php:20 #: ../../../templates/importNetscape.tpl.php:21 msgid "Private" msgstr "" -#: ../../../templates/editbookmark.tpl.php:70 +#: ../../../templates/editbookmark.tpl.php:74 msgid "Delete Bookmark" msgstr "" -#: ../../../templates/editbookmark.tpl.php:97 +#: ../../../templates/editbookmark.tpl.php:101 msgid "Bookmarklet" msgstr "" -#: ../../../templates/editbookmark.tpl.php:98 +#: ../../../templates/editbookmark.tpl.php:102 #, php-format msgid "" "Drag one of the following bookmarklets to your browser's bookmarks and click " "it whenever you want to add the page you are on to %s" msgstr "" -#: ../../../templates/editbookmark.tpl.php:110 +#: ../../../templates/editbookmark.tpl.php:114 #, php-format msgid "Post to %s" msgstr "" -#: ../../../templates/editbookmark.tpl.php:111 +#: ../../../templates/editbookmark.tpl.php:115 #, php-format msgid "Post to %s (Pop-up)" msgstr "" -#: ../../../templates/editbookmark.tpl.php:115 +#: ../../../templates/editbookmark.tpl.php:119 #: ../../../templates/importDelicious.tpl.php:26 #: ../../../templates/importNetscape.tpl.php:27 msgid "Import" msgstr "" -#: ../../../templates/editbookmark.tpl.php:117 +#: ../../../templates/editbookmark.tpl.php:121 msgid "Import bookmarks from bookmark file" msgstr "" -#: ../../../templates/editbookmark.tpl.php:117 +#: ../../../templates/editbookmark.tpl.php:121 msgid "Internet Explorer, Mozilla Firefox and Netscape" msgstr "" -#: ../../../templates/editbookmark.tpl.php:118 +#: ../../../templates/editbookmark.tpl.php:122 msgid "Import bookmarks from del.icio.us" msgstr "" @@ -853,11 +857,11 @@ msgstr "" msgid "Antispam question" msgstr "" -#: ../../../templates/sidebar.block.linked.php:72 +#: ../../../templates/sidebar.block.linked.php:97 msgid "Linked Tags" msgstr "" -#: ../../../templates/sidebar.block.linked.php:75 +#: ../../../templates/sidebar.block.linked.php:100 msgid "plus" msgstr "" diff --git a/services/tag2tagservice.php b/services/tag2tagservice.php index f46ef7c..d37ab8b 100644 --- a/services/tag2tagservice.php +++ b/services/tag2tagservice.php @@ -59,7 +59,7 @@ class Tag2TagService { if($uId != null) { $query.= " AND uId = '".$uId."'"; } - +//die($query); if (! ($dbresult =& $this->db->sql_query_limit($query, $limit)) ){ message_die(GENERAL_ERROR, 'Could not get related tags', '', __LINE__, __FILE__, $query, $this->db); return false; @@ -69,6 +69,7 @@ class Tag2TagService { $output = array(); foreach($rowset as $row) { if(!in_array($row['tag'], $stopList)) { + $output[] = $row['tag']; } } @@ -89,19 +90,18 @@ class Tag2TagService { $asFlatList = true; //we disable the tree list parameter for the moment if(in_array($tag1, $stopList)) { - return $tag1; + return array(); } - $stopList2 = $stopList; - $stopList2[] = $tag1; - $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId, false, $stopList2); + $stopList[] = $tag1; + $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId, false, $stopList); if($relationType != '=') { - $linkedTags = array_merge($linkedTags, $this->getLinkedTags($tag1, '=', $uId, false, $stopList2)); + $linkedTags = array_merge($linkedTags, $this->getLinkedTags($tag1, '=', $uId, false, $stopList)); } if(count($linkedTags) == 0) { - return $tag1; + return array(); } else { $output = array(); if($asFlatList == true) { @@ -110,13 +110,13 @@ class Tag2TagService { $output = array('node'=>$tag1); } - $stopList[] = $tag1; foreach($linkedTags as $linkedTag) { $allLinkedTags = $this->getAllLinkedTags($linkedTag, $relationType, $uId, $asFlatList, $stopList); if($asFlatList == true) { + $output[] = $linkedTag; if(is_array($allLinkedTags)) { - $output[] = $linkedTag; + $output = array_merge($output, $allLinkedTags); } else { $output[] = $allLinkedTags; diff --git a/services/tagservice.php b/services/tagservice.php index 509e575..bbf3574 100644 --- a/services/tagservice.php +++ b/services/tagservice.php @@ -86,22 +86,37 @@ class TagService { } } + $bs =& ServiceFactory::getServiceInstance('BookmarkService'); + $tts =& ServiceFactory::getServiceInstance('Tag2TagService'); + // Create links between tags foreach($tags as $key => $tag) { - // case ">" - $pieces = explode('>', $tag); - $nbPieces = count($pieces); - if($nbPieces > 1) { - for($i = 0; $i < $nbPieces-1; $i++) { - $bs =& ServiceFactory::getServiceInstance('BookmarkService'); - $tts =& ServiceFactory::getServiceInstance('Tag2TagService'); - - $bookmark = $bs->getBookmark($bookmarkid); - $uId = $bookmark['uId']; - $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '>', $uId); - } - $tags[$key] = $pieces[$nbPieces-1]; // Attach just the last tag to the bookmark - } + if(strpos($tag, '=')) { + // case "=" + $pieces = explode('=', $tag); + $nbPieces = count($pieces); + if($nbPieces > 1) { + for($i = 0; $i < $nbPieces-1; $i++) { + $bookmark = $bs->getBookmark($bookmarkid); + $uId = $bookmark['uId']; + $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '=', $uId); + } + $tags[$key] = $pieces[0]; // Attach just the last tag to the bookmark + } + } else { + // case ">" + $pieces = explode('>', $tag); + $nbPieces = count($pieces); + if($nbPieces > 1) { + for($i = 0; $i < $nbPieces-1; $i++) { + $bookmark = $bs->getBookmark($bookmarkid); + $uId = $bookmark['uId']; + $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '>', $uId); + } + $tags[$key] = $pieces[$nbPieces-1]; // Attach just the last tag to the bookmark + } + } + } diff --git a/templates/editbookmark.tpl.php b/templates/editbookmark.tpl.php index f707668..3101431 100644 --- a/templates/editbookmark.tpl.php +++ b/templates/editbookmark.tpl.php @@ -49,6 +49,10 @@ window.onload = function() { " to include one tag in another. e.g.: europe>france>paris')?> + + + + diff --git a/templates/sidebar.block.linked.php b/templates/sidebar.block.linked.php index 24ca7e6..74516ae 100644 --- a/templates/sidebar.block.linked.php +++ b/templates/sidebar.block.linked.php @@ -3,15 +3,30 @@ $tag2tagservice =& ServiceFactory::getServiceInstance('Tag2TagService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); function displayLinkedTags($tag, $linkType, $uId, $cat_url, $user, $editingMode =false, $precedentTag =null, $level=0, $stopList=array()) { + + if(in_array($tag, $stopList)) { + return array('output' => '', 'stoplist' => $stopList); + } + $tag2tagservice =& ServiceFactory::getServiceInstance('Tag2TagService'); $tagstatservice =& ServiceFactory::getServiceInstance('TagStatService'); $output = ''; $output.= ''; $output.= ''; - $output.= ''. str_repeat(' ', $level*2) .''; + $output.= ''; + $output.= $level == 0?'':''; + $output.= str_repeat(' ', $level*2) .''; + $output.= $level == 1?'':''; //$output.= ' - '. $tagstatservice->getMaxDepth($tag, $linkType, $uId); + $synonymTags = $tag2tagservice->getAllLinkedTags($tag, '=', $uId); + $synonymTags = is_array($synonymTags)?$synonymTags:array($synonymTags); + sort($synonymTags); + foreach($synonymTags as $synonymTag) { + $output.= ", ".$synonymTag; + } + if($editingMode) { $output.= ' ('; $output.= 'add'; @@ -24,16 +39,26 @@ function displayLinkedTags($tag, $linkType, $uId, $cat_url, $user, $editingMode $output.= ''; $output.= ''; - if(!in_array($tag, $stopList)) { - $linkedTags = $tag2tagservice->getLinkedTags($tag, '>', $uId); - $precedentTag = $tag; - $stopList[] = $tag; - $level = $level + 1; - foreach($linkedTags as $linkedTag) { - $output.= displayLinkedTags($linkedTag, $linkType, $uId, $cat_url, $user, $editingMode, $precedentTag, $level, $stopList); - } - } - return $output; + $tags = array($tag); + $tags = array_merge($tags, $synonymTags); + foreach($tags as $tag) { + + if(!in_array($tag, $stopList)) { + $linkedTags = $tag2tagservice->getLinkedTags($tag, '>', $uId); + $precedentTag = $tag; + $stopList[] = $tag; + foreach($linkedTags as $linkedTag) { + $displayLinkedTags = displayLinkedTags($linkedTag, $linkType, $uId, $cat_url, $user, $editingMode, $precedentTag, $level + 1, $stopList); + $output.= $displayLinkedTags['output']; + } + if(is_array($displayLinkedTags['stopList'])) { + $stopList = array_merge($stopList, $displayLinkedTags['stopList']); + $stopList = array_unique($stopList); + } + } + + } + return array('output' => $output, 'stopList' => $stopList); } $logged_on_userid = $userservice->getCurrentUserId(); @@ -59,7 +84,7 @@ if ($currenttag) { if(count($explodedTags) > 0) { $displayLinkedZone = false; foreach($explodedTags as $explodedTag) { - if($tag2tagservice->getLinkedTags($explodedTag, '>', $userid)) { + if($tag2tagservice->getLinkedTags($explodedTag, '>', $userid) || $tag2tagservice->getLinkedTags($explodedTag, '>', $userid, true) || $tag2tagservice->getLinkedTags($explodedTag, '=', $userid)) { $displayLinkedZone = true; break; } @@ -86,8 +111,26 @@ if(count($explodedTags) > 0) { } else { $editingMode = false; } + $stopList = array(); foreach($explodedTags as $explodedTag) { - echo displayLinkedTags($explodedTag, '>', $userid, $cat_url, $user, $editingMode); + if(!in_array($explodedTag, $stopList)) { + // fathers tag + $fatherTags = $tag2tagservice->getLinkedTags($explodedTag, '>', $userid, true); + if(count($fatherTags)>0) { + foreach($fatherTags as $fatherTag) { + echo ''; + echo ''; + echo ''; + } + } + + $displayLinkedTags = displayLinkedTags($explodedTag, '>', $userid, $cat_url, $user, $editingMode, null, 0); + echo $displayLinkedTags['output']; + if(is_array($displayLinkedTags['stopList'])) { + $stopList = array_merge($stopList, $displayLinkedTags['stopList']); + } + } + } ?> diff --git a/tests/tag2TagTest.php b/tests/tag2TagTest.php index 83e7dbc..9a72eb8 100644 --- a/tests/tag2TagTest.php +++ b/tests/tag2TagTest.php @@ -44,6 +44,9 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase // basic test + $allLinkedTags = $tts->getAllLinkedTags('e', '>', 1, true); // as flat list + $this->assertEquals(array(), $allLinkedTags); + $allLinkedTags = $tts->getAllLinkedTags('d', '>', 1, true); // as flat list $this->assertEquals(array('e'), $allLinkedTags); @@ -125,8 +128,10 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $this->assertTrue(in_array('d', $linkedTags)); // '=' is bijective // test allLinkTags (with inference) + $allLinkedTags = $tts->getAllLinkedTags('a', '=', 1, true); // as flat list + $this->assertEquals(0, sizeof($allLinkedTags)); + $allLinkedTags = $tts->getAllLinkedTags('b', '=', 1, true); // as flat list - $this->assertEquals(array('d', 'e', 'f'), $allLinkedTags); $this->assertEquals(3, sizeof($allLinkedTags)); $this->assertTrue(in_array('d', $allLinkedTags)); $this->assertTrue(in_array('e', $allLinkedTags)); @@ -149,19 +154,36 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $this->assertTrue(in_array('f', $allLinkedTags)); $this->assertTrue(in_array('g', $allLinkedTags)); + $tts->addLinkedTags('g', 'h', '>', 1); + $tts->addLinkedTags('i', 'h', '=', 1); + $tts->addLinkedTags('j', 'f', '>', 1); + + $allLinkedTags = $tts->getAllLinkedTags('j', '>', 1, true); // as flat list + $this->assertEquals(8, sizeof($allLinkedTags)); + $this->assertTrue(in_array('b', $allLinkedTags)); + $this->assertTrue(in_array('c', $allLinkedTags)); + $this->assertTrue(in_array('d', $allLinkedTags)); + $this->assertTrue(in_array('e', $allLinkedTags)); + $this->assertTrue(in_array('f', $allLinkedTags)); + $this->assertTrue(in_array('g', $allLinkedTags)); + $this->assertTrue(in_array('h', $allLinkedTags)); + $this->assertTrue(in_array('i', $allLinkedTags)); + // complex case: test cycle $tts->addLinkedTags('g', 'a', '>', 1); $allLinkedTags = $tts->getAllLinkedTags('b', '>', 1, true); // as flat list - $this->assertEquals(6, sizeof($allLinkedTags)); + $this->assertEquals(8, sizeof($allLinkedTags)); $this->assertTrue(in_array('a', $allLinkedTags)); $this->assertTrue(in_array('c', $allLinkedTags)); $this->assertTrue(in_array('d', $allLinkedTags)); $this->assertTrue(in_array('e', $allLinkedTags)); $this->assertTrue(in_array('f', $allLinkedTags)); $this->assertTrue(in_array('g', $allLinkedTags)); + $this->assertTrue(in_array('h', $allLinkedTags)); + $this->assertTrue(in_array('i', $allLinkedTags)); } -/* + // Test function that select the best tags to display? public function testViewTag2TagRelations() { @@ -207,17 +229,19 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase public function testAddLinkedTagsThroughBookmarking() { $bs = $this->bs; - $tags = array('a>b', 'b>c', 'a>d>e', 'a>a', 'a'); + $tags = array('a>b', 'b>c', 'a>d>e', 'a>a', 'a', 'r=s', 's=t=u'); $bs->addBookmark("http://google.com", "title", "description", "status", $tags, null, false, false, 1); $bookmark = $bs->getBookmarkByAddress("http://google.com"); $ts = $this->ts; $savedTags = $ts->getTagsForBookmark(intval($bookmark['bId'])); - $this->assertEquals(4, sizeof($savedTags)); + $this->assertEquals(6, sizeof($savedTags)); $this->assertContains('b', $savedTags); $this->assertContains('c', $savedTags); $this->assertContains('e', $savedTags); $this->assertContains('a', $savedTags); + $this->assertContains('r', $savedTags); + $this->assertContains('s', $savedTags); $tts = $this->tts; $linkedTags = $tts->getLinkedTags('a', '>', 1); @@ -240,7 +264,7 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $bs->addBookmark("web1.com", "B1", "description", "status", $tags, null, false, false, 1); $tags = array('bb>gg', 'ee>ff'); $bs->addBookmark("web2.com", "B2", "description", "status", $tags, null, false, false, 1); - $tags = array('ee'); + $tags = array('ee=ii'); $bs->addBookmark("web3.com", "B3", "description", "status", $tags, null, false, false, 1); // Query format: @@ -263,8 +287,13 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $results = $bs->getBookmarks(0, NULL, 1, 'ee'); $this->assertSame(2, intval($results['total'])); - $this->assertSame('B2', $results['bookmarks'][0]['bTitle']); - $this->assertSame('B3', $results['bookmarks'][1]['bTitle']); + $this->assertSame('B2', $results['bookmarks'][1]['bTitle']); + $this->assertSame('B3', $results['bookmarks'][0]['bTitle']); + + $results = $bs->getBookmarks(0, NULL, 1, 'ii'); + $this->assertSame(2, intval($results['total'])); + $this->assertSame('B2', $results['bookmarks'][1]['bTitle']); + $this->assertSame('B3', $results['bookmarks'][0]['bTitle']); $results = $bs->getBookmarks(0, NULL, 1, 'aa+ee'); $this->assertSame(1, intval($results['total'])); @@ -362,6 +391,6 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase // advanced case with back loop //$tts->addLinkedTags('e', 'a', '>', 1); - }*/ + } } ?>