AntonLV 5 лет назад
Родитель
Сommit
e12954dbd5

+ 5 - 3
inc/classes/BxDolFavoriteQuery.php

@@ -36,13 +36,15 @@ class BxDolFavoriteQuery extends BxDolObjectQuery
         if(!empty($iPerPage))
             $sLimitClause = $this->prepareAsString(" LIMIT ?, ?", $iStart, $iPerPage);
 
-        $sQuery = $this->prepare("SELECT `author_id` FROM `{$this->_sTableTrack}` WHERE `object_id`=? ORDER BY `date` DESC" . $sLimitClause, $iObjectId);
+        $sQuery = $this->prepare("SELECT DISTINCT `author_id` FROM `{$this->_sTableTrack}` WHERE `object_id`=? ORDER BY `date` DESC" . $sLimitClause, $iObjectId);
         return $this->getAll($sQuery);
     }
 
-	public function getFavorite($iObjectId)
+    public function getFavorite($iObjectId)
     {
-        return array('count' => $this->getObjectCount($iObjectId));
+        return $this->getRow("SELECT COUNT(DISTINCT `author_id`) AS `count` FROM `{$this->_sTableTrack}` WHERE `object_id`=:object_id LIMIT 1", array(
+            'object_id' => $iObjectId
+        ));
     }
 
     public function clearFavorite($iObjectId, $iAuthorId)

+ 1 - 1
inc/classes/BxDolObjectQuery.php

@@ -223,7 +223,7 @@ class BxDolObjectQuery extends BxDolDb
     /**
      * Is used instead of 'updateTriggerTable' when trigger table contains 
      * only one field related to this object (View, Vote, Comment, etc).
-     * For example, it's used in Favourite and Feature objects.
+     * For example, it's used in Favourite (simple mode w\o lists) and Feature objects.
      */
     public function updateTriggerTableValue($iObjectId, $iValue)
     {

+ 20 - 20
template/scripts/BxBaseFavorite.php

@@ -227,7 +227,7 @@ class BxBaseFavorite extends BxDolFavorite
                 return array('code' => 2, 'message' => $this->msgErrAllowedFavorite());
 
             if($bPerformed && !$bUndo)
-        	    return array('code' => 3, 'message' => _t('_favorite_err_duplicate_favorite'));
+                return array('code' => 3, 'message' => _t('_favorite_err_duplicate_favorite'));
 
             if(!$this->_oQuery->{($bPerformUndo ? 'un' : '') . 'doFavorite'}($iObjectId, $iAuthorId))
                 return array('code' => 4, 'message' => _t('_favorite_err_cannot_perform_action'));
@@ -242,10 +242,10 @@ class BxBaseFavorite extends BxDolFavorite
 
             $aFavorite = $this->_oQuery->getFavorite($iObjectId);
             return array(
-        	    'eval' => $this->getJsObjectName() . '.onFavorite(oData, oElement)',
-        	    'code' => 0, 
-        	    'count' => $aFavorite['count'],
-        	    'countf' => (int)$aFavorite['count'] > 0 ? $this->_getCounterLabel($aFavorite['count']) : '',
+                'eval' => $this->getJsObjectName() . '.onFavorite(oData, oElement)',
+                'code' => 0, 
+                'count' => $aFavorite['count'],
+                'countf' => (int)$aFavorite['count'] > 0 ? $this->_getCounterLabel($aFavorite['count']) : '',
                 'label_icon' => $this->_getIconDoFavorite(!$bPerformed),
                 'label_title' => _t($this->_getTitleDoFavorite(!$bPerformed)),
                 'disabled' => !$bPerformed && !$bUndo
@@ -274,36 +274,36 @@ class BxBaseFavorite extends BxDolFavorite
         $CNF = $oModule->_oConfig->CNF;    
 
         $oPrivacy = BxDolPrivacy::getObjectInstance($CNF["OBJECT_PRIVACY_LIST_VIEW"]);
-        if(!$oPrivacy) 
+        if (!$oPrivacy) 
             return array('code' => 5, 'message' => _t('_favorite_err_cannot_perform_action'));
 
         $aSave = array('db' => array('pass' => 'Xss'));
         $aGroupChooser = $oPrivacy->getGroupChooser($CNF["OBJECT_PRIVACY_LIST_VIEW"]);
         $oForm->aInputs["allow_view_favorite_list_to"] = array_merge($oForm->aInputs["allow_view_favorite_list_to"], $aGroupChooser, $aSave);
         
-        if($oForm->isSubmittedAndValid()) {
-           
+        if ($oForm->isSubmittedAndValid()) {
             $mList = $oForm->getCleanValue('list');
             $aList = is_array($mList) ? $mList : array();
-            
+
             $sTitle = $oForm->getCleanValue('title');
-            if ($sTitle){
+            if ($sTitle) {
                  $sAllowViewTo = $oForm->getCleanValue('allow_view_favorite_list_to');
                  $iAddList = $this->_oQuery->addList($iAuthorId, $sTitle, $sAllowViewTo);
                  array_push($aList, $iAddList);
             }
+
             $this->_oQuery->clearFavorite($iObjectId, $iAuthorId);
-           
-            $bPerformed = count($aList) > 0 ? true: false;
-            
-            foreach($aList as $iList) {
+            foreach ($aList as $iList) {
                 $this->_oQuery->doFavorite($iObjectId, $iAuthorId, $iList);
             }
+
+            $this->_trigger();
+
             bx_alert($this->_sSystem, 'favorite', $iObjectId, $iAuthorId, array('favorite_author_id' => $iAuthorId, 'object_author_id' => $iObjectAuthorId, 'list_ids' => $aList));
             bx_alert('favorite', 'do', 0, $iAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iObjectId, 'object_author_id' => $iObjectAuthorId, 'list_ids' => $aList));
-            
+
+            $bPerformed = count($aList) > 0;
             $aFavorite = $this->_oQuery->getFavorite($iObjectId);
-            
             return array(
         	    'eval' => $this->getJsObjectName() . '.onFavorite(oData, oElement)',
         	    'code' => 0, 
@@ -314,13 +314,13 @@ class BxBaseFavorite extends BxDolFavorite
                 'disabled' => false
             );
         }
-        
+
         $sPopupId = $this->_aHtmlIds['do_popup'];
         $sPopupContent = BxTemplFunctions::getInstance()->transBox($sPopupId, $this->_oTemplate->parseHtmlByName('favorite_do_favorite_popup.html', array(
             'style_prefix' => $this->_sStylePrefix,
-                'js_object' => $this->getJsObjectName(),
-                'form' => str_replace('{js_object}', $this->getJsObjectName(), $oForm->getCode()),
-                'form_id' => $oForm->id,
+            'js_object' => $this->getJsObjectName(),
+            'form' => str_replace('{js_object}', $this->getJsObjectName(), $oForm->getCode()),
+            'form_id' => $oForm->id,
         )));
 
         return array('popup' => $sPopupContent, 'popup_id' => $sPopupId);