Improve admin page (add new projects)
This commit is contained in:
73
inc/feed.php
73
inc/feed.php
@@ -2,10 +2,7 @@
|
||||
|
||||
/**
|
||||
* Feed Class
|
||||
* Also takes care of spot (device) & messages
|
||||
*
|
||||
* To add a new feed, create a new records in the feed table:
|
||||
* INSERT INTO feeds (ref_feed_id, id_spot, id_project) VALUES ('<feed_id>', '<related_spot_id>', '<related_project_id>');
|
||||
* Also manages spots (devices) & messages
|
||||
*/
|
||||
class Feed extends PhpObject {
|
||||
|
||||
@@ -29,24 +26,68 @@ class Feed extends PhpObject {
|
||||
private $sRefFeedId;
|
||||
private $iLastUpdate;
|
||||
|
||||
public function __construct(Db &$oDb, $iFeedId) {
|
||||
public function __construct(Db &$oDb, $iFeedId=0) {
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setFeedId($iFeedId);
|
||||
if($iFeedId > 0) $this->setFeedId($iFeedId);
|
||||
}
|
||||
|
||||
public function getFeedId() {
|
||||
return $this->iFeedId;
|
||||
}
|
||||
|
||||
public function setFeedId($iFeedId) {
|
||||
$this->iFeedId = $iFeedId;
|
||||
$asFeed = $this->oDb->selectRow(self::FEED_TABLE, $this->iFeedId);
|
||||
$asFeed = $this->getFeed();
|
||||
$this->sRefFeedId = $asFeed['ref_feed_id'];
|
||||
$this->iLastUpdate = strtotime($asFeed['last_update']);
|
||||
}
|
||||
|
||||
public function createFeedId($oProjectId) {
|
||||
$this->setFeedId($this->oDb->insertRow(self::FEED_TABLE, array(
|
||||
Db::getId(Project::PROJ_TABLE) => $oProjectId,
|
||||
'status' => 'INACTIVE'
|
||||
)));
|
||||
return $this->getFeedId();
|
||||
}
|
||||
|
||||
public function setRefFeedId($sRefFeedId) {
|
||||
return $this->updateField('ref_feed_id', $sRefFeedId);
|
||||
}
|
||||
|
||||
public function setSpotId($iSpotId) {
|
||||
return $this->updateField(Db::getId(self::SPOT_TABLE), $iSpotId);
|
||||
}
|
||||
|
||||
public function setProjectId($iProjectId) {
|
||||
return $this->updateField(Db::getId(Project::PROJ_TABLE), $iProjectId);
|
||||
}
|
||||
|
||||
public function getSpots() {
|
||||
$asSpots = $this->oDb->selectRows(array('from'=>self::SPOT_TABLE));
|
||||
foreach($asSpots as &$asSpot) $asSpot['id'] = $asSpot[Db::getId(self::SPOT_TABLE)];
|
||||
return $asSpots;
|
||||
}
|
||||
|
||||
public function getFeeds($iFeedId=0) {
|
||||
$asInfo = array('from'=>self::FEED_TABLE);
|
||||
if($iFeedId > 0) $asInfo['constraint'] = array(Db::getId(self::FEED_TABLE)=>$iFeedId);
|
||||
$asFeeds = $this->oDb->selectRows($asInfo);
|
||||
|
||||
foreach($asFeeds as &$asFeed) $asFeed['id'] = $asFeed[Db::getId(self::FEED_TABLE)];
|
||||
return $asFeeds;
|
||||
}
|
||||
|
||||
public function getFeed() {
|
||||
$asFeeds = $this->getFeeds($this->getFeedId());
|
||||
return array_shift($asFeeds);
|
||||
}
|
||||
|
||||
public function getMessages($asActivePeriod = array()) {
|
||||
$asInfo = array(
|
||||
'select' => array('id_message', 'ref_msg_id', 'type', 'latitude', 'longitude', 'site_time', 'unix_time'),
|
||||
'from' => self::MSG_TABLE,
|
||||
'constraint'=> array(Db::getId(self::FEED_TABLE) => $this->iFeedId),
|
||||
'constraint'=> array(Db::getId(self::FEED_TABLE) => $this->getFeedId()),
|
||||
'constOpe' => array(Db::getId(self::FEED_TABLE) => "="),
|
||||
'orderBy' => array('site_time'=>'ASC')
|
||||
);
|
||||
@@ -114,12 +155,22 @@ class Feed extends PhpObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
else $this->oDb->updateRow(self::FEED_TABLE, $this->iFeedId, array('last_update'=>$sLastUpdate));
|
||||
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array('last_update'=>$sLastUpdate));
|
||||
}
|
||||
|
||||
private function retrieveFeed() {
|
||||
$sUrl = self::FEED_HOOK.$this->sRefFeedId.self::FEED_TYPE_JSON;
|
||||
$sContent = file_get_contents($sUrl);
|
||||
$sContent = '[]';
|
||||
if($this->sRefFeedId !='') {
|
||||
$sUrl = self::FEED_HOOK.$this->sRefFeedId.self::FEED_TYPE_JSON;
|
||||
$sContent = file_get_contents($sUrl);
|
||||
}
|
||||
return json_decode($sContent, true);
|
||||
}
|
||||
|
||||
private function updateField($sField, $oValue) {
|
||||
$bResult = ($this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array($sField=>$oValue)) > 0);
|
||||
$this->setFeedId($this->getFeedId());
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ class Project extends PhpObject {
|
||||
private $asActive;
|
||||
private $asGeo;
|
||||
|
||||
public function __construct(Db &$oDb) {
|
||||
public function __construct(Db &$oDb, $iProjectId=0) {
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
if($iProjectId > 0) $this->setProjectId($iProjectId);
|
||||
}
|
||||
|
||||
public function getProjectId() {
|
||||
@@ -64,10 +65,23 @@ class Project extends PhpObject {
|
||||
$this->setProjectInfo();
|
||||
}
|
||||
|
||||
public function createProjectId() {
|
||||
$this->setProjectId($this->oDb->insertRow(self::PROJ_TABLE, array('timezone'=>Settings::TIMEZONE)));
|
||||
return $this->getProjectId();
|
||||
}
|
||||
|
||||
public function getMode() {
|
||||
return $this->sMode;
|
||||
}
|
||||
|
||||
public function getProjectName() {
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
public function setProjectName($sName) {
|
||||
return $this->updateField('name', $sName);
|
||||
}
|
||||
|
||||
public function getProjectCodeName() {
|
||||
return $this->sCodeName;
|
||||
}
|
||||
@@ -130,7 +144,7 @@ class Project extends PhpObject {
|
||||
case 2: $asProject['mode'] = self::MODE_HISTO; break;
|
||||
}
|
||||
|
||||
if(!Converter::isGeoJsonValid($sCodeName)) Converter::convertToGeoJson($sCodeName);
|
||||
if($sCodeName!= '' && !Converter::isGeoJsonValid($sCodeName)) Converter::convertToGeoJson($sCodeName);
|
||||
|
||||
$asProject['geofilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, GeoJson::EXT));
|
||||
$asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, Gpx::EXT));
|
||||
|
||||
73
inc/spot.php
73
inc/spot.php
@@ -338,30 +338,73 @@ class Spot extends Main
|
||||
}
|
||||
|
||||
public function getAdminSettings() {
|
||||
return self::getJsonResult(true, '', array('projects'=>$this->oProject->getProjects()));
|
||||
$oFeed = new Feed($this->oDb);
|
||||
return self::getJsonResult(true, '', array(
|
||||
'project' => $this->oProject->getProjects(),
|
||||
'feed' => $oFeed->getFeeds(),
|
||||
'spot' => $oFeed->getSpots()
|
||||
));
|
||||
}
|
||||
|
||||
public function setAdminSettings($sField, $sValue) {
|
||||
public function setAdminSettings($sType, $iId, $sField, $sValue) {
|
||||
$bSuccess = false;
|
||||
$sDesc = '';
|
||||
|
||||
switch($sField) {
|
||||
case 'codename':
|
||||
$bSuccess = $this->oProject->setProjectCodeName($sValue);
|
||||
switch($sType) {
|
||||
case 'project':
|
||||
$oProject = new Project($this->oDb, $iId);
|
||||
switch($sField) {
|
||||
case 'name':
|
||||
$bSuccess = $oProject->setProjectName($sValue);
|
||||
break;
|
||||
case 'codename':
|
||||
$bSuccess = $oProject->setProjectCodeName($sValue);
|
||||
break;
|
||||
case 'active_from':
|
||||
$bSuccess = $oProject->setActivePeriod($sValue.' 00:00:00', 'from');
|
||||
break;
|
||||
case 'active_to':
|
||||
$bSuccess = $oProject->setActivePeriod($sValue.' 23:59:59', 'to');
|
||||
break;
|
||||
case 'timezone':
|
||||
$bSuccess = $oProject->setTimeZone($sValue);
|
||||
break;
|
||||
}
|
||||
$asResult = $oProject->getProject();
|
||||
break;
|
||||
case 'active_from':
|
||||
$bSuccess = $this->oProject->setActivePeriod($sValue.' 00:00:00', 'from');
|
||||
break;
|
||||
case 'active_to':
|
||||
$bSuccess = $this->oProject->setActivePeriod($sValue.' 23:59:59', 'to');
|
||||
break;
|
||||
case 'timezone':
|
||||
$bSuccess = $this->oProject->setTimeZone($sValue);
|
||||
case 'feed':
|
||||
case 'spot':
|
||||
$oFeed = new Feed($this->oDb, $iId);
|
||||
switch($sField) {
|
||||
case 'ref_feed_id':
|
||||
$bSuccess = $oFeed->setRefFeedId($sValue);
|
||||
break;
|
||||
case 'spot_id':
|
||||
$bSuccess = $oFeed->setSpotId($sValue);
|
||||
break;
|
||||
case 'project_id':
|
||||
$bSuccess = $oFeed->setProjectId($sValue);
|
||||
break;
|
||||
}
|
||||
$asResult = $oFeed->getFeed();
|
||||
break;
|
||||
}
|
||||
if(!$bSuccess) $sDesc = Mask::LANG_PREFIX.'error_commit_db';
|
||||
|
||||
return self::getJsonResult($bSuccess, $sDesc, array('values'=>$this->oProject->getProject()));
|
||||
return self::getJsonResult($bSuccess, $sDesc, array($sType=>array($asResult)));
|
||||
}
|
||||
|
||||
public function createProject() {
|
||||
$oProject = new Project($this->oDb);
|
||||
$iNewProjectId = $oProject->createProjectId();
|
||||
|
||||
$oFeed = new Feed($this->oDb);
|
||||
$oFeed->createFeedId($iNewProjectId);
|
||||
|
||||
return self::getJsonResult($iNewProjectId>0, '', array(
|
||||
'project' => array($oProject->getProject()),
|
||||
'feed' => array($oFeed->getFeed())
|
||||
));
|
||||
}
|
||||
|
||||
public function convertGpxToGeojson($sGeoFileName) {
|
||||
@@ -385,7 +428,7 @@ class Spot extends Main
|
||||
//Seconds
|
||||
$fSecond = round($dLeft * 3600, 1);
|
||||
|
||||
return $iDegree.'°'.$iMinute.'\''.$fSecond.'"'.$sDirection;
|
||||
return $iDegree.'°'.$iMinute."'".$fSecond.'"'.$sDirection;
|
||||
}
|
||||
|
||||
public function getTimeFormat($iTime) {
|
||||
|
||||
Reference in New Issue
Block a user