-
app/Providers/EventServiceProvider.php
Open in GitHubuse 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 GitHubuse 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 GitHubuse 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 GitHubuse 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(); } } }