Added order:fav_date
This commit is contained in:
parent
1081dfb718
commit
6470704f43
4 changed files with 38 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
17
src/Upgrades/mysql/Upgrade13.sql
Normal file
17
src/Upgrades/mysql/Upgrade13.sql
Normal 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;
|
17
src/Upgrades/sqlite/Upgrade13.sql
Normal file
17
src/Upgrades/sqlite/Upgrade13.sql
Normal 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;
|
Loading…
Reference in a new issue