summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-28 08:02:17 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-28 08:02:17 +0000
commita3ba58dfc048c948230317191c67101c4aa80bfb (patch)
tree75dc0309ac92381e3df31820894aa79f320b9e1f /src
parenta63765a4ad05b83f4c4ffcb7790b528f09f20a43 (diff)
downloadsemanticscuttle-a3ba58dfc048c948230317191c67101c4aa80bfb.tar.gz
semanticscuttle-a3ba58dfc048c948230317191c67101c4aa80bfb.tar.bz2
basic ajax voting support. has a bad counting bug somewhere
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@445 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'src')
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 3a7edd9..1054360 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -80,19 +80,51 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
+ /**
+ * Load a single bookmark and return it
+ *
+ * @param integer $bid Bookmark ID
+ * @param boolean $include_tags If tags shall be loaded
+ *
+ * @return mixed Array with bookmark data or false in case
+ * of an error.
+ */
function getBookmark($bid, $include_tags = false)
{
- if (!is_numeric($bid))
- return;
+ if (!is_numeric($bid)) {
+ return false;
+ }
- $sql = 'SELECT * FROM '. $this->getTableName() .' WHERE bId = '. $this->db->sql_escape($bid);
+ $userservice = SemanticScuttle_Service_Factory::get('User');
- if (!($dbresult = & $this->db->sql_query($sql)))
- message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
+ $query_1 = '*';
+ $query_2 = $this->getTableName() . ' as B';
+
+ //Voting system
+ //needs to be directly after FROM bookmarks
+ if ($GLOBALS['enableVoting'] && $userservice->isLoggedOn()) {
+ $currentuser = $userservice->getCurrentUser();
+ $vs = SemanticScuttle_Service_Factory::get('Vote');
+ $query_1 .= ', !ISNULL(V.bId) as hasVoted, V.vote as vote';
+ $query_2 .= ' LEFT JOIN ' . $vs->getTableName() . ' AS V'
+ . ' ON B.bId = V.bId'
+ . ' AND V.uId = ' . (int)$currentuser['uId'];
+ }
+
+ $sql = 'SELECT ' . $query_1 . ' FROM '
+ . $query_2
+ .' WHERE B.bId = '. $this->db->sql_escape($bid);
+
+ if (!($dbresult = & $this->db->sql_query($sql))) {
+ message_die(
+ GENERAL_ERROR, 'Could not get bookmark',
+ '', __LINE__, __FILE__, $sql, $this->db
+ );
+ }
- if ($row = & $this->db->sql_fetchrow($dbresult)) {
+ if ($row = $this->db->sql_fetchrow($dbresult)) {
if ($include_tags) {
- $b2tservice = SemanticScuttle_Service_Factory :: get('Bookmark2Tag');
+ $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$row['tags'] = $b2tservice->getTagsForBookmark($bid);
}
$output = $row;