summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-04-21 15:43:00 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-04-21 15:43:00 +0000
commit3b79d6b9cc75eaf2b54f6d41843a313b13395c8d (patch)
treeccacf4d7d95197c700c25b28abc469a50706616f /services
parent4de56ed6623c57c1c767be192ffe2af5926fe598 (diff)
downloadsemanticscuttle-3b79d6b9cc75eaf2b54f6d41843a313b13395c8d.tar.gz
semanticscuttle-3b79d6b9cc75eaf2b54f6d41843a313b13395c8d.tar.bz2
New feature: private descriptions for tags
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@117 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services')
-rw-r--r--services/tagservice.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/services/tagservice.php b/services/tagservice.php
new file mode 100644
index 0000000..fbb7fa3
--- /dev/null
+++ b/services/tagservice.php
@@ -0,0 +1,88 @@
+<?php
+class TagService {
+ var $db;
+ var $tablename;
+
+ 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 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 ($row =& $this->db->sql_fetchrow($dbresult)) {
+ return $row;
+ } else {
+ return array();
+ }
+ }
+
+ 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;
+ }
+
+ 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);
+ }
+
+ $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);
+ }
+
+
+
+ function deleteAll() {
+ $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+ $this->db->sql_query($query);
+ }
+
+ // Properties
+ function getTableName() { return $this->tablename; }
+ function setTableName($value) { $this->tablename = $value; }
+}
+?>