Просмотр исходного кода

Ticket #2377 - for attached Polls in Text based modules.

AntonLV 7 лет назад
Родитель
Сommit
7ba545d9dd

+ 11 - 7
modules/base/text/classes/BxBaseModTextDb.php

@@ -55,21 +55,25 @@ class BxBaseModTextDb extends BxBaseModGeneralDb
      * Internal Polls related methods. 
      * 
      */
-    public function isPollPerformed($iPollId, $iAuthorId)
+    public function isPollPerformed($iPollId, $iAuthorId, $iAuthorIp = 0)
     {
         $CNF = &$this->_oConfig->CNF;
 
         if(empty($CNF['TABLE_POLLS_ANSWERS_VOTES_TRACK']))
             return false;
 
-        if(empty($iAuthorId))
-            $iAuthorId = bx_get_logged_profile_id();
+        $iAuthorId = (int)$iAuthorId;
 
-        $aAnswers = $this->getPollAnswers(array('type' => 'poll_id_pairs', 'poll_id' => $iPollId));
+        $aBindings = array('author_id' => $iAuthorId);
+        $sWhereClause = "AND `author_id`=:author_id";
+
+        if(empty($iAuthorId)) {
+            $aBindings['author_nip'] = $iAuthorIp;
+            $sWhereClause .= " AND `author_nip`=:author_nip";
+        }
 
-        return (int)$this->getOne("SELECT `object_id` FROM `" . $CNF['TABLE_POLLS_ANSWERS_VOTES_TRACK'] . "` WHERE `object_id` IN (" . $this->implode_escape(array_keys($aAnswers)) . ") AND `author_id`=:author_id LIMIT 1", array(
-            'author_id' => $iAuthorId
-        )) != 0;
+        $aAnswers = $this->getPollAnswers(array('type' => 'poll_id_pairs', 'poll_id' => $iPollId));
+        return (int)$this->getOne("SELECT `object_id` FROM `" . $CNF['TABLE_POLLS_ANSWERS_VOTES_TRACK'] . "` WHERE `object_id` IN (" . $this->implode_escape(array_keys($aAnswers)) . ") " . $sWhereClause . " LIMIT 1", $aBindings) != 0;
     }
 
     public function getPolls($aParams)

+ 14 - 4
modules/base/text/classes/BxBaseModTextModule.php

@@ -102,7 +102,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         if(!$iPollId)
             return false;
 
-        if(!$bForceDisplay && $this->_oDb->isPollPerformed($iPollId, bx_get_logged_profile_id()))
+        if(!$bForceDisplay && $this->isPollPerformed($iPollId))
             return $this->serviceGetBlockPollResults($iPollId);
 
         return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
@@ -124,9 +124,9 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         return $mixedResult !== false ? $mixedResult : '';
     }
 
-	public function serviceGetMenuAddonManageTools()
-	{
-		bx_import('SearchResult', $this->_aModule);
+    public function serviceGetMenuAddonManageTools()
+    {
+        bx_import('SearchResult', $this->_aModule);
         $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
         $o = new $sClass();
         $o->unsetPaginate();
@@ -288,6 +288,16 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         return CHECK_ACTION_RESULT_ALLOWED;
     }
 
+    public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
+    {
+        if(empty($iAuthorId)) {
+            $iAuthorId = bx_get_logged_profile_id();
+            $iAuthorIp = ip2long(getVisitorIP());
+        }
+
+        return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
+    }
+
     // ====== COMMON METHODS
     public function onPublished($iContentId)
     {

+ 6 - 4
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -246,7 +246,8 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
     public function getPollItem($mixedPoll, $iProfileId = 0, $aParams = array())
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
         $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
         if(empty($aPoll) || !is_array($aPoll))
@@ -260,7 +261,7 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
         $bForceDisplayAnswers = isset($aParams['force_display_answers']) && (bool)$aParams['force_display_answers'] === true;
 
         $iPollId = (int)$aPoll[$CNF['FIELD_POLL_ID']];
-        $sPollView = !$bForceDisplayAnswers && $this->_oDb->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
+        $sPollView = !$bForceDisplayAnswers && $oModule->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
         
         $sMethod = '_getPoll' . ucfirst($sPollView);
         if(!method_exists($this, $sMethod))
@@ -438,7 +439,8 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
     protected function _getPollBlockMenu($aPoll, $sSelected = '', $aParams = array())
     {
-        $CNF = &$this->getModule()->_oConfig->CNF;
+        $oModule = $this->getModule();
+        $CNF = &$oModule->_oConfig->CNF;
 
         $sPostfix = '-' . time() . rand(0, PHP_INT_MAX);
         $sJsObject = $this->_oConfig->getJsObject('poll');
@@ -446,7 +448,7 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
         $aViews = array(
             'answers' => true, 
-            'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $this->_oDb->isPollPerformed($iPollId, bx_get_logged_profile_id())
+            'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $oModule->isPollPerformed($iPollId)
         );
 
         $aMenu = array();

+ 1 - 1
modules/base/text/classes/BxBaseModTextVotePollAnswers.php

@@ -89,7 +89,7 @@ class BxBaseModTextVotePollAnswers extends BxTemplVoteLikes
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        return $this->_oModule->_oDb->isPollPerformed($this->_aPollInfo[$CNF['FIELD_POLL_ID']], $iAuthorId);
+        return $this->_oModule->isPollPerformed((int)$this->_aPollInfo[$CNF['FIELD_POLL_ID']], $iAuthorId, $iAuthorIp);
     }
 
     /**