diff --git a/models/Favorite.php b/models/Favorite.php
index bc50346..60cfd83 100644
--- a/models/Favorite.php
+++ b/models/Favorite.php
@@ -23,14 +23,34 @@ class Favorite extends Model
*/
public static function addRemove($pointId)
{
- if (!App::$user || !App::$user->id || !$pointId)
+ $pointId = intval($pointId);
+
+ if (!App::$user || !App::$user->id || !$pointId) {
return false;
+ }
+
+ $point = Point::model()->getByPK($pointId);
+ if (!$point) {
+ return FALSE;
+ }
+ $ownerId = $point->author;
$res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
if ($res) {
return Helper::boolval(Favorite::model()->delete($res->id));
} else {
+ // Оповещение автору точки
+ if ($ownerId != App::$user->id) {
+ Notifications::model()->add(array(
+ 'userId' => $ownerId,
+ 'fromUserId' => App::$user->id,
+ 'objectId' => $pointId,
+ 'type' => Notifications::typePointFav,
+ 'date' => time(),
+ ));
+ }
+
return Favorite::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
}
}
diff --git a/models/Like.php b/models/Like.php
index f4d2530..b1ff9a3 100644
--- a/models/Like.php
+++ b/models/Like.php
@@ -23,14 +23,34 @@ class Like extends Model
*/
public static function addRemove($pointId)
{
- if (!App::$user || !App::$user->id || !$pointId)
+ $pointId = intval($pointId);
+
+ if (!App::$user || !App::$user->id || !$pointId) {
return false;
+ }
+
+ $point = Point::model()->getByPK($pointId);
+ if (!$point) {
+ return FALSE;
+ }
+ $ownerId = $point->author;
$res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
if ($res) {
return Helper::boolval(Like::model()->delete($res->id));
} else {
+ // Оповещение автору точки
+ if ($ownerId != App::$user->id) {
+ Notifications::model()->add(array(
+ 'userId' => $ownerId,
+ 'fromUserId' => App::$user->id,
+ 'objectId' => $pointId,
+ 'type' => Notifications::typePointLike,
+ 'date' => time(),
+ ));
+ }
+
return Like::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
}
}
diff --git a/models/Notifications.php b/models/Notifications.php
index 9968100..35b8dc4 100644
--- a/models/Notifications.php
+++ b/models/Notifications.php
@@ -9,6 +9,8 @@ class Notifications extends Model
const typeReply = 'reply';
const typeNewCommentPoint = 'newCommentPoint';
const typeNewCommentArticle = 'newCommentArticle';
+ const typePointLike = 'pointLike';
+ const typePointFav = 'pointFav';
function __construct($fromArray = array())
{
diff --git a/views/user/notification.php b/views/user/notification.php
index 82cc5a2..c570233 100644
--- a/views/user/notification.php
+++ b/views/user/notification.php
@@ -24,6 +24,12 @@ switch ($notification->type) {
$comment = $notification->RefComment;
print strftime('%d %b %H:%M', $notification->date).' — '.$comment->RefUser->nick.' ответил(-а) на ваш комментарий.';
break;
+ case Notifications::typePointLike:
+ print strftime('%d %b %H:%M', $notification->date).' — '.$notification->RefFromUser->nick.' нравится ваша точка '.$notification->RefPoint->name.'.';
+ break;
+ case Notifications::typePointFav:
+ print strftime('%d %b %H:%M', $notification->date).' — '.$notification->RefFromUser->nick.' добавил(-а) вашу точку '.$notification->RefPoint->name.' в избранное.';
+ break;
default:
break;
}