reformat countOthers()
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@658 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
2f13a1c819
commit
91da444e76
1 changed files with 33 additions and 13 deletions
|
@ -889,31 +889,51 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function countOthers($address)
|
/**
|
||||||
|
* Counts the number of bookmarks that have the same address
|
||||||
|
* as the given address
|
||||||
|
*
|
||||||
|
* @param string $address Address/URL to look for
|
||||||
|
*
|
||||||
|
* @return integer Number of bookmarks minus one that have the address
|
||||||
|
*/
|
||||||
|
public function countOthers($address)
|
||||||
{
|
{
|
||||||
if (!$address) {
|
if (!$address) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$userservice = SemanticScuttle_Service_Factory :: get('User');
|
$us = SemanticScuttle_Service_Factory::get('User');
|
||||||
$sId = $userservice->getCurrentUserId();
|
$sId = (int)$us->getCurrentUserId();
|
||||||
|
|
||||||
if ($userservice->isLoggedOn()) {
|
if ($us->isLoggedOn()) {
|
||||||
// All public bookmarks, user's own bookmarks and any shared with user
|
//All public bookmarks, user's own bookmarks
|
||||||
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
|
// and any shared with our user
|
||||||
$watchnames = $userservice->getWatchNames($sId, true);
|
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = ' . $sId . ')';
|
||||||
foreach($watchnames as $watchuser) {
|
$watchnames = $us->getWatchNames($sId, true);
|
||||||
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
|
foreach ($watchnames as $watchuser) {
|
||||||
|
$privacy .= ' OR (U.username = "'
|
||||||
|
. $this->db->sql_escape($watchuser)
|
||||||
|
. '" AND B.bStatus = 1)';
|
||||||
}
|
}
|
||||||
$privacy .= ')';
|
$privacy .= ')';
|
||||||
} else {
|
} else {
|
||||||
// Just public bookmarks
|
//Just public bookmarks
|
||||||
$privacy = ' AND B.bStatus = 0';
|
$privacy = ' AND B.bStatus = 0';
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) as "0" FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy;
|
$sql = 'SELECT COUNT(*) as "0" FROM '
|
||||||
if (!($dbresult = & $this->db->sql_query($sql))) {
|
. $us->getTableName() . ' AS U'
|
||||||
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
. ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B'
|
||||||
|
. ' WHERE U.'. $us->getFieldName('primary') .' = B.uId'
|
||||||
|
. ' AND B.bHash = "'. md5($address) . '"'
|
||||||
|
. $privacy;
|
||||||
|
|
||||||
|
if (!($dbresult = $this->db->sql_query($sql))) {
|
||||||
|
message_die(
|
||||||
|
GENERAL_ERROR, 'Could not get other count',
|
||||||
|
'', __LINE__, __FILE__, $sql, $this->db
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $this->db->sql_fetchfield(0, 0);
|
$count = $this->db->sql_fetchfield(0, 0);
|
||||||
|
|
Loading…
Reference in a new issue