feed update: introduce reference point
This commit is contained in:
32
inc/Spot.php
32
inc/Spot.php
@@ -224,7 +224,7 @@ class Spot extends Main
|
|||||||
$oEmail->oTemplate->setTag('date_time', 'time:'.$asLastMessage['unix_time'], 'd/m/Y, H:i');
|
$oEmail->oTemplate->setTag('date_time', 'time:'.$asLastMessage['unix_time'], 'd/m/Y, H:i');
|
||||||
|
|
||||||
//Add latest news feed
|
//Add latest news feed
|
||||||
$asNews = $this->getNewsFeed(0, true);
|
$asNews = $this->getNewsFeed(0, 0, true);
|
||||||
$iPostCount = 0;
|
$iPostCount = 0;
|
||||||
foreach($asNews as $asPost) {
|
foreach($asNews as $asPost) {
|
||||||
if($asPost['type'] != 'message') {
|
if($asPost['type'] != 'message') {
|
||||||
@@ -425,7 +425,7 @@ class Spot extends Main
|
|||||||
if($sTimeZone != '') $asData['formatted_time_local'] = $this->getTimeFormat($iTime, $sTimeZone);
|
if($sTimeZone != '') $asData['formatted_time_local'] = $this->getTimeFormat($iTime, $sTimeZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNewsFeed($iChunk=0, $bInternal=false)
|
public function getNewsFeed($iChunk=0, $iRefTimePoint=0, $bInternal=false)
|
||||||
{
|
{
|
||||||
$bHistoMode = ($this->oProject->getMode() == Project::MODE_HISTO);
|
$bHistoMode = ($this->oProject->getMode() == Project::MODE_HISTO);
|
||||||
$asFeeds = array();
|
$asFeeds = array();
|
||||||
@@ -435,7 +435,7 @@ class Spot extends Main
|
|||||||
'feed' => $this->getSpotMessages(),
|
'feed' => $this->getSpotMessages(),
|
||||||
'priority' => 0
|
'priority' => 0
|
||||||
),
|
),
|
||||||
'media' => array(
|
'media' => array(
|
||||||
'table' => Media::MEDIA_TABLE,
|
'table' => Media::MEDIA_TABLE,
|
||||||
'feed' => $this->getMedias('posted_on'),
|
'feed' => $this->getMedias('posted_on'),
|
||||||
'priority' => 1
|
'priority' => 1
|
||||||
@@ -448,25 +448,31 @@ class Spot extends Main
|
|||||||
);
|
);
|
||||||
foreach($asFeedTypes as $sFeedType=>$asFeedTypeInfo) {
|
foreach($asFeedTypes as $sFeedType=>$asFeedTypeInfo) {
|
||||||
foreach($asFeedTypeInfo['feed'] as $asFeed) {
|
foreach($asFeedTypeInfo['feed'] as $asFeed) {
|
||||||
$sPriority = $asFeedTypeInfo['priority'];
|
|
||||||
if($bHistoMode) $sPriority = count($asFeedTypes) - 1 - $asFeedTypeInfo['priority'];
|
|
||||||
|
|
||||||
$iTableId = $asFeed[Db::getId($asFeedTypeInfo['table'])];
|
$iTableId = $asFeed[Db::getId($asFeedTypeInfo['table'])];
|
||||||
$iId = ($asFeed['unix_time'] * -1).'.'.$sPriority.$iTableId;
|
|
||||||
$asFeeds[$iId] = $asFeed;
|
//Build unique sorting ID
|
||||||
$asFeeds[$iId]['type'] = $sFeedType;
|
$iSort = $asFeed['unix_time'].'.'.$asFeedTypeInfo['priority'].$iTableId;
|
||||||
$asFeeds[$iId]['id'] = $iTableId;
|
|
||||||
|
//Build feed (not including new feeds added in between chunk by concurrent access)
|
||||||
|
if($iChunk == 0 || $iSort <= $iRefTimePoint) {
|
||||||
|
$asFeeds[$iSort] = $asFeed;
|
||||||
|
$asFeeds[$iSort]['type'] = $sFeedType;
|
||||||
|
$asFeeds[$iSort]['id'] = $iTableId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Build Reference Time Point (latest item extracted by first chunk)
|
||||||
|
if($iChunk == 0 && $iSort > $iRefTimePoint) $iRefTimePoint = $iSort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sort by key
|
//Sort by key
|
||||||
if($bHistoMode) krsort($asFeeds);
|
if($bHistoMode) ksort($asFeeds); //Old first
|
||||||
else ksort($asFeeds);
|
else krsort($asFeeds); //New first
|
||||||
|
|
||||||
//Split chunks
|
//Split chunks
|
||||||
$asFeeds = array_slice($asFeeds, $iChunk * self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE);
|
$asFeeds = array_slice($asFeeds, $iChunk * self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE);
|
||||||
|
|
||||||
return $bInternal?$asFeeds:self::getJsonResult(true, '', $asFeeds);
|
return $bInternal?$asFeeds:self::getJsonResult(true, '', array('ref_id'=>$iRefTimePoint, 'feed' => $asFeeds));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function syncMedias() {
|
public function syncMedias() {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ if($sAction!='')
|
|||||||
$sResult = $oSpot->getMarkers();
|
$sResult = $oSpot->getMarkers();
|
||||||
break;
|
break;
|
||||||
case 'feed':
|
case 'feed':
|
||||||
$sResult = $oSpot->getNewsFeed($iChunk);
|
$sResult = $oSpot->getNewsFeed($iChunk, $iId);
|
||||||
break;
|
break;
|
||||||
case 'add_post':
|
case 'add_post':
|
||||||
$sResult = $oSpot->addPost($sName, $sContent);
|
$sResult = $oSpot->addPost($sName, $sContent);
|
||||||
|
|||||||
@@ -720,6 +720,8 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
|||||||
bDiscrete = bDiscrete || false;
|
bDiscrete = bDiscrete || false;
|
||||||
fCallback = fCallback || function(){};
|
fCallback = fCallback || function(){};
|
||||||
|
|
||||||
|
if(bFirstChunk) self.tmp('ref_id', 0);
|
||||||
|
|
||||||
if(self.tmp('updatable')) {
|
if(self.tmp('updatable')) {
|
||||||
if(!self.tmp('out-of-data') || bFirstChunk) {
|
if(!self.tmp('out-of-data') || bFirstChunk) {
|
||||||
self.tmp('updatable', false);
|
self.tmp('updatable', false);
|
||||||
@@ -736,12 +738,14 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
|||||||
function(asData) {
|
function(asData) {
|
||||||
$('#loading').hide();
|
$('#loading').hide();
|
||||||
|
|
||||||
$.each(asData, function(iKey, asPost){
|
self.tmp('ref_id', asData.ref_id);
|
||||||
|
|
||||||
|
$.each(asData.feed, function(iKey, asPost){
|
||||||
$Posts.append(getPost(asPost));
|
$Posts.append(getPost(asPost));
|
||||||
});
|
});
|
||||||
|
|
||||||
self.tmp('news_chunk', self.tmp('news_chunk') + 1);
|
self.tmp('news_chunk', self.tmp('news_chunk') + 1);
|
||||||
self.tmp('out-of-data', Object.keys(asData).length != self.vars('chunk_size'));
|
self.tmp('out-of-data', Object.keys(asData.feed).length != self.vars('chunk_size'));
|
||||||
|
|
||||||
if(bFirstChunk===true) self.tmp('$PostList').empty();
|
if(bFirstChunk===true) self.tmp('$PostList').empty();
|
||||||
self.tmp('$PostList').append($Posts.children());
|
self.tmp('$PostList').append($Posts.children());
|
||||||
@@ -751,7 +755,8 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
|||||||
self.tmp('updatable', true);
|
self.tmp('updatable', true);
|
||||||
}, {
|
}, {
|
||||||
id_project: self.vars(['project', 'id']),
|
id_project: self.vars(['project', 'id']),
|
||||||
chunk: self.tmp('news_chunk')
|
chunk: self.tmp('news_chunk'),
|
||||||
|
id: self.tmp('ref_id')
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user