Первый вариант сохранения маршрутов
This commit is contained in:
parent
202a2ffb47
commit
73c2a8f9ed
|
|
@ -22,19 +22,30 @@ class IndexController extends Controller
|
||||||
|
|
||||||
$category = new Category();
|
$category = new Category();
|
||||||
|
|
||||||
|
$routes = array();
|
||||||
|
if (App::$user)
|
||||||
|
{
|
||||||
|
$routes = new Route();
|
||||||
|
$routes = $routes->getByAuthor(App::$user->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$res = App::$DB->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC);
|
$res = App::$DB->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC);
|
||||||
App::setConfig('title', $res['pointsCount'].' или даже больше поводов не сидеть дома');
|
App::setConfig('title', $res['pointsCount'].' или даже больше поводов не сидеть дома');
|
||||||
|
|
||||||
self::render('indexTemplate.php', array(
|
self::render('indexTemplate.php', array(
|
||||||
'categories' => $category->getAll('', 'ord'),
|
'categories' => $category->getAll('', 'ord'),
|
||||||
'user' => App::$user,
|
'user' => App::$user,
|
||||||
|
'routes' => $routes,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function actionUser()
|
static function actionUser()
|
||||||
{
|
{
|
||||||
print $_SERVER['HTTP_HOST'];
|
$routes = new Route();
|
||||||
var_dump(App::$user->id, App::$user->nick, App::$user->name, App::$user->network);
|
$routes = $routes->getByAuthor(App::$user->id);
|
||||||
|
|
||||||
|
var_dump($routes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function actionLogout()
|
static function actionLogout()
|
||||||
|
|
|
||||||
|
|
@ -111,4 +111,55 @@ class JsonController extends Controller
|
||||||
print json_encode($errors);
|
print json_encode($errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function actionSaveRoute()
|
||||||
|
{
|
||||||
|
$request = array(
|
||||||
|
'author' => App::$user->id,
|
||||||
|
'date' => time(),
|
||||||
|
'name' => $_POST['name'],
|
||||||
|
'points' => json_encode($_POST['points']),
|
||||||
|
);
|
||||||
|
|
||||||
|
$route = new Route();
|
||||||
|
$route = $route->add($request);
|
||||||
|
|
||||||
|
self::renderPartial('json.php', $route->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function actionRoute()
|
||||||
|
{
|
||||||
|
$id = (int) App::getParam('id');
|
||||||
|
if ($id)
|
||||||
|
{
|
||||||
|
$route = new Route();
|
||||||
|
$route = $route->getByPK($id);
|
||||||
|
self::renderPartial('json.php', $route->points);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function actionDeleteRoute()
|
||||||
|
{
|
||||||
|
$id = (int) App::getParam('id');
|
||||||
|
if ($id && App::$user)
|
||||||
|
{
|
||||||
|
$route = new Route();
|
||||||
|
$route = $route->getByPK($id);
|
||||||
|
|
||||||
|
if ($route->author == App::$user->id)
|
||||||
|
{
|
||||||
|
$route->delete($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::renderPartial('json.php', true);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Route extends Model
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->_tableName_ = 'routes';
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getByAuthor($authorId)
|
||||||
|
{
|
||||||
|
return $this->getAll('`author` = '.$authorId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -4,9 +4,25 @@
|
||||||
<div class="popover-content">
|
<div class="popover-content">
|
||||||
<div id="wayPoints"></div>
|
<div id="wayPoints"></div>
|
||||||
<button class="btn btn-default" type="button" onclick="$('#routeWindow').toggle(200)">Скрыть</button>
|
<button class="btn btn-default" type="button" onclick="$('#routeWindow').toggle(200)">Скрыть</button>
|
||||||
|
<?php if ($user): ?>
|
||||||
|
<button class="btn btn-default" onclick="saveRoute()"><span class="glyphicon glyphicon-cloud-upload"></span> Сохранить</button>
|
||||||
|
<?php endif; ?>
|
||||||
<button class="btn btn-info" onclick="buildRoute()"><span class="glyphicon glyphicon-send"></span> Проложить</button>
|
<button class="btn btn-info" onclick="buildRoute()"><span class="glyphicon glyphicon-send"></span> Проложить</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if ($user && $routes): ?>
|
||||||
|
<div id="myRoutesWindow" class="popover fade in" style="display: none; position: absolute; top: 50px; right: 7px; left: auto; max-width: none;">
|
||||||
|
<h3 class="popover-title">Мои маршруты</h3>
|
||||||
|
<div class="popover-content">
|
||||||
|
<div id="routes">
|
||||||
|
<?php foreach ($routes as $route) : ?>
|
||||||
|
<div class="route" onclick="loadRoute(<?= $route['id'] ?>)"><span onclick="deleteRoute(<?= $route['id'] ?>);$(this).parent().remove();event.stopPropagation();">×</span> <?= $route['name'] ?></div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-default" type="button" onclick="$('#myRoutesWindow').toggle(200)">Скрыть</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<table width="100%">
|
<table width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -22,7 +38,10 @@
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-default" type="button" onclick="$('#routeWindow').toggle(200)"><span class="glyphicon glyphicon-align-justify"></span> Маршрут</button>
|
<button class="btn btn-default" type="button" onclick="$('#myRoutesWindow').hide(200);$('#routeWindow').toggle(200)"><span class="glyphicon glyphicon-align-justify"></span> Маршрут</button>
|
||||||
|
<?php if ($user): ?>
|
||||||
|
<button class="btn btn-default" type="button" onclick="$('#routeWindow').hide(200);$('#myRoutesWindow').toggle(200);"><span class="glyphicon glyphicon-cloud-download"></span> Мои маршруты</button>
|
||||||
|
<?php endif; ?>
|
||||||
<button class="btn btn-default" type="button" onclick="showMeOnTheMap()"><span class="glyphicon glyphicon-screenshot"></span> Я на карте</button>
|
<button class="btn btn-default" type="button" onclick="showMeOnTheMap()"><span class="glyphicon glyphicon-screenshot"></span> Я на карте</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
|
|
|
||||||
|
|
@ -25,4 +25,8 @@ div#footer table{}
|
||||||
|
|
||||||
#wayPoints {margin-bottom: 10px;}
|
#wayPoints {margin-bottom: 10px;}
|
||||||
#wayPoints .wayPoint {cursor: pointer; border: solid 1px #999; padding: 2px 5px; margin-bottom: 3px;}
|
#wayPoints .wayPoint {cursor: pointer; border: solid 1px #999; padding: 2px 5px; margin-bottom: 3px;}
|
||||||
#wayPoints .wayPoint span {font-weight: bold; color: red;}
|
#wayPoints .wayPoint span {font-weight: bold; color: red;}
|
||||||
|
|
||||||
|
#routes {margin-bottom: 10px;}
|
||||||
|
#routes .route {cursor: pointer; border: solid 1px #999; padding: 2px 5px; margin-bottom: 3px;}
|
||||||
|
#routes .route span {font-weight: bold; color: red;}
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,66 @@ function buildRoute()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveRoute()
|
||||||
|
{
|
||||||
|
wayPoints = Array();
|
||||||
|
name = prompt('Как назвать маршрут?', 'Мой маршрут');
|
||||||
|
|
||||||
|
$('#wayPoints div').each(function(i, el)
|
||||||
|
{
|
||||||
|
wayPoints.push($(el).attr('pointId'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (name && name != '')
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/json/saveroute/",
|
||||||
|
data: {
|
||||||
|
name: name,
|
||||||
|
points: wayPoints
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
console.log(data);
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadRoute(id)
|
||||||
|
{
|
||||||
|
$('#myRoutesWindow').hide(200);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/json/route/id/" + id,
|
||||||
|
success: function(data)
|
||||||
|
{
|
||||||
|
$('#wayPoints').text('');
|
||||||
|
|
||||||
|
response = JSON.parse(data);
|
||||||
|
for (var k in response)
|
||||||
|
{
|
||||||
|
addToRoute(response[k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRoute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRoute(id)
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
url: "/json/deleteroute/id/" + id,
|
||||||
|
success: function(data)
|
||||||
|
{
|
||||||
|
console.log('Route '+id+' was removed.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function addToRoute(id)
|
function addToRoute(id)
|
||||||
{
|
{
|
||||||
$('#wayPoints').append('<div pointid="' + id + '" class="wayPoint"><span onclick="$(this).parent().remove()">×</span> ' + points[id].properties.get('hintContent') + '</div>');
|
$('#wayPoints').append('<div pointid="' + id + '" class="wayPoint"><span onclick="$(this).parent().remove()">×</span> ' + points[id].properties.get('hintContent') + '</div>');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue