Parcourir la source

Ticket #4971 - Build-in API support: Get rid of validation. Timeline.

AntonLV il y a 11 mois
Parent
commit
2d585b37f5

+ 3 - 11
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -679,8 +679,6 @@ class BxTimelineDb extends BxBaseModNotificationsDb
             'params' => &$aParams,
         ]);
 
-        $bValidate = !empty($aParams['validate']) && is_array($aParams['validate']);
-
         $sTable = isset($aParams['from_cache']) && $aParams['from_cache'] === true ? $this->_sTableSlice : $this->_sTable;
         $sTableAlias = $this->getTableAlias();
 
@@ -772,16 +770,10 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         if($bCount)
             return array_sum($aSqlParts);
 
-        $sSqlMaskUnion = '(' . implode(') UNION (', $aSqlParts) . ')';
-        if($bValidate)
-            $sSqlMaskUnion = 'SELECT MIN(`tu`.`id`) AS `min_id`, MAX(`tu`.`id`) AS `max_id` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
-        else
-            $sSqlMaskUnion = 'SELECT *, GROUP_CONCAT(`owner_id`) AS `owner_id_grouped` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
-        $sSqlMaskUnion .= ' {order} {limit}';
-
+        $sSqlMaskUnion = 'SELECT *, GROUP_CONCAT(`owner_id`) AS `owner_id_grouped` FROM ((' . implode(') UNION (', $aSqlParts) . ')) AS `tu` GROUP BY `tu`.`source` {order} {limit}';
         $sSql = bx_replace_markers($sSqlMaskUnion, [
-            'order' => str_replace("`{$sTableAlias}`.", $bValidate ? '`tu`.' : '', $sOrderClause),
-            'limit' => str_replace("`{$sTableAlias}`.", $bValidate ? '`tu`.' : '', $sLimitClause),
+            'order' => str_replace("`{$sTableAlias}`.", '', $sOrderClause),
+            'limit' => str_replace("`{$sTableAlias}`.", '', $sLimitClause),
         ]);
 
         //echoDbg($sSql); exit;

+ 3 - 60
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -5841,56 +5841,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         $aParams = $this->_prepareParams($aBrowseParams);
         $this->_iOwnerId = $aParams['owner_id'];
 
-        if(isset($aParams['validate']) && is_array($aParams['validate'])) {
-            $iSlice = count($aParams['validate']);
-
-            $aEventsIds = $this->_oDb->getEvents(array_merge($aParams, [
-                'start' => 0,
-                'per_page' => 2 * $iSlice,
-                'from_cache' => $this->_oConfig->isCacheTable()
-            ]));
-
-            $iIds = 0;
-            $aIds = [];
-            $sModule = $this->_oConfig->getName();
-            foreach($aEventsIds as $aEventId) {
-                $aEvent = [];
-                if((int)$aEventId['min_id'] != (int)$aEventId['max_id']) {
-                    $aEs = [
-                        $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['min_id']]),
-                        $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['max_id']])
-                    ];
-
-                    foreach($aEs as $aE) {
-                        $bEs = (int)$aE['system'] != 0;
-                        if(($bEs ? $aE['type'] : $sModule) . '_' . abs($aE['object_owner_id']) . '_' . ($bEs ? $aE['object_id'] : $aE['id']) != $aE['source']) 
-                            continue;
-
-                        $aEvent = $aE;
-                        break;
-                    }
-                }
-                else 
-                    $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['min_id']]);
-
-                if(empty($aEvent) || !is_array($aEvent))
-                    continue;
-
-                $sEvent = $this->_oTemplate->getPost($aEvent, $aParams);
-                if(empty($sEvent))
-                    continue;
-
-                $aIds[] = $aEvent['id'];
-                if(++$iIds == $iSlice)
-                    break;
-            }
-
-            sort($aIds);
-            sort($aParams['validate']);
-            $aResult = $aIds == $aParams['validate'] ? 'valid' : 'invalid';
-        }
-        else 
-            $aResult = $this->_oTemplate->getViewBlock($aParams);
+        $aResult = $this->_oTemplate->getViewBlock($aParams);
 
         return $this->_bIsApi ? [bx_api_get_block('browse', [
             'unit' => 'feed',  
@@ -6343,9 +6294,6 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if(empty($aParams['viewer_id']) || (int)$aParams['viewer_id'] != $iViewerId)
             $aParams['viewer_id'] = $iViewerId;
 
-        if(isset($aParams['validate']) && !is_array($aParams['validate']))
-            $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
-
         if(empty($aParams['status']))
             $aParams['status'] = BX_TIMELINE_STATUS_ACTIVE;
 
@@ -6360,7 +6308,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
     protected function _prepareParamsGet($mParams = false)
     {
-        $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'per_page_default', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id', 'validate'];
+        $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'per_page_default', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id'];
 
         $aParams = [];
         if(!empty($mParams) && is_array($mParams))
@@ -6394,17 +6342,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
             $aParams['viewer_id'] = $iViewerId;
 
-        if(isset($aParams['validate']) && !is_array($aParams['validate']))
-            $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
-
-        $aParams = array_merge($aParams, [
+        return array_merge($aParams, [
             'browse' => 'list',
             'status' => BX_TIMELINE_STATUS_ACTIVE,
             'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
             'dynamic_mode' => true,
         ]);
-
-        return $aParams;
     }
 
     protected function _prepareTextForSave($s)