ADD система уведомлений. Пока только о том, что точка прошла можерацию

This commit is contained in:
Krivchikov Dmitry 2015-11-14 11:01:11 +03:00
parent f42f52857f
commit 22426d5e8a
8 changed files with 156 additions and 2 deletions

View File

@ -256,8 +256,19 @@ class JsonController extends Controller
// Редактирование существующей точки
$id = (int) $_POST['id'];
$_POST['dateEdit'] = time();
$_POST['moderate'] = (App::$user && App::$user->isAdmin == 1) ? $_POST['moderate'] : 0;
$point = $point->getByPK($id);
if ($point->moderate == 0 AND $_POST['moderate'] == 1) {
Notifications::model()->add(array(
'userId' => $point->author,
'objectId' => $id,
'type' => Notifications::typePointConfirmed,
'date' => time(),
));
}
$point->setValues($_POST);
$point->save();
} else {

View File

@ -6,7 +6,11 @@ class UserController extends Controller
{
if (!App::getParam('id')) {
if (App::$user) {
if (Notifications::getUnreadedCount() > 0) {
App::redirect('/user/notifications/');
} else {
App::redirect('/user/'.App::$user->id);
}
} else {
App::redirect('/');
}
@ -59,4 +63,40 @@ class UserController extends Controller
'randomPoint' => $randomPoint,
));
}
static function actionNotifications()
{
if (!App::$user) {
App::redirect('/');
}
self::$layout = 'layouts/page.php';
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');
self::addScript('/js/leaflet-0.7.3.js');
self::addScript('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js');
self::addScript('/js/app.js?ver=' . App::getConfig('version'));
self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version'));
self::addStyle('/css/bootstrap.min.css');
self::addStyle('/css/bootstrap-theme.min.css');
self::addStyle('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css');
$notifications = Notifications::model()->getAll(array(
'where' => '`userId` = '.App::$user->id,
'order' => 'readed ASC, date DESC'
));
Notifications::model()->setAllReaded();
$randomPoint = Point::model()->getRandom();
$randomPoint->description = mb_substr($randomPoint->description, 0, 400, 'UTF-8');
$randomPoint->description = Helper::replaceLinks($randomPoint->description);
self::render('user/notifications.php', array(
'notifications' => $notifications,
'randomPoint' => $randomPoint,
));
}
}

View File

@ -0,0 +1,49 @@
<?php
class Notifications extends Model
{
private static $count = NULL;
const typePointConfirmed = 'pointConfirmed';
const typeReply = 'reply';
const typeNewCommentPoint = 'newCommentPoint';
const typeNewCommentArticle = 'newCommentArticle';
function __construct($fromArray = array())
{
$this->_tableName_ = 'notifications';
parent::__construct($fromArray);
$this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE);
$this->setRelation('RefFromUser', 'fromUserId', 'User', 'id', self::TO_ONE);
$this->setRelation('RefPoint', 'objectId', 'Point', 'id', self::TO_ONE);
}
static function model()
{
return new self();
}
public static function getUnreadedCount()
{
if (!App::$user) {
return 0;
}
if (self::$count === NULL) {
self::$count = self::model()->getCount(array(
'where' => '`userId` = '.App::$user->id.' AND `readed` = 0',
));
}
return (int) self::$count;
}
public function setAllReaded()
{
if (!App::$user) {
throw new Exception('Попытка пометить все новости прочитанными у неизвестного пользователя.');
}
return App::DB()->query('UPDATE `' . $this->_tableName_ . '` SET `readed` = 1 WHERE `userId` = ' . App::$user->id);
}
}

View File

@ -22,7 +22,11 @@ if (App::$user) {
<div class="glyphicon _t" id="addPointButton" title="Добавить точку" onclick="<?= $addWithoutConfirm ? 'activateAddPoint()' : 'showPointagreement()'; ?>"><img src="/img/buttons/addPoint.png" style="margin-top: -10px; height: 30px;" /></div>
<div class="glyphicon glyphicon-star _c boxButtonFavorites" onclick="openBox('Favorites')" title="Хочу посетить"></div>
<div class="glyphicon glyphicon-cloud-download _c boxButtonRoutes" onclick="openBox('Routes')" title="Мои маршруты"></div>
<div class="glyphicon glyphicon-user _b boxButtonUser" onclick="location.href='/user/'" title="Профиль"></div>
<div class="glyphicon glyphicon-user _b boxButtonUser" onclick="location.href='/user/'" title="Профиль">
<?php if(Notifications::getUnreadedCount()): ?>
<div id="notify"><?= Notifications::getUnreadedCount(); ?></div>
<?php endif; ?>
</div>
<?php else: ?>
<div class="glyphicon _t" id="addPointButton" onclick="$('#loginModal').modal('show');" title="Добавить точку"><img src="/img/buttons/addPoint.png" style="margin-top: -10px; height: 30px;" /></div>
<div class="glyphicon glyphicon-user _b" id="loginButton" onclick="$('#loginModal').modal('show');" title="Войти для добавления точки"></div>

View File

@ -26,6 +26,7 @@ $statuses = array(
<h2>
<?php if ($imAuthor) : ?>
<a href="/article/new/" class="pull-right btn btn-success"><span class="glyphicon glyphicon-plus"></span> Новая запись</a>
<a href="/user/notifications/" class="pull-right btn btn-link">Уведомления <span class="glyphicon glyphicon-bullhorn"></span></a>
<?php endif; ?>
Записи:
</h2>

View File

@ -0,0 +1,14 @@
<?php
setlocale(LC_ALL, 'ru_RU.UTF-8');
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::typeNewCommentPoint:
break;
default:
break;
}

View File

@ -0,0 +1,34 @@
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
<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">
<h1 style="text-align: right;">Лента событий</h1>
<hr/>
<?php if ($notifications): foreach ($notifications as $notification): ?>
<div>
<?= self::renderPartial('/user/notification.php', array('notification'=>$notification),true) ?>
</div>
<?php endforeach; ?>
<?php else: ?>
Нет уведомлений.
<?php endif; ?>
</div>
</div>
<hr style="margin-bottom: 50px;"/>
<!--googleoff: all-->
<!--noindex-->
<div class="row">
<div class="col-md-12">
<a href="/point/<?= $randomPoint->id ?>" style="float: left; margin: 0 20px 0 0;"><img src="<?= $randomPoint->getImg() ?>" style="width: 200px;"/></a>
<h3 style="margin-top: 0;">Это интересно: <?= $randomPoint->name ?></h3>
<p>
<?= mb_substr($randomPoint->description, 0, 400, 'UTF-8') ?>
<a class="" href="/point/<?= $randomPoint->id ?>" role="button"><nobr> читать далее »</nobr></a>
</p>
</div>
</div>
<!--/noindex-->
<!--googleon: all-->
</div>

View File

@ -77,6 +77,7 @@ div#control div._c {border-radius: 0; border-bottom: solid 1px #666; margin-bott
div#control div._b {border-radius: 0 0 0 8px;}
div#control div.space {height: 10px; background-color: transparent; padding: 0;}
div#control div._t2 {background-color: rgba(200, 200, 200, 0.65); border-radius: 8px 0 0 0;border-bottom: solid 1px #ddd; margin-bottom: 0;}
div#control div#notify {position: absolute; background-color: red;color: white;border-radius: 50%; width: 20px;height: 20px;margin: 0;padding: 0;padding-top: 2px;text-align: center;font-weight: bolder;font-size: 15px;vertical-align: middle;font-family: sans-serif;top: 18px;left: -7px;}
/*BOX*/
body.openBox div#box {display: block; z-index: 100;}