2008-02-13 18:34:18 +01:00
|
|
|
<?php
|
|
|
|
class CommonDescriptionService {
|
2008-11-25 16:57:29 +01:00
|
|
|
var $db;
|
|
|
|
var $tablename;
|
|
|
|
|
|
|
|
function &getInstance(&$db) {
|
|
|
|
static $instance;
|
|
|
|
if (!isset($instance))
|
|
|
|
$instance =& new CommonDescriptionService($db);
|
|
|
|
return $instance;
|
2008-02-19 15:43:00 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
function CommonDescriptionService(&$db) {
|
|
|
|
$this->db =& $db;
|
|
|
|
$this->tablename = $GLOBALS['tableprefix'] .'commondescription';
|
|
|
|
}
|
2008-02-13 18:34:18 +01:00
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
function addTagDescription($tag, $desc, $uId, $time) {
|
|
|
|
// Check if no modification
|
|
|
|
$lastDesc = $this->getLastTagDescription($tag);
|
|
|
|
if($lastDesc['cdDescription'] == $desc) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If modification
|
|
|
|
$datetime = gmdate('Y-m-d H:i:s', $time);
|
|
|
|
$values = array('tag'=>$tag, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
|
|
|
|
$sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
|
|
|
|
|
|
|
|
if (!($dbresult =& $this->db->sql_query($sql))) {
|
|
|
|
$this->db->sql_transaction('rollback');
|
|
|
|
message_die(GENERAL_ERROR, 'Could not add tag description', '', __LINE__, __FILE__, $sql, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-02-13 18:34:18 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
function getLastTagDescription($tag) {
|
|
|
|
$query = "SELECT *";
|
|
|
|
$query.= " FROM `". $this->getTableName() ."`";
|
|
|
|
$query.= " WHERE tag='".$tag."'";
|
|
|
|
$query.= " ORDER BY cdDatetime DESC";
|
|
|
|
|
|
|
|
if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
|
|
|
|
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 false;
|
|
|
|
}
|
2008-02-19 15:43:00 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
function getAllTagsDescription($tag) {
|
|
|
|
$query = "SELECT *";
|
|
|
|
$query.= " FROM `". $this->getTableName() ."`";
|
|
|
|
$query.= " WHERE tag='".$tag."'";
|
|
|
|
$query.= " ORDER BY cdDatetime DESC";
|
|
|
|
|
|
|
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
|
|
|
message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->db->sql_fetchrowset($dbresult);
|
2008-02-13 18:34:18 +01:00
|
|
|
|
|
|
|
}
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
function getDescriptionById($cdId) {
|
|
|
|
$query = "SELECT *";
|
|
|
|
$query.= " FROM `". $this->getTableName() ."`";
|
|
|
|
$query.= " WHERE cdId='".$cdId."'";
|
|
|
|
|
|
|
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
|
|
|
message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($row =& $this->db->sql_fetchrow($dbresult)) {
|
|
|
|
return $row;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function addBookmarkDescription($bHash, $title, $desc, $uId, $time) {
|
|
|
|
// Check if no modification
|
|
|
|
$lastDesc = $this->getLastBookmarkDescription($bHash);
|
|
|
|
if($lastDesc['cdTitle'] == $title && $lastDesc['cdDescription'] == $desc) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If modification
|
|
|
|
$datetime = gmdate('Y-m-d H:i:s', $time);
|
|
|
|
$values = array('bHash'=>$bHash, 'cdTitle'=>$title, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
|
|
|
|
$sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
|
|
|
|
|
|
|
|
if (!($dbresult =& $this->db->sql_query($sql))) {
|
|
|
|
$this->db->sql_transaction('rollback');
|
|
|
|
message_die(GENERAL_ERROR, 'Could not add bookmark description', '', __LINE__, __FILE__, $sql, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLastBookmarkDescription($bHash) {
|
|
|
|
$query = "SELECT *";
|
|
|
|
$query.= " FROM `". $this->getTableName() ."`";
|
|
|
|
$query.= " WHERE bHash='".$bHash."'";
|
|
|
|
$query.= " ORDER BY cdDatetime DESC";
|
|
|
|
|
|
|
|
if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
|
|
|
|
message_die(GENERAL_ERROR, 'Could not get bookmark description', '', __LINE__, __FILE__, $query, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($row =& $this->db->sql_fetchrow($dbresult)) {
|
|
|
|
return $row;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllBookmarksDescription($bHash) {
|
|
|
|
$query = "SELECT *";
|
|
|
|
$query.= " FROM `". $this->getTableName() ."`";
|
|
|
|
$query.= " WHERE bHash='".$bHash."'";
|
|
|
|
$query.= " ORDER BY cdDatetime DESC";
|
|
|
|
|
|
|
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
|
|
|
message_die(GENERAL_ERROR, 'Could not get bookmark descriptions', '', __LINE__, __FILE__, $query, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->db->sql_fetchrowset($dbresult);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-07 10:10:28 +01:00
|
|
|
function deleteDescriptionsForUser($uId){
|
|
|
|
$query = 'DELETE FROM '. $this->getTableName() . ' WHERE uId = '. intval($uId);
|
|
|
|
|
|
|
|
$this->db->sql_transaction('begin');
|
|
|
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
|
|
|
$this->db->sql_transaction('rollback');
|
|
|
|
message_die(GENERAL_ERROR, 'Could not delete user descriptions', '',
|
|
|
|
__LINE__, __FILE__, $query, $this->db);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
function deleteAll() {
|
|
|
|
$query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
|
|
|
|
$this->db->sql_query($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
function getTableName() { return $this->tablename; }
|
|
|
|
function setTableName($value) { $this->tablename = $value; }
|
2008-02-13 18:34:18 +01:00
|
|
|
}
|
|
|
|
?>
|