Первый вариант МОДЕРАЦИИ ТОЧЕК. Готово: отдельная иконка, добавляемые точки отправляются на модерацию, можно опубликовать или скрыть точку, автор видит свои неопубликованные точки

This commit is contained in:
Krivchikov Dmitry 2015-05-26 16:23:00 +03:00
parent 6ecf6ae31e
commit 89c53fe881
7 changed files with 37 additions and 6 deletions

View File

@ -61,7 +61,7 @@ class IndexController extends Controller
self::addVar('isAdmin', (int) (App::$user && App::$user->isAdmin == 1)); self::addVar('isAdmin', (int) (App::$user && App::$user->isAdmin == 1));
$res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC); $res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points` where `moderate` = 1")->fetch(PDO::FETCH_ASSOC);
App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома'); App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома');
self::addVar('pointsCount', $res['pointsCount']); self::addVar('pointsCount', $res['pointsCount']);

View File

@ -8,7 +8,12 @@ class JsonController extends Controller
*/ */
static function actionPoints() static function actionPoints()
{ {
$points = Point::model()->getAll(); if (App::$user && App::$user->isAdmin == 1) {
$points = Point::model()->getAll();
} else {
$points = Point::model()->getAllPublished();
}
$categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));
$result = array(); $result = array();
@ -22,6 +27,7 @@ class JsonController extends Controller
$result[$id]['lng'] = $point->lng; $result[$id]['lng'] = $point->lng;
$result[$id]['categoryId'] = $point->categoryId; $result[$id]['categoryId'] = $point->categoryId;
$result[$id]['categoryIcon'] = $categories[$point->categoryId]['icon']; $result[$id]['categoryIcon'] = $categories[$point->categoryId]['icon'];
$result[$id]['moderate'] = $point->moderate ? 'show' : 'hide';
} }
self::renderPartial('json.php', array( self::renderPartial('json.php', array(

View File

@ -88,5 +88,11 @@ class Point extends Model
{ {
return $this->getAll(array('where' => "`name` LIKE '%$search%' OR `description` LIKE '%$search%'", 'limit' => 20)); return $this->getAll(array('where' => "`name` LIKE '%$search%' OR `description` LIKE '%$search%'", 'limit' => 20));
} }
public function getAllPublished()
{
$userId = App::$user ? App::$user->id : 0;
return $this->getAll(array('where' => "`moderate` = 1 OR `author` = ".$userId));
}
} }

View File

@ -23,7 +23,7 @@
<div class="form-group extraImage asLink"> <div class="form-group extraImage asLink">
<label class="control-label" for="imgs">Файлы и ссылки на изображения</label> <label class="control-label" for="imgs">Файлы и ссылки на изображения</label>
<label class="control-label error" for="imgs">(Что-то не так с изображениями!)</label> <label class="control-label error" for="imgs">(Что-то не так с изображениями!)</label>
<span class="btn btn-sm add button" onclick="addNewImage()" title="Добавить ещё одно изображение"><span class="glyphicon glyphicon-plus"></span></span> <span class="btn btn-sm add button" onclick="addNewImage()" title="Добавить ещё одно изображение"><span class="glyphicon glyphicon-plus"></span> <span class="glyphicon glyphicon-camera"></span></span>
</div> </div>
<div id="imgsContainer"> <div id="imgsContainer">
</div> </div>

BIN
public/ico/lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -22,6 +22,13 @@ categories.im = L.icon({
popupAnchor: [0, 1] popupAnchor: [0, 1]
}); });
categories.lock = L.icon({
iconUrl: '/ico/lock.png',
iconSize: [32, 37],
iconAnchor: [16, 37],
popupAnchor: [0, 1]
});
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/** /**
@ -134,10 +141,17 @@ function init(lat, lng) {
*/ */
function constructPoint(data) function constructPoint(data)
{ {
console.log(data);
id = data['id']; id = data['id'];
icon = categories[data['categoryId']];
if (data['moderate'] != 'show') {
icon = categories.lock;
data['name'] = 'На модерации: '+data['name'];
}
points[id] = L.marker( points[id] = L.marker(
[data['lat'], data['lng']], {icon: categories[data['categoryId']], title: data['name'], id: id, categoryId: data['categoryId']} [data['lat'], data['lng']], {icon: icon, title: data['name'], id: id, categoryId: data['categoryId']}
).on('click', function (e) { ).on('click', function (e) {
showInfo(e.target.options.id); showInfo(e.target.options.id);
}); });
@ -214,7 +228,12 @@ function showInfo(id)
photos = '<img src="' + data.img + '" onclick="showImage(\'' + id + '\')" />'; photos = '<img src="' + data.img + '" onclick="showImage(\'' + id + '\')" />';
} }
description = '<div class="infoCard">' + '<h3>' + data.name + '</h3>' + photos; onModerate = '';
if (data.moderate != 'show') {
onModerate = 'На модерации: ';
}
description = '<div class="infoCard">' + '<h3>' + onModerate + data.name + '</h3>' + photos;
description += data.descriptionHtml; description += data.descriptionHtml;
description += '</div><div class="clear"></div>'; description += '</div><div class="clear"></div>';
description += '<div class="btn-group control">'; description += '<div class="btn-group control">';