Support geo located images & videos
This commit is contained in:
29
inc/Spot.php
29
inc/Spot.php
@@ -87,7 +87,7 @@ class Spot extends Main
|
||||
Feed::SPOT_TABLE => array('ref_spot_id', 'name', 'model'),
|
||||
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to'),
|
||||
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone'),
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'width', 'height', 'rotate', 'comment'),
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'comment'),
|
||||
User::USER_TABLE => array('name', 'email', 'gravatar', 'language', 'timezone', 'active', 'clearance'),
|
||||
Map::MAP_TABLE => array('codename', 'pattern', 'token', 'tile_size', 'min_zoom', 'max_zoom', 'attribution'),
|
||||
Map::MAPPING_TABLE => array(Db::getId(Map::MAP_TABLE) , Db::getId(Project::PROJ_TABLE))
|
||||
@@ -110,6 +110,7 @@ class Spot extends Main
|
||||
'last_update' => "TIMESTAMP DEFAULT 0",
|
||||
'latitude' => "DECIMAL(7,5)",
|
||||
'longitude' => "DECIMAL(8,5)",
|
||||
'altitude' => "SMALLINT",
|
||||
'model' => "VARCHAR(20)",
|
||||
'name' => "VARCHAR(100)",
|
||||
'pattern' => "VARCHAR(200) NOT NULL",
|
||||
@@ -121,7 +122,7 @@ class Spot extends Main
|
||||
'site_time' => "TIMESTAMP DEFAULT 0", //DEFAULT 0 removes auto-set to current time
|
||||
'status' => "VARCHAR(10)",
|
||||
'taken_on' => "TIMESTAMP DEFAULT 0",
|
||||
'timezone' => "CHAR(64) NOT NULL", //see mysql.time_zone_name
|
||||
'timezone' => "CHAR(64) NOT NULL", //see mysql.time_zone_name
|
||||
'token' => "VARCHAR(4096)",
|
||||
'type' => "VARCHAR(20)",
|
||||
'unix_time' => "INT",
|
||||
@@ -269,23 +270,24 @@ class Spot extends Main
|
||||
public function getMarkers($asMessageIds=array(), $asMediaIds=array(), $bInternal=false)
|
||||
{
|
||||
$asMessages = $this->getSpotMessages($asMessageIds);
|
||||
$asGeoMedias = array();
|
||||
usort($asMessages, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
$bHasMsg = !empty($asMessages);
|
||||
|
||||
//Add medias
|
||||
if(!empty($asMessages)) {
|
||||
$asMedias = $this->getMedias('taken_on', $asMediaIds);
|
||||
usort($asMedias, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
$asMedias = $this->getMedias('taken_on', $asMediaIds);
|
||||
usort($asMedias, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
|
||||
//Assign medias to closest message
|
||||
$iIndex = 0;
|
||||
$iMaxIndex = count($asMessages) - 1;
|
||||
foreach($asMedias as $asMedia) {
|
||||
while($iIndex <= $iMaxIndex && $asMedia['unix_time'] > $asMessages[$iIndex]['unix_time']) {
|
||||
$iIndex++;
|
||||
}
|
||||
//Assign medias to closest message
|
||||
$iIndex = 0;
|
||||
$iMaxIndex = count($asMessages) - 1;
|
||||
foreach($asMedias as $asMedia) {
|
||||
if($asMedia['latitude']!='' && $asMedia['longitude']!='') $asGeoMedias[] = $asMedia;
|
||||
elseif($bHasMsg) {
|
||||
while($iIndex <= $iMaxIndex && $asMedia['unix_time'] > $asMessages[$iIndex]['unix_time']) $iIndex++;
|
||||
|
||||
//All medias before first message or after last message are assigned to first/last message respectively
|
||||
if($iIndex == 0) $iMsgIndex = $iIndex;
|
||||
if($iIndex == 0) $iMsgIndex = $iIndex;
|
||||
elseif($iIndex > $iMaxIndex) $iMsgIndex = $iMaxIndex;
|
||||
else {
|
||||
$iHalfWayPoint = ($asMessages[$iIndex - 1]['unix_time'] + $asMessages[$iIndex]['unix_time'])/2;
|
||||
@@ -302,6 +304,7 @@ class Spot extends Main
|
||||
|
||||
$asResult = array(
|
||||
'messages' => $asMessages,
|
||||
'medias' => $asGeoMedias,
|
||||
'maps' => $this->oMap->getProjectMaps($this->oProject->getProjectId()),
|
||||
'last_update' => $asLastUpdate
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user