From 22426d5e8a3024b5e5d5dc3a144b5b366bd914dd Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sat, 14 Nov 2015 11:01:11 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9.=20=D0=9F=D0=BE=D0=BA=D0=B0=20=D1=82=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=BE=20=D0=BE=20=D1=82=D0=BE=D0=BC,=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=20=D1=82=D0=BE=D1=87=D0=BA=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=88=D0=BB=D0=B0=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/JsonController.php | 11 ++++++ ground/controllers/UserController.php | 42 ++++++++++++++++++++++- ground/models/Notifications.php | 49 +++++++++++++++++++++++++++ ground/views/indexTemplate.php | 6 +++- ground/views/user/index.php | 1 + ground/views/user/notification.php | 14 ++++++++ ground/views/user/notifications.php | 34 +++++++++++++++++++ public/css/style.css | 1 + 8 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 ground/models/Notifications.php create mode 100644 ground/views/user/notification.php create mode 100644 ground/views/user/notifications.php diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 8864b3c..be771dd 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -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 { diff --git a/ground/controllers/UserController.php b/ground/controllers/UserController.php index 85e3d24..954d32f 100644 --- a/ground/controllers/UserController.php +++ b/ground/controllers/UserController.php @@ -6,7 +6,11 @@ class UserController extends Controller { if (!App::getParam('id')) { if (App::$user) { - App::redirect('/user/'.App::$user->id); + 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, + )); + } } diff --git a/ground/models/Notifications.php b/ground/models/Notifications.php new file mode 100644 index 0000000..b35c108 --- /dev/null +++ b/ground/models/Notifications.php @@ -0,0 +1,49 @@ +_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); + } +} diff --git a/ground/views/indexTemplate.php b/ground/views/indexTemplate.php index 238cdc5..716a52b 100644 --- a/ground/views/indexTemplate.php +++ b/ground/views/indexTemplate.php @@ -22,7 +22,11 @@ if (App::$user) {
-
+
+ +
+ +
diff --git a/ground/views/user/index.php b/ground/views/user/index.php index f4ed2bc..64620d8 100644 --- a/ground/views/user/index.php +++ b/ground/views/user/index.php @@ -26,6 +26,7 @@ $statuses = array(

Новая запись + Уведомления Записи:

diff --git a/ground/views/user/notification.php b/ground/views/user/notification.php new file mode 100644 index 0000000..77d5cd9 --- /dev/null +++ b/ground/views/user/notification.php @@ -0,0 +1,14 @@ +type) { + case Notifications::typePointConfirmed: + print strftime('%d %b %H:%M', $notification->date).' — Ваша точка "'.$notification->RefPoint->name.'" прошла модерацию.'; + break; + case Notifications::typeNewCommentPoint: + + + break; + default: + break; +} diff --git a/ground/views/user/notifications.php b/ground/views/user/notifications.php new file mode 100644 index 0000000..4286137 --- /dev/null +++ b/ground/views/user/notifications.php @@ -0,0 +1,34 @@ +
+
+
+
+

Лента событий

+
+ +
+ $notification),true) ?> +
+ + + Нет уведомлений. + + +
+
+ +
+ + +
+
+ +

Это интересно: name ?>

+

+ description, 0, 400, 'UTF-8') ?>… + читать далее » +

+
+
+ + +
diff --git a/public/css/style.css b/public/css/style.css index 5e0cf7a..3b12def 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -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;}