summaryrefslogtreecommitdiffstatshomepage
path: root/src/SemanticScuttle/Service/Tag.php
diff options
context:
space:
mode:
authorGravatar cweiske2009-10-24 09:12:10 +0000
committerGravatar cweiske2009-10-24 09:12:10 +0000
commit9f53c3325c99c1602f570efdaf0b6e0df2944f95 (patch)
tree89aa64a2c4538ffda43d1f2c7c87f6e814b4d623 /src/SemanticScuttle/Service/Tag.php
parent5d11ae2fd5a88b5605aa70167516a571822f0e06 (diff)
downloadscuttle-9f53c3325c99c1602f570efdaf0b6e0df2944f95.tar.gz
scuttle-9f53c3325c99c1602f570efdaf0b6e0df2944f95.zip
convert tabs to spaces
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@407 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'src/SemanticScuttle/Service/Tag.php')
-rw-r--r--src/SemanticScuttle/Service/Tag.php220
1 files changed, 110 insertions, 110 deletions
diff --git a/src/SemanticScuttle/Service/Tag.php b/src/SemanticScuttle/Service/Tag.php
index c863640..93cfd45 100644
--- a/src/SemanticScuttle/Service/Tag.php
+++ b/src/SemanticScuttle/Service/Tag.php
@@ -8,121 +8,121 @@ class SemanticScuttle_Service_Tag extends SemanticScuttle_DbService
*
* @return SemanticScuttle_Service
*/
- public static function getInstance($db)
+ public static function getInstance($db)
{
- static $instance;
- if (!isset($instance)) {
+ static $instance;
+ if (!isset($instance)) {
$instance = new self($db);
}
- return $instance;
- }
+ return $instance;
+ }
- public function __construct($db)
+ public function __construct($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('tDescription'=>'');
- }
- }
-
- function existsDescription($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 true;
- } else {
- return false;
- }
- }
-
- 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($this->existsDescription($tag, $uId)) {
- $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) {
- $newname = $this->normalize($newName);
-
- $query = 'UPDATE `'. $this->getTableName() .'`';
- $query.= ' SET tag="'.$newName.'"';
- $query.= ' WHERE tag="'.$oldName.'"';
- $query.= ' AND uId="'.$uId.'"';
- $this->db->sql_query($query);
- return true;
- }
-
- /* normalize the input tags which could be a string or an array*/
- function normalize($tags) {
- //clean tags from strange characters
- $tags = str_replace(array('"', '\'', '/'), "_", $tags);
-
- //normalize
- if(!is_array($tags)) {
- $tags = strtolower(trim($tags));
- } else {
- for($i=0; $i<count($tags); $i++) {
- $tags[$i] = strtolower(trim($tags[$i]));
- }
- }
- return $tags;
- }
-
- function deleteAll() {
- $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
- $this->db->sql_query($query);
- }
+ $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('tDescription'=>'');
+ }
+ }
+
+ function existsDescription($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 true;
+ } else {
+ return false;
+ }
+ }
+
+ 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($this->existsDescription($tag, $uId)) {
+ $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) {
+ $newname = $this->normalize($newName);
+
+ $query = 'UPDATE `'. $this->getTableName() .'`';
+ $query.= ' SET tag="'.$newName.'"';
+ $query.= ' WHERE tag="'.$oldName.'"';
+ $query.= ' AND uId="'.$uId.'"';
+ $this->db->sql_query($query);
+ return true;
+ }
+
+ /* normalize the input tags which could be a string or an array*/
+ function normalize($tags) {
+ //clean tags from strange characters
+ $tags = str_replace(array('"', '\'', '/'), "_", $tags);
+
+ //normalize
+ if(!is_array($tags)) {
+ $tags = strtolower(trim($tags));
+ } else {
+ for($i=0; $i<count($tags); $i++) {
+ $tags[$i] = strtolower(trim($tags[$i]));
+ }
+ }
+ return $tags;
+ }
+
+ function deleteAll() {
+ $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+ $this->db->sql_query($query);
+ }
}
?>