Added order:fav_date

This commit is contained in:
Marcin Kurczewski 2014-03-03 19:27:43 +01:00
parent 1081dfb718
commit 6470704f43
4 changed files with 38 additions and 0 deletions

View file

@ -241,6 +241,9 @@ class PostSearchParser extends AbstractSearchParser
elseif (in_array($orderByString, ['commentdate', 'comment_date']))
$orderColumn = 'comment_date';
elseif (in_array($orderByString, ['favdate', 'fav_date']))
$orderColumn = 'fav_date';
elseif ($orderByString == 'random')
{
//seeding works like this: if you visit anything

View file

@ -156,6 +156,7 @@ class UserModel extends AbstractCrudModel
$stmt->setTable('favoritee');
$stmt->setColumn('post_id', new Sql\Binding($post->id));
$stmt->setColumn('user_id', new Sql\Binding($user->id));
$stmt->setColumn('fav_date', time());
Database::exec($stmt);
});
}

View file

@ -0,0 +1,17 @@
ALTER TABLE favoritee ADD COLUMN fav_date INTEGER DEFAULT NULL;
ALTER TABLE post ADD COLUMN fav_date INTEGER DEFAULT NULL;
CREATE TRIGGER favoritee_update_date AFTER UPDATE ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;
CREATE TRIGGER favoritee_insert_date AFTER INSERT ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;
CREATE TRIGGER favoritee_delete_date AFTER DELETE ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;

View file

@ -0,0 +1,17 @@
ALTER TABLE favoritee ADD COLUMN fav_date INTEGER DEFAULT NULL;
ALTER TABLE post ADD COLUMN fav_date INTEGER DEFAULT NULL;
CREATE TRIGGER favoritee_update_date AFTER UPDATE ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;
CREATE TRIGGER favoritee_insert_date AFTER INSERT ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;
CREATE TRIGGER favoritee_delete_date AFTER DELETE ON favoritee FOR EACH ROW
BEGIN
UPDATE post SET fav_date = (SELECT MAX(fav_date) FROM favoritee WHERE favoritee.post_id = post.id);
END;