Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

OpenLitterMap/openlittermap-web

122 stars
4 code files
View OpenLitterMap/openlittermap-web on GitHub

app/Providers/EventServiceProvider.php

Open in GitHub
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
 
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
//
'App\Events\Photo\IncrementPhotoMonth' => [
'App\Listeners\UpdateTimes\IncrementCountryMonth',
'App\Listeners\UpdateTimes\IncrementStateMonth',
'App\Listeners\UpdateTimes\IncrementCityMonth',
]
];
 
public function boot()
{
parent::boot();
}
}

app/Events/Photo/IncrementPhotoMonth.php

Open in GitHub
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
 
class IncrementPhotoMonth implements ShouldQueue
{
use Dispatchable, InteractsWithSockets, SerializesModels;
 
public $country_id, $state_id, $city_id, $created_at;
 
public function __construct ($country_id, $state_id, $city_id, $created_at)
{
$this->country_id = $country_id;
$this->state_id = $state_id;
$this->city_id = $city_id;
$this->created_at = $created_at;
}
 
public function broadcastOn ()
{
return new PrivateChannel('channel-name');
}
}

app/Listeners/UpdateTags/ResetCompileString.php

Open in GitHub
use App\Events\ResetTagsCountAdmin;
use App\Models\Photo;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
 
class ResetCompileString
{
public function handle (ResetTagsCountAdmin $event)
{
if ($photo = Photo::find($event->photo_id))
{
$photo->result_string = null;
$photo->save();
}
}
}

app/Listeners/UpdateTags/DecrementCity.php

Open in GitHub
use App\Events\ResetTagsCountAdmin;
use App\Models\Location\City;
use App\Models\Photo;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
 
class DecrementCity
{
//
public function handle (ResetTagsCountAdmin $event)
{
$photo = Photo::find($event->photo_id);
 
if ($city = City::find($photo->city_id))
{
$total_count = 0;
 
foreach ($photo->categories() as $category)
{
if ($photo->$category)
{
$total = $photo->$category->total();
 
$total_string = "total_" . $category; // total_smoking, total_food...
 
$city->$total_string -= $total;
 
$total_count += $total; // total counts of all categories
}
}
 
$city->total_litter -= $total_count;
$city->total_images--;
$city->save();
}
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.