]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
introduce voting config value and provide current user voting status in getBookmarks()
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Mon, 26 Oct 2009 18:52:02 +0000 (18:52 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Mon, 26 Oct 2009 18:52:02 +0000 (18:52 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@431 b3834d28-1941-0410-a4f8-b48e95affb8f

data/config.default.php
src/SemanticScuttle/Service/Bookmark.php
src/SemanticScuttle/Service/Vote.php

index 3c54ce16e099c566ead5bcd1932f31d9a208dd8b..11aa997a236c6e0f9b4b80d66a28ce0022780e06 100644 (file)
@@ -408,6 +408,12 @@ $filetypes = array(
  */
 $enableCommonBookmarkDescription = true;
 
+/**
+ * Enable bookmark voting system
+ *
+ * @var boolean
+ */
+$enableVoting = true;
 
 
 /****************************
index a48624bebb124625de561e1b1f7820537144d5fe..34a819c861a7c56a386610bd8d920e90952fa491 100644 (file)
@@ -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)))) {
index 7adf54901d10b974c29a9076f1d33581f977deec..6db940cc9073220e43024665e0c0f163351f5846 100644 (file)
@@ -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;