From c4377d62d52d62bb52d8661657a1e8dd571d060e Mon Sep 17 00:00:00 2001 From: franzz Date: Sun, 3 Feb 2019 19:00:23 +0100 Subject: [PATCH] sort feed ascending on histo mode --- inc/spot.php | 70 +++++++++++++++++++++++++--------------------------- todo | 4 +-- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/inc/spot.php b/inc/spot.php index c39d877..7945a0b 100755 --- a/inc/spot.php +++ b/inc/spot.php @@ -324,11 +324,6 @@ class Spot extends Main return $asPosts; } - private static function getJsonId($iTimeStamp, $sPriority='0', $iDbId=0) - { - return ($iTimeStamp * -1).'.'.$sPriority.$iDbId; - } - private function addTimeStamp(&$asData, $iTime) { $asData['unix_timestamp'] = (int) $iTime; $asData['relative_time'] = Toolbox::getDateTimeDesc($iTime, 'fr'); @@ -337,43 +332,46 @@ class Spot extends Main public function getNewsFeed($iChunk=0) { - $asFeed = array(); - - //Messages - $asMessages = $this->getSpotMessages(); - foreach($asMessages as $iIndex=>$asMessage) - { - $iId = self::getJsonId($asMessage['unix_timestamp'], '0', $asMessage[Db::getId(self::MSG_TABLE)]); - $asFeed[$iId] = $asMessage; - $asFeed[$iId]['type'] = 'message'; - $asFeed[$iId]['displayed_id'] = 'N°'.$iIndex; - } - - //Pictures - $asPics = $this->getPictures('added_on'); - foreach($asPics as $iKey=>$asPic) - { - $iId = self::getJsonId($asPic['unix_timestamp'], '1', $iKey); - $asFeed[$iId] = $asPic; - $asFeed[$iId]['type'] = 'picture'; - } - - //Post - $asPosts = $this->getPosts(); - foreach($asPosts as $asPost) - { - $iId = self::getJsonId($asPost['unix_timestamp'], '2', $asPost[Db::getId(self::POST_TABLE)]); - $asFeed[$iId] = $asPost; - $asFeed[$iId]['type'] = 'post'; + $bHistoMode = ($this->oProject->getMode() == Project::MODE_HISTO); + $asFeeds = array(); + $asFeedTypes = array( + 'message' => array( + 'table' => self::MSG_TABLE, + 'feed' => $this->getSpotMessages(), + 'priority' => 0 + ), + 'picture' => array( + 'table' => Picture::PIC_TABLE, + 'feed' => $this->getPictures('added_on'), + 'priority' => 1 + ), + 'post' => array( + 'table' => self::POST_TABLE, + 'feed' => $this->getPosts(), + 'priority' => 2 + ) + ); + foreach($asFeedTypes as $sFeedType=>$asFeedTypeInfo) { + foreach($asFeedTypeInfo['feed'] as $iIndex=>$asFeed) { + $sPriority = $asFeedTypeInfo['priority']; + if($bHistoMode) $sPriority = count($asFeedTypes) - 1 - $asFeedTypeInfo['priority']; + + $iId = ($asFeed['unix_timestamp'] * -1).'.'.$sPriority.$asFeed[Db::getId($asFeedTypeInfo['table'])]; + + $asFeeds[$iId] = $asFeed; + $asFeeds[$iId]['type'] = $sFeedType; + if($sFeedType!='post') $asFeeds[$iId]['displayed_id'] = 'N°'.($iIndex + 1); + } } //Sort by key - ksort($asFeed); + if($bHistoMode) krsort($asFeeds); + else ksort($asFeeds); //Split chunks - $asFeed = array_slice($asFeed, $iChunk*self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE); + $asFeeds = array_slice($asFeeds, $iChunk*self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE); - return self::getJsonResult(true, '', $asFeed); + return self::getJsonResult(true, '', $asFeeds); } public function syncPics() { diff --git a/todo b/todo index 84afb86..b0247b9 100644 --- a/todo +++ b/todo @@ -5,5 +5,5 @@ To Do List - Manage projects.timezone - Remove files2/ on server - Replace all images with FA icons -- in histo mode, sort posts ascending -- add timezone to feed \ No newline at end of file +- add timezone to feed +- on hover sur message : open popup on map (check zoom) \ No newline at end of file