Przeglądaj źródła

Ticket #3676 - Allow author (author's admins) to see pending comments.

AntonLV 4 lat temu
rodzic
commit
140b0e93ca

+ 3 - 3
inc/classes/BxDolCmts.php

@@ -1121,13 +1121,13 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function isMoreAllowed ($aCmt, $isPerformAction = false)
     {
         $oMenuManage = BxDolMenu::getObjectInstance($this->_sMenuObjManage);
-	    $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
+        $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
     	return $oMenuManage->isVisible();
     }
 
-    public function isModerator()
+    public function isModerator($isPerformAction = false)
     {
-        return $this->isEditAllowedAll() || $this->isRemoveAllowedAll();
+        return $this->isEditAllowedAll($isPerformAction) || $this->isRemoveAllowedAll($isPerformAction);
     }
 
     /**

+ 30 - 3
inc/classes/BxDolCmtsQuery.php

@@ -329,12 +329,11 @@ class BxDolCmtsQuery extends BxDolDb
     {
     	$aBindings = array(
             'cmt_object_id' => $iId,
-            'system_id' => $this->_oMain->getSystemId(),
-            'status_admin' => BX_CMT_STATUS_ACTIVE
+            'system_id' => $this->_oMain->getSystemId()
     	);
         $sFields = $sJoin = "";
 
-        $sWhereStatus = " AND `{$this->_sTableIds}`.`status_admin`=:status_admin";
+        $sWhereStatus = $this->getCommentsCheckStatus($iAuthorId);
 
         $sWhereParent = '';
         if((int)$iCmtVParentId >= 0) {
@@ -415,6 +414,34 @@ class BxDolCmtsQuery extends BxDolDb
         return $this->getAll($sQuery, $aBindings);
     }
 
+    protected function getCommentsCheckStatus($iAuthorId, $sStatus = BX_CMT_STATUS_ACTIVE)
+    {
+        if($this->_oMain->isModerator()) 
+            return '';
+
+        //--- Check viewer as comment author.
+        $sWhereClause = $this->prepareAsString("`{$this->_sTable}`.`cmt_author_id`=?", $iAuthorId);
+
+        //--- Check viewer as an administrator/moderator of comment author.
+        $aGroups = [];
+        $aModules = bx_srv('system', 'get_modules_by_type', ['profile']);
+        foreach($aModules as $aModule) {
+            $oModule = BxDolModule::getInstance($aModule['name']);
+            if(!$oModule || !($oModule instanceof BxBaseModGroupsModule))
+                continue;
+
+            $aGroups = array_merge($aGroups, $oModule->getGroupsByFan($iAuthorId, [
+                BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR,
+                BX_BASE_MOD_GROUPS_ROLE_MODERATOR
+            ]));
+        }
+
+        if(!empty($aGroups))
+            $sWhereClause .= " OR `{$this->_sTable}`.`cmt_author_id` IN (" . $this->implode_escape($aGroups) . ")";
+
+        return $this->prepareAsString(" AND IF(" . $sWhereClause . ", 1, `{$this->_sTableIds}`.`status_admin`=?) ", $sStatus);
+    }
+
     function getCommentsBy($aParams = array())
     {
     	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query', 1 => array()));

+ 16 - 0
modules/base/groups/classes/BxBaseModGroupsDb.php

@@ -177,6 +177,22 @@ class BxBaseModGroupsDb extends BxBaseModProfileDb
                 }
                 break;
 
+            case 'group_pids_by_fan_id':
+                $aMethod['name'] = 'getColumn';
+                $aMethod['params'][1] = [
+                    'fan_id' => $aParams['fan_id'],
+                ];
+
+                $sSelectClause = "`ta`.`group_profile_id`";
+                $sWhereClause = "AND `ta`.`fan_id` = :fan_id";
+
+                if(!empty($aParams['role'])) {
+                    $aMethod['params'][1]['role'] = $aParams['role'];
+
+                    $sWhereClause .= " AND `ta`.`role` = :role";
+                }
+                break;
+
             case 'expired':
                 $sWhereClause .= "AND `ta`.`added` < UNIX_TIMESTAMP() AND `ta`.`expired` <> 0 AND `ta`.`expired` < UNIX_TIMESTAMP()";
                 break;

+ 34 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1706,6 +1706,40 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
     }
 
+    public function getGroupsByFan($iProfileId, $mixedRole = false)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!isset($CNF['OBJECT_CONNECTIONS']))
+            return false;
+
+        if($mixedRole === false)
+            $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
+
+        if(!is_array($mixedRole))
+            $mixedRole = [$mixedRole];
+
+        $aResult = [];
+        foreach($mixedRole as $iRole) {
+            switch($iRole) {
+                case BX_BASE_MOD_GROUPS_ROLE_COMMON:
+                    $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
+                    break;
+
+                default:
+                    $aIds = $this->_oDb->getRoles([
+                        'type' => 'group_pids_by_fan_id', 
+                        'fan_id' => $iProfileId,
+                        'role' => $iRole
+                    ]);
+            }
+
+            $aResult = array_merge($aResult, $aIds);
+        }
+
+        return $aResult;
+    }
+
     protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
     {
         $CNF = &$this->_oConfig->CNF;