ADD use dateEdit in JSON request

This commit is contained in:
Krivchikov Dmitry 2015-07-04 16:10:45 +03:00
parent ee30d63f7a
commit c803a18534
2 changed files with 7 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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)"));
}
}