Просмотр исходного кода

#2709 serviceBrowseByAcl method don't work for "Standard" and other system membership levels

Alex Trofimov 6 лет назад
Родитель
Сommit
ae1dace1d1
2 измененных файлов с 92 добавлено и 38 удалено
  1. 53 27
      inc/classes/BxDolAcl.php
  2. 39 11
      inc/classes/BxDolAclQuery.php

+ 53 - 27
inc/classes/BxDolAcl.php

@@ -137,36 +137,62 @@ class BxDolAcl extends BxDolFactory implements iBxDolSingleton
      */
     public function getContentByLevelAsCondition($sContentField, $mixedLevelId)
     {
-        return array(
-        	'restriction_sql' => ' AND (`tlm`.DateStarts IS NULL OR `tlm`.DateStarts <= NOW()) AND (`tlm`.DateExpires IS NULL OR `tlm`.DateExpires > NOW())',
-            'restriction' => array (
-                'acl_members' => array(
-                    'value' => $mixedLevelId,
-                    'field' => 'IDLevel',
-                    'operator' => is_array($mixedLevelId) ? 'in' : '=',
-                    'table' => 'tlm',
+        $iLevelId = !is_array($mixedLevelId) ? $mixedLevelId : 0;
+        if (!$iLevelId && is_array($mixedLevelId) && 1 == count($mixedLevelId)) {
+            $a = array_values($mixedLevelId);
+            $iLevelId = array_shift($a);
+        }
+
+        // unconfirmed
+        if (MEMBERSHIP_ID_UNCONFIRMED == $iLevelId) {
+            return array(
+                'restriction_sql' => ' AND `sys_accounts`.`email_confirmed` = 0 ',
+                'restriction' => array (),
+                'join' => array (),
+            );
+        }
+        // standard
+        elseif (MEMBERSHIP_ID_STANDARD == $iLevelId) {
+            return array(
+                'restriction_sql' => ' AND (`tlm`.DateStarts IS NULL OR `tlm`.DateStarts <= NOW()) AND (`tlm`.DateExpires IS NULL OR `tlm`.DateExpires > NOW()) AND `tlm`.`IDMember` IS NULL AND `sys_accounts`.`email_confirmed` != 0 ',
+                'restriction' => array (
+                ),
+                'join' => array (
+                    'acl_members' => array(
+                        'type' => 'LEFT',
+                        'table' => 'sys_acl_levels_members',
+                        'table_alias' => 'tlm',
+                        'mainField' => $sContentField,
+                        'onField' => 'IDMember',
+                        'joinFields' => array(),
+                    ),
                 ),
-            ),
-            'join' => array (
-                'acl_members' => array(
-                    'type' => 'INNER',
-                    'table' => 'sys_acl_levels_members',
-                    'table_alias' => 'tlm',
-                    'mainField' => $sContentField,
-                    'onField' => 'IDMember',
-                    'joinFields' => array(),
+            );
+        }
+        // other levels
+        else {
+            return array(
+                'restriction_sql' => ' AND (`tlm`.DateStarts IS NULL OR `tlm`.DateStarts <= NOW()) AND (`tlm`.DateExpires IS NULL OR `tlm`.DateExpires > NOW()) AND `sys_accounts`.`email_confirmed` != 0 ',
+                'restriction' => array (
+                    'acl_members' => array(
+                        'value' => $mixedLevelId,
+                        'field' => 'IDLevel',
+                        'operator' => is_array($mixedLevelId) ? 'in' : '=',
+                        'table' => 'tlm',
+                    ),
                 ),
-                'acl_levels' => array(
-                    'type' => 'INNER',
-                    'table' => 'sys_acl_levels',
-                    'table_alias' => 'tl',
-                    'mainTable' => 'tlm',
-                    'mainField' => 'IDLevel',
-                    'onField' => 'ID',
-                    'joinFields' => array(),
+                'join' => array (
+                    'acl_members' => array(
+                        'type' => 'INNER',
+                        'table' => 'sys_acl_levels_members',
+                        'table_alias' => 'tlm',
+                        'mainField' => $sContentField,
+                        'onField' => 'IDMember',
+                        'joinFields' => array(),
+                    ),
                 ),
-            ),
-        );
+            );
+        }
     }
 
 	/**

+ 39 - 11
inc/classes/BxDolAclQuery.php

@@ -392,20 +392,48 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
 	function getContentByLevelAsSQLPart($sContentTable, $sContentField, $mixedLevelId)
     {
     	$sJoin = $sWhere = ""; 
+        $iLevelId = !is_array($mixedLevelId) ? $mixedLevelId : 0;
+        if (!$iLevelId && is_array($mixedLevelId) && 1 == count($mixedLevelId)) {
+            $a = array_values($mixedLevelId);
+            $iLevelId = array_shift($a);
+        }
 
-        if(is_array($mixedLevelId))
-            $sWhere .= " AND `tlm`.`IDLevel` IN (" . $this->implode_escape($mixedLevelId) . ")";
-        else
-            $sWhere .= $this->prepareAsString(" AND `tlm`.`IDLevel` = ?", (int)$mixedLevelId);
-		$sWhere .= " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW())";
+        // unconfirmed
+        if (MEMBERSHIP_ID_UNCONFIRMED == $iLevelId) {
+            return array(
+                'where' => " AND `sys_accounts`.`email_confirmed` = 0 ",
+                'join' => '',
+            );
+        }
+        // standard
+        elseif (MEMBERSHIP_ID_STANDARD == $iLevelId) {
 
-		$sJoin .= " INNER JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember`";
-		$sJoin .= " INNER JOIN `sys_acl_levels` AS `tl` ON `tlm`.`IDLevel`=`tl`.`ID`"; 
+            $sWhere .= " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW()) AND `tlm`.`IDMember` IS NULL AND `sys_accounts`.`email_confirmed` != 0 ";
 
-        return array(
-            'where' => $sWhere,
-        	'join' => $sJoin
-        );
+            $sJoin .= " LEFT JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember`";
+
+            return array(
+                'where' => $sWhere,
+                'join' => $sJoin
+            );
+        }
+        // other levels
+        else {
+
+            if(is_array($mixedLevelId))
+                $sWhere .= " AND `tlm`.`IDLevel` IN (" . $this->implode_escape($mixedLevelId) . ")";
+            else
+                $sWhere .= $this->prepareAsString(" AND `tlm`.`IDLevel` = ?", (int)$mixedLevelId);
+
+            $sWhere .= " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW()) AND `sys_accounts`.`email_confirmed` != 0 ";
+
+            $sJoin .= " INNER JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember`";
+
+            return array(
+                'where' => $sWhere,
+                'join' => $sJoin
+            );
+        }
     }
 
     function getProfilesByMembership($mixedLevelId)