diff options
author | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-25 15:57:29 +0000 |
---|---|---|
committer | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-25 15:57:29 +0000 |
commit | 15b91c7e661d928d8b125ec9cfbda1702319c8b4 (patch) | |
tree | 092d474c05e414bb04a8c428b8ff6cb9ccab765d /services/tagservice.php | |
parent | 9aafe7551eb5a73739709e72465031db7a1531b4 (diff) | |
download | semanticscuttle-15b91c7e661d928d8b125ec9cfbda1702319c8b4.tar.gz semanticscuttle-15b91c7e661d928d8b125ec9cfbda1702319c8b4.tar.bz2 |
Major refactoring: transform user into object, define parameters used into each file, ...
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@173 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services/tagservice.php')
-rw-r--r-- | services/tagservice.php | 141 |
1 files changed, 71 insertions, 70 deletions
diff --git a/services/tagservice.php b/services/tagservice.php index 47f82d6..83349c6 100644 --- a/services/tagservice.php +++ b/services/tagservice.php @@ -1,89 +1,90 @@ <?php class TagService { - var $db; - var $tablename; + var $db; + var $tablename; - function &getInstance(&$db) { - static $instance; - if (!isset($instance)) - $instance =& new TagService($db); - return $instance; - } + function &getInstance(&$db) { + static $instance; + if (!isset($instance)) + $instance =& new TagService($db); + return $instance; + } - function TagService(&$db) { - $this->db =& $db; - $this->tablename = $GLOBALS['tableprefix'] .'tags'; - } + function TagService(&$db) { + $this->db =& $db; + $this->tablename = $GLOBALS['tableprefix'] .'tags'; + } - function getDescription($tag, $uId) { - $query = 'SELECT tag, uId, tDescription'; - $query.= ' FROM '.$this->getTableName(); - $query.= ' WHERE tag = "'.$tag.'"'; - $query.= ' AND uId = "'.$uId.'"'; + function getDescription($tag, $uId) { + $query = 'SELECT tag, uId, tDescription'; + $query.= ' FROM '.$this->getTableName(); + $query.= ' WHERE tag = "'.$tag.'"'; + $query.= ' AND uId = "'.$uId.'"'; - if (!($dbresult = & $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db); - return false; - } + if (!($dbresult = & $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db); + return false; + } - if ($row =& $this->db->sql_fetchrow($dbresult)) { - return $row; - } else { - return array(); - } - } + if ($row =& $this->db->sql_fetchrow($dbresult)) { + return $row; + } else { + return array('tDescription'=>''); + } + } - function getAllDescriptions($tag) { - $query = 'SELECT tag, uId, tDescription'; - $query.= ' FROM '.$this->getTableName(); - $query.= ' WHERE tag = "'.$tag.'"'; + function getAllDescriptions($tag) { + $query = 'SELECT tag, uId, tDescription'; + $query.= ' FROM '.$this->getTableName(); + $query.= ' WHERE tag = "'.$tag.'"'; - if (!($dbresult = & $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db); - return false; - } + if (!($dbresult = & $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db); + return false; + } - return $this->db->sql_fetchrowset($dbresult); - } + return $this->db->sql_fetchrowset($dbresult); + } - function updateDescription($tag, $uId, $desc) { - if(count($this->getDescription($tag, $uId))>0) { - $query = 'UPDATE '.$this->getTableName(); - $query.= ' SET tDescription="'.$this->db->sql_escape($desc).'"'; - $query.= ' WHERE tag="'.$tag.'" AND uId="'.$uId.'"'; - } else { - $values = array('tag'=>$tag, 'uId'=>$uId, 'tDescription'=>$desc); - $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); + function updateDescription($tag, $uId, $desc) { + $objectTag = $this->getDescription($tag, $uId); + if(count($objectTag)>0 && $objectTag['tDescription'] != '') { + $query = 'UPDATE '.$this->getTableName(); + $query.= ' SET tDescription="'.$this->db->sql_escape($desc).'"'; + $query.= ' WHERE tag="'.$tag.'" AND uId="'.$uId.'"'; + } else { + $values = array('tag'=>$tag, 'uId'=>$uId, 'tDescription'=>$desc); + $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); + } + + $this->db->sql_transaction('begin'); + if (!($dbresult = & $this->db->sql_query($query))) { + $this->db->sql_transaction('rollback'); + message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + $this->db->sql_transaction('commit'); + return true; } - $this->db->sql_transaction('begin'); - if (!($dbresult = & $this->db->sql_query($query))) { - $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - $this->db->sql_transaction('commit'); - return true; - } + function renameTag($uId, $oldName, $newName) { + $query = 'UPDATE `'. $this->getTableName() .'`'; + $query.= ' SET tag="'.$newName.'"'; + $query.= ' WHERE tag="'.$oldName.'"'; + $query.= ' AND uId="'.$uId.'"'; + $this->db->sql_query($query); + return true; + } - function renameTag($uId, $oldName, $newName) { - $query = 'UPDATE `'. $this->getTableName() .'`'; - $query.= ' SET tag="'.$newName.'"'; - $query.= ' WHERE tag="'.$oldName.'"'; - $query.= ' AND uId="'.$uId.'"'; - $this->db->sql_query($query); - return true; - } - - function deleteAll() { - $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`'; - $this->db->sql_query($query); - } + function deleteAll() { + $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`'; + $this->db->sql_query($query); + } - // Properties - function getTableName() { return $this->tablename; } - function setTableName($value) { $this->tablename = $value; } + // Properties + function getTableName() { return $this->tablename; } + function setTableName($value) { $this->tablename = $value; } } ?> |