Новый статус для точки - отклонена модератором
This commit is contained in:
parent
1815000ba7
commit
226509fb7a
|
|
@ -22,7 +22,7 @@ class FeedController extends Controller
|
|||
|
||||
// --------- POINTS
|
||||
$points = Point::model()->getAll(array(
|
||||
'where' => '`moderate` = 1',
|
||||
'where' => '`status` = "published"',
|
||||
'order' => '`ord` DESC',
|
||||
'limit' => 5,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class JsonController extends Controller
|
|||
static function actionPoints()
|
||||
{
|
||||
if (App::$user && App::$user->isAdmin == 1) {
|
||||
$points = Point::model()->getAll();
|
||||
$points = Point::model()->getAll(array('where' => '`status` != "del"'));
|
||||
} 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])) {
|
||||
|
|
@ -34,7 +34,7 @@ class JsonController extends Controller
|
|||
$tempPoint['lat'] = $point->lat;
|
||||
$tempPoint['lng'] = $point->lng;
|
||||
$tempPoint['categoryId'] = $point->categoryId;
|
||||
$tempPoint['moderate'] = $point->moderate ? 'show' : 'hide';
|
||||
$tempPoint['status'] = $point->status;
|
||||
|
||||
$result[] = $tempPoint;
|
||||
}
|
||||
|
|
@ -56,7 +56,6 @@ class JsonController extends Controller
|
|||
$point->descriptionHtml = nl2br($point->description);
|
||||
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'js');
|
||||
$point->name = htmlspecialchars($point->name);
|
||||
$point->moderate = $point->moderate ? 'show' : 'hide';
|
||||
$imgs = $point->photos;
|
||||
$photosCount = 1;
|
||||
|
||||
|
|
@ -117,7 +116,7 @@ class JsonController extends Controller
|
|||
{
|
||||
$logName = isset($_POST['id']) && $_POST['id'] ? 'point_'.intval($_POST['id']) : 'point_0_NEW';
|
||||
App::log('points/'.$logName, array(
|
||||
'user' => App::$user->getValues(),
|
||||
'user' => App::$user ? App::$user->getValues() : NULL,
|
||||
'POST' => $_POST,
|
||||
));
|
||||
$errors = array();
|
||||
|
|
@ -131,7 +130,7 @@ class JsonController extends Controller
|
|||
$id = (int) $_POST['id'];
|
||||
$point = $point->getByPK($id);
|
||||
|
||||
if ($point->author != App::$user->id || $point->moderate == 1) {
|
||||
if ($point->author != App::$user->id || $point->status == Point::statusPublished) {
|
||||
$errors[9] = 'Редактирование точек достурно только администратору или автору!';
|
||||
}
|
||||
}
|
||||
|
|
@ -265,16 +264,16 @@ class JsonController extends Controller
|
|||
if (App::$request['ajax']) {
|
||||
$point = new Point();
|
||||
unset($_POST['img']);
|
||||
|
||||
if (isset($_POST['id']) && $_POST['id']) {
|
||||
// Редактирование существующей точки
|
||||
$id = (int) $_POST['id'];
|
||||
$_POST['dateEdit'] = time();
|
||||
$_POST['moderate'] = (App::$user && App::$user->isAdmin == 1) ? $_POST['moderate'] : 0;
|
||||
$_POST['status'] = (App::$user && App::$user->isAdmin == 1) ? Point::getStatusByString($_POST['status']) : Point::statusModeration;
|
||||
|
||||
$point = $point->getByPK($id);
|
||||
|
||||
if ($point->moderate == 0 AND $_POST['moderate'] == 1) {
|
||||
// Публикация ранее неопубликованной точки
|
||||
if ($point->status == Point::statusModeration AND Point::getStatusByString($_POST['status']) == Point::statusPublished) {
|
||||
Notifications::model()->add(array(
|
||||
'userId' => $point->author,
|
||||
'objectId' => $id,
|
||||
|
|
@ -284,13 +283,23 @@ class JsonController extends Controller
|
|||
$_POST['ord'] = time();
|
||||
}
|
||||
|
||||
if (Point::getStatusByString($_POST['status']) == Point::statusDel) {
|
||||
Notifications::model()->add(array(
|
||||
'userId' => $point->author,
|
||||
'objectId' => $id,
|
||||
'type' => Notifications::typePointDeleted,
|
||||
'date' => time(),
|
||||
));
|
||||
$_POST['ord'] = time();
|
||||
}
|
||||
|
||||
$point->setValues($_POST);
|
||||
$point->save();
|
||||
} else {
|
||||
$_POST['author'] = App::$user->id;
|
||||
$_POST['date'] = time();
|
||||
$_POST['dateEdit'] = time();
|
||||
$_POST['moderate'] = (App::$user && App::$user->isAdmin == 1) ? $_POST['moderate'] : 0;
|
||||
$_POST['status'] = (App::$user && App::$user->isAdmin == 1) ? Point::getStatusByString($_POST['status']) : Point::statusModeration;
|
||||
$_POST['ord'] = (App::$user && App::$user->isAdmin == 1) ? time() : 0;
|
||||
$point->add($_POST);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class PageController extends Controller
|
|||
// On moderation
|
||||
if (App::$user && App::$user->isAdmin) {
|
||||
$param['order'] = 'id DESC';
|
||||
$param['where'] = '`moderate` = 0';
|
||||
$param['where'] = '`status` = "moderation"';
|
||||
$points = Point::model()->getAll($param);
|
||||
$categories = Category::model()->getAll(array('order' => 'ord ASC'));
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ class PageController extends Controller
|
|||
// ------------------------------------------
|
||||
|
||||
$param = array();
|
||||
$param['where'] = '`moderate` = 1';
|
||||
$param['where'] = '`status` = "published"';
|
||||
$pointsCount = Point::model()->getCount($param);
|
||||
$pagesCount = intval(ceil($pointsCount/self::elementsByPage));
|
||||
$page = isset($_GET['page']) ? abs((int)$_GET['page']) : $pagesCount;
|
||||
|
|
@ -77,11 +77,11 @@ class PageController extends Controller
|
|||
$param = array();
|
||||
$param['order'] = '`ord` DESC';
|
||||
if (App::getParam('category')) {
|
||||
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `moderate` = 1';
|
||||
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `status` = "published"';
|
||||
} else if (App::getParam('user')) {
|
||||
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `moderate` = 1';
|
||||
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `status` = "published"';
|
||||
} else {
|
||||
$param['where'] = '`moderate` = 1';
|
||||
$param['where'] = '`status` = "published"';
|
||||
$param['limit'] = self::elementsByPage;
|
||||
if($page) {
|
||||
$param['offset'] = self::elementsByPage * ($pagesCount - $page);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,21 @@
|
|||
|
||||
class PointController extends Controller
|
||||
{
|
||||
|
||||
static function actionIndex()
|
||||
{
|
||||
self::$layout = 'layouts/page.php';
|
||||
|
||||
$pointId = (int) App::getParam('id');
|
||||
if ($pointId) {
|
||||
if (!$pointId) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$point = Point::model()->getByPK($pointId);
|
||||
if (!$point->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
self::addScript('/js/jquery-2.1.0.min.js');
|
||||
self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
|
||||
self::addScript('/js/bootstrap.min.js');
|
||||
|
|
@ -35,12 +44,11 @@ class PointController extends Controller
|
|||
self::addScript('//ulogin.ru/js/ulogin.js');
|
||||
}
|
||||
|
||||
$point = Point::model()->getByPK($pointId);
|
||||
|
||||
if ($point->id == NULL) {
|
||||
if ($point->status != Point::statusPublished && !App::$user->isAdmin && $point->author != App::$user->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
|
||||
$point->descriptionHtml = nl2br($point->description);
|
||||
$point->name = htmlspecialchars($point->name);
|
||||
App::setConfig('title', $point->name . ' – wikipoints.ru');
|
||||
|
|
@ -70,7 +78,7 @@ class PointController extends Controller
|
|||
}
|
||||
$photoLinksRes = implode('; ', array_keys($photoLinksRes));
|
||||
|
||||
$similarPoints = Point::model()->getAll(array('where' => '`moderate` = 1 AND categoryId = ' . $point->categoryId . ' AND `id` <> ' . $point->id . ' ORDER BY RAND() LIMIT 6;'));
|
||||
$similarPoints = Point::model()->getAll(array('where' => '`status` = "published" AND categoryId = ' . $point->categoryId . ' AND `id` <> ' . $point->id . ' ORDER BY RAND() LIMIT 6;'));
|
||||
$closestPoints = Point::model()->getClosestPoints($pointId);
|
||||
$randomPoint = Point::model()->getRandom();
|
||||
$randomPoint->description = mb_substr($randomPoint->description, 0, 400, 'UTF-8');
|
||||
|
|
@ -103,8 +111,6 @@ class PointController extends Controller
|
|||
'extraParams' => $point->getExtraParams(),
|
||||
'goods' => Goods::model()->getRandom(6),
|
||||
));
|
||||
} else {
|
||||
App::error404();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ class Notifications extends Model
|
|||
private static $count = NULL;
|
||||
|
||||
const typePointConfirmed = 'pointConfirmed';
|
||||
const typePointDeleted = 'pointDeleted';
|
||||
const typeReply = 'reply';
|
||||
const typeNewCommentPoint = 'newCommentPoint';
|
||||
const typeNewCommentArticle = 'newCommentArticle';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
class Point extends Model
|
||||
{
|
||||
const statusModeration = 'moderation';
|
||||
const statusPublished = 'published';
|
||||
const statusDel = 'del';
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
|
|
@ -35,10 +38,10 @@ class Point extends Model
|
|||
|
||||
public function getRandom()
|
||||
{
|
||||
$res = App::DB()->query("SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `" . $this->_tableName_ . "` WHERE `moderate` = 1")->fetch(PDO::FETCH_ASSOC);
|
||||
$res = App::DB()->query("SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `" . $this->_tableName_ . '` WHERE `status` = "published"')->fetch(PDO::FETCH_ASSOC);
|
||||
$offset = $res['offset'];
|
||||
|
||||
$res = App::DB()->query('SELECT `id` FROM ' . $this->_tableName_ . ' WHERE `moderate` = 1 LIMIT ' . $offset . ',1;')->fetch(PDO::FETCH_ASSOC);
|
||||
$res = App::DB()->query('SELECT `id` FROM ' . $this->_tableName_ . ' WHERE `status` = "published" LIMIT ' . $offset . ',1;')->fetch(PDO::FETCH_ASSOC);
|
||||
$pointId = $res['id'];
|
||||
|
||||
return $this->getByPK($pointId);
|
||||
|
|
@ -52,10 +55,10 @@ class Point extends Model
|
|||
|
||||
$query = '
|
||||
SELECT *, (
|
||||
SQRT(POW(`lat`-:lat,2)+POW(`lng`-:lng,2))
|
||||
(POW(`lat`-:lat,2)+POW(`lng`-:lng,2))
|
||||
) AS `dist` FROM `' . $this->_tableName_ . '`
|
||||
WHERE
|
||||
`moderate` = 1
|
||||
`status` = "published"
|
||||
AND
|
||||
`lat` BETWEEN :minLat AND :maxLat
|
||||
AND
|
||||
|
|
@ -81,7 +84,7 @@ class Point extends Model
|
|||
|
||||
public function getCountByUser($userId)
|
||||
{
|
||||
$res = App::DB()->query('SELECT count(`id`) AS `cnt` FROM ' . $this->_tableName_ . ' WHERE `author` = ' . $userId . ' AND `moderate` = 1 ;')->fetch(PDO::FETCH_ASSOC);
|
||||
$res = App::DB()->query('SELECT count(`id`) AS `cnt` FROM ' . $this->_tableName_ . ' WHERE `author` = ' . $userId . ' AND `status` = "published";')->fetch(PDO::FETCH_ASSOC);
|
||||
return $res['cnt'];
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +95,7 @@ class Point extends Model
|
|||
|
||||
public function getAllPublished($bounds = false, $minEditDate = 0)
|
||||
{
|
||||
$userId = App::$user ? App::$user->id : 0;
|
||||
$userId = App::$user ? intval(App::$user->id) : 0;
|
||||
$minEditDate = intval($minEditDate);
|
||||
if ($bounds) {
|
||||
$b0 = $bounds[0] < $bounds[2] ? $bounds[0] : $bounds[2];
|
||||
|
|
@ -100,9 +103,9 @@ class Point extends Model
|
|||
$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 (`dateEdit` >= $minEditDate) AND (`lat` BETWEEN '$b0' AND '$b2') AND(`lng` BETWEEN '$b1' AND '$b3')"));
|
||||
return $this->getAll(array('where' => "((`status` = '" . Point::statusPublished . "') OR (`status` = '" . Point::statusModeration . "' AND `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 . ") AND (`dateEdit` >= $minEditDate)"));
|
||||
return $this->getAll(array('where' => "((`status` = '" . Point::statusPublished . "') OR (`status` = '" . Point::statusModeration . "' AND `author` = $userId)) AND (`dateEdit` >= $minEditDate)"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,4 +128,18 @@ class Point extends Model
|
|||
$res = App::DB()->query('SELECT count(`id`) AS `cnt` FROM ' . $this->_tableName_ . ' WHERE `author` = ' . $userId . ' AND `date` >= ' . $time . ';')->fetch(PDO::FETCH_ASSOC);
|
||||
return (int)$res['cnt'];
|
||||
}
|
||||
|
||||
public static function getStatusByString($status)
|
||||
{
|
||||
switch (strtolower($status)) {
|
||||
case 'del':
|
||||
return self::statusDel;
|
||||
break;
|
||||
case 'published':
|
||||
return self::statusPublished;
|
||||
break;
|
||||
default:
|
||||
return self::statusModeration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ function addPoint()
|
|||
source: $('#addPointSource').val(),
|
||||
lat: $('#addPointLat').val(),
|
||||
lng: $('#addPointLng').val(),
|
||||
moderate: $('#moderate').val() == 'show' ? 1:0,
|
||||
status: $('#moderate').val(),
|
||||
id: id
|
||||
},
|
||||
success: function (data) {
|
||||
|
|
@ -384,7 +384,7 @@ function editPoint(id)
|
|||
$('#addPointSource').val(pointsSources[id].source);
|
||||
$('#addPointLat').val(pointsSources[id].lat);
|
||||
$('#addPointLng').val(pointsSources[id].lng);
|
||||
$('#moderate').val(pointsSources[id].moderate);
|
||||
$('#moderate').val(pointsSources[id].status);
|
||||
|
||||
$('.extraImage', '#imgsContainer').remove();
|
||||
$('.extraParam', '#extraParamsContainer').remove();
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ function constructPoint(data)
|
|||
id = data['id'];
|
||||
|
||||
icon = categories[data['categoryId']];
|
||||
if (data['moderate'] != 'show') {
|
||||
if (data['status'] != 'published') {
|
||||
icon = categories.lock;
|
||||
data['name'] = 'На модерации: ' + data['name'];
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ function drawInfoPopup(id, showPopup, doNotPushToHistory) {
|
|||
}
|
||||
|
||||
onModerate = '';
|
||||
if (data.moderate != 'show') {
|
||||
if (data.status != 'published') {
|
||||
onModerate = 'На модерации: ';
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ function drawInfoPopup(id, showPopup, doNotPushToHistory) {
|
|||
description += '<button type="button" class="btn btn-default" onclick="addRemoveLike(' + id + ')"><span id="myLikesButton" class="glyphicon glyphicon-' + (data.iLike ? 'ok' : 'thumbs-up') + '"></span> <span class="label">Нравится</span></button>';
|
||||
description += '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
||||
|
||||
if (isAdmin == '1' || data.moderate == "hide")
|
||||
if (isAdmin == '1' || data.status == "moderation")
|
||||
{
|
||||
description += '<button type="button" class="btn btn-default" onclick="editPoint(' + id + ')"><span class="glyphicon glyphicon-pencil"></span> <span class="label">Редактировать</span></button>';
|
||||
if (getURLParameter('edit') == 'true')
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel">Добавление новой точки</h4>
|
||||
</div>
|
||||
<form method="POST" action="/json/addpoint/" id="addPointForm" enctype="multipart/form-data">
|
||||
<div class="modal-body" style="padding-bottom: 0;">
|
||||
<?php if (!App::$user->isAdmin && Point::model()->getCountMyPointsToday() >= 3): ?>
|
||||
Ещё раз здравствуйте!<br/>
|
||||
|
|
@ -13,7 +14,6 @@
|
|||
<br/>
|
||||
<?php else: ?>
|
||||
<img id="imgPreview" style="display: none; position: absolute; top: 10px; left: 180px; height: 150px; border: solid 3px #777;" src="" onclick="hidePerview()"/>
|
||||
<form method="POST" action="/json/addpoint/" id="addPointForm" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="name">Название</label>
|
||||
<label class="control-label error" for="name">(Слишком короткое название точки — мининум 5 символов)</label>
|
||||
|
|
@ -57,16 +57,19 @@
|
|||
<input type="text" id="addPointLng" name="lng" class="form-control input-sm" style="width: 145px; display: inline-block;" readonly="readonly" />
|
||||
<button type="button" class="btn btn-sm btn-default" onclick="editSetNewCoords();"><span class="glyphicon glyphicon-screenshot"></span> изменить координаты</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<select id="moderate" name="moderate" class="form-control" style="width: 40%; display: <?= (App::$user && App::$user->isAdmin == 1) ? 'inline-block' : 'none' ?>; padding-top: 5px; float: left;">
|
||||
<option value="hide">Скрыта - на модераци</option>
|
||||
<option value="show">Опубликована</option>
|
||||
<?php if (App::$user && App::$user->isAdmin == 1): ?>
|
||||
<select id="moderate" name="status" class="form-control" style="width: 40%; display:inline-block; padding-top: 5px; float: left;">
|
||||
<option value="moderation">Скрыта - на модераци</option>
|
||||
<option value="published">Опубликована</option>
|
||||
<option value="del">Отклонена, Удалена, Уничтожена</option>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
|
||||
<button type="button" class="btn btn-primary" onclick="addPoint();">Сохранить</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="newIm">
|
||||
<div class="form-group extraImage asLink" style="display: none;">
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ $index = 0;
|
|||
<div class="container" style="background-color: rgba(255,255,255, 0.8);margin-top: -10px;padding-bottom: 30px;">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php if ($point->status != Point::statusPublished): ?>
|
||||
<h1 style="text-align: right; color: red;">Точка скрыта</h1>
|
||||
<?php endif; ?>
|
||||
<h1 style="text-align: right;"><?= $point->name ?></h1>
|
||||
<div class="coords-container">
|
||||
Координаты:
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ switch ($notification->type) {
|
|||
case Notifications::typePointConfirmed:
|
||||
print strftime('%d %b %H:%M', $notification->date).' — Ваша точка <a href="/point/'.$notification->objectId.'">"'.$notification->RefPoint->name.'"</a> прошла модерацию.';
|
||||
break;
|
||||
case Notifications::typePointDeleted:
|
||||
print strftime('%d %b %H:%M', $notification->date).' — Ваша точка <a href="/point/'.$notification->objectId.'">"'.$notification->RefPoint->name.'"</a> ОТКЛОНЕНА модератором.';
|
||||
break;
|
||||
case Notifications::typeNewCommentPoint:
|
||||
$comment = $notification->RefComment;
|
||||
$point = Point::model()->getByPK($comment->parentId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue