ADD уведомления при лайке точки и при добавлении точки в избранное

This commit is contained in:
Krivchikov Dmitry 2015-12-26 23:46:52 +03:00
parent 5fb86e958a
commit 72dd3abd40
4 changed files with 50 additions and 2 deletions

View File

@ -23,14 +23,34 @@ class Favorite extends Model
*/ */
public static function addRemove($pointId) public static function addRemove($pointId)
{ {
if (!App::$user || !App::$user->id || !$pointId) $pointId = intval($pointId);
if (!App::$user || !App::$user->id || !$pointId) {
return false; 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)); $res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
if ($res) { if ($res) {
return Helper::boolval(Favorite::model()->delete($res->id)); return Helper::boolval(Favorite::model()->delete($res->id));
} else { } 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)); return Favorite::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
} }
} }

View File

@ -23,14 +23,34 @@ class Like extends Model
*/ */
public static function addRemove($pointId) public static function addRemove($pointId)
{ {
if (!App::$user || !App::$user->id || !$pointId) $pointId = intval($pointId);
if (!App::$user || !App::$user->id || !$pointId) {
return false; 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)); $res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
if ($res) { if ($res) {
return Helper::boolval(Like::model()->delete($res->id)); return Helper::boolval(Like::model()->delete($res->id));
} else { } 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)); return Like::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
} }
} }

View File

@ -9,6 +9,8 @@ class Notifications extends Model
const typeReply = 'reply'; const typeReply = 'reply';
const typeNewCommentPoint = 'newCommentPoint'; const typeNewCommentPoint = 'newCommentPoint';
const typeNewCommentArticle = 'newCommentArticle'; const typeNewCommentArticle = 'newCommentArticle';
const typePointLike = 'pointLike';
const typePointFav = 'pointFav';
function __construct($fromArray = array()) function __construct($fromArray = array())
{ {

View File

@ -24,6 +24,12 @@ switch ($notification->type) {
$comment = $notification->RefComment; $comment = $notification->RefComment;
print strftime('%d %b %H:%M', $notification->date).' — '.$comment->RefUser->nick.' <a href="/'.$comment->parentType.'/'.$comment->parentId.'#comment'.$comment->id.'">ответил(-а)</a> на ваш комментарий.'; print strftime('%d %b %H:%M', $notification->date).' — '.$comment->RefUser->nick.' <a href="/'.$comment->parentType.'/'.$comment->parentId.'#comment'.$comment->id.'">ответил(-а)</a> на ваш комментарий.';
break; break;
case Notifications::typePointLike:
print strftime('%d %b %H:%M', $notification->date).' — <a href="/user/'.$notification->fromUserId.'">'.$notification->RefFromUser->nick.'</a> нравится ваша точка <a href="/point/'.$notification->objectId.'">'.$notification->RefPoint->name.'</a>.';
break;
case Notifications::typePointFav:
print strftime('%d %b %H:%M', $notification->date).' — <a href="/user/'.$notification->fromUserId.'">'.$notification->RefFromUser->nick.'</a> добавил(-а) вашу точку <a href="/point/'.$notification->objectId.'">'.$notification->RefPoint->name.'</a> в избранное.';
break;
default: default:
break; break;
} }