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) {


+ = mb_substr($randomPoint->description, 0, 400, 'UTF-8') ?>…
+