]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
document attachlinkedtag
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 20:05:25 +0000 (20:05 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 20:05:25 +0000 (20:05 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@423 b3834d28-1941-0410-a4f8-b48e95affb8f

src/SemanticScuttle/Service/Tag2Tag.php

index dcbcf2eacbab60b260808d3f67e10b481c36aeae..b78864ac282ff03fb5ef91eb3128993c5c62c305 100644 (file)
@@ -24,24 +24,49 @@ class SemanticScuttle_Service_Tag2Tag extends SemanticScuttle_DbService
         $this->tablename = $GLOBALS['tableprefix'] .'tags2tags';
     }
 
-    function addLinkedTags($tag1, $tag2, $relationType, $uId) {
-        $tagservice =SemanticScuttle_Service_Factory::get('Tag');
+    /**
+     * Add a tag-to-tag link relation
+     *
+     * @param string  $tag1         First tag
+     * @param string  $tag2         Second tag
+     * @param string  $relationType Relation:
+     *                              "=" (both tags are equal)
+     *                              ">" (tag2 is part of tag1)
+     * @param integer $uId          User ID
+     *
+     * @return boolean True when it was created, false in case of
+     *                 an error or when the link already existed.
+     */
+    public function addLinkedTags($tag1, $tag2, $relationType, $uId)
+    {
+        $tagservice = SemanticScuttle_Service_Factory::get('Tag');
         $tag1 = $tagservice->normalize($tag1);
         $tag2 = $tagservice->normalize($tag2);
 
-        if($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0
-        || ($relationType != ">" && $relationType != "=")
-        || !is_numeric($uId) || $uId<=0
-        || ($this->existsLinkedTags($tag1, $tag2, $relationType, $uId))) {
+        if ($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0
+            || ($relationType != '>' && $relationType != '=')
+            || !is_numeric($uId) || $uId<=0
+            || ($this->existsLinkedTags($tag1, $tag2, $relationType, $uId))
+        ) {
             return false;
         }
 
-        $values = array('tag1' => $tag1, 'tag2' => $tag2, 'relationType'=> $relationType, 'uId'=> $uId);
-        $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+        $values = array(
+            'tag1'         => $tag1,
+            'tag2'         => $tag2,
+            'relationType' => $relationType,
+            'uId'          => $uId
+        );
+        $query = 'INSERT INTO ' . $this->getTableName()
+            . ' ' . $this->db->sql_build_array('INSERT', $values);
+
         //die($query);
         if (!($dbresult = $this->db->sql_query($query))) {
             $this->db->sql_transaction('rollback');
-            message_die(GENERAL_ERROR, 'Could not attach tag to tag', '', __LINE__, __FILE__, $query, $this->db);
+            message_die(
+                GENERAL_ERROR, 'Could not attach tag to tag',
+                '', __LINE__, __FILE__, $query, $this->db
+            );
             return false;
         }
         $this->db->sql_transaction('commit');