sort feed ascending on histo mode

This commit is contained in:
2019-02-03 19:00:23 +01:00
parent bab12f64b0
commit 4e761a898f
2 changed files with 36 additions and 38 deletions

View File

@@ -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() {

4
todo
View File

@@ -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
- add timezone to feed
- on hover sur message : open popup on map (check zoom)