Преглед изворни кода

#2055 Convos: conversation deletion problem + some other bugfixes

Alex Trofimov пре 7 година
родитељ
комит
b4e057f246

+ 1 - 0
modules/boonex/convos/classes/BxCnvConfig.php

@@ -85,6 +85,7 @@ class BxCnvConfig extends BxBaseModTextConfig
 
             // some language keys
             'T' => array (
+                'grid_action_err_delete' => '_bx_cnv_grid_action_err_delete',
                 'txt_sample_single' => '_bx_cnv_txt_sample_single',
             	'txt_folder_' . BX_CNV_FOLDER_INBOX => '_bx_cnv_folder_inbox',
 	            'txt_folder_' . BX_CNV_FOLDER_DRAFTS => '_bx_cnv_folder_drafts',

+ 5 - 5
modules/boonex/convos/classes/BxCnvDb.php

@@ -84,7 +84,7 @@ class BxCnvDb extends BxBaseModTextDb
         $sQuery = $this->prepare("SELECT `folder_id` FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ? AND `collaborator` = ?", $iConversationId, $iProfileId);
         $iFolderIdOld = $this->getOne($sQuery);
         if (BX_CNV_FOLDER_TRASH == $iFolderIdOld) // if convo is already in trash folder - delete it
-            return $this->deleteConvo($iConversationId, $iProfileId);
+            return '' === $this->deleteConvo($iConversationId, $iProfileId) ? true : false;
 
         $sQuery = $this->prepare("UPDATE `" . $this->getPrefix() . "conv2folder` SET `folder_id` = ? WHERE `conv_id` = ? AND `collaborator` = ?", $iFolderId, $iConversationId, $iProfileId);
         return $this->query($sQuery);
@@ -94,7 +94,7 @@ class BxCnvDb extends BxBaseModTextDb
     {
         $aContentInfo = $this->getContentInfoById ($iConversationId);
         if (!$aContentInfo)
-            return true;
+            return '';
 
         // delete convo
         $aBindings = array(
@@ -113,16 +113,16 @@ class BxCnvDb extends BxBaseModTextDb
 
         // delete whole conversation if there is no refencences to the conversation in conv2folder table
         if ($this->getCollaborators($iConversationId))
-            return false;
+            return '';
             
         $sQuery = $this->prepare("SELECT `id` FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ?", $iConversationId);
         if (!$this->getOne($sQuery)) {
             $CNF = &$this->_oConfig->CNF;
             $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
-            return $oForm->delete((int)$iConversationId, $aContentInfo);
+            return $oForm->delete((int)$iConversationId, $aContentInfo) ? '' : _t('_sys_txt_error_occured');
         }
 
-        return true;
+        return '';
     }
 
     public function getUnreadMessagesNum ($iProfileId, $iFolderId = BX_CNV_FOLDER_INBOX)

+ 8 - 4
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -34,7 +34,7 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
 
             $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
             if ($aContentInfo && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']]) // allow to edit participants for author only
-                $this->_updateParticipants ($iContentId, $iFolder, $iFolder == BX_CNV_FOLDER_DRAFTS ? true : false);
+                $this->updateParticipants ($iContentId, $iFolder, $iFolder == BX_CNV_FOLDER_DRAFTS ? true : false);
         }
 
         return $bRet;
@@ -86,19 +86,20 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
         } 
         else {
             $iFolder = $bSpam ? BX_CNV_FOLDER_SPAM : BX_CNV_FOLDER_INBOX;
-            $this->_updateParticipants ($iContentId, $iFolder, $bDraft);
+            $this->updateParticipants ($iContentId, $iFolder, $bDraft);
         }
 
         return $iContentId;
     }
 
-    protected function _updateParticipants ($iContentId, $iFolder, $bDraft) 
+    public function updateParticipants ($iContentId, $iFolder, $bDraft, $aRecipientsAdd = array()) 
     {
         $iSender = bx_get_logged_profile_id();
         $aRecipientsOld = $this->_oModule->_oDb->getCollaborators($iContentId);
 
         // place conversation to "inbox" (or "spam" - in case of spam) folder
-        $aRecipients = array_unique(array_merge($this->getCleanValue('recipients'), array($iSender)), SORT_NUMERIC);
+        $aRecipientsFormForm = $this->getCleanValue('recipients') ? $this->getCleanValue('recipients') : array();
+        $aRecipients = array_unique(array_merge($aRecipientsFormForm, array($iSender), $aRecipientsAdd), SORT_NUMERIC);
         foreach ($aRecipients as $iProfile) {
             $oProfile = BxDolProfile::getInstance($iProfile);
             if(!$oProfile)
@@ -115,6 +116,9 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
                         $iFolder = BX_CNV_FOLDER_SPAM;
                 }
 
+                if ($aRecipientsAdd && in_array($iRecipient, $aRecipientsAdd))
+                    $this->_oModule->_oDb->removeCollaborator($iContentId, $iRecipient);
+
                 $this->_oModule->_oDb->conversationToFolder($iContentId, $iFolder, $iRecipient, $iRecipient == $iSender ? 0 : -1);
             }
         }

+ 2 - 2
modules/boonex/convos/classes/BxCnvGrid.php

@@ -146,11 +146,11 @@ class BxCnvGrid extends BxBaseModGeneralGridAdministration
         return parent::_getCellDefault ('<div class="bx-cnv-grid-field-messages"><span>' . (1 + $mixedValue) . '</span>' . $s . '</div>', $sKey, $aField, $aRow);
     }
 
-    protected function _delete ($mixedId)
+    protected function _doDelete ($iId, $aParams = array())
     {
         $oModule = BxDolModule::getInstance($this->MODULE);
 
-        if ($sErrorMsg = $oModule->deleteConvo ($mixedId))
+        if ($sErrorMsg = $oModule->deleteConvo ($iId))
             return 0;
 
         return 1;

+ 12 - 5
modules/boonex/convos/classes/BxCnvModule.php

@@ -115,10 +115,7 @@ class BxCnvModule extends BxBaseModTextModule
      */
     public function deleteConvoForever ($iContentId)
     {
-        if (!$this->_oDb->deleteConvo((int)$iContentId))
-            return _t('_error occured');
-
-        return '';
+        return $this->_oDb->deleteConvo((int)$iContentId);
     }
 
     public function actionMarkUnread($iContentId)
@@ -289,6 +286,17 @@ class BxCnvModule extends BxBaseModTextModule
         if (!$aContentInfo)
             return false;
 
+        // add author to the list of collaborators when somebody replies
+        // if author is removed from collaborators
+        // of if authot placed message to trash
+        $aCollaborators = $this->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
+        if (!isset($aCollaborators[$aContentInfo[$CNF['FIELD_AUTHOR']]]) || BX_CNV_FOLDER_TRASH == $this->_oDb->getConversationFolder($aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']])) {
+            $oFormsHelper = $this->serviceFormsHelper ();
+            $oForm = $oFormsHelper->getObjectFormEdit();
+            $oForm->updateParticipants($aContentInfo[$CNF['FIELD_ID']], BX_CNV_FOLDER_INBOX, false, array($aContentInfo[$CNF['FIELD_AUTHOR']]));
+        }
+
+
         $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
         if(!$oCmts)
             return false;
@@ -304,7 +312,6 @@ class BxCnvModule extends BxBaseModTextModule
 
         // send notification to all collaborators
         if ($oProfile = BxDolProfile::getInstance($iProfileId)) {
-            $aCollaborators = $this->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
             foreach ($aCollaborators as $iCollaborator => $iReadComments) {
                 if ($iCollaborator == $iProfileId)
                     continue;

+ 1 - 0
modules/boonex/convos/install/langs/en.xml

@@ -99,6 +99,7 @@
     <string name="_bx_cnv_field_preview"><![CDATA[Preview]]></string>
     <string name="_bx_cnv_field_collaborators"><![CDATA[Participants]]></string>
 
+    <string name="_bx_cnv_grid_action_err_delete"><![CDATA[Cannot delete the selected conversation(s).]]></string>
     <string name="_bx_cnv_grid_action_delete"><![CDATA[Delete]]></string>
     <string name="_bx_cnv_grid_action_compose"><![CDATA[Compose]]></string>
 	<string name="_bx_cnv_grid_filter_item_title_adm_all"><![CDATA[All]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/bx_convos/ru.xml

@@ -99,6 +99,7 @@
     <string name="_bx_cnv_field_preview"><![CDATA[Предпросмотр]]></string>
     <string name="_bx_cnv_field_collaborators"><![CDATA[Адресаты]]></string>
 
+    <string name="_bx_cnv_grid_action_err_delete"><![CDATA[Невозможно удалить выбранное(ные) сообщение(ния).]]></string>
     <string name="_bx_cnv_grid_action_delete"><![CDATA[Удалить]]></string>
     <string name="_bx_cnv_grid_action_compose"><![CDATA[Новое сообщение]]></string>
     <string name="_bx_cnv_grid_filter_item_title_adm_all"><![CDATA[Все]]></string>