AntonLV 5 лет назад
Родитель
Сommit
92e05764ba
1 измененных файлов с 78 добавлено и 1 удалено
  1. 78 1
      modules/base/general/classes/BxBaseModGeneralModule.php

+ 78 - 1
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -1291,6 +1291,42 @@ class BxBaseModGeneralModule extends BxDolModule
         return $oMenu ? $oMenu->getCode() : false;
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_base_general Base General
+     * @subsection bx_base_general-page_blocks Page Blocks
+     * @subsubsection bx_base_general-entity_reports entity_reports
+     * 
+     * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
+     * 
+     * Get content reports
+     * @param $iContentId content ID
+     * 
+     * @see BxBaseModGeneralModule::serviceEntityReports
+     */
+    /** 
+     * @ref bx_base_general-entity_reports "entity_reports"
+     */
+    public function serviceEntityReports ($iContentId = 0)
+    {
+        $mixedContent = $this->_getContent($iContentId);
+        list($iContentId, $aContentInfo) = $mixedContent;
+        
+        if($iContentId === false)
+            return false;
+        
+        $CNF = &$this->_oConfig->CNF;
+        
+        if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
+            return false;
+
+        if(!(BxDolAcl::getInstance()->isMemberLevelInSet(192) || bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']]))
+            return false;
+
+        $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
+        return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
+    }
+    
     /**
      * @page service Service Calls
      * @section bx_base_general Base General
@@ -1995,11 +2031,19 @@ class BxBaseModGeneralModule extends BxDolModule
     
     public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments) 
     {
+        //negative id used in comments for reports
+        if ($iContentId < 0)
+            return CHECK_ACTION_RESULT_ALLOWED;
+        
         return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
     }
     
     public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments) 
     {
+        //negative id used in comments for reports
+        if ($iContentId < 0)
+            return CHECK_ACTION_RESULT_ALLOWED;
+        
         return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
     }
 
@@ -2195,7 +2239,7 @@ class BxBaseModGeneralModule extends BxDolModule
     public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
     {
         // moderator always has access
-        if ($this->_isModerator($isPerformAction))
+        if ($this->_isAdministrator($isPerformAction))
             return CHECK_ACTION_RESULT_ALLOWED;
 
         // check ACL
@@ -2245,6 +2289,14 @@ class BxBaseModGeneralModule extends BxDolModule
     	return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
     }
     
+    /**
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
+     */
+    public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
+    {
+    	return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
+    }
+    
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
      */
@@ -2260,6 +2312,21 @@ class BxBaseModGeneralModule extends BxDolModule
     	return _t('_sys_txt_access_denied');
     }
 
+    /**
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
+     */
+    public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
+    {
+        if(!$iProfileId)
+            $iProfileId = $this->_iProfileId;
+
+    	$aCheck = checkActionModule($iProfileId, 'delete any entry', $this->getName(), $isPerformAction);
+    	if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
+    		return CHECK_ACTION_RESULT_ALLOWED;
+
+    	return _t('_sys_txt_access_denied');
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
      */
@@ -2593,6 +2660,16 @@ class BxBaseModGeneralModule extends BxDolModule
         return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
     }
 
+    public function _isAdministrator ($isPerformAction = false)
+    {
+        return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
+    }
+
+    public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
+    {
+        return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
+    }
+
     public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams  = array())
     {
         $CNF = &$this->_oConfig->CNF;