add message minimaps
This commit is contained in:
85
inc/spot.php
85
inc/spot.php
@@ -30,10 +30,10 @@ class Spot extends Main
|
||||
protected function install()
|
||||
{
|
||||
//Install DB
|
||||
$this->oMySql->install();
|
||||
$this->oDb->install();
|
||||
|
||||
//Add feed
|
||||
//$this->oMySql->insertRow(self::FEED_TABLE, array('ref_feed_id'=>self::FEED_ID));
|
||||
//$this->oDb->insertRow(self::FEED_TABLE, array('ref_feed_id'=>self::FEED_ID));
|
||||
}
|
||||
|
||||
protected function getSqlOptions()
|
||||
@@ -42,8 +42,8 @@ class Spot extends Main
|
||||
(
|
||||
'tables' => array
|
||||
(
|
||||
self::MSG_TABLE => array('ref_msg_id', MySqlManager::getId(self::FEED_TABLE), 'type', 'latitude', 'longitude', 'timestamp', 'unix_timestamp', 'content', 'battery_state'),
|
||||
self::FEED_TABLE => array('ref_feed_id', MySqlManager::getId(self::SPOT_TABLE), 'name', 'description', 'status'),
|
||||
self::MSG_TABLE => array('ref_msg_id', Db::getId(self::FEED_TABLE), 'type', 'latitude', 'longitude', 'timestamp', 'unix_timestamp', 'content', 'battery_state'),
|
||||
self::FEED_TABLE => array('ref_feed_id', Db::getId(self::SPOT_TABLE), 'name', 'description', 'status'),
|
||||
self::SPOT_TABLE => array('ref_spot_id', 'name', 'model'),
|
||||
self::POST_TABLE => array('name', 'content')
|
||||
),
|
||||
@@ -80,11 +80,20 @@ class Spot extends Main
|
||||
);
|
||||
}
|
||||
|
||||
public function getMainPage()
|
||||
public function getMainPage($asGlobalVars = array(), $sMainPage = 'index', $asMainPageTags=array())
|
||||
{
|
||||
return parent::getMainPage(array('vars'=>array( 'feed_id' => self::FEED_ID,
|
||||
'chunk_size'=> self::FEED_CHUNK_SIZE,
|
||||
'mode' => Settings::MODE)));
|
||||
return parent::getMainPage(
|
||||
array(
|
||||
'vars' => array(
|
||||
'feed_id' => self::FEED_ID,
|
||||
'chunk_size'=> self::FEED_CHUNK_SIZE,
|
||||
'mode' => Settings::MODE,
|
||||
'google_api'=> Settings::GOOGLE_MAPS_API_KEY
|
||||
)
|
||||
),
|
||||
'index',
|
||||
array('GOOGLE_MAPS_API_KEY' => Settings::GOOGLE_MAPS_API_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
/* Getting & Storing messages */
|
||||
@@ -107,30 +116,34 @@ class Spot extends Main
|
||||
//Update Spot Info
|
||||
$asFirstMsg = array_values($asMsgs)[0];
|
||||
$asSpotInfo = array('ref_spot_id'=>$asFirstMsg['messengerId'], 'name'=>$asFirstMsg['messengerName'], 'model'=>$asFirstMsg['modelId']);
|
||||
$iSpotId = $this->oMySql->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id'));
|
||||
$iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id'));
|
||||
|
||||
//Update Feed Info
|
||||
$asFeedInfo = array('ref_feed_id' => $sRefFeedId,
|
||||
MySqlManager::getId(self::SPOT_TABLE) => $iSpotId,
|
||||
'name' => $asFeed['name'],
|
||||
'description' => $asFeed['description'],
|
||||
'status' => $asFeed['status'],
|
||||
'led' => date(MySqlManager::MYSQL_TIMESTAMP)); //update with current time
|
||||
$iFeedId = $this->oMySql->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id'));
|
||||
$asFeedInfo = array(
|
||||
'ref_feed_id' => $sRefFeedId,
|
||||
Db::getId(self::SPOT_TABLE) => $iSpotId,
|
||||
'name' => $asFeed['name'],
|
||||
'description' => $asFeed['description'],
|
||||
'status' => $asFeed['status'],
|
||||
'led' => date(Db::MYSQL_TIMESTAMP) //update with current time
|
||||
);
|
||||
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id'));
|
||||
|
||||
//Update Messages
|
||||
foreach($asMsgs as $asMsg)
|
||||
{
|
||||
$asMsg = array( 'ref_msg_id' => $asMsg['id'],
|
||||
MySqlManager::getId(self::FEED_TABLE) => $iFeedId,
|
||||
'type' => $asMsg['messageType'],
|
||||
'latitude' => $asMsg['latitude'],
|
||||
'longitude' => $asMsg['longitude'],
|
||||
'timestamp' => date(MySqlManager::MYSQL_TIMESTAMP, strtotime($asMsg['dateTime'])), //Stored in Local Time
|
||||
'unix_timestamp' => $asMsg['unixTime'], //Stored in UNIX time
|
||||
'content' => $asMsg['messageContent'],
|
||||
'battery_state' => $asMsg['batteryState']);
|
||||
$this->oMySql->insertUpdateRow(self::MSG_TABLE, $asMsg, array('ref_msg_id'));
|
||||
$asMsg = array(
|
||||
'ref_msg_id' => $asMsg['id'],
|
||||
Db::getId(self::FEED_TABLE) => $iFeedId,
|
||||
'type' => $asMsg['messageType'],
|
||||
'latitude' => $asMsg['latitude'],
|
||||
'longitude' => $asMsg['longitude'],
|
||||
'timestamp' => date(Db::MYSQL_TIMESTAMP, strtotime($asMsg['dateTime'])), //Stored in Local Time
|
||||
'unix_timestamp' => $asMsg['unixTime'], //Stored in UNIX time
|
||||
'content' => $asMsg['messageContent'],
|
||||
'battery_state' => $asMsg['batteryState']
|
||||
);
|
||||
$this->oDb->insertUpdateRow(self::MSG_TABLE, $asMsg, array('ref_msg_id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,16 +152,16 @@ class Spot extends Main
|
||||
{
|
||||
//Adding another point to test
|
||||
/*
|
||||
$test = $this->oMySql->selectRow(self::MSG_TABLE, 1);
|
||||
$test = $this->oDb->selectRow(self::MSG_TABLE, 1);
|
||||
unset($test['id_message']);
|
||||
$test['ref_msg_id'] = $test['ref_msg_id'] + 1;
|
||||
$test['latitude'] = '-41.4395';
|
||||
$test['longitude'] = '172.1936';
|
||||
$this->oMySql->insertUpdateRow(self::MSG_TABLE, $test, array('ref_msg_id'));
|
||||
$this->oDb->insertUpdateRow(self::MSG_TABLE, $test, array('ref_msg_id'));
|
||||
*/
|
||||
|
||||
//Check last message & update feed if necessary (max once a day)
|
||||
$sLastMsg = $this->oMySql->selectValue(self::FEED_TABLE, 'led', array('ref_feed_id'=>$sRefFeedId));
|
||||
$sLastMsg = $this->oDb->selectValue(self::FEED_TABLE, 'led', array('ref_feed_id'=>$sRefFeedId));
|
||||
if(Settings::MODE!=self::MODE_HISTO && mb_substr($sLastMsg, 0, 10) != date('Y-m-d')) $this->updateFeed($sRefFeedId);
|
||||
|
||||
//Extract messages
|
||||
@@ -161,7 +174,7 @@ class Spot extends Main
|
||||
|
||||
private function getSpotMessages()
|
||||
{
|
||||
$asMessages = $this->oMySql->selectRows(array('from'=>self::MSG_TABLE, 'orderBy'=>array('timestamp'=>'ASC')));
|
||||
$asMessages = $this->oDb->selectRows(array('from'=>self::MSG_TABLE, 'orderBy'=>array('timestamp'=>'ASC')));
|
||||
foreach($asMessages as $iKey=>$asMessage)
|
||||
{
|
||||
$iUnixTimeStamp = strtotime($asMessage['timestamp']);
|
||||
@@ -179,10 +192,10 @@ class Spot extends Main
|
||||
$asMessages = $this->getSpotMessages();
|
||||
foreach($asMessages as $asMessage)
|
||||
{
|
||||
$iId = ($asMessage['unix_timestamp']*-1).'.0'.$asMessage[MySqlManager::getId(self::MSG_TABLE)];
|
||||
$iId = ($asMessage['unix_timestamp']*-1).'.0'.$asMessage[Db::getId(self::MSG_TABLE)];
|
||||
$asFeed[$iId] = $asMessage;// array('type'=>'message', 'time'=>$asMessage['relative_time'], 'text'=>$asMessage['relative_time']);
|
||||
$asFeed[$iId]['type'] = 'message';
|
||||
$asFeed[$iId]['id'] = $asMessage[MySqlManager::getId(self::MSG_TABLE)];
|
||||
$asFeed[$iId]['id'] = $asMessage[Db::getId(self::MSG_TABLE)];
|
||||
}
|
||||
|
||||
//Pictures
|
||||
@@ -209,15 +222,15 @@ class Spot extends Main
|
||||
}
|
||||
|
||||
//Post
|
||||
$asPosts = $this->oMySql->selectRows(array('from'=>self::POST_TABLE));
|
||||
$asPosts = $this->oDb->selectRows(array('from'=>self::POST_TABLE));
|
||||
foreach($asPosts as $asPost)
|
||||
{
|
||||
$iUnixTimeStamp = strtotime($asPost['led']);
|
||||
$iId = ($iUnixTimeStamp*-1).'.2'.$asPost[MySqlManager::getId(self::POST_TABLE)];
|
||||
$iId = ($iUnixTimeStamp*-1).'.2'.$asPost[Db::getId(self::POST_TABLE)];
|
||||
$asFeed[$iId] = array('name'=>Toolbox::mb_ucwords($asPost['name']), 'post'=>$asPost['content'], 'type'=>'post');;
|
||||
$asFeed[$iId]['relative_time'] = Toolbox::getDateTimeDesc($iUnixTimeStamp);
|
||||
$asFeed[$iId]['formatted_time'] = date(self::FORMAT_TIME, $iUnixTimeStamp);
|
||||
//$asFeed[$iId]['id'] = $asPost[MySqlManager::getId(self::POST_TABLE)];
|
||||
//$asFeed[$iId]['id'] = $asPost[Db::getId(self::POST_TABLE)];
|
||||
}
|
||||
|
||||
ksort($asFeed);
|
||||
@@ -231,7 +244,7 @@ class Spot extends Main
|
||||
public function addPost($sName, $sPost)
|
||||
{
|
||||
$asData = array('name'=>mb_strtolower(trim($sName)), 'content'=>trim($sPost));
|
||||
$iPostId = $this->oMySql->insertRow(self::POST_TABLE, $asData);
|
||||
$iPostId = $this->oDb->insertRow(self::POST_TABLE, $asData);
|
||||
return self::getJsonResult(($iPostId > 0), '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user