document attachlinkedtag

git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@423 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
cweiske 2009-10-25 20:05:25 +00:00
parent edfefe3eeb
commit 6fad03eb7a

View file

@ -24,24 +24,49 @@ class SemanticScuttle_Service_Tag2Tag extends SemanticScuttle_DbService
$this->tablename = $GLOBALS['tableprefix'] .'tags2tags'; $this->tablename = $GLOBALS['tableprefix'] .'tags2tags';
} }
function addLinkedTags($tag1, $tag2, $relationType, $uId) { /**
* 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'); $tagservice = SemanticScuttle_Service_Factory::get('Tag');
$tag1 = $tagservice->normalize($tag1); $tag1 = $tagservice->normalize($tag1);
$tag2 = $tagservice->normalize($tag2); $tag2 = $tagservice->normalize($tag2);
if ($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0 if ($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0
|| ($relationType != ">" && $relationType != "=") || ($relationType != '>' && $relationType != '=')
|| !is_numeric($uId) || $uId<=0 || !is_numeric($uId) || $uId<=0
|| ($this->existsLinkedTags($tag1, $tag2, $relationType, $uId))) { || ($this->existsLinkedTags($tag1, $tag2, $relationType, $uId))
) {
return false; return false;
} }
$values = array('tag1' => $tag1, 'tag2' => $tag2, 'relationType'=> $relationType, 'uId'=> $uId); $values = array(
$query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); 'tag1' => $tag1,
'tag2' => $tag2,
'relationType' => $relationType,
'uId' => $uId
);
$query = 'INSERT INTO ' . $this->getTableName()
. ' ' . $this->db->sql_build_array('INSERT', $values);
//die($query); //die($query);
if (!($dbresult = $this->db->sql_query($query))) { if (!($dbresult = $this->db->sql_query($query))) {
$this->db->sql_transaction('rollback'); $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; return false;
} }
$this->db->sql_transaction('commit'); $this->db->sql_transaction('commit');