From c803a185343b4a96be78c190642c3c5b8ad2d971 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sat, 4 Jul 2015 16:10:45 +0300 Subject: [PATCH] ADD use dateEdit in JSON request --- ground/controllers/JsonController.php | 5 +++-- ground/models/Point.php | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 838b875..f3322b4 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -11,15 +11,16 @@ class JsonController extends Controller if (App::$user && App::$user->isAdmin == 1) { $points = Point::model()->getAll(); } else { + $minEditDate = isset($_GET['time']) ? (int)$_GET['time'] : 0; if (!isset($_GET['bounds']) || !isset($_GET['bounds'][0]) || !isset($_GET['bounds'][1]) || !isset($_GET['bounds'][2]) || !isset($_GET['bounds'][3])) { - $points = Point::model()->getAllPublished(false); + $points = Point::model()->getAllPublished(false, $minEditDate); } else { $_GET['bounds'][0] = floatval($_GET['bounds'][0]); $_GET['bounds'][1] = floatval($_GET['bounds'][1]); $_GET['bounds'][2] = floatval($_GET['bounds'][2]); $_GET['bounds'][3] = floatval($_GET['bounds'][3]); - $points = Point::model()->getAllPublished($_GET['bounds']); + $points = Point::model()->getAllPublished($_GET['bounds'], $minEditDate); } } diff --git a/ground/models/Point.php b/ground/models/Point.php index 3ce717d..e002273 100644 --- a/ground/models/Point.php +++ b/ground/models/Point.php @@ -89,18 +89,19 @@ class Point extends Model return $this->getAll(array('where' => "`name` LIKE '%$search%' OR `description` LIKE '%$search%'", 'limit' => 20)); } - public function getAllPublished($bounds = false) + public function getAllPublished($bounds = false, $minEditDate = 0) { $userId = App::$user ? App::$user->id : 0; + $minEditDate = intval($minEditDate); if ($bounds) { $b0 = $bounds[0]<$bounds[2]?$bounds[0]:$bounds[2]; $b2 = $bounds[0]<$bounds[2]?$bounds[2]:$bounds[0]; $b1 = $bounds[1]<$bounds[3]?$bounds[1]:$bounds[3]; $b3 = $bounds[1]<$bounds[3]?$bounds[3]:$bounds[1]; - return $this->getAll(array('where' => "(`moderate` = 1 OR `author` = $userId) AND (`lat` BETWEEN '$b0' AND '$b2') AND(`lng` BETWEEN '$b1' AND '$b3')")); + return $this->getAll(array('where' => "(`moderate` = 1 OR `author` = $userId) AND (`dateEdit` >= $minEditDate) AND (`lat` BETWEEN '$b0' AND '$b2') AND(`lng` BETWEEN '$b1' AND '$b3')")); } else { - return $this->getAll(array('where' => "`moderate` = 1 OR `author` = ".$userId)); + return $this->getAll(array('where' => "(`moderate` = 1 OR `author` = ".$userId.") AND (`dateEdit` >= $minEditDate)")); } }