AntonLV 7 лет назад
Родитель
Сommit
7bb4b71ba9
2 измененных файлов с 22 добавлено и 7 удалено
  1. 10 7
      inc/classes/BxDolCmts.php
  2. 12 0
      inc/classes/BxDolCmtsQuery.php

+ 10 - 7
inc/classes/BxDolCmts.php

@@ -1049,25 +1049,28 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function remove($iCmtId)
     {
         $aCmt = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iCmtId));
-        if(!$aCmt) {
+        if(!$aCmt)
             return array('msg' => _t('_No such comment'));
-        }
         
         $iObjId = $this->getId();
-        if (!$iObjId){
+        if(!$iObjId){
             $this->setId($aCmt['cmt_object_id']);
             $iObjId = $aCmt['cmt_object_id'];
         }
         $iObjAthrId = $this->getObjectAuthorId($iObjId);
         
-        if ($aCmt['cmt_replies'] > 0) {
-            return array('msg' => _t('_Can not delete comments with replies'));
+        if($aCmt['cmt_replies'] > 0) {
+            if(!$this->isModerator())
+                return array('msg' => _t('_Can not delete comments with replies'));
+
+            $aReplies = $this->_oQuery->getCommentsBy(array('type' => 'parent_id', 'parent_id' => $iCmtId));
+            foreach($aReplies as $aReply)
+                $this->remove($aReply['cmt_id']);
         }
 
         $iPerformerId = $this->_getAuthorId();
-        if(!$this->isRemoveAllowed($aCmt)) {
+        if(!$this->isRemoveAllowed($aCmt))
             return array('msg' => $aCmt['cmt_author_id'] == $iPerformerId ? strip_tags($this->msgErrRemoveAllowed()) : _t('_Access denied'));
-        }
 
         if($this->_oQuery->removeComment($iObjId, $iCmtId, $aCmt['cmt_parent_id'])) {
             $this->_triggerComment();

+ 12 - 0
inc/classes/BxDolCmtsQuery.php

@@ -204,6 +204,18 @@ class BxDolCmtsQuery extends BxDolDb
 
                 break;
 
+            case 'parent_id':
+                $aMethod['params'][1]['cmt_parent_id'] = (int)$aParams['parent_id'];
+
+                $sWhereClause .= " AND `{$this->_sTable}`.`cmt_parent_id` = :cmt_parent_id";
+
+                $sOrderClause = "`{$this->_sTable}`.`cmt_time` ASC";
+                $sLimitClause = "";
+                if(isset($aParams['per_page']))
+                    $sLimitClause = $this->prepareAsString("?, ?", $aParams['start'], $aParams['per_page']);
+
+                break;
+
             case 'object_id':
                 $aMethod['params'][1]['cmt_object_id'] = (int)$aParams['object_id'];