Quellcode durchsuchen

Ticket #2377 - for Polls module.

AntonLV vor 7 Jahren
Ursprung
Commit
79afe152e6

+ 12 - 4
modules/boonex/polls/classes/BxPollsDb.php

@@ -28,14 +28,22 @@ class BxPollsDb extends BxBaseModTextDb
         return $aContentInfo;
     }
 
-    public function isPerformed($iEntryId, $iAuthorId)
+    public function isPerformed($iEntryId, $iAuthorId, $iAuthorIp)
     {
         $CNF = &$this->_oConfig->CNF;
 
+        $iAuthorId = (int)$iAuthorId;
+
+        $aBindings = array('author_id' => $iAuthorId);
+        $sWhereClause = "AND `author_id`=:author_id";
+
+        if(empty($iAuthorId)) {
+            $aBindings['author_nip'] = $iAuthorIp;
+            $sWhereClause .= " AND `author_nip`=:author_nip";
+        }
+
         $aSubentries = $this->getSubentries(array('type' => 'entry_id_pairs', 'entry_id' => $iEntryId));
-        return (int)$this->getOne("SELECT `object_id` FROM `" . $CNF['TABLE_VOTES_SUBENTRIES_TRACK'] . "` WHERE `object_id` IN (" . $this->implode_escape(array_keys($aSubentries)) . ") AND `author_id`=:author_id LIMIT 1", array(
-            'author_id' => $iAuthorId
-        )) != 0;
+        return (int)$this->getOne("SELECT `object_id` FROM `" . $CNF['TABLE_VOTES_SUBENTRIES_TRACK'] . "` WHERE `object_id` IN (" . $this->implode_escape(array_keys($aSubentries)) . ") " . $sWhereClause . " LIMIT 1", $aBindings) != 0;
     }
 
     public function getContentInfoBySubentryId ($iSubentryId)

+ 1 - 1
modules/boonex/polls/classes/BxPollsMenuSnippetMeta.php

@@ -36,7 +36,7 @@ class BxPollsMenuSnippetMeta extends BxBaseModTextMenuSnippetMeta
         $CNF = &$this->_oModule->_oConfig->CNF;
 
         $iContentId = (int)$this->_aContentInfo[$CNF['FIELD_ID']];
-        $bPerformed = $this->_oModule->_oDb->isPerformed($iContentId, bx_get_logged_profile_id());
+        $bPerformed = $this->_oModule->isPerformed($iContentId);
         if((int)$this->_aContentInfo[$CNF['FIELD_HIDDEN_RESULTS']] != 0 && !$bPerformed)
             return false;
 

+ 12 - 2
modules/boonex/polls/classes/BxPollsModule.php

@@ -116,7 +116,7 @@ class BxPollsModule extends BxBaseModTextModule
         if (!$iContentId)
             return false;
 
-        if(!$bForceDisplay && $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id()))
+        if(!$bForceDisplay && $this->isPerformed($iContentId))
             return $this->serviceGetBlockResults($iContentId);
 
         return $this->_serviceTemplateFunc('entrySubentries', $iContentId);
@@ -192,6 +192,16 @@ class BxPollsModule extends BxBaseModTextModule
         return CHECK_ACTION_RESULT_ALLOWED;
     }
 
+    public function isPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
+    {
+        if(empty($iAuthorId)) {
+            $iAuthorId = bx_get_logged_profile_id();
+            $iAuthorIp = ip2long(getVisitorIP());
+        }
+
+        return $this->_oDb->isPerformed($iObjectId, $iAuthorId, $iAuthorIp);
+    }
+
 
     /**
      * INTERNAL METHODS
@@ -223,7 +233,7 @@ class BxPollsModule extends BxBaseModTextModule
         $sInclude = '';
         $sInclude .= $this->_oTemplate->addCss(array('main.css'), $bDynamic);
 
-        $aBlock = $this->_oTemplate->{$this->_oDb->isPerformed($aContentInfo[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'entryResults' : 'entrySubentries'}($aContentInfo, $bDynamic);
+        $aBlock = $this->_oTemplate->{$this->isPerformed($aContentInfo[$CNF['FIELD_ID']]) ? 'entryResults' : 'entrySubentries'}($aContentInfo, $bDynamic);
 
         $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
         $aResult['title'] = $this->_oConfig->getTitle($aContentInfo);

+ 12 - 8
modules/boonex/polls/classes/BxPollsTemplate.php

@@ -25,13 +25,14 @@ class BxPollsTemplate extends BxBaseModTextTemplate
 
     public function embedEntry($mixedContentInfo, $aParams = array())
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
         $aContentInfo = is_array($mixedContentInfo) ? $mixedContentInfo : $this->_oDb->getContentInfoById((int)$mixedContentInfo);
         if(empty($aContentInfo) || !is_array($aContentInfo))
             return;
 
-        $aBlock = $this->{$this->_oDb->isPerformed((int)$aContentInfo[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'entryResults' : 'entrySubentries'}($aContentInfo);
+        $aBlock = $this->{$oModule->isPerformed((int)$aContentInfo[$CNF['FIELD_ID']]) ? 'entryResults' : 'entrySubentries'}($aContentInfo);
 
         $this->addJs(array('entry.js'));
         $this->addCss(array('entry.css'));
@@ -80,11 +81,12 @@ class BxPollsTemplate extends BxBaseModTextTemplate
 
     public function entryTextAndSubentries($aData, $bForceDisplaySubentries = false)
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
         $sMethod = '_getGetBlockContent';
         $sMenuItem = '';
-        if(!$bForceDisplaySubentries && $this->_oDb->isPerformed($aData[$CNF['FIELD_ID']], bx_get_logged_profile_id())) {
+        if(!$bForceDisplaySubentries && $oModule->isPerformed($aData[$CNF['FIELD_ID']])) {
             $sMethod .= 'Results';
             $sMenuItem = 'results';
         }
@@ -129,9 +131,10 @@ class BxPollsTemplate extends BxBaseModTextTemplate
 
     protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
-        $aBlock = $this->{$this->_oDb->isPerformed($aData[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'entryResults' : 'entrySubentries'}($aData);
+        $aBlock = $this->{$oModule->isPerformed($aData[$CNF['FIELD_ID']]) ? 'entryResults' : 'entrySubentries'}($aData);
 
         return $aBlock['content'];
     }
@@ -166,14 +169,15 @@ class BxPollsTemplate extends BxBaseModTextTemplate
 
     protected function _getGetBlockMenu($aData, $sSelected = '')
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
         $sJsObject = $this->_oConfig->getJsObject('entry');
         $iContentId = $aData[$CNF['FIELD_ID']];
 
         $aBlocks = array(
             'subentries' => true, 
-            'results' => (int)$aData[$CNF['FIELD_HIDDEN_RESULTS']] == 0 || $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id())
+            'results' => (int)$aData[$CNF['FIELD_HIDDEN_RESULTS']] == 0 || $oModule->isPerformed($iContentId)
         );
 
         $aMenu = array();

+ 2 - 2
modules/boonex/polls/classes/BxPollsVoteSubentries.php

@@ -94,10 +94,10 @@ class BxPollsVoteSubentries extends BxTemplVoteLikes
     {
         $CNF = $this->_oModule->_oConfig->CNF;
 
-        return $this->_oModule->_oDb->isPerformed($this->getEntryField($CNF['FIELD_ID']), $iAuthorId);
+        return $this->_oModule->isPerformed((int)$this->getEntryField($CNF['FIELD_ID']), $iAuthorId, $iAuthorIp);
     }
 
-	/**
+    /**
      * Permissions functions
      */
     public function isAllowedVote($isPerformAction = false)