summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/config.default.php6
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php16
-rw-r--r--src/SemanticScuttle/Service/Vote.php4
3 files changed, 25 insertions, 1 deletions
diff --git a/data/config.default.php b/data/config.default.php
index 3c54ce1..11aa997 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -408,6 +408,12 @@ $filetypes = array(
*/
$enableCommonBookmarkDescription = true;
+/**
+ * Enable bookmark voting system
+ *
+ * @var boolean
+ */
+$enableVoting = true;
/****************************
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index a48624b..34a819c 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -432,6 +432,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
* - if the $user is set and IS the logged-in user, then
* get all bookmarks.
*
+ * In case voting is enabled and a user is logged in,
+ * each bookmark array contains two additional keys:
+ * 'hasVoted' and 'vote'.
+ *
* @param integer $start Page number
* @param integer $perpage Number of bookmarks per page
* @param integer $user User ID
@@ -601,6 +605,18 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
if ($hash) {
$query_4 .= ' AND B.bHash = "'. $hash .'"';
}
+
+ //Voting system
+ 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'];
+ }
+
+
$query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5;
if (!($dbresult = & $this->db->sql_query_limit($query, intval($perpage), intval($start)))) {
diff --git a/src/SemanticScuttle/Service/Vote.php b/src/SemanticScuttle/Service/Vote.php
index 7adf549..6db940c 100644
--- a/src/SemanticScuttle/Service/Vote.php
+++ b/src/SemanticScuttle/Service/Vote.php
@@ -221,7 +221,9 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService
*/
public function vote($bookmark, $user, $vote = 1)
{
- //FIXME: check if voting is enabled (global conf var)
+ if ($GLOBALS['enableVoting'] == false) {
+ return false;
+ }
if ($this->hasVoted($bookmark, $user)) {
return false;