Bläddra i källkod

#133 - content deletions in convos module

Alex Trofimov 11 år sedan
förälder
incheckning
fa09d2bbd5

+ 7 - 15
modules/boonex/convos/classes/BxCnvAlertsResponse.php

@@ -9,30 +9,22 @@
  * @{
  * @{
  */
  */
 
 
-/**
- * alerts handler
- */
-class BxCnvAlertsResponse extends BxDolAlertsResponse
-{
-    protected $MODULE;
+bx_import('BxBaseModTextAlertsResponse');
 
 
+class BxCnvAlertsResponse extends BxBaseModTextAlertsResponse
+{
     public function __construct()
     public function __construct()
     {
     {
-        parent::__construct();
         $this->MODULE = 'bx_convos';
         $this->MODULE = 'bx_convos';
+        parent::__construct();        
     }
     }
 
 
     public function response($oAlert)
     public function response($oAlert)
     {
     {
-        if ($this->MODULE == $oAlert->sUnit) {
-
-            switch ($oAlert->sAction) {
-                case 'commentPost':
-                    BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id']));
-                    break;
-            }
+        if ($this->MODULE == $oAlert->sUnit && 'commentPost' == $oAlert->sAction)
+            BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id']));
 
 
-        }
+        parent::response($oAlert);
     }
     }
 }
 }
 
 

+ 12 - 4
modules/boonex/convos/classes/BxCnvDb.php

@@ -68,11 +68,19 @@ class BxCnvDb extends BxBaseModTextDb
         return $this->query($sQuery);
         return $this->query($sQuery);
     }
     }
 
 
-    public function deleteConvo($iConversationId, $iProfileId)
+    public function deleteConvo($iConversationId, $iProfileId = 0)
     {
     {
+        $aContentInfo = $this->getContentInfoById ($iConversationId);
+        if (!$aContentInfo)
+            return true;
+
         // delete convo
         // delete convo
-        $sQuery = $this->prepare("DELETE FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ? AND `collaborator` = ?", $iConversationId, $iProfileId);
-        if (!$this->query($sQuery))
+        $sWhere = '';
+        if ($iProfileId)
+            $sWhere = $this->prepare(" AND `collaborator` = ?", $iProfileId);
+
+        $sQuery = $this->prepare("DELETE FROM `" . $this->getPrefix() . "conv2folder` WHERE `conv_id` = ?", $iConversationId);
+        if (!$this->query($sQuery . $sWhere))
             return false;
             return false;
 
 
         // delete whole conversation if there is no refencences to the conversation in conv2folder table
         // delete whole conversation if there is no refencences to the conversation in conv2folder table
@@ -81,7 +89,7 @@ class BxCnvDb extends BxBaseModTextDb
             $CNF = &$this->_oConfig->CNF;
             $CNF = &$this->_oConfig->CNF;
             bx_import('BxDolForm');
             bx_import('BxDolForm');
             $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
             $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
-            return $oForm->delete((int)$iConversationId);
+            return $oForm->delete((int)$iConversationId, $aContentInfo);
         }
         }
 
 
         return true;
         return true;

+ 16 - 0
modules/boonex/convos/classes/BxCnvFormsEntryHelper.php

@@ -20,6 +20,22 @@ class BxCnvFormsEntryHelper extends BxBaseModTextFormsEntryHelper
     {
     {
         parent::__construct($oModule);
         parent::__construct($oModule);
     }
     }
+
+    public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if ($sErrorMsg = $this->_oModule->deleteConvoForever ($iContentId))
+            return $sErrorMsg;
+
+        if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
+            return $sResult;
+
+        // create an alert
+        bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
+
+        return '';
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 13 - 1
modules/boonex/convos/classes/BxCnvModule.php

@@ -94,7 +94,7 @@ class BxCnvModule extends BxBaseModTextModule
     }
     }
 
 
     /**
     /**
-     * Delete conversation for current user by content id
+     * Delete conversation for current user by content id, before deletetion it checks user permission to delete convos
      * @return error string on error, or empty string on success
      * @return error string on error, or empty string on success
      */
      */
     public function deleteConvo ($iContentId)
     public function deleteConvo ($iContentId)
@@ -112,6 +112,18 @@ class BxCnvModule extends BxBaseModTextModule
         return '';
         return '';
     }
     }
 
 
+    /**
+     * Delete whole conversation for all users by content id
+     * @return error string on error, or empty string on success
+     */
+    public function deleteConvoForever ($iContentId)
+    {
+        if (!$this->_oDb->deleteConvo((int)$iContentId))
+            return _t('_error occured');
+
+        return '';
+    }
+
     public function actionMarkUnread($iContentId)
     public function actionMarkUnread($iContentId)
     {
     {
         header('Content-Type:text/plain; charset=utf-8');
         header('Content-Type:text/plain; charset=utf-8');

+ 2 - 1
modules/boonex/convos/install/sql/enable.sql

@@ -189,5 +189,6 @@ SET @iHandler := LAST_INSERT_ID();
 
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_convos', 'commentPost', @iHandler),
 ('bx_convos', 'commentPost', @iHandler),
-('bx_convos', 'commentRemoved', @iHandler);
+('bx_convos', 'commentRemoved', @iHandler),
+('profile', 'delete', @iHandler);