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

Ticket #5010 - Reputation: Add actions to get points for.

AntonLV 1 год назад
Родитель
Сommit
db0a0f3cd1

+ 24 - 3
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1584,16 +1584,37 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
      */
     public function serviceGetReputationData()
     {
+        $sModule = $this->_aModule['name'];
+
         $aResult = parent::serviceGetReputationData();
 
-    	$sModule = $this->_aModule['name'];
+        $bHandlers = !empty($aResult['handlers']) && is_array($aResult['handlers']);
+        $bAlerts = !empty($aResult['alerts']) && is_array($aResult['alerts']);
 
-        if(!empty($aResult['handlers']) && is_array($aResult['handlers']))
+        /**
+         * Add Connections related handlers/alerts.
+         */
+        if($bHandlers)
+            $aResult['handlers'] = array_merge($aResult['handlers'], [
+                ['group' => $sModule . '_fan', 'type' => 'insert', 'alert_unit' => $sModule . '_fans', 'alert_action' => 'connection_added', 'points_active' => 1, 'points_passive' => 0],
+                ['group' => $sModule . '_fan', 'type' => 'delete', 'alert_unit' => $sModule . '_fans', 'alert_action' => 'connection_removed', 'points_active' => -1, 'points_passive' => 0]
+            ]);
+
+        if($bAlerts)
+            $aResult['alerts'] = array_merge($aResult['alerts'], [
+                ['unit' => $sModule . '_fans', 'action' => 'connection_added'],
+                ['unit' => $sModule . '_fans', 'action' => 'connection_removed']
+            ]);
+
+        /**
+         * Remove Comments and Reactions related handlers/alerts because these actions aren't available in Contexts for now.
+         */
+        if($bHandlers)
             foreach($aResult['handlers'] as $iKey => $aHandler)
                 if(in_array($aHandler['group'], [$sModule . '_comment', $sModule . '_reaction']))
                     unset($aResult['handlers'][$iKey]);
 
-        if(!empty($aResult['alerts']) && is_array($aResult['alerts']))
+        if($bAlerts)
             foreach($aResult['alerts'] as $iKey => $aAlert)
                 if($aAlert['unit'] == $sModule . '_reactions' || in_array($aAlert['action'], ['commentPost', 'commentRemoved']))
                     unset($aResult['alerts'][$iKey]);

+ 11 - 0
modules/boonex/reputation/classes/BxReputationAlertsResponse.php

@@ -45,6 +45,9 @@ class BxReputationAlertsResponse extends BxBaseModNotificationsResponse
             'alert' => &$oAlert,
         ]);
 
+        if(($sMethod = '_checkByAction' . bx_gen_method_name($oAlert->sAction)) && method_exists($this, $sMethod) && !$this->$sMethod($oAlert))
+            return;
+
         $aHandler = $this->_oModule->_oConfig->getHandlers($oAlert->sUnit . '_' . $oAlert->sAction);
         if(empty($aHandler) || !is_array($aHandler))
             return;
@@ -81,6 +84,14 @@ class BxReputationAlertsResponse extends BxBaseModNotificationsResponse
         }
     }
 
+    protected function _checkByActionConnectionAdded($oAlert)
+    {
+        if(($sType = $oAlert->aExtras['object']->getType()) && ($sType == 'one-way' || ($sType == 'mutual' && $oAlert->aExtras['mutual'])))
+            return true;
+
+        return false;
+    }
+
     protected function _processProfileDelete($oAlert)
     {
         $this->_oModule->_oDb->deleteProfile($oAlert->iObject);

+ 17 - 3
modules/boonex/reputation/classes/BxReputationGridHandlers.php

@@ -41,8 +41,8 @@ class BxReputationGridHandlers extends BxTemplGrid
 
         $aUnits = $this->_oModule->_oDb->getHandlers(['type' => 'alert_units_list']);
         if(!empty($aUnits) && is_array($aUnits))
-            foreach($aUnits as $sUnit)
-                $this->_aFilter1Values[$sUnit] = _t('_' . $sUnit);
+            foreach($aUnits as $sUnit) 
+                $this->_aFilter1Values[$sUnit] = $this->_getTitleByUnit($sUnit);
 
     	$sFilter1 = bx_get($this->_sFilter1Name);
         if(!empty($sFilter1)) {
@@ -124,7 +124,7 @@ class BxReputationGridHandlers extends BxTemplGrid
 
     protected function _getCellAlertUnit($mixedValue, $sKey, $aField, $aRow)
     {
-        return self::_getCellDefault(_t('_' . $mixedValue), $sKey, $aField, $aRow);
+        return self::_getCellDefault($this->_getTitleByUnit($mixedValue), $sKey, $aField, $aRow);
     }
     
     protected function _getCellAlertAction($mixedValue, $sKey, $aField, $aRow)
@@ -235,6 +235,20 @@ class BxReputationGridHandlers extends BxTemplGrid
 
         return $aIds;
     }
+    
+    protected function _getTitleByUnit($sUnit)
+    {
+        if(($sKey = '_' . $sUnit) && ($_sKey = _t($sKey)) && strcmp($sKey, $_sKey) != 0)
+            return $_sKey;
+
+        if(($sKey = '_bx_reputation_grid_column_title_hdr_au_' . $sUnit) && ($_sKey = _t($sKey)) && strcmp($sKey, $_sKey) != 0)
+            return $_sKey;
+
+        if(($iPosition = strpos($sUnit, '_fans')) !== false)
+            return _t('_bx_reputation_grid_column_title_hdr_au_module_fans', _t('_' . substr($sUnit, 0, $iPosition)));
+
+        return $sUnit;
+    }
 }
 
 /** @} */

+ 5 - 0
modules/boonex/reputation/install/langs/en.xml

@@ -81,6 +81,11 @@
     <string name="_bx_reputation_grid_column_value_hdr_aa_undoVoteUp"><![CDATA[Undo up vote]]></string>
     <string name="_bx_reputation_grid_column_value_hdr_aa_doVoteDown"><![CDATA[Do down vote]]></string>
     <string name="_bx_reputation_grid_column_value_hdr_aa_undoVoteDown"><![CDATA[Undo down vote]]></string>
+    <string name="_bx_reputation_grid_column_value_hdr_aa_connection_added"><![CDATA[Add connection]]></string>
+    <string name="_bx_reputation_grid_column_value_hdr_aa_connection_removed"><![CDATA[Remove connection]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_sys_profiles_friends"><![CDATA[Friendship]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_sys_profiles_subscriptions"><![CDATA[Following]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_module_fans"><![CDATA[{0}' members]]></string>
     <string name="_bx_reputation_grid_column_title_hdr_points_active"><![CDATA[Points (active)]]></string>
     <string name="_bx_reputation_grid_column_title_hdr_points_passive"><![CDATA[Points (passive)]]></string>
     <string name="_bx_reputation_grid_action_title_hdr_activate"><![CDATA[Activate]]></string>

+ 8 - 1
modules/boonex/reputation/install/sql/enable.sql

@@ -88,4 +88,11 @@ INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALU
 SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
-('profile', 'delete', @iHandler);
+('profile', 'delete', @iHandler),
+
+('sys_profiles_friends', 'connection_added', @iHandler),
+('sys_profiles_friends', 'connection_removed', @iHandler),
+
+('sys_profiles_subscriptions', 'connection_added', @iHandler),
+('sys_profiles_subscriptions', 'connection_removed', @iHandler);
+

+ 10 - 0
modules/boonex/reputation/install/sql/install.sql

@@ -15,6 +15,16 @@ CREATE TABLE IF NOT EXISTS `bx_reputation_handlers` (
   UNIQUE `alert` (`alert_unit`, `alert_action`)
 );
 
+-- Friendship
+INSERT INTO `bx_reputation_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `points_active`, `points_passive`, `active`) VALUES 
+('friendship', 'insert', 'sys_profiles_friends', 'connection_added', '2', '0', '1'),
+('friendship', 'delete', 'sys_profiles_friends', 'connection_removed', '-2', '0', '1');
+
+-- Subscription
+INSERT INTO `bx_reputation_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `points_active`, `points_passive`, `active`) VALUES 
+('subscription', 'insert', 'sys_profiles_subscriptions', 'connection_added', '1', '0', '1'),
+('subscription', 'delete', 'sys_profiles_subscriptions', 'connection_removed', '-1', '0', '1');
+
 -- TABLES: events
 CREATE TABLE IF NOT EXISTS `bx_reputation_events` (
   `id` int(11) NOT NULL auto_increment,

+ 5 - 0
modules/boonex/russian/data/langs/bx_reputation/ru.xml

@@ -78,6 +78,11 @@
     <string name="_bx_reputation_grid_column_value_hdr_aa_undoVoteUp"><![CDATA[Отменить голосование 'за']]></string>
     <string name="_bx_reputation_grid_column_value_hdr_aa_doVoteDown"><![CDATA[Проголосовать 'против']]></string>
     <string name="_bx_reputation_grid_column_value_hdr_aa_undoVoteDown"><![CDATA[Отменить голосование 'против']]></string>
+    <string name="_bx_reputation_grid_column_value_hdr_aa_connection_added"><![CDATA[Добавить соединение]]></string>
+    <string name="_bx_reputation_grid_column_value_hdr_aa_connection_removed"><![CDATA[Удалить соединение]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_sys_profiles_friends"><![CDATA[Дружба]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_sys_profiles_subscriptions"><![CDATA[Подписка]]></string>
+    <string name="_bx_reputation_grid_column_title_hdr_au_module_fans"><![CDATA[{0}' пользователи]]></string>
     <string name="_bx_reputation_grid_column_title_hdr_points_active"><![CDATA[Баллы (активные)]]></string>
     <string name="_bx_reputation_grid_column_title_hdr_points_passive"><![CDATA[Баллы (пассивные)]]></string>
     <string name="_bx_reputation_grid_action_title_hdr_activate"><![CDATA[Активировать]]></string>