AntonLV 6 年之前
父節點
當前提交
ccaa543649

+ 24 - 2
modules/base/notifications/classes/BxBaseModNotificationsDb.php

@@ -241,7 +241,7 @@ class BxBaseModNotificationsDb extends BxBaseModGeneralDb
                     'user_id' => $aParams['user_id']
                     'user_id' => $aParams['user_id']
                 );
                 );
 
 
-                $sSelectClause = "`ts`.`active` AS `active_adm`, IF(NOT ISNULL(`tsu`.`active`), `tsu`.`active`, 1) AS `active_pnl`";
+                $sSelectClause = "`ts`.`active` AS `active_adm`, IF(NOT ISNULL(`tsu`.`active`), `tsu`.`active`, `ts`.`value`) AS `active_pnl`";
                 $sJoinClause = "LEFT JOIN `" . $this->_sTableSettings2Users . "` AS `tsu` ON `ts`.`id`=`tsu`.`setting_id` AND `tsu`.`user_id`=:user_id";
                 $sJoinClause = "LEFT JOIN `" . $this->_sTableSettings2Users . "` AS `tsu` ON `ts`.`id`=`tsu`.`setting_id` AND `tsu`.`user_id`=:user_id";
                 $sWhereClause = " AND `ts`.`handler_id`=:handler_id AND `ts`.`delivery`=:delivery AND `ts`.`type`=:type";
                 $sWhereClause = " AND `ts`.`handler_id`=:handler_id AND `ts`.`delivery`=:delivery AND `ts`.`type`=:type";
                 break;
                 break;
@@ -335,6 +335,27 @@ class BxBaseModNotificationsDb extends BxBaseModGeneralDb
             'active' => (int)$bActive
             'active' => (int)$bActive
         ));
         ));
     }
     }
+    
+    public function changeSettingById($sField, $mixedValue, $mixedId)
+    {
+        if(!is_array($mixedId))
+            $mixedId = array($mixedId);
+
+        return $this->query("UPDATE `{$this->_sTableSettings}` SET `" . $sField . "`=:value WHERE `id` IN (" . $this->implode_escape($mixedId) . ")", array(
+            'value' => $mixedValue
+        ));
+    }
+
+    public function changeSettingByIdUser($sField, $mixedValue, $iUserId, $mixedSettingId)
+    {
+        if(!is_array($mixedSettingId))
+            $mixedSettingId = array($mixedSettingId);
+
+        return $this->query("UPDATE `{$this->_sTableSettings2Users}` SET `" . $sField . "`=:value WHERE `user_id`=:user_id AND `setting_id` IN (" . $this->implode_escape($mixedSettingId) . ")", array(
+            'user_id' => $iUserId, 
+            'value' => $mixedValue
+        ));
+    }
 
 
     public function initSettingUser($iUserId)
     public function initSettingUser($iUserId)
     {
     {
@@ -347,7 +368,8 @@ class BxBaseModNotificationsDb extends BxBaseModGeneralDb
 
 
             $this->insertSettingUser(array(
             $this->insertSettingUser(array(
                 'user_id' => $iUserId,
                 'user_id' => $iUserId,
-                'setting_id' => $aSetting['id']
+                'setting_id' => $aSetting['id'],
+                'active' => $aSetting['value']
             ));
             ));
         }
         }
 
 

+ 3 - 3
modules/boonex/notifications/classes/BxNtfsDb.php

@@ -168,7 +168,7 @@ class BxNtfsDb extends BxBaseModNotificationsDb
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
 
 
                     $sJoinClause .= $sJoinClauseS2U;
                     $sJoinClause .= $sJoinClauseS2U;
-                    $sWhereClause .= "AND (ISNULL(`{$this->_sTableSettings2Users}`.`active`) OR `{$this->_sTableSettings2Users}`.`active`='1') ";
+                    $sWhereClause .= "AND ((ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings}`.`value`='1') OR (NOT ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings2Users}`.`active`='1')) ";
 
 
                     $sWhereClause .= $this->prepareAsString("AND `{$this->_sTable}`.`owner_id`<>`{$this->_sTable}`.`object_owner_id` AND ((`{$this->_sTable}`.`owner_id`=? AND `{$this->_sTable}`.`object_privacy_view`<0 AND `{$this->_sTable}`.`owner_id`=ABS(`{$this->_sTable}`.`object_privacy_view`)) OR `{$this->_sTable}`.`object_owner_id`=?) ", $aParams['owner_id'], $aParams['owner_id']);
                     $sWhereClause .= $this->prepareAsString("AND `{$this->_sTable}`.`owner_id`<>`{$this->_sTable}`.`object_owner_id` AND ((`{$this->_sTable}`.`owner_id`=? AND `{$this->_sTable}`.`object_privacy_view`<0 AND `{$this->_sTable}`.`owner_id`=ABS(`{$this->_sTable}`.`object_privacy_view`)) OR `{$this->_sTable}`.`object_owner_id`=?) ", $aParams['owner_id'], $aParams['owner_id']);
                     break;
                     break;
@@ -192,7 +192,7 @@ class BxNtfsDb extends BxBaseModNotificationsDb
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
 
 
                     $sJoinClause .= $sJoinClauseS2U;
                     $sJoinClause .= $sJoinClauseS2U;
-                    $sWhereClause .= "AND (ISNULL(`{$this->_sTableSettings2Users}`.`active`) OR `{$this->_sTableSettings2Users}`.`active`='1') ";
+                    $sWhereClause .= "AND ((ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings}`.`value`='1') OR (NOT ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings2Users}`.`active`='1')) ";
                     break;
                     break;
 
 
                 case BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS:
                 case BX_NTFS_TYPE_OBJECT_OWNER_AND_CONNECTIONS:
@@ -229,7 +229,7 @@ class BxNtfsDb extends BxBaseModNotificationsDb
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
                         $sJoinClauseS2U .= $this->prepareAsString("AND `{$this->_sTableSettings2Users}`.`user_id`=? ", $aParams['owner_id']);
 
 
                     $sJoinClause .= $sJoinClauseS2U;
                     $sJoinClause .= $sJoinClauseS2U;
-                    $sWhereClause .= "AND (ISNULL(`{$this->_sTableSettings2Users}`.`active`) OR `{$this->_sTableSettings2Users}`.`active`='1') ";
+                    $sWhereClause .= "AND ((ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings}`.`value`='1') OR (NOT ISNULL(`{$this->_sTableSettings2Users}`.`active`) AND `{$this->_sTableSettings2Users}`.`active`='1')) ";
 
 
                     $sWhereClause .= "AND ((" . $sWhereClauseObjectOwner . ") || (" . $sWhereClauseConnections . ")) ";
                     $sWhereClause .= "AND ((" . $sWhereClauseObjectOwner . ") || (" . $sWhereClauseConnections . ")) ";
                     break;
                     break;

+ 47 - 6
modules/boonex/notifications/classes/BxNtfsGridSettingsAdministration.php

@@ -80,6 +80,29 @@ class BxNtfsGridSettingsAdministration extends BxTemplGrid
     {
     {
         parent::performActionEnable();
         parent::performActionEnable();
     }
     }
+    
+    public function performActionChangeValue()
+    {
+        $aIds = bx_get('ids');
+        if(empty($aIds) || !is_array($aIds))
+            return echoJson(array());
+
+        $iId = array_shift($aIds);
+        $iValue = $this->_switcherChecked2State((int)bx_get('checked'));
+
+        if(!$this->_bGrouped)
+            $mixedResult = $this->_oModule->_oDb->updateSetting(array('value' => $iValue), array('id' => $iId));
+        else 
+            $mixedResult = $this->_oModule->_changeSettingsValueLike($iId, 'value', $iValue, $this->_bAdministration);
+
+        $aResult = array();
+        if($mixedResult === false)
+            $aResult = array('msg' => _t('_bx_ntfs_txt_err_cannot_perform'));
+        else if((int)$mixedResult == 0)
+            $aResult = array('msg' => _t('_bx_ntfs_txt_err_nothing_changed'));
+
+        return echoJson($aResult);
+    }
 
 
     protected function _enable ($mixedId, $isChecked)
     protected function _enable ($mixedId, $isChecked)
     {
     {
@@ -97,12 +120,30 @@ class BxNtfsGridSettingsAdministration extends BxTemplGrid
         return parent::_getFilterControls();
         return parent::_getFilterControls();
     }
     }
 
 
-    protected function _getRowHead()
-    {
-        if($this->_bGrouped)
-            return '';
-
-        return parent::_getRowHead();
+    protected function _getCellValue($mixedValue, $sKey, $aField, $aRow)
+    {
+        $sAttr = $this->_convertAttrs(
+            $aField, 'attr_cell',
+            'bx-def-padding-sec-bottom bx-def-padding-sec-top',
+            isset($aField['width']) ? 'width:' . $aField['width'] : false
+        );
+
+        $oForm = new BxTemplFormView(array(), $this->_oTemplate);
+        $oForm->addCssJs();
+        $aInput = array(
+            'type' => 'switcher',
+            'name' => $this->_sObject . '_change_value_' . $aRow[$this->_aOptions['field_id']],
+            'caption' => '',
+            'attrs' => array (
+                'bx_grid_action_single' => 'change_value',
+                'bx_grid_action_confirm' => '',
+                'bx_grid_action_data' => $aRow[$this->_aOptions['field_id']],
+            ),
+            'value' => $aRow[$this->_aOptions['field_id']],
+            'checked' => $this->_isSwitcherOn($mixedValue, $sKey, $aField, $aRow),
+        );
+        $sSwitcher = $oForm->genInput($aInput);
+        return '<td ' . $sAttr . '>' . $sSwitcher . '</td>';
     }
     }
 
 
     protected function _getCellUnit($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellUnit($mixedValue, $sKey, $aField, $aRow)

+ 30 - 0
modules/boonex/notifications/classes/BxNtfsModule.php

@@ -412,6 +412,36 @@ class BxNtfsModule extends BxBaseModNotificationsModule
         return $mixedResult;
         return $mixedResult;
     }
     }
 
 
+    public function _changeSettingsValueLike($iId, $sField, $mixedValue, $bAdministration = false)
+    {
+        $aSetting = $this->_oDb->getSetting(array(
+            'by' => $bAdministration ? 'id' : 'tsu_id', 
+            'id' => (int)$iId
+        ));
+        if(empty($aSetting) || !is_array($aSetting))
+            return false;
+
+        $aSettingsIds = $this->_oDb->getSetting(array(
+            'by' => 'group_type_delivery', 
+            'group' => $aSetting['group'], 
+            'delivery' => $aSetting['delivery'], 
+            'type' => $aSetting['type'], 
+            'active' => !$bAdministration
+        ));
+        if(empty($aSettingsIds) || !is_array($aSettingsIds))
+            return false;
+
+        $iUserId = bx_get_logged_profile_id();
+
+        $mixedResult = false;
+        if($bAdministration)
+            $mixedResult =  $this->_oDb->changeSettingById($sField, $mixedValue, $aSettingsIds);
+        else
+            $mixedResult = $this->_oDb->changeSettingByIdUser($sField, $mixedValue, $iUserId, $aSettingsIds);
+
+        return $mixedResult;
+    }
+
     public function sendNotificationEmail($oProfile, $aNotification)
     public function sendNotificationEmail($oProfile, $aNotification)
     {
     {
         if(!$oProfile)
         if(!$oProfile)

+ 4 - 0
modules/boonex/notifications/install/langs/en.xml

@@ -99,6 +99,8 @@
     <string name="_bx_ntfs_alert_action_connection_added"><![CDATA[add connection]]></string>
     <string name="_bx_ntfs_alert_action_connection_added"><![CDATA[add connection]]></string>
 
 
     <string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Empty]]></string>
     <string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Empty]]></string>
+    <string name="_bx_ntfs_txt_err_nothing_changed"><![CDATA[Nothing was changed.]]></string>
+    <string name="_bx_ntfs_txt_err_cannot_perform"><![CDATA[Cannot perform the action.]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> in <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> in <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Failed to publish your {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Failed to publish your {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
@@ -115,9 +117,11 @@
 <p> </p>
 <p> </p>
 {email_footer}]]></string>
 {email_footer}]]></string>
 
 
+    <string name="_bx_ntfs_grid_column_title_active"><![CDATA[Active]]></string>
     <string name="_bx_ntfs_grid_column_title_unit"><![CDATA[Module]]></string>
     <string name="_bx_ntfs_grid_column_title_unit"><![CDATA[Module]]></string>
     <string name="_bx_ntfs_grid_column_title_type"><![CDATA[Type]]></string>
     <string name="_bx_ntfs_grid_column_title_type"><![CDATA[Type]]></string>
     <string name="_bx_ntfs_grid_column_title_title"><![CDATA[Notification]]></string>
     <string name="_bx_ntfs_grid_column_title_title"><![CDATA[Notification]]></string>
     <string name="_bx_ntfs_grid_column_title_title_warning"><![CDATA[The setting's value is corrupted. It is recommended to enable/disable it and reload the page.]]></string>
     <string name="_bx_ntfs_grid_column_title_title_warning"><![CDATA[The setting's value is corrupted. It is recommended to enable/disable it and reload the page.]]></string>
+    <string name="_bx_ntfs_grid_column_title_value"><![CDATA[Default value]]></string>
     <string name="_bx_ntfs_grid_action_title_deactivate"><![CDATA[Deactivate]]></string>
     <string name="_bx_ntfs_grid_action_title_deactivate"><![CDATA[Deactivate]]></string>
 </resources>
 </resources>

+ 3 - 2
modules/boonex/notifications/install/sql/enable.sql

@@ -145,8 +145,9 @@ INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `fie
 
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable`, `chars_limit`, `params`, `order`) VALUES
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable`, `chars_limit`, `params`, `order`) VALUES
 ('bx_notifications_settings_administration', 'checkbox', '', '1%', 0, '', '', 1),
 ('bx_notifications_settings_administration', 'checkbox', '', '1%', 0, '', '', 1),
-('bx_notifications_settings_administration', 'switcher', '', '10%', 0, '', '', 2),
-('bx_notifications_settings_administration', 'title', '_bx_ntfs_grid_column_title_title', '89%', 1, '', '', 10),
+('bx_notifications_settings_administration', 'switcher', '_bx_ntfs_grid_column_title_active', '10%', 0, '', '', 2),
+('bx_notifications_settings_administration', 'title', '_bx_ntfs_grid_column_title_title', '79%', 1, '', '', 10),
+('bx_notifications_settings_administration', 'value', '_bx_ntfs_grid_column_title_value', '10%', 0, '', '', 20),
 
 
 ('bx_notifications_settings_common', 'checkbox', '', '1%', 0, '', '', 1),
 ('bx_notifications_settings_common', 'checkbox', '', '1%', 0, '', '', 1),
 ('bx_notifications_settings_common', 'switcher', '', '10%', 0, '', '', 2),
 ('bx_notifications_settings_common', 'switcher', '', '10%', 0, '', '', 2),

+ 1 - 0
modules/boonex/notifications/install/sql/install.sql

@@ -47,6 +47,7 @@ CREATE TABLE IF NOT EXISTS `bx_notifications_settings` (
   `delivery` enum('site','email','push') NOT NULL DEFAULT 'site',
   `delivery` enum('site','email','push') NOT NULL DEFAULT 'site',
   `type` enum('personal','follow_member','follow_context','other') NOT NULL DEFAULT 'personal',
   `type` enum('personal','follow_member','follow_context','other') NOT NULL DEFAULT 'personal',
   `title` varchar(64) NOT NULL default '',
   `title` varchar(64) NOT NULL default '',
+  `value` tinyint(4) NOT NULL default '1',
   `active` tinyint(4) NOT NULL default '1',
   `active` tinyint(4) NOT NULL default '1',
   `order` int(11) NOT NULL default '0',
   `order` int(11) NOT NULL default '0',
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),

+ 4 - 0
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -99,6 +99,8 @@
     <string name="_bx_ntfs_alert_action_connection_added"><![CDATA[добавить связь]]></string>	
     <string name="_bx_ntfs_alert_action_connection_added"><![CDATA[добавить связь]]></string>	
 
 
     <string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Пусто]]></string>
     <string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Пусто]]></string>
+    <string name="_bx_ntfs_txt_err_nothing_changed"><![CDATA[Ничего не изменилось.]]></string>
+    <string name="_bx_ntfs_txt_err_cannot_perform"><![CDATA[Невозможно выполнить действие.]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> в <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> в <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Ошибка при публикации: {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Ошибка при публикации: {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
@@ -115,9 +117,11 @@
 <p> </p>
 <p> </p>
 {email_footer}]]></string>
 {email_footer}]]></string>
 
 
+    <string name="_bx_ntfs_grid_column_title_active"><![CDATA[Включено]]></string>
     <string name="_bx_ntfs_grid_column_title_unit"><![CDATA[Модуль]]></string>
     <string name="_bx_ntfs_grid_column_title_unit"><![CDATA[Модуль]]></string>
     <string name="_bx_ntfs_grid_column_title_type"><![CDATA[Тип]]></string>
     <string name="_bx_ntfs_grid_column_title_type"><![CDATA[Тип]]></string>
     <string name="_bx_ntfs_grid_column_title_title"><![CDATA[Оповещение]]></string>
     <string name="_bx_ntfs_grid_column_title_title"><![CDATA[Оповещение]]></string>
     <string name="_bx_ntfs_grid_column_title_title_warning"><![CDATA[Значение данной настройки не корректно. Рекомендуется вкл\выкл настройку и обновить страницу.]]></string>
     <string name="_bx_ntfs_grid_column_title_title_warning"><![CDATA[Значение данной настройки не корректно. Рекомендуется вкл\выкл настройку и обновить страницу.]]></string>
+    <string name="_bx_ntfs_grid_column_title_value"><![CDATA[Значение по умолчанию]]></string>
     <string name="_bx_ntfs_grid_action_title_deactivate"><![CDATA[Отключить]]></string>
     <string name="_bx_ntfs_grid_action_title_deactivate"><![CDATA[Отключить]]></string>
 </resources>
 </resources>