From 73c2a8f9edee25e55d34edbe40897bc4338d9cbf Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sun, 4 May 2014 20:58:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B0=D1=80=D1=88?= =?UTF-8?q?=D1=80=D1=83=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/IndexController.php | 15 ++++++- ground/controllers/JsonController.php | 51 ++++++++++++++++++++++ ground/models/Route.php | 17 ++++++++ ground/views/indexTemplate.php | 21 ++++++++- public/css/style.css | 6 ++- public/js/main.js | 60 ++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 ground/models/Route.php diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index 4cf5910..09c24ff 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -22,19 +22,30 @@ class IndexController extends Controller $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); App::setConfig('title', $res['pointsCount'].' или даже больше поводов не сидеть дома'); self::render('indexTemplate.php', array( 'categories' => $category->getAll('', 'ord'), 'user' => App::$user, + 'routes' => $routes, )); } static function actionUser() { - print $_SERVER['HTTP_HOST']; - var_dump(App::$user->id, App::$user->nick, App::$user->name, App::$user->network); + $routes = new Route(); + $routes = $routes->getByAuthor(App::$user->id); + + var_dump($routes); } static function actionLogout() diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 3ca4c4c..fe66c4f 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -111,4 +111,55 @@ class JsonController extends Controller 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(); + } + } + + } diff --git a/ground/models/Route.php b/ground/models/Route.php new file mode 100644 index 0000000..6773397 --- /dev/null +++ b/ground/models/Route.php @@ -0,0 +1,17 @@ +_tableName_ = 'routes'; + parent::__construct(); + } + + function getByAuthor($authorId) + { + return $this->getAll('`author` = '.$authorId); + } +} + diff --git a/ground/views/indexTemplate.php b/ground/views/indexTemplate.php index 96b2196..f2eba0e 100644 --- a/ground/views/indexTemplate.php +++ b/ground/views/indexTemplate.php @@ -4,9 +4,25 @@
+ + +
+ + +