Favoriting a post automatically votes it up now

It's still possible for user to withdraw his vote afterwards for whatever
reason.
This commit is contained in:
Marcin Kurczewski 2014-02-23 22:46:51 +01:00
parent 72946c3922
commit 2aefafa473
3 changed files with 39 additions and 0 deletions

View file

@ -346,6 +346,7 @@ class PostController
if (!$this->context->loggedIn) if (!$this->context->loggedIn)
throw new SimpleException('Not logged in'); throw new SimpleException('Not logged in');
UserModel::updateUserScore($this->context->user, $post, 1);
UserModel::addToUserFavorites($this->context->user, $post); UserModel::addToUserFavorites($this->context->user, $post);
StatusHelper::success(); StatusHelper::success();
} }

View file

@ -0,0 +1,19 @@
INSERT
INTO post_score(user_id, post_id, score)
SELECT user_id, favoritee.post_id, 1
FROM favoritee WHERE NOT EXISTS
(
SELECT *
FROM post_score ps2
WHERE favoritee.post_id = ps2.post_id
AND favoritee.user_id = ps2.user_id
);
UPDATE post_score
SET score = 1
WHERE user_id IN
(
SELECT user_id
FROM favoritee
WHERE favoritee.post_id = post_score.post_id
);

View file

@ -0,0 +1,19 @@
INSERT
INTO post_score(user_id, post_id, score)
SELECT user_id, favoritee.post_id, 1
FROM favoritee WHERE NOT EXISTS
(
SELECT *
FROM post_score ps2
WHERE favoritee.post_id = ps2.post_id
AND favoritee.user_id = ps2.user_id
);
UPDATE post_score
SET score = 1
WHERE user_id IN
(
SELECT user_id
FROM favoritee
WHERE favoritee.post_id = post_score.post_id
);