Added favorite bulk actions
This commit is contained in:
parent
ed17a631d0
commit
0a30ec6cfa
@ -167,6 +167,45 @@ class Favorites extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
if (!$user->is_anonymous()) {
|
||||||
|
$event->add_action("bulk_favorite", "Favorite");
|
||||||
|
$event->add_action("bulk_unfavorite", "Un-Favorite");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBulkAction(BulkActionEvent $event)
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
switch ($event->action) {
|
||||||
|
case "bulk_favorite":
|
||||||
|
if (!$user->is_anonymous()) {
|
||||||
|
$total = 0;
|
||||||
|
foreach ($event->items as $image) {
|
||||||
|
send_event(new FavoriteSetEvent($image->id, $user, true));
|
||||||
|
$total++;
|
||||||
|
}
|
||||||
|
flash_message("Added $total items to favorites");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "bulk_unfavorite":
|
||||||
|
if (!$user->is_anonymous()) {
|
||||||
|
$total = 0;
|
||||||
|
foreach ($event->items as $image) {
|
||||||
|
send_event(new FavoriteSetEvent($image->id, $user, false));
|
||||||
|
$total++;
|
||||||
|
}
|
||||||
|
flash_message("Removed $total items from favorites");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function install()
|
private function install()
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
@ -203,10 +242,12 @@ class Favorites extends Extension
|
|||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
if ($do_set) {
|
if ($do_set) {
|
||||||
|
if(!$database->exists("select 1 from user_favorites where image_id=:image_id and user_id=:user_id",["image_id"=>$image_id, "user_id"=>$user_id])) {
|
||||||
$database->Execute(
|
$database->Execute(
|
||||||
"INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())",
|
"INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())",
|
||||||
["image_id"=>$image_id, "user_id"=>$user_id]
|
["image_id"=>$image_id, "user_id"=>$user_id]
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$database->Execute(
|
$database->Execute(
|
||||||
"DELETE FROM user_favorites WHERE image_id = :image_id AND user_id = :user_id",
|
"DELETE FROM user_favorites WHERE image_id = :image_id AND user_id = :user_id",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user