diff --git a/controllers/ApiController.php b/controllers/ApiController.php new file mode 100644 index 0000000..72440f0 --- /dev/null +++ b/controllers/ApiController.php @@ -0,0 +1,141 @@ +getAllPublished(false, $minEditDate); + $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); + + $result = array(); + + foreach ($points as $point) { + $tempPoint['id'] = $point->id; + $tempPoint['name'] = $point->name; + $tempPoint['lat'] = $point->lat; + $tempPoint['lng'] = $point->lng; + $tempPoint['categoryId'] = $point->categoryId; + $tempPoint['status'] = $point->status; + + $result[] = $tempPoint; + } + + return array('data' => $result); + } + + /** + * Точка + */ + static private function getPoint($data) + { + $id = isset($data['id']) ? intval($data['id']) : NULL; + + if (!$id) { + return FALSE; + } + + $point = Point::model()->getByPK($id); + + if (!$point) { + return FALSE; + } + + $point->descriptionHtml = nl2br($point->description); + $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'js'); + $point->name = htmlspecialchars($point->name); + $imgs = $point->photos; + $photosCount = 1; + + if ($point->img == '' && !empty($imgs)) { + $img = array_shift($imgs); + $point->img = $img->name; + } + + $imgs = $point->photos; + if (!empty($imgs)) { + $tmp = array(); + $photosCount = count($imgs); + foreach ($imgs as $img) { + $tmp[] = $img->name; + } + $point->images = $tmp; + } + + $extraParams = $point->getExtraParams(); + if (!empty($extraParams)) { + $tmp = array(); + foreach ($extraParams as $extraParam) { + $tmp[] = array($extraParam->name, $extraParam->value); + } + $point->extraParams = $tmp; + } + + $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); + + $point->categoryIcon = $categories[$point->categoryId]['icon']; + $point->categoryName = $categories[$point->categoryId]['name']; + $point->photosCount = $photosCount; + $point->inFavorites = Favorite::model()->checkIsMy($id); + $point->iLike = Like::model()->checkIsMy($id); + + return array('data' => $point->getValues()); + } + + /** + * Категории + */ + static private function getCategories() + { + $categories = Category::model()->getAll(array('order' => 'ord DESC', 'asArray' => true, 'noKeys' => true)); + + $categories[] = array( + "id" => "0", + "name" => "Все точки", + "icon" => "/ico/all.png", + "ord" => "0" + ); + + $categories = array_reverse($categories); + + return array('data' => $categories); + } + +}