diff --git a/app/Actions/Photos/DeleteTagsFromPhotoAction.php b/app/Actions/Photos/DeleteTagsFromPhotoAction.php index a2976f1aa..8fe05ac4c 100644 --- a/app/Actions/Photos/DeleteTagsFromPhotoAction.php +++ b/app/Actions/Photos/DeleteTagsFromPhotoAction.php @@ -3,7 +3,6 @@ namespace App\Actions\Photos; use App\Models\Photo; -use Illuminate\Support\Collection; class DeleteTagsFromPhotoAction { @@ -11,10 +10,6 @@ class DeleteTagsFromPhotoAction * Clear all tags on an image * * Returns the total number of tags that were deleted, separated from brands - * - * @param Photo $photo - * - * @return array */ public function run(Photo $photo): array { @@ -33,14 +28,14 @@ private function deleteLitter(Photo $photo): int { $categories = collect($photo->categories()) ->filter(function ($category) use ($photo) { - return $category !== 'brands' && !!$photo->$category; + return $category !== 'brands' && (bool) $photo->$category; }); $total = $categories->sum(function ($category) use ($photo) { return $photo->$category->total(); }); - $categories->each(function ($category) use ($photo) { + $categories->each(function ($category) use ($photo): void { $photo->$category->delete(); }); @@ -49,7 +44,7 @@ private function deleteLitter(Photo $photo): int private function deleteBrands(Photo $photo): int { - if (!$photo->brands) { + if (! $photo->brands) { return 0; } diff --git a/app/Actions/Photos/MakeImageAction.php b/app/Actions/Photos/MakeImageAction.php index 886f79e58..560d93bab 100644 --- a/app/Actions/Photos/MakeImageAction.php +++ b/app/Actions/Photos/MakeImageAction.php @@ -14,20 +14,17 @@ class MakeImageAction /** * Create an instance of Intervention Image using an UploadedFile * - * @param UploadedFile $file - * @param bool $resize * - * @return array * @throws Exception */ - public function run (UploadedFile $file, bool $resize = false): array + public function run(UploadedFile $file, bool $resize = false): array { $imageAndExifData = $this->getImageAndExifData($file); if ($resize) { $imageAndExifData['image']->resize(500, 500); - $imageAndExifData['image']->resize(500, 500, function ($constraint) { + $imageAndExifData['image']->resize(500, 500, function ($constraint): void { $constraint->aspectRatio(); }); } @@ -36,18 +33,16 @@ public function run (UploadedFile $file, bool $resize = false): array } /** - * @param UploadedFile $file - * @return array * @throws Exception */ - protected function getImageAndExifData (UploadedFile $file): array + protected function getImageAndExifData(UploadedFile $file): array { $extension = $file->getClientOriginalExtension(); // If the image is not type HEIC, HEIF // We can assume its jpg, png, and can be handled by the default GD image library // Otherwise, we are going to have to handle HEIC separately. - if (!in_array(strtolower($extension), ['heif', 'heic'])) { + if (! in_array(strtolower($extension), ['heif', 'heic'])) { $image = Image::make($file)->orientate(); $exif = $image->exif(); @@ -61,21 +56,21 @@ protected function getImageAndExifData (UploadedFile $file): array // Path for a temporary file from the upload -> storage/app/heic_images/sample1.heic $tmpFilepath = storage_path( - self::TEMP_HEIC_STORAGE_DIR . - $randomFilename . ".$extension" + self::TEMP_HEIC_STORAGE_DIR. + $randomFilename.".$extension" ); // Path for a converted temporary file -> storage/app/heic_images/sample1.jpg $convertedFilepath = storage_path( - self::TEMP_HEIC_STORAGE_DIR . - $randomFilename . '.jpg' + self::TEMP_HEIC_STORAGE_DIR. + $randomFilename.'.jpg' ); // Store the uploaded HEIC file on the server File::put($tmpFilepath, $file->getContent()); // Run a shell command to execute ImageMagick conversion - exec('magick convert ' . $tmpFilepath . ' ' . $convertedFilepath); + exec('magick convert '.$tmpFilepath.' '.$convertedFilepath); // Make the image from the new converted file $image = Image::make($convertedFilepath)->orientate(); diff --git a/app/Console/Commands/Clusters/GenerateClusters.php b/app/Console/Commands/Clusters/GenerateClusters.php index f790cd0df..731b45c27 100644 --- a/app/Console/Commands/Clusters/GenerateClusters.php +++ b/app/Console/Commands/Clusters/GenerateClusters.php @@ -2,9 +2,8 @@ namespace App\Console\Commands\Clusters; -use App\Models\Photo; use App\Models\Cluster; - +use App\Models\Photo; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; @@ -35,14 +34,14 @@ public function handle() $start = microtime(true); foreach ($this->getYearsWithNewPhotos() as $year) { - $this->line("\nYear: " . ($year ?: 'All Time')); + $this->line("\nYear: ".($year ?: 'All Time')); $this->generateFeatures($year); $this->generateClusters($year); } $finish = microtime(true); $this->newLine(); - $this->info("Total Time: " . ($finish - $start) . "\n"); + $this->info('Total Time: '.($finish - $start)."\n"); \Log::info('--- Clustering finished ---'); } @@ -56,7 +55,7 @@ public function handle() * * We save this file to storage and use it to populate the clusters with a node script in the backend */ - protected function generateFeatures (int $year = null): void + protected function generateFeatures(?int $year = null): void { $this->info('Generating features...'); @@ -74,14 +73,13 @@ protected function generateFeatures (int $year = null): void $features = []; - foreach ($photos->cursor() as $photo) - { + foreach ($photos->cursor() as $photo) { $feature = [ 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [$photo->lon, $photo->lat] - ] + 'coordinates' => [$photo->lon, $photo->lat], + ], ]; $features[] = $feature; @@ -102,11 +100,10 @@ protected function generateFeatures (int $year = null): void * Using the features.json file, we cluster our data at various zoom levels. * * First, we need to delete all clusters. Then we re-create them from scratch. - * */ - protected function generateClusters (int $year = null): void + protected function generateClusters(?int $year = null): void { - $this->info("Generating clusters for each zoom level..."); + $this->info('Generating clusters for each zoom level...'); // Delete all clusters for year if ($year) { @@ -123,11 +120,10 @@ protected function generateClusters (int $year = null): void $zoomLevels = range(2, 16); // For each zoom level, create clusters. - foreach ($zoomLevels as $zoomLevel) - { + foreach ($zoomLevels as $zoomLevel) { // Supercluster is awesome open-source javascript code from MapBox that we made executable on the backend with php // This file uses features.json to create clusters.json for a specific zoom level. - exec('node app/Node/supercluster-php ' . base_path() . ' ' . $zoomLevel); + exec('node app/Node/supercluster-php '.base_path().' '.$zoomLevel); // We then use the clusters.json and save it to the clusters table collect(json_decode(Storage::get('/data/clusters.json'))) @@ -142,11 +138,11 @@ protected function generateClusters (int $year = null): void 'point_count_abbreviated' => $cluster->properties->point_count_abbreviated, 'geohash' => \GeoHash::encode($cluster->geometry->coordinates[1], $cluster->geometry->coordinates[0]), 'zoom' => $zoomLevel, - 'year' => $year + 'year' => $year, ]; }) ->chunk(1000) - ->each(function ($chunk) { + ->each(function ($chunk): void { Cluster::insert($chunk->toArray()); }); @@ -171,7 +167,7 @@ private function getYearsWithNewPhotos(): array foreach ($years as $year) { $hasRecentPhotosForYear = Photo::query()->where([ ['created_at', '>=', now()->subDay()->startOfDay()], - [DB::raw('year(datetime)'), '=', $year] + [DB::raw('year(datetime)'), '=', $year], ])->exists(); if ($hasRecentPhotosForYear) { diff --git a/app/Console/Commands/Clusters/GenerateTeamClusters.php b/app/Console/Commands/Clusters/GenerateTeamClusters.php index bbbca17ad..2858d471a 100644 --- a/app/Console/Commands/Clusters/GenerateTeamClusters.php +++ b/app/Console/Commands/Clusters/GenerateTeamClusters.php @@ -25,6 +25,7 @@ class GenerateTeamClusters extends Command protected $description = 'Generate all clusters for teams photos'; private $clustersDir = 'team-clusters.json'; + private $featuresDir = 'team-features.json'; /** @@ -48,7 +49,7 @@ public function handle() $finish = microtime(true); $this->newLine(); - $this->info("Total Time: " . ($finish - $start) . "\n"); + $this->info('Total Time: '.($finish - $start)."\n"); return 0; } @@ -58,7 +59,7 @@ public function handle() */ protected function generateFeatures(Team $team): void { - $this->info("Generating features..."); + $this->info('Generating features...'); $bar = $this->output->createProgressBar( Photo::whereTeamId($team->id)->count() @@ -78,8 +79,8 @@ protected function generateFeatures(Team $team): void 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [$photo->lon, $photo->lat] - ] + 'coordinates' => [$photo->lon, $photo->lat], + ], ]; $features[] = $feature; @@ -100,7 +101,7 @@ protected function generateFeatures(Team $team): void */ protected function generateClusters(Team $team): void { - $this->info("Generating clusters for each zoom level..."); + $this->info('Generating clusters for each zoom level...'); $rootDir = base_path(); $zoomLevels = range(2, 16); @@ -132,7 +133,7 @@ protected function generateClusters(Team $team): void ]; }) ->chunk(1000) - ->each(function ($chunk) { + ->each(function ($chunk): void { TeamCluster::insert($chunk->all()); }); @@ -144,12 +145,9 @@ protected function generateClusters(Team $team): void $this->info("\nClusters finished..."); } - /** - * @param Team $team - */ protected function deleteClusters(Team $team) { - $this->info("Deleting clusters..."); + $this->info('Deleting clusters...'); TeamCluster::whereTeamId($team->id)->delete(); } diff --git a/app/Console/Commands/Photos/Resize500x500.php b/app/Console/Commands/Photos/Resize500x500.php index d97d8d5ec..fbc15a345 100644 --- a/app/Console/Commands/Photos/Resize500x500.php +++ b/app/Console/Commands/Photos/Resize500x500.php @@ -44,11 +44,9 @@ public function handle() Photo::where([ ['verified', '>=', 2], ['filename', '!=', '/assets/verified.jpg'], - 'five_hundred_square_filepath' => null - ])->chunk(500, function ($photos) - { - foreach ($photos as $photo) - { + 'five_hundred_square_filepath' => null, + ])->chunk(500, function ($photos): void { + foreach ($photos as $photo) { echo "Photo id $photo->id \n"; // Create an image object @@ -68,7 +66,7 @@ public function handle() $x = explode('/', $photo->filename); // Get the last element which is the filename with extension - $filename = $x[sizeof($x) -1]; + $filename = $x[count($x) - 1]; $filepath = $year.'/'.$month.'/'.$day.'/'.$filename; $s3 = \Storage::disk('bbox'); diff --git a/app/Console/Commands/Twitter/DailyReportTweet.php b/app/Console/Commands/Twitter/DailyReportTweet.php index 849c2a780..309bb3e7f 100644 --- a/app/Console/Commands/Twitter/DailyReportTweet.php +++ b/app/Console/Commands/Twitter/DailyReportTweet.php @@ -2,15 +2,15 @@ namespace App\Console\Commands\Twitter; -use App\Models\CustomTag; -use Carbon\Carbon; -use App\Models\Photo; -use Spatie\Emoji\Emoji; use App\Helpers\Twitter; -use App\Models\User\User; +use App\Models\CustomTag; use App\Models\Littercoin; use App\Models\Location\Country; +use App\Models\Photo; +use App\Models\User\User; +use Carbon\Carbon; use Illuminate\Console\Command; +use Spatie\Emoji\Emoji; class DailyReportTweet extends Command { @@ -18,7 +18,7 @@ class DailyReportTweet extends Command protected $description = 'Send a daily report about OLM to Twitter OLM_bot account'; - public function handle () + public function handle() { $startOfYesterday = Carbon::yesterday()->startOfDay(); $endOfYesterday = Carbon::yesterday()->endOfDay(); @@ -58,7 +58,7 @@ public function handle () $photos = Photo::select('id', 'created_at', 'country_id', 'total_litter') ->whereDate('created_at', '>=', $startOfYesterday) ->whereDate('created_at', '<=', $endOfYesterday) - ->orWhereHas('customTags', function ($query) use ($startOfYesterday, $endOfYesterday) { + ->orWhereHas('customTags', function ($query) use ($startOfYesterday, $endOfYesterday): void { $query->whereDate('created_at', '>=', $startOfYesterday) ->whereDate('created_at', '<=', $endOfYesterday); }) @@ -66,10 +66,8 @@ public function handle () $countryIds = []; - foreach ($photos as $photo) - { - if (!array_key_exists($photo->country_id, $countryIds)) - { + foreach ($photos as $photo) { + if (! array_key_exists($photo->country_id, $countryIds)) { $countryIds[$photo->country_id] = 0; } @@ -131,7 +129,7 @@ public function handle () } } - $message .= " #openlittermap #OLMbot 🌍"; + $message .= ' #openlittermap #OLMbot 🌍'; Twitter::sendTweet($message); } diff --git a/app/Console/Commands/Users/UpdateRedisBoundingBoxXp.php b/app/Console/Commands/Users/UpdateRedisBoundingBoxXp.php index 82af16a28..3adbcdbde 100644 --- a/app/Console/Commands/Users/UpdateRedisBoundingBoxXp.php +++ b/app/Console/Commands/Users/UpdateRedisBoundingBoxXp.php @@ -43,9 +43,9 @@ public function __construct(UpdateLeaderboardsXpAction $xpAction) */ public function handle() { - $this->line("Updating XP from bounding boxes"); + $this->line('Updating XP from bounding boxes'); - $this->withProgressBar(User::all(), function (User $user) { + $this->withProgressBar(User::all(), function (User $user): void { $addedBoxes = $user->boxes()->count(); $verifiedBoxes = $user->boxesVerified()->count(); diff --git a/app/Console/Commands/Users/UpdateRedisLocationsXp.php b/app/Console/Commands/Users/UpdateRedisLocationsXp.php index d51be99e7..91d95925d 100644 --- a/app/Console/Commands/Users/UpdateRedisLocationsXp.php +++ b/app/Console/Commands/Users/UpdateRedisLocationsXp.php @@ -46,11 +46,11 @@ public function __construct(UpdateLeaderboardsForLocationAction $action) */ public function handle() { - $this->withProgressBar(User::all(), function (User $user) { + $this->withProgressBar(User::all(), function (User $user): void { $user->photos() ->with(Photo::categories()) ->lazyById() - ->each(function (Photo $photo) { + ->each(function (Photo $photo): void { $xp = $this->calculateXp($photo); $this->updateLeaderboardsAction->run($photo, $photo->user_id, $xp); @@ -60,10 +60,6 @@ public function handle() return 0; } - /** - * @param Photo $photo - * @return int - */ private function calculateXp(Photo $photo): int { $xpFromPhoto = 1; diff --git a/app/Helpers/Get/LoadDataHelper.php b/app/Helpers/Get/LoadDataHelper.php index 6c4c4cb0f..081ba6f43 100644 --- a/app/Helpers/Get/LoadDataHelper.php +++ b/app/Helpers/Get/LoadDataHelper.php @@ -14,12 +14,8 @@ class LoadDataHelper * Get the States for a Country * * /world/{country} - * - * @param string $url - * - * @return array */ - public static function getStates (string $url) : array + public static function getStates(string $url): array { $urlText = urldecode($url); @@ -28,10 +24,10 @@ public static function getStates (string $url) : array ->orWhere('shortcode', $urlText) ->first(); - if (!$country) { + if (! $country) { return [ 'success' => false, - 'msg' => 'country not found' + 'msg' => 'country not found', ]; } @@ -46,34 +42,33 @@ public static function getStates (string $url) : array 'updated_at', 'user_id_last_uploaded' ) - ->with([ - 'creator' => function ($q) { - $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby') - ->where('show_name_createdby', true) - ->orWhere('show_username_createdby', true); - }, - 'lastUploader' => function ($q) { - $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') - ->where('show_name_createdby', true) - ->orWhere('show_username_createdby', true); - } - ]) - ->where([ - 'country_id' => $country->id, - 'manual_verify' => 1, - ['total_litter', '>', 0], - ['total_contributors', '>', 0] - ]) - ->orderBy('state', 'asc') - ->get(); + ->with([ + 'creator' => function ($q): void { + $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby') + ->where('show_name_createdby', true) + ->orWhere('show_username_createdby', true); + }, + 'lastUploader' => function ($q): void { + $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') + ->where('show_name_createdby', true) + ->orWhere('show_username_createdby', true); + }, + ]) + ->where([ + 'country_id' => $country->id, + 'manual_verify' => 1, + ['total_litter', '>', 0], + ['total_contributors', '>', 0], + ]) + ->orderBy('state', 'asc') + ->get(); $total_litter = 0; $total_photos = 0; $countryName = $country->country; - foreach ($states as $state) - { + foreach ($states as $state) { // Get Creator info $state = LocationHelper::getCreatorInfo($state); @@ -99,22 +94,18 @@ public static function getStates (string $url) : array 'countryName' => $countryName, 'states' => $states, 'total_litter' => $total_litter, - 'total_photos' => $total_photos + 'total_photos' => $total_photos, ]; } /** * Get the cities for the /country/state * - * @param null $country (string) - * @param string $state - * - * @return array + * @param null $country (string) */ - public static function getCities ($country, string $state) : array + public static function getCities($country, string $state): array { - if ($country) - { + if ($country) { $countryText = urldecode($country); $country = Country::where('id', $countryText) @@ -122,7 +113,9 @@ public static function getCities ($country, string $state) : array ->orWhere('shortcode', $countryText) ->first(); - if (!$country) return ['success' => false, 'msg' => 'country not found']; + if (! $country) { + return ['success' => false, 'msg' => 'country not found']; + } } $stateText = urldecode($state); @@ -133,7 +126,9 @@ public static function getCities ($country, string $state) : array ->orWhere('statenameb', $stateText) ->first(); - if (!$state) return ['success' => false, 'msg' => 'state not found']; + if (! $state) { + return ['success' => false, 'msg' => 'state not found']; + } /** * Instead of loading the photos here on the city model, @@ -151,38 +146,37 @@ public static function getCities ($country, string $state) : array 'total_contributors', 'user_id_last_uploaded' ) - ->with([ - 'creator' => function ($q) { - $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby') - ->where('show_name_createdby', true) - ->orWhere('show_username_createdby', true); - }, - 'lastUploader' => function ($q) { - $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') - ->where('show_name_createdby', true) - ->orWhere('show_username_createdby', true); - } - ]) - ->where([ - ['state_id', $state->id], - ['total_images', '>', 0], - ['total_litter', '>', 0], - ['total_contributors', '>', 0] - ]) - ->orderBy('city', 'asc') - ->get(); + ->with([ + 'creator' => function ($q): void { + $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby') + ->where('show_name_createdby', true) + ->orWhere('show_username_createdby', true); + }, + 'lastUploader' => function ($q): void { + $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') + ->where('show_name_createdby', true) + ->orWhere('show_username_createdby', true); + }, + ]) + ->where([ + ['state_id', $state->id], + ['total_images', '>', 0], + ['total_litter', '>', 0], + ['total_contributors', '>', 0], + ]) + ->orderBy('city', 'asc') + ->get(); $countryName = $country->country; $stateName = $state->state; - foreach ($cities as $city) - { + foreach ($cities as $city) { // Get Creator info $city = LocationHelper::getCreatorInfo($city); // Get Leaderboard -// $leaderboardIds = Redis::zrevrange("xp.country.$country->id.state.$state->id.city.$city->id", 0, 9, 'withscores'); -// $city['leaderboard'] = Leaderboard::getLeadersByUserIds($leaderboardIds); + // $leaderboardIds = Redis::zrevrange("xp.country.$country->id.state.$state->id.city.$city->id", 0, 9, 'withscores'); + // $city['leaderboard'] = Leaderboard::getLeadersByUserIds($leaderboardIds); $city['leaderboard'] = []; $city['avg_photo_per_user'] = $city->total_contributors > 0 @@ -198,7 +192,7 @@ public static function getCities ($country, string $state) : array 'success' => true, 'country' => $countryName, 'state' => $stateName, - 'cities' => $cities + 'cities' => $cities, ]; } } diff --git a/app/Http/Controllers/API/GetMyPaginatedUploadsController.php b/app/Http/Controllers/API/GetMyPaginatedUploadsController.php index ed6f4477c..6095b353a 100644 --- a/app/Http/Controllers/API/GetMyPaginatedUploadsController.php +++ b/app/Http/Controllers/API/GetMyPaginatedUploadsController.php @@ -17,11 +17,8 @@ class GetMyPaginatedUploadsController * A lot of duplication here with GetPaginatedHistoryController * * Todo - validate the request - * - * @param Request $request - * @return JsonResponse */ - public function __invoke (Request $request): JsonResponse + public function __invoke(Request $request): JsonResponse { $user = Auth::guard('api')->user(); @@ -36,37 +33,36 @@ public function __invoke (Request $request): JsonResponse ->where('user_id', $user->id) - ->when($request->filterCountry !== 'all', function ($q) use ($request) { + ->when($request->filterCountry !== 'all', function ($q) use ($request): void { $q->where('country_id', $request->filterCountry); }) - ->when($request->filterDateFrom, function ($q) use ($request) { + ->when($request->filterDateFrom, function ($q) use ($request): void { $q->whereDate('created_at', '>=', $request->filterDateFrom); }) - ->when($request->filterDateTo, function ($q) use ($request) { + ->when($request->filterDateTo, function ($q) use ($request): void { $q->whereDate('created_at', '<=', $request->filterDateTo); }) // Filter by tags: needs improvement to search by category, item, quantity // instead of looking at the result_string, we should be looking at the photos relationships - ->when($request->filterTag, function ($q) use ($request) { - $q->where('result_string', 'like', '%' . $request->filterTag . '%'); + ->when($request->filterTag, function ($q) use ($request): void { + $q->where('result_string', 'like', '%'.$request->filterTag.'%'); }) - ->when($request->filterCustomTag, function ($q) use ($request) { - $q->whereHas('customTags', function ($q) use ($request) { - $q->where('tag', 'like', '%' . $request->filterCustomTag . '%'); + ->when($request->filterCustomTag, function ($q) use ($request): void { + $q->whereHas('customTags', function ($q) use ($request): void { + $q->where('tag', 'like', '%'.$request->filterCustomTag.'%'); }); }); - $notInclude = CustomTag::notIncludeTags(); - $query->whereDoesntHave('customTags', function ($q) use ($notInclude) { + $query->whereDoesntHave('customTags', function ($q) use ($notInclude): void { $q->whereIn('tag', $notInclude); }); - $photos = $query->with(['customTags' => function ($query) use ($notInclude) { + $photos = $query->with(['customTags' => function ($query) use ($notInclude): void { $query->whereNotIn('tag', $notInclude); }]) ->orderBy('id', 'desc') @@ -74,7 +70,7 @@ public function __invoke (Request $request): JsonResponse return response()->json([ 'success' => true, - 'photos' => $photos + 'photos' => $photos, ]); } } diff --git a/app/Http/Controllers/Admin/FindPhotoByIdController.php b/app/Http/Controllers/Admin/FindPhotoByIdController.php index 56c454298..f056d197a 100644 --- a/app/Http/Controllers/Admin/FindPhotoByIdController.php +++ b/app/Http/Controllers/Admin/FindPhotoByIdController.php @@ -2,31 +2,31 @@ namespace App\Http\Controllers\Admin; +use App\Http\Controllers\Controller; use App\Models\Photo; -use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; -use App\Http\Controllers\Controller; +use Illuminate\Http\Request; class FindPhotoByIdController extends Controller { /** * Admin can load any photo by its ID */ - public function __invoke (Request $request): JsonResponse + public function __invoke(Request $request): JsonResponse { $photo = Photo::with([ 'customTags', - 'user' => function ($q) { + 'user' => function ($q): void { $q->select('id', 'username'); - } + }, ]) - ->where('id', $request['photoId']) - ->first(); + ->where('id', $request['photoId']) + ->first(); - if (!$photo) { + if (! $photo) { return response()->json([ 'success' => false, - 'photo' => null + 'photo' => null, ]); } @@ -34,7 +34,7 @@ public function __invoke (Request $request): JsonResponse return response()->json([ 'success' => true, - 'photo' => $photo + 'photo' => $photo, ]); } } diff --git a/app/Http/Controllers/Admin/GetNextImageToVerifyController.php b/app/Http/Controllers/Admin/GetNextImageToVerifyController.php index b2a34eefa..ad6a57719 100644 --- a/app/Http/Controllers/Admin/GetNextImageToVerifyController.php +++ b/app/Http/Controllers/Admin/GetNextImageToVerifyController.php @@ -2,50 +2,43 @@ namespace App\Http\Controllers\Admin; -use App\Models\Photo; -use App\Http\Requests\GetImageForVerificationRequest; - use App\Http\Controllers\Controller; - -use Illuminate\Support\Facades\Redis; +use App\Http\Requests\GetImageForVerificationRequest; +use App\Models\Photo; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Facades\Redis; class GetNextImageToVerifyController extends Controller { /** * Get the next image to verify - * - * @param GetImageForVerificationRequest $request - * @return array */ - public function __invoke (GetImageForVerificationRequest $request): array + public function __invoke(GetImageForVerificationRequest $request): array { // Photos that are uploaded and tagged come first /** @var Photo $photo */ $photo = $this->filterPhotos() - ->when($request->skip, function ($q) use ($request) { + ->when($request->skip, function ($q) use ($request): void { $q->skip((int) $request->skip); }) ->where('verification', 0.1) ->first(); - if (!$photo) - { + if (! $photo) { // Photos that have been uploaded, but not tagged or submitted for verification /** @var Photo $photo */ $photo = $this->filterPhotos() - ->when($request->skip, function ($q) use ($request) { + ->when($request->skip, function ($q) use ($request): void { $q->skip($request->skip); }) ->where('verification', 0) ->first(); } - if (!$photo) - { + if (! $photo) { return [ 'success' => false, - 'msg' => 'photo not found' + 'msg' => 'photo not found', ]; } @@ -75,9 +68,8 @@ public function __invoke (GetImageForVerificationRequest $request): array $userVerificationCount = false; - if (Redis::hexists("user_verification_count", $photo->user_id)) - { - $userVerificationCount = Redis::hget("user_verification_count", $photo->user_id); + if (Redis::hexists('user_verification_count', $photo->user_id)) { + $userVerificationCount = Redis::hget('user_verification_count', $photo->user_id); } return [ @@ -85,12 +77,13 @@ public function __invoke (GetImageForVerificationRequest $request): array 'photosNotProcessed' => $photosNotProcessed, 'photosAwaitingVerification' => $photosAwaitingVerification, 'userVerificationCount' => $userVerificationCount, - 'photosNotProcessedForAdminTagging' => $photosNotProcessedForAdminTagging + 'photosNotProcessedForAdminTagging' => $photosNotProcessedForAdminTagging, ]; } /** * Generates a query builder with filtered photos + * * @return Builder|mixed */ private function filterPhotos(): Builder @@ -99,7 +92,7 @@ private function filterPhotos(): Builder ->whereHas('user', function ($q) { return $q->where('verification_required', true); }) - ->with(['user' => function ($q) { + ->with(['user' => function ($q): void { $q->select('id', 'username', 'verification_required'); }]) ->with('customTags') diff --git a/app/Http/Controllers/Admin/GoBackOnePhotoController.php b/app/Http/Controllers/Admin/GoBackOnePhotoController.php index 004387ed0..372b50ee4 100644 --- a/app/Http/Controllers/Admin/GoBackOnePhotoController.php +++ b/app/Http/Controllers/Admin/GoBackOnePhotoController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers\Admin; -use App\Models\Photo; use App\Http\Controllers\Controller; +use App\Models\Photo; use Illuminate\Http\Request; class GoBackOnePhotoController extends Controller @@ -13,39 +13,35 @@ class GoBackOnePhotoController extends Controller * * Allow them to go back 1 photo */ - public function __invoke (Request $request) + public function __invoke(Request $request) { - $photoId = (int)$request['photoId']; - $filterMyOwnPhotos = (boolean)$request['filterMyOwnPhotos']; + $photoId = (int) $request['photoId']; + $filterMyOwnPhotos = (bool) $request['filterMyOwnPhotos']; $userId = auth()->user()->id; $query = Photo::query(); - if ($filterMyOwnPhotos) - { + if ($filterMyOwnPhotos) { $query->where('user_id', $userId) - ->where('id', '<', $photoId) - ->orderBy('id', 'desc'); - } - else - { - $photoId = $photoId -1; + ->where('id', '<', $photoId) + ->orderBy('id', 'desc'); + } else { + $photoId = $photoId - 1; $query->where('id', $photoId); } $photo = $query->with([ 'customTags', - 'user' => function ($q) { + 'user' => function ($q): void { $q->select('id', 'username'); - } + }, ])->first(); - if (!$photo) - { + if (! $photo) { return [ 'success' => false, - 'msg' => 'photo not found' + 'msg' => 'photo not found', ]; } @@ -54,7 +50,7 @@ public function __invoke (Request $request) return [ 'success' => true, - 'photo' => $photo + 'photo' => $photo, ]; } } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 54e67bde4..7a2ae40c8 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -4,12 +4,10 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; - -use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Password; - +use Illuminate\Support\Str; class ResetPasswordController extends Controller { @@ -46,7 +44,6 @@ public function __construct() /** * Reset the given user's password. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ public function reset(Request $request) @@ -57,7 +54,7 @@ public function reset(Request $request) // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( - $this->credentials($request), function ($user, $password) { + $this->credentials($request), function ($user, $password): void { $this->resetPassword($user, $password); } ); @@ -97,7 +94,6 @@ protected function validationErrorMessages() /** * Get the password reset credentials from the request. * - * @param \Illuminate\Http\Request $request * @return array */ protected function credentials(Request $request) @@ -128,14 +124,14 @@ protected function resetPassword($user, $password) /** * Get the response for a successful password reset. * - * @param string $response + * @param string $response * @return \Illuminate\Http\JsonResponse */ protected function sendResetResponse($response) { return response()->json([ 'success' => true, - 'message' => trans($response) + 'message' => trans($response), ]); } @@ -150,7 +146,7 @@ protected function sendResetFailedResponse(Request $request, $response) { return response()->json([ 'success' => false, - 'errors' => ['email' => [trans($response)]] + 'errors' => ['email' => [trans($response)]], ], 422); } @@ -174,7 +170,6 @@ protected function guard() return Auth::guard(); } - /** * Get the post register / login redirect path. * @@ -188,5 +183,4 @@ public function redirectPath() return property_exists($this, 'redirectTo') ? $this->redirectTo : '/'; } - } diff --git a/app/Http/Controllers/Cleanups/GetCleanupsGeoJsonController.php b/app/Http/Controllers/Cleanups/GetCleanupsGeoJsonController.php index 0318128b0..3b90fbbd0 100644 --- a/app/Http/Controllers/Cleanups/GetCleanupsGeoJsonController.php +++ b/app/Http/Controllers/Cleanups/GetCleanupsGeoJsonController.php @@ -5,7 +5,6 @@ use App\Http\Controllers\Controller; use App\Models\Cleanups\Cleanup; use App\Traits\GeoJson\CreateGeoJsonPoints; -use Illuminate\Http\Request; class GetCleanupsGeoJsonController extends Controller { @@ -14,20 +13,20 @@ class GetCleanupsGeoJsonController extends Controller /** * Return geojson array of cleanups */ - public function __invoke () + public function __invoke() { // Only load cleanups where the date is in the future // Todo: Load name, username, team of user when its set to public - $cleanups = Cleanup::with(['users' => function ($q) { + $cleanups = Cleanup::with(['users' => function ($q): void { $q->select('user_id'); }]) - ->get(); + ->get(); - $geojson = $this->createGeojsonPoints("OLM Cleanups", $cleanups); + $geojson = $this->createGeojsonPoints('OLM Cleanups', $cleanups); return [ 'success' => true, - 'geojson' => $geojson + 'geojson' => $geojson, ]; } } diff --git a/app/Http/Controllers/Cleanups/JoinCleanupController.php b/app/Http/Controllers/Cleanups/JoinCleanupController.php index 795524033..373951c46 100644 --- a/app/Http/Controllers/Cleanups/JoinCleanupController.php +++ b/app/Http/Controllers/Cleanups/JoinCleanupController.php @@ -5,38 +5,35 @@ use App\Http\Controllers\Controller; use App\Models\Cleanups\Cleanup; use App\Models\Cleanups\CleanupUser; -use Illuminate\Http\Request; class JoinCleanupController extends Controller { /** * Join a cleanup */ - public function __invoke ($link) + public function __invoke($link) { - $cleanup = Cleanup::with(['users' => function ($q) { + $cleanup = Cleanup::with(['users' => function ($q): void { $q->select('user_id'); }]) - ->where('invite_link', $link) - ->first(); + ->where('invite_link', $link) + ->first(); - if (!$cleanup) - { + if (! $cleanup) { return [ 'success' => false, - 'msg' => 'cleanup not found' + 'msg' => 'cleanup not found', ]; } // If the user is not logged in // - zoom to location // - ask them to create an account - if (!auth()->check()) - { + if (! auth()->check()) { return [ 'success' => false, 'msg' => 'unauthenticated', - 'cleanup' => $cleanup + 'cleanup' => $cleanup, ]; } @@ -45,33 +42,31 @@ public function __invoke ($link) $exists = CleanupUser::where([ 'cleanup_id' => $cleanup->id, - 'user_id' => $user->id + 'user_id' => $user->id, ])->first(); - if ($exists) - { + if ($exists) { return [ 'success' => false, 'msg' => 'already joined', - 'cleanup' => $cleanup + 'cleanup' => $cleanup, ]; } try { $cleanup->users()->attach($user); - } - catch (\Exception $e) { + } catch (\Exception $e) { \Log::info(['JoinCleanupController', $e->getMessage()]); return [ 'success' => false, - 'msg' => 'problem joining cleanup' + 'msg' => 'problem joining cleanup', ]; } return [ 'success' => true, - 'cleanup' => $cleanup + 'cleanup' => $cleanup, ]; } } diff --git a/app/Http/Controllers/DownloadsController.php b/app/Http/Controllers/DownloadsController.php index c1c8bddb8..7616a715f 100644 --- a/app/Http/Controllers/DownloadsController.php +++ b/app/Http/Controllers/DownloadsController.php @@ -2,2183 +2,2173 @@ namespace App\Http\Controllers; -use Excel; -use App\Models\Litter\Categories\Smoking; use App\Models\Litter\Categories\Alcohol; +use App\Models\Litter\Categories\Art; +use App\Models\Litter\Categories\Brand; +use App\Models\Litter\Categories\Coastal; use App\Models\Litter\Categories\Coffee; use App\Models\Litter\Categories\Food; -use App\Models\Litter\Categories\SoftDrinks; -use App\Models\Litter\Categories\Drugs; -use App\Models\Litter\Categories\Sanitary; use App\Models\Litter\Categories\Other; -use App\Models\Litter\Categories\Coastal; use App\Models\Litter\Categories\Pathway; -use App\Models\Litter\Categories\Art; -use App\Models\Litter\Categories\Brand; -use App\Models\Litter\Categories\TrashDog; -use App\Models\Litter\Categories\Dumping; -use App\Models\Litter\Categories\Industrial; - -use App\Models\Photo; - +use App\Models\Litter\Categories\Sanitary; +use App\Models\Litter\Categories\Smoking; +use App\Models\Litter\Categories\SoftDrinks; +use App\Models\Location\City; use App\Models\Location\Country; use App\Models\Location\State; -use App\Models\Location\City; -use Illuminate\Http\Request; +use App\Models\Photo; +use Excel; class DownloadsController extends Controller { + public function getDataByState($state = null) + { + if ($state) { + // State only + // need to pass the variable down the chain + Excel::create('Open Litter Map', function ($excel) use ($state): void { + + $excel->sheet('OLM', function ($sheet) use ($state): void { + + $state = State::where('state', $state)->first(); + + $photos = Photo::where([ + ['state_id', $state->id], + ['verified', '>', 0], + ])->get(); + + $export = []; + foreach ($photos as $index => $photo) { + $index++; + $export[$index]['id'] = $index; + $export[$index]['verification'] = $photo->verified; + $export[$index]['phone'] = $photo->model; + $export[$index]['datetime'] = $photo->datetime; + $export[$index]['lat'] = $photo->lat; + $export[$index]['lon'] = $photo->lon; + $export[$index]['city'] = $photo->city; + $export[$index]['state'] = $photo->county; + $export[$index]['country'] = $photo->country; + $export[$index]['remaining_beta'] = $photo->remaining; + $export[$index]['address'] = $photo->display_name; + $export[$index]['total_litter'] = $photo->total_litter; + + $export[$index]['cigaretteButts'] = 0; + $export[$index]['lighters'] = 0; + $export[$index]['cigaretteBox'] = 0; + $export[$index]['tobaccoPouch'] = 0; + $export[$index]['papers_filters'] = 0; + $export[$index]['plastic_smoking_pk'] = 0; + $export[$index]['filters'] = 0; + $export[$index]['filterbox'] = 0; + $export[$index]['smokingOther'] = 0; + + $export[$index]['sweetWrappers'] = 0; + $export[$index]['paperFoodPackaging'] = 0; + $export[$index]['plasticFoodPackaging'] = 0; + $export[$index]['plasticCutlery'] = 0; + $export[$index]['crisp_small'] = 0; + $export[$index]['crisp_large'] = 0; + $export[$index]['styrofoam_plate'] = 0; + $export[$index]['napkins'] = 0; + $export[$index]['sauce_packet'] = 0; + $export[$index]['glass_jar'] = 0; + $export[$index]['glass_jar_lid'] = 0; + $export[$index]['foodOther'] = 0; + + $export[$index]['coffeeCups'] = 0; + $export[$index]['coffeeLids'] = 0; + $export[$index]['coffeeOther'] = 0; + + $export[$index]['beerCan'] = 0; + $export[$index]['beerBottle'] = 0; + $export[$index]['spiritBottle'] = 0; + $export[$index]['wineBottle'] = 0; + $export[$index]['brokenGlass'] = 0; + $export[$index]['paperCardAlcoholPackaging'] = 0; + $export[$index]['plasticAlcoholPackaging'] = 0; + $export[$index]['bottleTops'] = 0; + $export[$index]['alcoholOther'] = 0; + + $export[$index]['plasticWaterBottle'] = 0; + $export[$index]['fizzyDrinkBottle'] = 0; + $export[$index]['bottleLid'] = 0; + $export[$index]['bottleLabel'] = 0; + $export[$index]['tinCan'] = 0; + $export[$index]['sportsDrink'] = 0; + $export[$index]['straws'] = 0; + $export[$index]['plastic_cups'] = 0; + $export[$index]['plastic_cup_tops'] = 0; + $export[$index]['milk_bottle'] = 0; + $export[$index]['milk_carton'] = 0; + $export[$index]['paper_cups'] = 0; + $export[$index]['juice_cartons'] = 0; + $export[$index]['juice_bottles'] = 0; + $export[$index]['juice_packet'] = 0; + $export[$index]['ice_tea_bottles'] = 0; + $export[$index]['ice_tea_can'] = 0; + $export[$index]['energy_can'] = 0; + $export[$index]['softDrinkOther'] = 0; + + $export[$index]['gloves'] = 0; + $export[$index]['facemasks'] = 0; + $export[$index]['condoms'] = 0; + $export[$index]['mental'] = 0; + $export[$index]['deodorant'] = 0; + $export[$index]['ear_swabs'] = 0; + $export[$index]['tooth_pick'] = 0; + $export[$index]['tooth_brush'] = 0; + $export[$index]['sanitaryOther'] = 0; + + $export[$index]['dogshit'] = 0; + $export[$index]['Random_dump'] = 0; + $export[$index]['No_id_plastic'] = 0; + $export[$index]['Metal_object'] = 0; + $export[$index]['plastic_bags'] = 0; + $export[$index]['election_posters'] = 0; + $export[$index]['forsale_posters'] = 0; + $export[$index]['books'] = 0; + $export[$index]['magazines'] = 0; + $export[$index]['paper'] = 0; + $export[$index]['stationary'] = 0; + $export[$index]['washing_up'] = 0; + $export[$index]['hair_tie'] = 0; + $export[$index]['ear_plugs'] = 0; + $export[$index]['batteries'] = 0; + $export[$index]['elec_small'] = 0; + $export[$index]['elec_large'] = 0; + $export[$index]['Other_Unknown'] = 0; + + $export[$index]['microplastics'] = 0; + $export[$index]['mediumplastics'] = 0; + $export[$index]['macroplastics'] = 0; + $export[$index]['rope_small'] = 0; + $export[$index]['rope_medium'] = 0; + $export[$index]['rope_large'] = 0; + $export[$index]['fishing_gear_nets'] = 0; + $export[$index]['buoys'] = 0; + $export[$index]['degraded_plasticbottle'] = 0; + $export[$index]['degraded_plasticbag'] = 0; + $export[$index]['degraded_straws'] = 0; + $export[$index]['degraded_lighters'] = 0; + $export[$index]['baloons'] = 0; + $export[$index]['lego'] = 0; + $export[$index]['shotgun_cartridges'] = 0; + $export[$index]['coastal_other'] = 0; + + $export[$index]['adidas'] = 0; + $export[$index]['amazon'] = 0; + $export[$index]['aldi'] = 0; + $export[$index]['apple'] = 0; + $export[$index]['applegreen'] = 0; + $export[$index]['asahi'] = 0; + $export[$index]['avoca'] = 0; + + $export[$index]['ballygowan'] = 0; + $export[$index]['bewleys'] = 0; + $export[$index]['brambles'] = 0; + $export[$index]['budweiser'] = 0; + $export[$index]['bulmers'] = 0; + $export[$index]['burgerking'] = 0; + $export[$index]['butlers'] = 0; + + $export[$index]['cadburys'] = 0; + $export[$index]['cafe_nero'] = 0; + $export[$index]['camel'] = 0; + $export[$index]['carlsberg'] = 0; + $export[$index]['centra'] = 0; + $export[$index]['coke'] = 0; + $export[$index]['circlek'] = 0; + $export[$index]['coles'] = 0; + $export[$index]['colgate'] = 0; + $export[$index]['corona'] = 0; + $export[$index]['costa'] = 0; + + $export[$index]['doritos'] = 0; + $export[$index]['drpepper'] = 0; + $export[$index]['dunnes'] = 0; + $export[$index]['duracell'] = 0; + $export[$index]['durex'] = 0; + + $export[$index]['esquires'] = 0; + + $export[$index]['frank_and_honest'] = 0; + $export[$index]['fritolay'] = 0; + + $export[$index]['gatorade'] = 0; + $export[$index]['gillette'] = 0; + $export[$index]['guinness'] = 0; + + $export[$index]['haribo'] = 0; + $export[$index]['heineken'] = 0; + + $export[$index]['insomnia'] = 0; + + $export[$index]['kellogs'] = 0; + $export[$index]['kfc'] = 0; + + $export[$index]['lego'] = 0; + $export[$index]['lidl'] = 0; + $export[$index]['lindenvillage'] = 0; + $export[$index]['lolly_and_cookes'] = 0; + $export[$index]['loreal'] = 0; + $export[$index]['lucozade'] = 0; + + $export[$index]['nero'] = 0; + $export[$index]['nescafe'] = 0; + $export[$index]['nestle'] = 0; + + $export[$index]['marlboro'] = 0; + $export[$index]['mars'] = 0; + $export[$index]['mcdonalds'] = 0; + + $export[$index]['nike'] = 0; + + $export[$index]['obriens'] = 0; + + $export[$index]['pepsi'] = 0; + $export[$index]['powerade'] = 0; + + $export[$index]['redbull'] = 0; + $export[$index]['ribena'] = 0; + + $export[$index]['samsung'] = 0; + $export[$index]['sainsburys'] = 0; + $export[$index]['spar'] = 0; + $export[$index]['subway'] = 0; + $export[$index]['supermacs'] = 0; + $export[$index]['supervalu'] = 0; + $export[$index]['starbucks'] = 0; + + $export[$index]['tayto'] = 0; + $export[$index]['tesco'] = 0; + $export[$index]['thins'] = 0; + + $export[$index]['volvic'] = 0; + + $export[$index]['waitrose'] = 0; + $export[$index]['walkers'] = 0; + $export[$index]['woolworths'] = 0; + $export[$index]['wilde_and_greene'] = 0; + $export[$index]['wrigleys'] = 0; + + if ($photo['smoking_id']) { + $smoking = Smoking::find($photo['smoking_id']); + if ($smoking['butts']) { + $export[$index]['cigaretteButts'] = $smoking['butts']; + } + if ($smoking['lighters']) { + $export[$index]['lighters'] = $smoking['lighters']; + } + if ($smoking['cigaretteBox']) { + $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; + } + if ($smoking['tobaccoPouch']) { + $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; + } + if ($smoking['skins']) { + $export[$index]['papers_filters'] = $smoking['skins']; + } + if ($smoking['plastic']) { + $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; + } + if ($smoking['filters']) { + $export[$index]['filters'] = $smoking['filters']; + } + if ($smoking['filterbox']) { + $export[$index]['filterbox'] = $smoking['filterbox']; + } + if ($smoking['smokingOther']) { + $export[$index]['smokingOther'] = $smoking['smokingOther']; + } + } + + if ($photo['food_id']) { + $food = Food::find($photo['food_id']); + if ($food['sweetWrappers']) { + $export[$index]['sweetWrappers'] = $food['sweetWrappers']; + } + if ($food['paperFoodPackaging']) { + $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; + } + if ($food['plasticFoodPackaging']) { + $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; + } + if ($food['plasticCutlery']) { + $export[$index]['plasticCutlery'] = $food['plasticCutlery']; + } + if ($food['crisp_small']) { + $export[$index]['crisp_small'] = $food['crisp_small']; + } + if ($food['crisp_large']) { + $export[$index]['crisp_large'] = $food['crisp_large']; + } + if ($food['styrofoam_plate']) { + $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; + } + if ($food['napkins']) { + $export[$index]['napkins'] = $food['napkins']; + } + if ($food['sauce_packet']) { + $export[$index]['sauce_packet'] = $food['sauce_packet']; + } + if ($food['glass_jar']) { + $export[$index]['glass_jar'] = $food['glass_jar']; + } + if ($food['glass_jar_lid']) { + $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; + } + if ($food['foodOther']) { + $export[$index]['foodOther'] = $food['foodOther']; + } + } + + if ($photo['coffee_id']) { + $coffee = Coffee::find($photo['coffee_id']); + if ($coffee['coffeeCups']) { + $export[$index]['coffeeCups'] = $coffee['coffeeCups']; + } + if ($coffee['coffeeLids']) { + $export[$index]['coffeeLids'] = $coffee['coffeeLids']; + } + if ($coffee['coffeeOther']) { + $export[$index]['coffeeOther'] = $coffee['coffeeOther']; + } + } + + if ($photo['alcohol_id']) { + $alcohol = Alcohol::find($photo['alcohol_id']); + if ($alcohol['beerBottle']) { + $export[$index]['beerBottle'] = $alcohol['beerBottle']; + } + if ($alcohol['spiritBottle']) { + $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; + } + if ($alcohol['beerCan']) { + $export[$index]['beerCan'] = $alcohol['beerCan']; + } + if ($alcohol['brokenGlass']) { + $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; + } + if ($alcohol['paperCardAlcoholPackaging']) { + $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; + } + if ($alcohol['plasticAlcoholPackaging']) { + $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; + } + if ($alcohol['bottleTops']) { + $export[$index]['bottleTops'] = $alcohol['bottleTops']; + } + if ($alcohol['wineBottle']) { + $export[$index]['wineBottle'] = $alcohol['wineBottle']; + } + if ($alcohol['alcoholOther']) { + $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; + } + } + + if ($photo['softdrinks_id']) { + $softdrinks = SoftDrinks::find($photo['softdrinks_id']); + if ($softdrinks['waterBottle']) { + $export[$index]['plasticWaterBottle'] = $softdrinks['waterBottle']; + } + if ($softdrinks['fizzyDrinkBottle']) { + $export[$index]['fizzyDrinkBottle'] = $softdrinks['fizzyDrinkBottle']; + } + if ($softdrinks['bottleLid']) { + $export[$index]['bottleLid'] = $softdrinks['bottleLid']; + } + if ($softdrinks['bottleLabel']) { + $export[$index]['bottleLabel'] = $softdrinks['bottleLabel']; + } + if ($softdrinks['tinCan']) { + $export[$index]['tinCan'] = $softdrinks['tinCan']; + } + if ($softdrinks['sportsDrink']) { + $export[$index]['sportsDrink'] = $softdrinks['sportsDrink']; + } + if ($softdrinks['paper_cups']) { + $export[$index]['paper_cups'] = $softdrinks['paper_cups']; + } + if ($softdrinks['juice_cartons']) { + $export[$index]['juice_cartons'] = $softdrinks['juice_cartons']; + } + if ($softdrinks['juice_bottles']) { + $export[$index]['juice_bottles'] = $softdrinks['juice_bottles']; + } + if ($softdrinks['juice_packet']) { + $export[$index]['juice_packet'] = $softdrinks['juice_packet']; + } + if ($softdrinks['ice_tea_bottles']) { + $export[$index]['ice_tea_bottles'] = $softdrinks['ice_tea_bottles']; + } + if ($softdrinks['ice_tea_can']) { + $export[$index]['ice_tea_can'] = $softdrinks['ice_tea_can']; + } + if ($softdrinks['energy_can']) { + $export[$index]['energy_can'] = $softdrinks['energy_can']; + } + if ($softdrinks['softDrinkOther']) { + $export[$index]['softDrinkOther'] = $softdrinks['softDrinkOther']; + } + } + + if ($photo['sanitary_id']) { + $sanitary = Sanitary::find($photo['sanitary_id']); + if ($sanitary['gloves']) { + $export[$index]['gloves'] = $sanitary['gloves']; + } + if ($sanitary['facemasks']) { + $export[$index]['facemasks'] = $sanitary['facemasks']; + } + if ($sanitary['condoms']) { + $export[$index]['condoms'] = $sanitary['condoms']; + } + if ($sanitary['nappies']) { + $export[$index]['nappies'] = $sanitary['nappies']; + } + if ($sanitary['menstral']) { + $export[$index]['menstral'] = $sanitary['menstral']; + } + if ($sanitary['deodorant']) { + $export[$index]['deodorant'] = $sanitary['deodorant']; + } + if ($sanitary['sanitaryOther']) { + $export[$index]['sanitaryOther'] = $sanitary['sanitaryOther']; + } + } + + if ($photo['other_id']) { + $other = Other::find($photo['other_id']); + if ($other['dogshit']) { + $export[$index]['dogshit'] = $other['dogshit']; + } + if ($other['dump']) { + $export[$index]['Random_dump'] = $other['dump']; + } + if ($other['plastic']) { + $export[$index]['No_id_plastic'] = $other['plastic']; + } + if ($other['metal']) { + $export[$index]['Metal_object'] = $other['metal']; + } + if ($other['washing_up']) { + $export[$index]['washing_up'] = $other['washing_up']; + } + if ($other['hair_tie']) { + $export[$index]['hair_tie'] = $other['hair_tie']; + } + if ($other['ear_plugs']) { + $export[$index]['ear_plugs'] = $other['ear_plugs']; + } + if ($other['batteries']) { + $export[$index]['batteries'] = $other['batteries']; + } + if ($other['elec_small']) { + $export[$index]['elec_small'] = $other['elec_small']; + } + if ($other['elec_large']) { + $export[$index]['elec_large'] = $other['elec_large']; + } + if ($other['other']) { + $export[$index]['Unknown'] = $other['other']; + } + } + + if ($photo['coastal_id']) { + $coastal = Coastal::find($photo['coastal_id']); + if ($coastal['microplastics']) { + $export[$index]['microplastics'] = $coastal['microplastics']; + } + if ($coastal['mediumplastics']) { + $export[$index]['mediumplastics'] = $coastal['mediumplastics']; + } + if ($coastal['macroplastics']) { + $export[$index]['macroplastics'] = $coastal['macroplastics']; + } + if ($coastal['rope_small']) { + $export[$index]['rope_small'] = $coastal['rope_small']; + } + if ($coastal['rope_medium']) { + $export[$index]['rope_medium'] = $coastal['rope_medium']; + } + if ($coastal['rope_large']) { + $export[$index]['rope_large'] = $coastal['rope_large']; + } + if ($coastal['fishing_gear_nets']) { + $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; + } + if ($coastal['buoys']) { + $export[$index]['buoys'] = $coastal['buoys']; + } + if ($coastal['degraded_plasticbottle']) { + $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; + } + if ($coastal['degraded_plasticbag']) { + $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; + } + if ($coastal['degraded_straws']) { + $export[$index]['degraded_straws'] = $coastal['degraded_straws']; + } + if ($coastal['degraded_lighters']) { + $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; + } + if ($coastal['baloons']) { + $export[$index]['baloons'] = $coastal['baloons']; + } + if ($coastal['lego']) { + $export[$index]['lego'] = $coastal['lego']; + } + if ($coastal['shotgun_cartridges']) { + $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; + } + if ($coastal['coastal_other']) { + $export[$index]['coastal_other'] = $coastal['coastal_other']; + } + } + + // if($photo["art_id"]) { + // $art = Art::find($photo["art_id"]); + // if($art['item']) { + // $export[$index]['art'] = $art['item']; + // } + // } + + if ($photo['brands_id']) { + $brands = Brand::find($photo['brands_id']); + if ($brands['adidas']) { + $export[$index]['adidas'] = $brands['adidas']; + } + if ($brands['amazon']) { + $export[$index]['amazon'] = $brands['amazon']; + } + if ($brands['apple']) { + $export[$index]['apple'] = $brands['apple']; + } + if ($brands['budweiser']) { + $export[$index]['budweiser'] = $brands['budweiser']; + } + if ($brands['coke']) { + $export[$index]['coke'] = $brands['coke']; + } + if ($brands['colgate']) { + $export[$index]['colgate'] = $brands['colgate']; + } + if ($brands['corona']) { + $export[$index]['corona'] = $brands['corona']; + } + if ($brands['fritolay']) { + $export[$index]['fritolay'] = $brands['fritolay']; + } + if ($brands['gillette']) { + $export[$index]['gillette'] = $brands['gillette']; + } + if ($brands['heineken']) { + $export[$index]['heineken'] = $brands['heineken']; + } + if ($brands['kellogs']) { + $export[$index]['kellogs'] = $brands['kellogs']; + } + if ($brands['lego']) { + $export[$index]['lego'] = $brands['lego']; + } + if ($brands['loreal']) { + $export[$index]['loreal'] = $brands['loreal']; + } + if ($brands['nescafe']) { + $export[$index]['nescafe'] = $brands['nescafe']; + } + if ($brands['nestle']) { + $export[$index]['nestle'] = $brands['nestle']; + } + if ($brands['marlboro']) { + $export[$index]['marlboro'] = $brands['marlboro']; + } + if ($brands['mcdonalds']) { + $export[$index]['mcdonalds'] = $brands['mcdonalds']; + } + if ($brands['nike']) { + $export[$index]['nike'] = $brands['nike']; + } + if ($brands['pepsi']) { + $export[$index]['pepsi'] = $brands['pepsi']; + } + if ($brands['redbull']) { + $export[$index]['redbull'] = $brands['redbull']; + } + if ($brands['samsung']) { + $export[$index]['samsung'] = $brands['samsung']; + } + if ($brands['subway']) { + $export[$index]['subway'] = $brands['subway']; + } + if ($brands['starbucks']) { + $export[$index]['starbucks'] = $brands['starbucks']; + } + if ($brands['tayto']) { + $export[$index]['tayto'] = $brands['tayto']; + } + } + } + // return $export; + $sheet->fromModel($export); + })->export('csv'); + // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); + }); + } + } - public function getDataByState ($state = null) + /** + * Export Excel data from Verification Stage One to theauthenticated user + */ + public function getDataByCountry($country) { - if ($state) - { - // State only - // need to pass the variable down the chain - Excel::create('Open Litter Map', function($excel) use ($state) { - - $excel->sheet('OLM', function($sheet) use ($state) { - - $state = State::where('state', $state)->first(); - - $photos = Photo::where([ - ['state_id', $state->id], - ['verified', '>', 0] - ])->get(); - - $export = []; - foreach($photos as $index => $photo) { - $index++; - $export[$index]['id'] = $index; - $export[$index]['verification'] = $photo->verified; - $export[$index]['phone'] = $photo->model; - $export[$index]['datetime'] = $photo->datetime; - $export[$index]['lat'] = $photo->lat; - $export[$index]['lon'] = $photo->lon; - $export[$index]['city'] = $photo->city; - $export[$index]['state'] = $photo->county; - $export[$index]['country'] = $photo->country; - $export[$index]['remaining_beta'] = $photo->remaining; - $export[$index]['address'] = $photo->display_name; - $export[$index]['total_litter'] = $photo->total_litter; - - $export[$index]['cigaretteButts'] = 0; - $export[$index]['lighters'] = 0; - $export[$index]['cigaretteBox'] = 0; - $export[$index]['tobaccoPouch'] = 0; - $export[$index]['papers_filters'] = 0; - $export[$index]['plastic_smoking_pk'] = 0; - $export[$index]['filters'] = 0; - $export[$index]['filterbox'] = 0; - $export[$index]['smokingOther'] = 0; - - $export[$index]['sweetWrappers'] = 0; - $export[$index]['paperFoodPackaging'] = 0; - $export[$index]['plasticFoodPackaging'] = 0; - $export[$index]['plasticCutlery'] = 0; - $export[$index]['crisp_small'] = 0; - $export[$index]['crisp_large'] = 0; - $export[$index]['styrofoam_plate'] = 0; - $export[$index]['napkins'] = 0; - $export[$index]['sauce_packet'] = 0; - $export[$index]['glass_jar'] = 0; - $export[$index]['glass_jar_lid'] = 0; - $export[$index]['foodOther'] = 0; - - $export[$index]['coffeeCups'] = 0; - $export[$index]['coffeeLids'] = 0; - $export[$index]['coffeeOther'] = 0; - - $export[$index]['beerCan'] = 0; - $export[$index]['beerBottle'] = 0; - $export[$index]['spiritBottle'] = 0; - $export[$index]['wineBottle'] = 0; - $export[$index]['brokenGlass'] = 0; - $export[$index]['paperCardAlcoholPackaging'] = 0; - $export[$index]['plasticAlcoholPackaging'] = 0; - $export[$index]['bottleTops'] = 0; - $export[$index]['alcoholOther'] = 0; - - $export[$index]['plasticWaterBottle'] = 0; - $export[$index]['fizzyDrinkBottle'] = 0; - $export[$index]['bottleLid'] = 0; - $export[$index]['bottleLabel'] = 0; - $export[$index]['tinCan'] = 0; - $export[$index]['sportsDrink'] = 0; - $export[$index]['straws'] = 0; - $export[$index]['plastic_cups'] = 0; - $export[$index]['plastic_cup_tops'] = 0; - $export[$index]['milk_bottle'] = 0; - $export[$index]['milk_carton'] = 0; - $export[$index]['paper_cups'] = 0; - $export[$index]['juice_cartons'] = 0; - $export[$index]['juice_bottles'] = 0; - $export[$index]['juice_packet'] = 0; - $export[$index]['ice_tea_bottles'] = 0; - $export[$index]['ice_tea_can'] = 0; - $export[$index]['energy_can'] = 0; - $export[$index]['softDrinkOther'] = 0; - - $export[$index]['gloves'] = 0; - $export[$index]['facemasks'] = 0; - $export[$index]['condoms'] = 0; - $export[$index]['mental'] = 0; - $export[$index]['deodorant'] = 0; - $export[$index]['ear_swabs'] = 0; - $export[$index]['tooth_pick'] = 0; - $export[$index]['tooth_brush'] = 0; - $export[$index]['sanitaryOther'] = 0; - - $export[$index]['dogshit'] = 0; - $export[$index]['Random_dump'] = 0; - $export[$index]['No_id_plastic'] = 0; - $export[$index]['Metal_object'] = 0; - $export[$index]['plastic_bags'] = 0; - $export[$index]['election_posters'] = 0; - $export[$index]['forsale_posters'] = 0; - $export[$index]['books'] = 0; - $export[$index]['magazines'] = 0; - $export[$index]['paper'] = 0; - $export[$index]['stationary'] = 0; - $export[$index]['washing_up'] = 0; - $export[$index]['hair_tie'] = 0; - $export[$index]['ear_plugs'] = 0; - $export[$index]['batteries'] = 0; - $export[$index]['elec_small'] = 0; - $export[$index]['elec_large'] = 0; - $export[$index]['Other_Unknown'] = 0; - - $export[$index]['microplastics'] = 0; - $export[$index]['mediumplastics'] = 0; - $export[$index]['macroplastics'] = 0; - $export[$index]['rope_small'] = 0; - $export[$index]['rope_medium'] = 0; - $export[$index]['rope_large'] = 0; - $export[$index]['fishing_gear_nets'] = 0; - $export[$index]['buoys'] = 0; - $export[$index]['degraded_plasticbottle'] = 0; - $export[$index]['degraded_plasticbag'] = 0; - $export[$index]['degraded_straws'] = 0; - $export[$index]['degraded_lighters'] = 0; - $export[$index]['baloons'] = 0; - $export[$index]['lego'] = 0; - $export[$index]['shotgun_cartridges'] = 0; - $export[$index]['coastal_other'] = 0; - - $export[$index]['adidas'] = 0; - $export[$index]['amazon'] = 0; - $export[$index]['aldi'] = 0; - $export[$index]['apple'] = 0; - $export[$index]['applegreen'] = 0; - $export[$index]['asahi'] = 0; - $export[$index]['avoca'] = 0; - - $export[$index]['ballygowan'] = 0; - $export[$index]['bewleys'] = 0; - $export[$index]['brambles'] = 0; - $export[$index]['budweiser'] = 0; - $export[$index]['bulmers'] = 0; - $export[$index]['burgerking'] = 0; - $export[$index]['butlers'] = 0; - - $export[$index]['cadburys'] = 0; - $export[$index]['cafe_nero'] = 0; - $export[$index]['camel'] = 0; - $export[$index]['carlsberg'] = 0; - $export[$index]['centra'] = 0; - $export[$index]['coke'] = 0; - $export[$index]['circlek'] = 0; - $export[$index]['coles'] = 0; - $export[$index]['colgate'] = 0; - $export[$index]['corona'] = 0; - $export[$index]['costa'] = 0; - - $export[$index]['doritos'] = 0; - $export[$index]['drpepper'] = 0; - $export[$index]['dunnes'] = 0; - $export[$index]['duracell'] = 0; - $export[$index]['durex'] = 0; - - $export[$index]['esquires'] = 0; - - $export[$index]['frank_and_honest'] = 0; - $export[$index]['fritolay'] = 0; - - $export[$index]['gatorade'] = 0; - $export[$index]['gillette'] = 0; - $export[$index]['guinness'] = 0; - - $export[$index]['haribo'] = 0; - $export[$index]['heineken'] = 0; - - $export[$index]['insomnia'] = 0; - - $export[$index]['kellogs'] = 0; - $export[$index]['kfc'] = 0; - - $export[$index]['lego'] = 0; - $export[$index]['lidl'] = 0; - $export[$index]['lindenvillage'] = 0; - $export[$index]['lolly_and_cookes'] = 0; - $export[$index]['loreal'] = 0; - $export[$index]['lucozade'] = 0; - - $export[$index]['nero'] = 0; - $export[$index]['nescafe'] = 0; - $export[$index]['nestle'] = 0; - - $export[$index]['marlboro'] = 0; - $export[$index]['mars'] = 0; - $export[$index]['mcdonalds'] = 0; - - $export[$index]['nike'] = 0; - - $export[$index]['obriens'] = 0; - - $export[$index]['pepsi'] = 0; - $export[$index]['powerade'] = 0; - - $export[$index]['redbull'] = 0; - $export[$index]['ribena'] = 0; - - $export[$index]['samsung'] = 0; - $export[$index]['sainsburys'] = 0; - $export[$index]['spar'] = 0; - $export[$index]['subway'] = 0; - $export[$index]['supermacs'] = 0; - $export[$index]['supervalu'] = 0; - $export[$index]['starbucks'] = 0; - - $export[$index]['tayto'] = 0; - $export[$index]['tesco'] = 0; - $export[$index]['thins'] = 0; - - $export[$index]['volvic'] = 0; - - $export[$index]['waitrose'] = 0; - $export[$index]['walkers'] = 0; - $export[$index]['woolworths'] = 0; - $export[$index]['wilde_and_greene'] = 0; - $export[$index]['wrigleys'] = 0; - - if($photo['smoking_id']) { - $smoking = Smoking::find($photo['smoking_id']); - if($smoking['butts']) { - $export[$index]['cigaretteButts'] = $smoking['butts']; - } - if($smoking['lighters']) { - $export[$index]['lighters'] = $smoking['lighters']; - } - if($smoking['cigaretteBox']) { - $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; - } - if($smoking['tobaccoPouch']) { - $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; - } - if($smoking['skins']) { - $export[$index]['papers_filters'] = $smoking['skins']; - } - if($smoking['plastic']) { - $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; - } - if($smoking['filters']) { - $export[$index]['filters'] = $smoking['filters']; - } - if($smoking['filterbox']) { - $export[$index]['filterbox'] = $smoking['filterbox']; - } - if($smoking['smokingOther']) { - $export[$index]['smokingOther'] = $smoking['smokingOther']; - } - } - - if($photo['food_id']) { - $food = Food::find($photo['food_id']); - if($food['sweetWrappers']) { - $export[$index]['sweetWrappers'] = $food['sweetWrappers']; - } - if($food['paperFoodPackaging']) { - $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; - } - if($food['plasticFoodPackaging']) { - $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; - } - if($food['plasticCutlery']) { - $export[$index]['plasticCutlery'] = $food['plasticCutlery']; - } - if($food['crisp_small']) { - $export[$index]['crisp_small'] = $food['crisp_small']; - } - if($food['crisp_large']) { - $export[$index]['crisp_large'] = $food['crisp_large']; - } - if($food['styrofoam_plate']) { - $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; - } - if($food['napkins']) { - $export[$index]['napkins'] = $food['napkins']; - } - if($food['sauce_packet']) { - $export[$index]['sauce_packet'] = $food['sauce_packet']; - } - if($food['glass_jar']) { - $export[$index]['glass_jar'] = $food['glass_jar']; - } - if($food['glass_jar_lid']) { - $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; - } - if($food['foodOther']) { - $export[$index]['foodOther'] = $food['foodOther']; - } - } - - if($photo['coffee_id']) { - $coffee = Coffee::find($photo['coffee_id']); - if($coffee['coffeeCups']) { - $export[$index]['coffeeCups'] = $coffee['coffeeCups']; - } - if($coffee['coffeeLids']) { - $export[$index]['coffeeLids'] = $coffee['coffeeLids']; - } - if($coffee['coffeeOther']) { - $export[$index]['coffeeOther'] = $coffee['coffeeOther']; - } - } - - if($photo['alcohol_id']) { - $alcohol = Alcohol::find($photo['alcohol_id']); - if($alcohol['beerBottle']) { - $export[$index]['beerBottle'] = $alcohol['beerBottle']; - } - if($alcohol['spiritBottle']) { - $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; - } - if($alcohol['beerCan']) { - $export[$index]['beerCan'] = $alcohol['beerCan']; - } - if($alcohol['brokenGlass']) { - $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; - } - if($alcohol['paperCardAlcoholPackaging']) { - $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; - } - if($alcohol['plasticAlcoholPackaging']) { - $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; - } - if($alcohol['bottleTops']) { - $export[$index]['bottleTops'] = $alcohol['bottleTops']; - } - if($alcohol['wineBottle']) { - $export[$index]['wineBottle'] = $alcohol['wineBottle']; - } - if($alcohol['alcoholOther']) { - $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; - } - } - - if($photo["softdrinks_id"]) { - $softdrinks = SoftDrinks::find($photo["softdrinks_id"]); - if($softdrinks['waterBottle']) { - $export[$index]['plasticWaterBottle'] = $softdrinks["waterBottle"]; - } - if($softdrinks['fizzyDrinkBottle']) { - $export[$index]['fizzyDrinkBottle'] = $softdrinks["fizzyDrinkBottle"]; - } - if($softdrinks['bottleLid']) { - $export[$index]['bottleLid'] = $softdrinks["bottleLid"]; - } - if($softdrinks['bottleLabel']) { - $export[$index]['bottleLabel'] = $softdrinks["bottleLabel"]; - } - if($softdrinks['tinCan']) { - $export[$index]['tinCan'] = $softdrinks["tinCan"]; - } - if($softdrinks['sportsDrink']) { - $export[$index]['sportsDrink'] = $softdrinks["sportsDrink"]; - } - if($softdrinks['paper_cups']) { - $export[$index]['paper_cups'] = $softdrinks["paper_cups"]; - } - if($softdrinks['juice_cartons']) { - $export[$index]['juice_cartons'] = $softdrinks["juice_cartons"]; - } - if($softdrinks['juice_bottles']) { - $export[$index]['juice_bottles'] = $softdrinks["juice_bottles"]; - } - if($softdrinks['juice_packet']) { - $export[$index]['juice_packet'] = $softdrinks["juice_packet"]; - } - if($softdrinks['ice_tea_bottles']) { - $export[$index]['ice_tea_bottles'] = $softdrinks["ice_tea_bottles"]; - } - if($softdrinks['ice_tea_can']) { - $export[$index]['ice_tea_can'] = $softdrinks["ice_tea_can"]; - } - if($softdrinks['energy_can']) { - $export[$index]['energy_can'] = $softdrinks["energy_can"]; - } - if($softdrinks['softDrinkOther']) { - $export[$index]['softDrinkOther'] = $softdrinks["softDrinkOther"]; - } - } - - if($photo["sanitary_id"]){ - $sanitary = Sanitary::find($photo["sanitary_id"]); - if ($sanitary['gloves']) { - $export[$index]['gloves'] = $sanitary['gloves']; - } - if ($sanitary['facemasks']) { - $export[$index]['facemasks'] = $sanitary['facemasks']; - } - if($sanitary["condoms"]) { - $export[$index]["condoms"] = $sanitary["condoms"]; - } - if($sanitary["nappies"]) { - $export[$index]["nappies"] = $sanitary["nappies"]; - } - if($sanitary["menstral"]) { - $export[$index]["menstral"] = $sanitary["menstral"]; - } - if($sanitary["deodorant"]) { - $export[$index]["deodorant"] = $sanitary["deodorant"]; - } - if($sanitary["sanitaryOther"]) { - $export[$index]["sanitaryOther"] = $sanitary["sanitaryOther"]; - } - } - - if($photo['other_id']) { - $other = Other::find($photo["other_id"]); - if($other['dogshit']) { - $export[$index]["dogshit"] = $other['dogshit']; - } - if($other["dump"]) { - $export[$index]["Random_dump"] = $other["dump"]; - } - if($other["plastic"]) { - $export[$index]["No_id_plastic"] = $other["plastic"]; - } - if($other["metal"]) { - $export[$index]["Metal_object"] = $other["metal"]; - } - if($other["washing_up"]) { - $export[$index]["washing_up"] = $other["washing_up"]; - } - if($other["hair_tie"]) { - $export[$index]["hair_tie"] = $other["hair_tie"]; - } - if($other["ear_plugs"]) { - $export[$index]["ear_plugs"] = $other["ear_plugs"]; - } - if($other["batteries"]) { - $export[$index]["batteries"] = $other["batteries"]; - } - if($other["elec_small"]) { - $export[$index]["elec_small"] = $other["elec_small"]; - } - if($other["elec_large"]) { - $export[$index]["elec_large"] = $other["elec_large"]; - } - if($other["other"]) { - $export[$index]["Unknown"] = $other["other"]; - } - } - - if($photo['coastal_id']) { - $coastal = Coastal::find($photo["coastal_id"]); - if($coastal['microplastics']) { - $export[$index]["microplastics"] = $coastal['microplastics']; - } - if($coastal['mediumplastics']) { - $export[$index]["mediumplastics"] = $coastal['mediumplastics']; - } - if($coastal['macroplastics']) { - $export[$index]['macroplastics'] = $coastal['macroplastics']; - } - if($coastal['rope_small']) { - $export[$index]['rope_small'] = $coastal['rope_small']; - } - if($coastal['rope_medium']) { - $export[$index]['rope_medium'] = $coastal['rope_medium']; - } - if($coastal['rope_large']) { - $export[$index]['rope_large'] = $coastal['rope_large']; - } - if($coastal['fishing_gear_nets']) { - $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; - } - if($coastal['buoys']) { - $export[$index]['buoys'] = $coastal['buoys']; - } - if($coastal['degraded_plasticbottle']) { - $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; - } - if($coastal['degraded_plasticbag']) { - $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; - } - if($coastal['degraded_straws']) { - $export[$index]['degraded_straws'] = $coastal['degraded_straws']; - } - if($coastal['degraded_lighters']) { - $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; - } - if($coastal['baloons']) { - $export[$index]['baloons'] = $coastal['baloons']; - } - if($coastal['lego']) { - $export[$index]['lego'] = $coastal['lego']; - } - if($coastal['shotgun_cartridges']) { - $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; - } - if($coastal['coastal_other']) { - $export[$index]['coastal_other'] = $coastal['coastal_other']; - } - } - - // if($photo["art_id"]) { - // $art = Art::find($photo["art_id"]); - // if($art['item']) { - // $export[$index]['art'] = $art['item']; - // } - // } - - if($photo["brands_id"]) { - $brands = Brand::find($photo["brands_id"]); - if($brands["adidas"]) { - $export[$index]['adidas'] = $brands["adidas"]; - } - if($brands["amazon"]) { - $export[$index]['amazon'] = $brands["amazon"]; - } - if($brands["apple"]) { - $export[$index]['apple'] = $brands["apple"]; - } - if($brands["budweiser"]) { - $export[$index]['budweiser'] = $brands["budweiser"]; - } - if($brands["coke"]) { - $export[$index]['coke'] = $brands["coke"]; - } - if($brands["colgate"]) { - $export[$index]['colgate'] = $brands["colgate"]; - } - if($brands["corona"]) { - $export[$index]['corona'] = $brands["corona"]; - } - if($brands["fritolay"]) { - $export[$index]['fritolay'] = $brands["fritolay"]; - } - if($brands["gillette"]) { - $export[$index]['gillette'] = $brands["gillette"]; - } - if($brands["heineken"]) { - $export[$index]['heineken'] = $brands["heineken"]; - } - if($brands["kellogs"]) { - $export[$index]['kellogs'] = $brands["kellogs"]; - } - if($brands["lego"]) { - $export[$index]['lego'] = $brands["lego"]; - } - if($brands["loreal"]) { - $export[$index]['loreal'] = $brands["loreal"]; - } - if($brands["nescafe"]) { - $export[$index]['nescafe'] = $brands["nescafe"]; - } - if($brands["nestle"]) { - $export[$index]['nestle'] = $brands["nestle"]; - } - if($brands["marlboro"]) { - $export[$index]['marlboro'] = $brands["marlboro"]; - } - if($brands["mcdonalds"]) { - $export[$index]['mcdonalds'] = $brands["mcdonalds"]; - } - if($brands["nike"]) { - $export[$index]['nike'] = $brands["nike"]; - } - if($brands["pepsi"]) { - $export[$index]['pepsi'] = $brands["pepsi"]; - } - if($brands["redbull"]) { - $export[$index]['redbull'] = $brands["redbull"]; - } - if($brands["samsung"]) { - $export[$index]['samsung'] = $brands["samsung"]; - } - if($brands["subway"]) { - $export[$index]['subway'] = $brands["subway"]; - } - if($brands["starbucks"]) { - $export[$index]['starbucks'] = $brands["starbucks"]; - } - if($brands["tayto"]) { - $export[$index]['tayto'] = $brands["tayto"]; - } - } - } - // return $export; - $sheet->fromModel($export); - })->export('csv'); - // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); - }); - } - } - - /** - * Export Excel data from Verification Stage One to theauthenticated user - */ - public function getDataByCountry($country) { - // Country only - // need to pass the variable down the chain - Excel::create('Open Litter Map', function($excel) use ($country) { - - $excel->sheet('OLM', function($sheet) use ($country) { - - $country = Country::where('country', $country)->first(); - - $photos = Photo::where([ - ['country_id', $country->id], - ['verified', '>', 0] - ])->get(); - - $export = []; - - foreach($photos as $index => $photo) { - $index++; - $export[$index]['id'] = $index; - $export[$index]['verification'] = $photo->verified; - $export[$index]['phone'] = $photo->model; - $export[$index]['datetime'] = $photo->datetime; - $export[$index]['lat'] = $photo->lat; - $export[$index]['lon'] = $photo->lon; - $export[$index]['country'] = $photo->country; - $export[$index]['state'] = $photo->county; - $export[$index]['city'] = $photo->city; - $export[$index]['remaining_beta'] = $photo->remaining; - $export[$index]['address'] = $photo->display_name; - $export[$index]['total_litter'] = $photo->total_litter; - - $export[$index]['cigaretteButts'] = 0; - $export[$index]['lighters'] = 0; - $export[$index]['cigaretteBox'] = 0; - $export[$index]['tobaccoPouch'] = 0; - $export[$index]['papers_filters'] = 0; - $export[$index]['plastic_smoking_pk'] = 0; - $export[$index]['filters'] = 0; - $export[$index]['filterbox'] = 0; - $export[$index]['smokingOther'] = 0; - - $export[$index]['sweetWrappers'] = 0; - $export[$index]['paperFoodPackaging'] = 0; - $export[$index]['plasticFoodPackaging'] = 0; - $export[$index]['plasticCutlery'] = 0; - $export[$index]['crisp_small'] = 0; - $export[$index]['crisp_large'] = 0; - $export[$index]['styrofoam_plate'] = 0; - $export[$index]['napkins'] = 0; - $export[$index]['sauce_packet'] = 0; - $export[$index]['glass_jar'] = 0; - $export[$index]['glass_jar_lid'] = 0; - $export[$index]['foodOther'] = 0; - - $export[$index]['coffeeCups'] = 0; - $export[$index]['coffeeLids'] = 0; - $export[$index]['coffeeOther'] = 0; - - $export[$index]['beerCan'] = 0; - $export[$index]['beerBottle'] = 0; - $export[$index]['spiritBottle'] = 0; - $export[$index]['wineBottle'] = 0; - $export[$index]['brokenGlass'] = 0; - $export[$index]['paperCardAlcoholPackaging'] = 0; - $export[$index]['plasticAlcoholPackaging'] = 0; - $export[$index]['bottleTops'] = 0; - $export[$index]['alcoholOther'] = 0; - - $export[$index]['plasticWaterBottle'] = 0; - $export[$index]['fizzyDrinkBottle'] = 0; - $export[$index]['bottleLid'] = 0; - $export[$index]['bottleLabel'] = 0; - $export[$index]['tinCan'] = 0; - $export[$index]['sportsDrink'] = 0; - $export[$index]['straws'] = 0; - $export[$index]['plastic_cups'] = 0; - $export[$index]['plastic_cup_tops'] = 0; - $export[$index]['milk_bottle'] = 0; - $export[$index]['milk_carton'] = 0; - $export[$index]['paper_cups'] = 0; - $export[$index]['juice_cartons'] = 0; - $export[$index]['juice_bottles'] = 0; - $export[$index]['juice_packet'] = 0; - $export[$index]['ice_tea_bottles'] = 0; - $export[$index]['ice_tea_can'] = 0; - $export[$index]['energy_can'] = 0; - $export[$index]['softDrinkOther'] = 0; - - - $export[$index]['gloves'] = 0; - $export[$index]['facemasks'] = 0; - $export[$index]['condoms'] = 0; - $export[$index]['mental'] = 0; - $export[$index]['deodorant'] = 0; - $export[$index]['ear_swabs'] = 0; - $export[$index]['tooth_pick'] = 0; - $export[$index]['tooth_brush'] = 0; - $export[$index]['sanitaryOther'] = 0; - $export[$index]['dogshit'] = 0; - $export[$index]['Random_dump'] = 0; - $export[$index]['No_id_plastic'] = 0; - $export[$index]['Metal_object'] = 0; - $export[$index]['plastic_bags'] = 0; - $export[$index]['election_posters'] = 0; - $export[$index]['forsale_posters'] = 0; - $export[$index]['books'] = 0; - $export[$index]['magazines'] = 0; - $export[$index]['paper'] = 0; - $export[$index]['stationary'] = 0; - $export[$index]['washing_up'] = 0; - $export[$index]['hair_tie'] = 0; - $export[$index]['ear_plugs'] = 0; - $export[$index]['batteries'] = 0; - $export[$index]['elec_small'] = 0; - $export[$index]['elec_large'] = 0; - $export[$index]['Other_Unknown'] = 0; - - $export[$index]['microplastics'] = 0; - $export[$index]['mediumplastics'] = 0; - $export[$index]['macroplastics'] = 0; - $export[$index]['rope_small'] = 0; - $export[$index]['rope_medium'] = 0; - $export[$index]['rope_large'] = 0; - $export[$index]['fishing_gear_nets'] = 0; - $export[$index]['buoys'] = 0; - $export[$index]['degraded_plasticbottle'] = 0; - $export[$index]['degraded_plasticbag'] = 0; - $export[$index]['degraded_straws'] = 0; - $export[$index]['degraded_lighters'] = 0; - $export[$index]['baloons'] = 0; - $export[$index]['lego'] = 0; - $export[$index]['shotgun_cartridges'] = 0; - $export[$index]['coastal_other'] = 0; - - $export[$index]['art'] = 0; - - $export[$index]['adidas'] = 0; - $export[$index]['amazon'] = 0; - $export[$index]['aldi'] = 0; - $export[$index]['apple'] = 0; - $export[$index]['applegreen'] = 0; - $export[$index]['asahi'] = 0; - $export[$index]['avoca'] = 0; - - $export[$index]['ballygowan'] = 0; - $export[$index]['bewleys'] = 0; - $export[$index]['brambles'] = 0; - $export[$index]['budweiser'] = 0; - $export[$index]['bulmers'] = 0; - $export[$index]['burgerking'] = 0; - $export[$index]['butlers'] = 0; - - $export[$index]['cadburys'] = 0; - $export[$index]['cafe_nero'] = 0; - $export[$index]['camel'] = 0; - $export[$index]['carlsberg'] = 0; - $export[$index]['centra'] = 0; - $export[$index]['coke'] = 0; - $export[$index]['circlek'] = 0; - $export[$index]['coles'] = 0; - $export[$index]['colgate'] = 0; - $export[$index]['corona'] = 0; - $export[$index]['costa'] = 0; - - $export[$index]['doritos'] = 0; - $export[$index]['drpepper'] = 0; - $export[$index]['dunnes'] = 0; - $export[$index]['duracell'] = 0; - $export[$index]['durex'] = 0; - - $export[$index]['esquires'] = 0; - - $export[$index]['frank_and_honest'] = 0; - $export[$index]['fritolay'] = 0; - - $export[$index]['gatorade'] = 0; - $export[$index]['gillette'] = 0; - $export[$index]['guinness'] = 0; - - $export[$index]['haribo'] = 0; - $export[$index]['heineken'] = 0; - - $export[$index]['insomnia'] = 0; - - $export[$index]['kellogs'] = 0; - $export[$index]['kfc'] = 0; - - $export[$index]['lego'] = 0; - $export[$index]['lidl'] = 0; - $export[$index]['lindenvillage'] = 0; - $export[$index]['lolly_and_cookes'] = 0; - $export[$index]['loreal'] = 0; - $export[$index]['lucozade'] = 0; - - $export[$index]['nero'] = 0; - $export[$index]['nescafe'] = 0; - $export[$index]['nestle'] = 0; - - $export[$index]['marlboro'] = 0; - $export[$index]['mars'] = 0; - $export[$index]['mcdonalds'] = 0; - - $export[$index]['nike'] = 0; - - $export[$index]['obriens'] = 0; - - $export[$index]['pepsi'] = 0; - $export[$index]['powerade'] = 0; - - $export[$index]['redbull'] = 0; - $export[$index]['ribena'] = 0; - - $export[$index]['samsung'] = 0; - $export[$index]['sainsburys'] = 0; - $export[$index]['spar'] = 0; - $export[$index]['subway'] = 0; - $export[$index]['supermacs'] = 0; - $export[$index]['supervalu'] = 0; - $export[$index]['starbucks'] = 0; - - $export[$index]['tayto'] = 0; - $export[$index]['tesco'] = 0; - $export[$index]['thins'] = 0; - - $export[$index]['volvic'] = 0; - - $export[$index]['waitrose'] = 0; - $export[$index]['walkers'] = 0; - $export[$index]['woolworths'] = 0; - $export[$index]['wilde_and_greene'] = 0; - $export[$index]['wrigleys'] = 0; - - if($photo['smoking_id']) { - $smoking = Smoking::find($photo['smoking_id']); - if($smoking['butts']) { - $export[$index]['cigaretteButts'] = $smoking['butts']; - } - if($smoking['lighters']) { - $export[$index]['lighters'] = $smoking['lighters']; - } - if($smoking['cigaretteBox']) { - $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; - } - if($smoking['tobaccoPouch']) { - $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; - } - if($smoking['skins']) { - $export[$index]['papers_filters'] = $smoking['skins']; - } - if($smoking['plastic']) { - $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; - } - if($smoking['filters']) { - $export[$index]['filters'] = $smoking['filters']; - } - if($smoking['filterbox']) { - $export[$index]['filterbox'] = $smoking['filterbox']; - } - if($smoking['smokingOther']) { - $export[$index]['smokingOther'] = $smoking['smokingOther']; - } - } - - if($photo['food_id']) { - $food = Food::find($photo['food_id']); - if($food['sweetWrappers']) { - $export[$index]['sweetWrappers'] = $food['sweetWrappers']; - } - if($food['paperFoodPackaging']) { - $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; - } - if($food['plasticFoodPackaging']) { - $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; - } - if($food['plasticCutlery']) { - $export[$index]['plasticCutlery'] = $food['plasticCutlery']; - } - if($food['crisp_small']) { - $export[$index]['crisp_small'] = $food['crisp_small']; - } - if($food['crisp_large']) { - $export[$index]['crisp_large'] = $food['crisp_large']; - } - if($food['styrofoam_plate']) { - $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; - } - if($food['napkins']) { - $export[$index]['napkins'] = $food['napkins']; - } - if($food['sauce_packet']) { - $export[$index]['sauce_packet'] = $food['sauce_packet']; - } - if($food['glass_jar']) { - $export[$index]['glass_jar'] = $food['glass_jar']; - } - if($food['glass_jar_lid']) { - $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; - } - if($food['foodOther']) { - $export[$index]['foodOther'] = $food['foodOther']; - } - } - - if($photo['coffee_id']) { - $coffee = Coffee::find($photo['coffee_id']); - if($coffee['coffeeCups']) { - $export[$index]['coffeeCups'] = $coffee['coffeeCups']; - } - if($coffee['coffeeLids']) { - $export[$index]['coffeeLids'] = $coffee['coffeeLids']; - } - if($coffee['coffeeOther']) { - $export[$index]['coffeeOther'] = $coffee['coffeeOther']; - } - } - - if($photo['alcohol_id']) { - $alcohol = Alcohol::find($photo['alcohol_id']); - if($alcohol['beerBottle']) { - $export[$index]['beerBottle'] = $alcohol['beerBottle']; - } - if($alcohol['spiritBottle']) { - $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; - } - if($alcohol['beerCan']) { - $export[$index]['beerCan'] = $alcohol['beerCan']; - } - if($alcohol['brokenGlass']) { - $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; - } - if($alcohol['paperCardAlcoholPackaging']) { - $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; - } - if($alcohol['plasticAlcoholPackaging']) { - $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; - } - if($alcohol['bottleTops']) { - $export[$index]['bottleTops'] = $alcohol['bottleTops']; - } - if($alcohol['wineBottle']) { - $export[$index]['wineBottle'] = $alcohol['wineBottle']; - } - if($alcohol['alcoholOther']) { - $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; - } - } - - if($photo["softdrinks_id"]) { - $softdrinks = SoftDrinks::find($photo["softdrinks_id"]); - if($softdrinks['waterBottle']) { - $export[$index]['plasticWaterBottle'] = $softdrinks["waterBottle"]; - } - if($softdrinks['fizzyDrinkBottle']) { - $export[$index]['fizzyDrinkBottle'] = $softdrinks["fizzyDrinkBottle"]; - } - if($softdrinks['bottleLid']) { - $export[$index]['bottleLid'] = $softdrinks["bottleLid"]; - } - if($softdrinks['bottleLabel']) { - $export[$index]['bottleLabel'] = $softdrinks["bottleLabel"]; - } - if($softdrinks['tinCan']) { - $export[$index]['tinCan'] = $softdrinks["tinCan"]; - } - if($softdrinks['sportsDrink']) { - $export[$index]['sportsDrink'] = $softdrinks["sportsDrink"]; - } - if($softdrinks['paper_cups']) { - $export[$index]['paper_cups'] = $softdrinks["paper_cups"]; - } - if($softdrinks['juice_cartons']) { - $export[$index]['juice_cartons'] = $softdrinks["juice_cartons"]; - } - if($softdrinks['juice_bottles']) { - $export[$index]['juice_bottles'] = $softdrinks["juice_bottles"]; - } - if($softdrinks['juice_packet']) { - $export[$index]['juice_packet'] = $softdrinks["juice_packet"]; - } - if($softdrinks['ice_tea_bottles']) { - $export[$index]['ice_tea_bottles'] = $softdrinks["ice_tea_bottles"]; - } - if($softdrinks['ice_tea_can']) { - $export[$index]['ice_tea_can'] = $softdrinks["ice_tea_can"]; - } - if($softdrinks['energy_can']) { - $export[$index]['energy_can'] = $softdrinks["energy_can"]; - } - if($softdrinks['softDrinkOther']) { - $export[$index]['softDrinkOther'] = $softdrinks["softDrinkOther"]; - } - } - - if($photo["sanitary_id"]){ - $sanitary = Sanitary::find($photo["sanitary_id"]); - if ($sanitary['gloves']) { - $export[$index]['gloves'] = $sanitary['gloves']; - } - if ($sanitary['facemasks']) { - $export[$index]['facemasks'] = $sanitary['facemasks']; - } - if($sanitary["condoms"]) { - $export[$index]["condoms"] = $sanitary["condoms"]; - } - if($sanitary["nappies"]) { - $export[$index]["nappies"] = $sanitary["nappies"]; - } - if($sanitary["menstral"]) { - $export[$index]["menstral"] = $sanitary["menstral"]; - } - if($sanitary["deodorant"]) { - $export[$index]["deodorant"] = $sanitary["deodorant"]; - } - if($sanitary["sanitaryOther"]) { - $export[$index]["sanitaryOther"] = $sanitary["sanitaryOther"]; - } - } - - if($photo['other_id']) { - $other = Other::find($photo["other_id"]); - if($other['dogshit']) { - $export[$index]["dogshit"] = $other['dogshit']; - } - if($other["dump"]) { - $export[$index]["Random_dump"] = $other["dump"]; - } - if($other["plastic"]) { - $export[$index]["No_id_plastic"] = $other["plastic"]; - } - if($other["metal"]) { - $export[$index]["Metal_object"] = $other["metal"]; - } - if($other["washing_up"]) { - $export[$index]["washing_up"] = $other["washing_up"]; - } - if($other["hair_tie"]) { - $export[$index]["hair_tie"] = $other["hair_tie"]; - } - if($other["ear_plugs"]) { - $export[$index]["ear_plugs"] = $other["ear_plugs"]; - } - if($other["batteries"]) { - $export[$index]["batteries"] = $other["batteries"]; - } - if($other["elec_small"]) { - $export[$index]["elec_small"] = $other["elec_small"]; - } - if($other["elec_large"]) { - $export[$index]["elec_large"] = $other["elec_large"]; - } - if($other["other"]) { - $export[$index]["Unknown"] = $other["other"]; - } - } - - if($photo['coastal_id']) { - $coastal = Coastal::find($photo["coastal_id"]); - if($coastal['microplastics']) { - $export[$index]["microplastics"] = $coastal['microplastics']; - } - if($coastal['mediumplastics']) { - $export[$index]["mediumplastics"] = $coastal['mediumplastics']; - } - if($coastal['macroplastics']) { - $export[$index]['macroplastics'] = $coastal['macroplastics']; - } - if($coastal['rope_small']) { - $export[$index]['rope_small'] = $coastal['rope_small']; - } - if($coastal['rope_medium']) { - $export[$index]['rope_medium'] = $coastal['rope_medium']; - } - if($coastal['rope_large']) { - $export[$index]['rope_large'] = $coastal['rope_large']; - } - if($coastal['fishing_gear_nets']) { - $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; - } - if($coastal['buoys']) { - $export[$index]['buoys'] = $coastal['buoys']; - } - if($coastal['degraded_plasticbottle']) { - $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; - } - if($coastal['degraded_plasticbag']) { - $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; - } - if($coastal['degraded_straws']) { - $export[$index]['degraded_straws'] = $coastal['degraded_straws']; - } - if($coastal['degraded_lighters']) { - $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; - } - if($coastal['baloons']) { - $export[$index]['baloons'] = $coastal['baloons']; - } - if($coastal['lego']) { - $export[$index]['lego'] = $coastal['lego']; - } - if($coastal['shotgun_cartridges']) { - $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; - } - if($coastal['coastal_other']) { - $export[$index]['coastal_other']; - } - } - - // if($photo["art_id"]) { - // $art = Art::find($photo["art_id"]); - // if($art['item']) { - // $export[$index]['art'] = $art['item']; - // } - // } - - if($photo["brands_id"]) { - $brands = Brand::find($photo["brands_id"]); - if($brands["adidas"]) { - $export[$index]['adidas'] = $brands["adidas"]; - } - if($brands["amazon"]) { - $export[$index]['amazon'] = $brands["amazon"]; - } - if($brands["aldi"]) { - $export[$index]['aldi'] = $brands["aldi"]; - } - if($brands["apple"]) { - $export[$index]['apple'] = $brands["apple"]; - } - if($brands["applegreen"]) { - $export[$index]['applegreen'] = $brands["applegreen"]; - } - if($brands["asahi"]) { - $export[$index]['asahi'] = $brands["asahi"]; - } - if($brands["avoca"]) { - $export[$index]['avoca'] = $brands["avoca"]; - } - if($brands["ballygowan"]) { - $export[$index]['ballygowan'] = $brands["ballygowan"]; - } - if($brands["bewleys"]) { - $export[$index]['bewleys'] = $brands["bewleys"]; - } - if($brands["brambles"]) { - $export[$index]['brambles'] = $brands["brambles"]; - } - if($brands["budweiser"]) { - $export[$index]['budweiser'] = $brands["budweiser"]; - } - if($brands["bulmers"]) { - $export[$index]['bulmers'] = $brands["bulmers"]; - } - if($brands["burgerking"]) { - $export[$index]['burgerking'] = $brands["burgerking"]; - } - if($brands["butlers"]) { - $export[$index]['butlers'] = $brands["butlers"]; - } - - if($brands["cadburys"]) { - $export[$index]['cadburys'] = $brands["cadburys"]; - } - if($brands["cafe_nero"]) { - $export[$index]['cafe_nero'] = $brands["cafe_nero"]; - } - if($brands["camel"]) { - $export[$index]['camel'] = $brands["camel"]; - } - if($brands["carlsberg"]) { - $export[$index]['carlsberg'] = $brands["carlsberg"]; - } - if($brands["centra"]) { - $export[$index]['centra'] = $brands["centra"]; - } - if($brands["coke"]) { - $export[$index]['coke'] = $brands["coke"]; - } - if($brands["circlek"]) { - $export[$index]['circlek'] = $brands["circlek"]; - } - if($brands["coles"]) { - $export[$index]['coles'] = $brands["coles"]; - } - if($brands["colgate"]) { - $export[$index]['colgate'] = $brands["colgate"]; - } - if($brands["corona"]) { - $export[$index]['corona'] = $brands["corona"]; - } - if($brands["costa"]) { - $export[$index]['costa'] = $brands["costa"]; - } - - if($brands["doritos"]) { - $export[$index]['doritos'] = $brands["doritos"]; - } - if($brands["drpepper"]) { - $export[$index]['drpepper'] = $brands["drpepper"]; - } - if($brands["dunnes"]) { - $export[$index]['dunnes'] = $brands["dunnes"]; - } - if($brands["duracell"]) { - $export[$index]['duracell'] = $brands["duracell"]; - } - if($brands["durex"]) { - $export[$index]['durex'] = $brands["durex"]; - } - - if($brands["esquires"]) { - $export[$index]['esquires'] = $brands["esquires"]; - } - - if($brands["frank_and_honest"]) { - $export[$index]['frank_and_honest'] = $brands["frank_and_honest"]; - } - if($brands["fritolay"]) { - $export[$index]['fritolay'] = $brands["fritolay"]; - } - - if($brands["gatorade"]) { - $export[$index]['gatorade'] = $brands["gatorade"]; - } - if($brands["gillette"]) { - $export[$index]['gillette'] = $brands["gillette"]; - } - if($brands["guinness"]) { - $export[$index]['guinness'] = $brands["gillette"]; - } - - if($brands["haribo"]) { - $export[$index]['haribo'] = $brands["haribo"]; - } - if($brands["heineken"]) { - $export[$index]['heineken'] = $brands["heineken"]; - } - - if($brands["insomnia"]) { - $export[$index]['insomnia'] = $brands["insomnia"]; - } - - if($brands["kellogs"]) { - $export[$index]['kellogs'] = $brands["kellogs"]; - } - if($brands["kfc"]) { - $export[$index]['kfc'] = $brands["kfc"]; - } - - if($brands["lego"]) { - $export[$index]['lego'] = $brands["lego"]; - } - if($brands["lidl"]) { - $export[$index]['lidl'] = $brands["lidl"]; - } - if($brands["lindenvillage"]) { - $export[$index]['lindenvillage'] = $brands["lindenvillage"]; - } - if($brands["lolly_and_cookes"]) { - $export[$index]['lolly_and_cookes'] = $brands["lolly_and_cookes"]; - } - if($brands["loreal"]) { - $export[$index]['loreal'] = $brands["loreal"]; - } - if($brands["lucozade"]) { - $export[$index]['lucozade'] = $brands["lucozade"]; - } - - if($brands["marlboro"]) { - $export[$index]['marlboro'] = $brands["marlboro"]; - } - if($brands["mars"]) { - $export[$index]['mars'] = $brands["mars"]; - } - if($brands["mcdonalds"]) { - $export[$index]['mcdonalds'] = $brands["mcdonalds"]; - } - - if($brands["nero"]) { - $export[$index]['nero'] = $brands["nero"]; - } - if($brands["nescafe"]) { - $export[$index]['nescafe'] = $brands["nescafe"]; - } - if($brands["nestle"]) { - $export[$index]['nestle'] = $brands["nestle"]; - } - if($brands["nike"]) { - $export[$index]['nike'] = $brands["nike"]; - } - - if($brands["obriens"]) { - $export[$index]['obriens'] = $brands["obriens"]; - } - - if($brands["pepsi"]) { - $export[$index]['pepsi'] = $brands["pepsi"]; - } - if($brands["powerade"]) { - $export[$index]['powerade'] = $brands["powerade"]; - } - - if($brands["redbull"]) { - $export[$index]['redbull'] = $brands["redbull"]; - } - if($brands["ribena"]) { - $export[$index]['ribena'] = $brands["ribena"]; - } - - if($brands["samsung"]) { - $export[$index]['samsung'] = $brands["samsung"]; - } - if($brands["sainsburys"]) { - $export[$index]['sainsburys'] = $brands["sainsburys"]; - } - if($brands["spar"]) { - $export[$index]['spar'] = $brands["spar"]; - } - if($brands["stella"]) { - $export[$index]['stella'] = $brands["stella"]; - } - if($brands["subway"]) { - $export[$index]['subway'] = $brands["subway"]; - } - if($brands["supermacs"]) { - $export[$index]['supermacs'] = $brands["supermacs"]; - } - if($brands["supervale"]) { - $export[$index]['supervale'] = $brands["supervale"]; - } - if($brands["starbucks"]) { - $export[$index]['starbucks'] = $brands["starbucks"]; - } - - if($brands["tayto"]) { - $export[$index]['tayto'] = $brands["tayto"]; - } - if($brands["tesco"]) { - $export[$index]['tesco'] = $brands["tesco"]; - } - if($brands["thins"]) { - $export[$index]['thins'] = $brands["thins"]; - } - - if($brands["volvic"]) { - $export[$index]['volvic'] = $brands["volvic"]; - } - - if($brands["waitrose"]) { - $export[$index]['waitrose'] = $brands["waitrose"]; - } - if($brands["walkers"]) { - $export[$index]['walkers'] = $brands["walkers"]; - } - if($brands["woolworths"]) { - $export[$index]['woolworths'] = $brands["woolworths"]; - } - if($brands["wilde_and_greene"]) { - $export[$index]['wilde_and_greene'] = $brands["wilde_and_greene"]; - } - if($brands["wrigleys"]) { - $export[$index]['wrigleys'] = $brands["wrigleys"]; - } - } - } - // return $export; - $sheet->fromModel($export); - })->export('csv'); - // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); - }); + // Country only + // need to pass the variable down the chain + Excel::create('Open Litter Map', function ($excel) use ($country): void { + + $excel->sheet('OLM', function ($sheet) use ($country): void { + + $country = Country::where('country', $country)->first(); + + $photos = Photo::where([ + ['country_id', $country->id], + ['verified', '>', 0], + ])->get(); + + $export = []; + + foreach ($photos as $index => $photo) { + $index++; + $export[$index]['id'] = $index; + $export[$index]['verification'] = $photo->verified; + $export[$index]['phone'] = $photo->model; + $export[$index]['datetime'] = $photo->datetime; + $export[$index]['lat'] = $photo->lat; + $export[$index]['lon'] = $photo->lon; + $export[$index]['country'] = $photo->country; + $export[$index]['state'] = $photo->county; + $export[$index]['city'] = $photo->city; + $export[$index]['remaining_beta'] = $photo->remaining; + $export[$index]['address'] = $photo->display_name; + $export[$index]['total_litter'] = $photo->total_litter; + + $export[$index]['cigaretteButts'] = 0; + $export[$index]['lighters'] = 0; + $export[$index]['cigaretteBox'] = 0; + $export[$index]['tobaccoPouch'] = 0; + $export[$index]['papers_filters'] = 0; + $export[$index]['plastic_smoking_pk'] = 0; + $export[$index]['filters'] = 0; + $export[$index]['filterbox'] = 0; + $export[$index]['smokingOther'] = 0; + + $export[$index]['sweetWrappers'] = 0; + $export[$index]['paperFoodPackaging'] = 0; + $export[$index]['plasticFoodPackaging'] = 0; + $export[$index]['plasticCutlery'] = 0; + $export[$index]['crisp_small'] = 0; + $export[$index]['crisp_large'] = 0; + $export[$index]['styrofoam_plate'] = 0; + $export[$index]['napkins'] = 0; + $export[$index]['sauce_packet'] = 0; + $export[$index]['glass_jar'] = 0; + $export[$index]['glass_jar_lid'] = 0; + $export[$index]['foodOther'] = 0; + + $export[$index]['coffeeCups'] = 0; + $export[$index]['coffeeLids'] = 0; + $export[$index]['coffeeOther'] = 0; + + $export[$index]['beerCan'] = 0; + $export[$index]['beerBottle'] = 0; + $export[$index]['spiritBottle'] = 0; + $export[$index]['wineBottle'] = 0; + $export[$index]['brokenGlass'] = 0; + $export[$index]['paperCardAlcoholPackaging'] = 0; + $export[$index]['plasticAlcoholPackaging'] = 0; + $export[$index]['bottleTops'] = 0; + $export[$index]['alcoholOther'] = 0; + + $export[$index]['plasticWaterBottle'] = 0; + $export[$index]['fizzyDrinkBottle'] = 0; + $export[$index]['bottleLid'] = 0; + $export[$index]['bottleLabel'] = 0; + $export[$index]['tinCan'] = 0; + $export[$index]['sportsDrink'] = 0; + $export[$index]['straws'] = 0; + $export[$index]['plastic_cups'] = 0; + $export[$index]['plastic_cup_tops'] = 0; + $export[$index]['milk_bottle'] = 0; + $export[$index]['milk_carton'] = 0; + $export[$index]['paper_cups'] = 0; + $export[$index]['juice_cartons'] = 0; + $export[$index]['juice_bottles'] = 0; + $export[$index]['juice_packet'] = 0; + $export[$index]['ice_tea_bottles'] = 0; + $export[$index]['ice_tea_can'] = 0; + $export[$index]['energy_can'] = 0; + $export[$index]['softDrinkOther'] = 0; + + $export[$index]['gloves'] = 0; + $export[$index]['facemasks'] = 0; + $export[$index]['condoms'] = 0; + $export[$index]['mental'] = 0; + $export[$index]['deodorant'] = 0; + $export[$index]['ear_swabs'] = 0; + $export[$index]['tooth_pick'] = 0; + $export[$index]['tooth_brush'] = 0; + $export[$index]['sanitaryOther'] = 0; + $export[$index]['dogshit'] = 0; + $export[$index]['Random_dump'] = 0; + $export[$index]['No_id_plastic'] = 0; + $export[$index]['Metal_object'] = 0; + $export[$index]['plastic_bags'] = 0; + $export[$index]['election_posters'] = 0; + $export[$index]['forsale_posters'] = 0; + $export[$index]['books'] = 0; + $export[$index]['magazines'] = 0; + $export[$index]['paper'] = 0; + $export[$index]['stationary'] = 0; + $export[$index]['washing_up'] = 0; + $export[$index]['hair_tie'] = 0; + $export[$index]['ear_plugs'] = 0; + $export[$index]['batteries'] = 0; + $export[$index]['elec_small'] = 0; + $export[$index]['elec_large'] = 0; + $export[$index]['Other_Unknown'] = 0; + + $export[$index]['microplastics'] = 0; + $export[$index]['mediumplastics'] = 0; + $export[$index]['macroplastics'] = 0; + $export[$index]['rope_small'] = 0; + $export[$index]['rope_medium'] = 0; + $export[$index]['rope_large'] = 0; + $export[$index]['fishing_gear_nets'] = 0; + $export[$index]['buoys'] = 0; + $export[$index]['degraded_plasticbottle'] = 0; + $export[$index]['degraded_plasticbag'] = 0; + $export[$index]['degraded_straws'] = 0; + $export[$index]['degraded_lighters'] = 0; + $export[$index]['baloons'] = 0; + $export[$index]['lego'] = 0; + $export[$index]['shotgun_cartridges'] = 0; + $export[$index]['coastal_other'] = 0; + + $export[$index]['art'] = 0; + + $export[$index]['adidas'] = 0; + $export[$index]['amazon'] = 0; + $export[$index]['aldi'] = 0; + $export[$index]['apple'] = 0; + $export[$index]['applegreen'] = 0; + $export[$index]['asahi'] = 0; + $export[$index]['avoca'] = 0; + + $export[$index]['ballygowan'] = 0; + $export[$index]['bewleys'] = 0; + $export[$index]['brambles'] = 0; + $export[$index]['budweiser'] = 0; + $export[$index]['bulmers'] = 0; + $export[$index]['burgerking'] = 0; + $export[$index]['butlers'] = 0; + + $export[$index]['cadburys'] = 0; + $export[$index]['cafe_nero'] = 0; + $export[$index]['camel'] = 0; + $export[$index]['carlsberg'] = 0; + $export[$index]['centra'] = 0; + $export[$index]['coke'] = 0; + $export[$index]['circlek'] = 0; + $export[$index]['coles'] = 0; + $export[$index]['colgate'] = 0; + $export[$index]['corona'] = 0; + $export[$index]['costa'] = 0; + + $export[$index]['doritos'] = 0; + $export[$index]['drpepper'] = 0; + $export[$index]['dunnes'] = 0; + $export[$index]['duracell'] = 0; + $export[$index]['durex'] = 0; + + $export[$index]['esquires'] = 0; + + $export[$index]['frank_and_honest'] = 0; + $export[$index]['fritolay'] = 0; + + $export[$index]['gatorade'] = 0; + $export[$index]['gillette'] = 0; + $export[$index]['guinness'] = 0; + + $export[$index]['haribo'] = 0; + $export[$index]['heineken'] = 0; + + $export[$index]['insomnia'] = 0; + + $export[$index]['kellogs'] = 0; + $export[$index]['kfc'] = 0; + + $export[$index]['lego'] = 0; + $export[$index]['lidl'] = 0; + $export[$index]['lindenvillage'] = 0; + $export[$index]['lolly_and_cookes'] = 0; + $export[$index]['loreal'] = 0; + $export[$index]['lucozade'] = 0; + + $export[$index]['nero'] = 0; + $export[$index]['nescafe'] = 0; + $export[$index]['nestle'] = 0; + + $export[$index]['marlboro'] = 0; + $export[$index]['mars'] = 0; + $export[$index]['mcdonalds'] = 0; + + $export[$index]['nike'] = 0; + + $export[$index]['obriens'] = 0; + + $export[$index]['pepsi'] = 0; + $export[$index]['powerade'] = 0; + + $export[$index]['redbull'] = 0; + $export[$index]['ribena'] = 0; + + $export[$index]['samsung'] = 0; + $export[$index]['sainsburys'] = 0; + $export[$index]['spar'] = 0; + $export[$index]['subway'] = 0; + $export[$index]['supermacs'] = 0; + $export[$index]['supervalu'] = 0; + $export[$index]['starbucks'] = 0; + + $export[$index]['tayto'] = 0; + $export[$index]['tesco'] = 0; + $export[$index]['thins'] = 0; + + $export[$index]['volvic'] = 0; + + $export[$index]['waitrose'] = 0; + $export[$index]['walkers'] = 0; + $export[$index]['woolworths'] = 0; + $export[$index]['wilde_and_greene'] = 0; + $export[$index]['wrigleys'] = 0; + + if ($photo['smoking_id']) { + $smoking = Smoking::find($photo['smoking_id']); + if ($smoking['butts']) { + $export[$index]['cigaretteButts'] = $smoking['butts']; + } + if ($smoking['lighters']) { + $export[$index]['lighters'] = $smoking['lighters']; + } + if ($smoking['cigaretteBox']) { + $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; + } + if ($smoking['tobaccoPouch']) { + $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; + } + if ($smoking['skins']) { + $export[$index]['papers_filters'] = $smoking['skins']; + } + if ($smoking['plastic']) { + $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; + } + if ($smoking['filters']) { + $export[$index]['filters'] = $smoking['filters']; + } + if ($smoking['filterbox']) { + $export[$index]['filterbox'] = $smoking['filterbox']; + } + if ($smoking['smokingOther']) { + $export[$index]['smokingOther'] = $smoking['smokingOther']; + } + } + + if ($photo['food_id']) { + $food = Food::find($photo['food_id']); + if ($food['sweetWrappers']) { + $export[$index]['sweetWrappers'] = $food['sweetWrappers']; + } + if ($food['paperFoodPackaging']) { + $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; + } + if ($food['plasticFoodPackaging']) { + $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; + } + if ($food['plasticCutlery']) { + $export[$index]['plasticCutlery'] = $food['plasticCutlery']; + } + if ($food['crisp_small']) { + $export[$index]['crisp_small'] = $food['crisp_small']; + } + if ($food['crisp_large']) { + $export[$index]['crisp_large'] = $food['crisp_large']; + } + if ($food['styrofoam_plate']) { + $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; + } + if ($food['napkins']) { + $export[$index]['napkins'] = $food['napkins']; + } + if ($food['sauce_packet']) { + $export[$index]['sauce_packet'] = $food['sauce_packet']; + } + if ($food['glass_jar']) { + $export[$index]['glass_jar'] = $food['glass_jar']; + } + if ($food['glass_jar_lid']) { + $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; + } + if ($food['foodOther']) { + $export[$index]['foodOther'] = $food['foodOther']; + } + } + + if ($photo['coffee_id']) { + $coffee = Coffee::find($photo['coffee_id']); + if ($coffee['coffeeCups']) { + $export[$index]['coffeeCups'] = $coffee['coffeeCups']; + } + if ($coffee['coffeeLids']) { + $export[$index]['coffeeLids'] = $coffee['coffeeLids']; + } + if ($coffee['coffeeOther']) { + $export[$index]['coffeeOther'] = $coffee['coffeeOther']; + } + } + + if ($photo['alcohol_id']) { + $alcohol = Alcohol::find($photo['alcohol_id']); + if ($alcohol['beerBottle']) { + $export[$index]['beerBottle'] = $alcohol['beerBottle']; + } + if ($alcohol['spiritBottle']) { + $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; + } + if ($alcohol['beerCan']) { + $export[$index]['beerCan'] = $alcohol['beerCan']; + } + if ($alcohol['brokenGlass']) { + $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; + } + if ($alcohol['paperCardAlcoholPackaging']) { + $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; + } + if ($alcohol['plasticAlcoholPackaging']) { + $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; + } + if ($alcohol['bottleTops']) { + $export[$index]['bottleTops'] = $alcohol['bottleTops']; + } + if ($alcohol['wineBottle']) { + $export[$index]['wineBottle'] = $alcohol['wineBottle']; + } + if ($alcohol['alcoholOther']) { + $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; + } + } + + if ($photo['softdrinks_id']) { + $softdrinks = SoftDrinks::find($photo['softdrinks_id']); + if ($softdrinks['waterBottle']) { + $export[$index]['plasticWaterBottle'] = $softdrinks['waterBottle']; + } + if ($softdrinks['fizzyDrinkBottle']) { + $export[$index]['fizzyDrinkBottle'] = $softdrinks['fizzyDrinkBottle']; + } + if ($softdrinks['bottleLid']) { + $export[$index]['bottleLid'] = $softdrinks['bottleLid']; + } + if ($softdrinks['bottleLabel']) { + $export[$index]['bottleLabel'] = $softdrinks['bottleLabel']; + } + if ($softdrinks['tinCan']) { + $export[$index]['tinCan'] = $softdrinks['tinCan']; + } + if ($softdrinks['sportsDrink']) { + $export[$index]['sportsDrink'] = $softdrinks['sportsDrink']; + } + if ($softdrinks['paper_cups']) { + $export[$index]['paper_cups'] = $softdrinks['paper_cups']; + } + if ($softdrinks['juice_cartons']) { + $export[$index]['juice_cartons'] = $softdrinks['juice_cartons']; + } + if ($softdrinks['juice_bottles']) { + $export[$index]['juice_bottles'] = $softdrinks['juice_bottles']; + } + if ($softdrinks['juice_packet']) { + $export[$index]['juice_packet'] = $softdrinks['juice_packet']; + } + if ($softdrinks['ice_tea_bottles']) { + $export[$index]['ice_tea_bottles'] = $softdrinks['ice_tea_bottles']; + } + if ($softdrinks['ice_tea_can']) { + $export[$index]['ice_tea_can'] = $softdrinks['ice_tea_can']; + } + if ($softdrinks['energy_can']) { + $export[$index]['energy_can'] = $softdrinks['energy_can']; + } + if ($softdrinks['softDrinkOther']) { + $export[$index]['softDrinkOther'] = $softdrinks['softDrinkOther']; + } + } + + if ($photo['sanitary_id']) { + $sanitary = Sanitary::find($photo['sanitary_id']); + if ($sanitary['gloves']) { + $export[$index]['gloves'] = $sanitary['gloves']; + } + if ($sanitary['facemasks']) { + $export[$index]['facemasks'] = $sanitary['facemasks']; + } + if ($sanitary['condoms']) { + $export[$index]['condoms'] = $sanitary['condoms']; + } + if ($sanitary['nappies']) { + $export[$index]['nappies'] = $sanitary['nappies']; + } + if ($sanitary['menstral']) { + $export[$index]['menstral'] = $sanitary['menstral']; + } + if ($sanitary['deodorant']) { + $export[$index]['deodorant'] = $sanitary['deodorant']; + } + if ($sanitary['sanitaryOther']) { + $export[$index]['sanitaryOther'] = $sanitary['sanitaryOther']; + } + } + + if ($photo['other_id']) { + $other = Other::find($photo['other_id']); + if ($other['dogshit']) { + $export[$index]['dogshit'] = $other['dogshit']; + } + if ($other['dump']) { + $export[$index]['Random_dump'] = $other['dump']; + } + if ($other['plastic']) { + $export[$index]['No_id_plastic'] = $other['plastic']; + } + if ($other['metal']) { + $export[$index]['Metal_object'] = $other['metal']; + } + if ($other['washing_up']) { + $export[$index]['washing_up'] = $other['washing_up']; + } + if ($other['hair_tie']) { + $export[$index]['hair_tie'] = $other['hair_tie']; + } + if ($other['ear_plugs']) { + $export[$index]['ear_plugs'] = $other['ear_plugs']; + } + if ($other['batteries']) { + $export[$index]['batteries'] = $other['batteries']; + } + if ($other['elec_small']) { + $export[$index]['elec_small'] = $other['elec_small']; + } + if ($other['elec_large']) { + $export[$index]['elec_large'] = $other['elec_large']; + } + if ($other['other']) { + $export[$index]['Unknown'] = $other['other']; + } + } + + if ($photo['coastal_id']) { + $coastal = Coastal::find($photo['coastal_id']); + if ($coastal['microplastics']) { + $export[$index]['microplastics'] = $coastal['microplastics']; + } + if ($coastal['mediumplastics']) { + $export[$index]['mediumplastics'] = $coastal['mediumplastics']; + } + if ($coastal['macroplastics']) { + $export[$index]['macroplastics'] = $coastal['macroplastics']; + } + if ($coastal['rope_small']) { + $export[$index]['rope_small'] = $coastal['rope_small']; + } + if ($coastal['rope_medium']) { + $export[$index]['rope_medium'] = $coastal['rope_medium']; + } + if ($coastal['rope_large']) { + $export[$index]['rope_large'] = $coastal['rope_large']; + } + if ($coastal['fishing_gear_nets']) { + $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; + } + if ($coastal['buoys']) { + $export[$index]['buoys'] = $coastal['buoys']; + } + if ($coastal['degraded_plasticbottle']) { + $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; + } + if ($coastal['degraded_plasticbag']) { + $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; + } + if ($coastal['degraded_straws']) { + $export[$index]['degraded_straws'] = $coastal['degraded_straws']; + } + if ($coastal['degraded_lighters']) { + $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; + } + if ($coastal['baloons']) { + $export[$index]['baloons'] = $coastal['baloons']; + } + if ($coastal['lego']) { + $export[$index]['lego'] = $coastal['lego']; + } + if ($coastal['shotgun_cartridges']) { + $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; + } + if ($coastal['coastal_other']) { + $export[$index]['coastal_other']; + } + } + + // if($photo["art_id"]) { + // $art = Art::find($photo["art_id"]); + // if($art['item']) { + // $export[$index]['art'] = $art['item']; + // } + // } + + if ($photo['brands_id']) { + $brands = Brand::find($photo['brands_id']); + if ($brands['adidas']) { + $export[$index]['adidas'] = $brands['adidas']; + } + if ($brands['amazon']) { + $export[$index]['amazon'] = $brands['amazon']; + } + if ($brands['aldi']) { + $export[$index]['aldi'] = $brands['aldi']; + } + if ($brands['apple']) { + $export[$index]['apple'] = $brands['apple']; + } + if ($brands['applegreen']) { + $export[$index]['applegreen'] = $brands['applegreen']; + } + if ($brands['asahi']) { + $export[$index]['asahi'] = $brands['asahi']; + } + if ($brands['avoca']) { + $export[$index]['avoca'] = $brands['avoca']; + } + if ($brands['ballygowan']) { + $export[$index]['ballygowan'] = $brands['ballygowan']; + } + if ($brands['bewleys']) { + $export[$index]['bewleys'] = $brands['bewleys']; + } + if ($brands['brambles']) { + $export[$index]['brambles'] = $brands['brambles']; + } + if ($brands['budweiser']) { + $export[$index]['budweiser'] = $brands['budweiser']; + } + if ($brands['bulmers']) { + $export[$index]['bulmers'] = $brands['bulmers']; + } + if ($brands['burgerking']) { + $export[$index]['burgerking'] = $brands['burgerking']; + } + if ($brands['butlers']) { + $export[$index]['butlers'] = $brands['butlers']; + } + + if ($brands['cadburys']) { + $export[$index]['cadburys'] = $brands['cadburys']; + } + if ($brands['cafe_nero']) { + $export[$index]['cafe_nero'] = $brands['cafe_nero']; + } + if ($brands['camel']) { + $export[$index]['camel'] = $brands['camel']; + } + if ($brands['carlsberg']) { + $export[$index]['carlsberg'] = $brands['carlsberg']; + } + if ($brands['centra']) { + $export[$index]['centra'] = $brands['centra']; + } + if ($brands['coke']) { + $export[$index]['coke'] = $brands['coke']; + } + if ($brands['circlek']) { + $export[$index]['circlek'] = $brands['circlek']; + } + if ($brands['coles']) { + $export[$index]['coles'] = $brands['coles']; + } + if ($brands['colgate']) { + $export[$index]['colgate'] = $brands['colgate']; + } + if ($brands['corona']) { + $export[$index]['corona'] = $brands['corona']; + } + if ($brands['costa']) { + $export[$index]['costa'] = $brands['costa']; + } + + if ($brands['doritos']) { + $export[$index]['doritos'] = $brands['doritos']; + } + if ($brands['drpepper']) { + $export[$index]['drpepper'] = $brands['drpepper']; + } + if ($brands['dunnes']) { + $export[$index]['dunnes'] = $brands['dunnes']; + } + if ($brands['duracell']) { + $export[$index]['duracell'] = $brands['duracell']; + } + if ($brands['durex']) { + $export[$index]['durex'] = $brands['durex']; + } + + if ($brands['esquires']) { + $export[$index]['esquires'] = $brands['esquires']; + } + + if ($brands['frank_and_honest']) { + $export[$index]['frank_and_honest'] = $brands['frank_and_honest']; + } + if ($brands['fritolay']) { + $export[$index]['fritolay'] = $brands['fritolay']; + } + + if ($brands['gatorade']) { + $export[$index]['gatorade'] = $brands['gatorade']; + } + if ($brands['gillette']) { + $export[$index]['gillette'] = $brands['gillette']; + } + if ($brands['guinness']) { + $export[$index]['guinness'] = $brands['gillette']; + } + + if ($brands['haribo']) { + $export[$index]['haribo'] = $brands['haribo']; + } + if ($brands['heineken']) { + $export[$index]['heineken'] = $brands['heineken']; + } + + if ($brands['insomnia']) { + $export[$index]['insomnia'] = $brands['insomnia']; + } + + if ($brands['kellogs']) { + $export[$index]['kellogs'] = $brands['kellogs']; + } + if ($brands['kfc']) { + $export[$index]['kfc'] = $brands['kfc']; + } + + if ($brands['lego']) { + $export[$index]['lego'] = $brands['lego']; + } + if ($brands['lidl']) { + $export[$index]['lidl'] = $brands['lidl']; + } + if ($brands['lindenvillage']) { + $export[$index]['lindenvillage'] = $brands['lindenvillage']; + } + if ($brands['lolly_and_cookes']) { + $export[$index]['lolly_and_cookes'] = $brands['lolly_and_cookes']; + } + if ($brands['loreal']) { + $export[$index]['loreal'] = $brands['loreal']; + } + if ($brands['lucozade']) { + $export[$index]['lucozade'] = $brands['lucozade']; + } + + if ($brands['marlboro']) { + $export[$index]['marlboro'] = $brands['marlboro']; + } + if ($brands['mars']) { + $export[$index]['mars'] = $brands['mars']; + } + if ($brands['mcdonalds']) { + $export[$index]['mcdonalds'] = $brands['mcdonalds']; + } + + if ($brands['nero']) { + $export[$index]['nero'] = $brands['nero']; + } + if ($brands['nescafe']) { + $export[$index]['nescafe'] = $brands['nescafe']; + } + if ($brands['nestle']) { + $export[$index]['nestle'] = $brands['nestle']; + } + if ($brands['nike']) { + $export[$index]['nike'] = $brands['nike']; + } + + if ($brands['obriens']) { + $export[$index]['obriens'] = $brands['obriens']; + } + + if ($brands['pepsi']) { + $export[$index]['pepsi'] = $brands['pepsi']; + } + if ($brands['powerade']) { + $export[$index]['powerade'] = $brands['powerade']; + } + + if ($brands['redbull']) { + $export[$index]['redbull'] = $brands['redbull']; + } + if ($brands['ribena']) { + $export[$index]['ribena'] = $brands['ribena']; + } + + if ($brands['samsung']) { + $export[$index]['samsung'] = $brands['samsung']; + } + if ($brands['sainsburys']) { + $export[$index]['sainsburys'] = $brands['sainsburys']; + } + if ($brands['spar']) { + $export[$index]['spar'] = $brands['spar']; + } + if ($brands['stella']) { + $export[$index]['stella'] = $brands['stella']; + } + if ($brands['subway']) { + $export[$index]['subway'] = $brands['subway']; + } + if ($brands['supermacs']) { + $export[$index]['supermacs'] = $brands['supermacs']; + } + if ($brands['supervale']) { + $export[$index]['supervale'] = $brands['supervale']; + } + if ($brands['starbucks']) { + $export[$index]['starbucks'] = $brands['starbucks']; + } + + if ($brands['tayto']) { + $export[$index]['tayto'] = $brands['tayto']; + } + if ($brands['tesco']) { + $export[$index]['tesco'] = $brands['tesco']; + } + if ($brands['thins']) { + $export[$index]['thins'] = $brands['thins']; + } + + if ($brands['volvic']) { + $export[$index]['volvic'] = $brands['volvic']; + } + + if ($brands['waitrose']) { + $export[$index]['waitrose'] = $brands['waitrose']; + } + if ($brands['walkers']) { + $export[$index]['walkers'] = $brands['walkers']; + } + if ($brands['woolworths']) { + $export[$index]['woolworths'] = $brands['woolworths']; + } + if ($brands['wilde_and_greene']) { + $export[$index]['wilde_and_greene'] = $brands['wilde_and_greene']; + } + if ($brands['wrigleys']) { + $export[$index]['wrigleys'] = $brands['wrigleys']; + } + } + } + // return $export; + $sheet->fromModel($export); + })->export('csv'); + // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); + }); } - public function getDataByCity($country, $state, $city) { - if($city) { - // City only - // need to pass the variable down the chain - Excel::create('Open Litter Map', function($excel) use ($city) { - $excel->sheet('OLM', function($sheet) use ($city) { - - $theCity = City::where('city', $city)->first(); - $photos = Photo::where([ - ['city_id', $theCity->id], - ['verified', '>', 0] - ])->get(); - - $export = []; - foreach($photos as $index => $photo) { - $index++; - $export[$index]['id'] = $index; - $export[$index]['verification'] = $photo->verified; - $export[$index]['phone'] = $photo->model; - $export[$index]['datetime'] = $photo->datetime; - $export[$index]['lat'] = $photo->lat; - $export[$index]['lon'] = $photo->lon; - $export[$index]['city'] = $photo->city; - $export[$index]['state'] = $photo->county; - $export[$index]['country'] = $photo->country; - $export[$index]['remaining_beta'] = $photo->remaining; - $export[$index]['address'] = $photo->display_name; - $export[$index]['total_litter'] = $photo->total_litter; - - $export[$index]['cigaretteButts'] = 0; - $export[$index]['lighters'] = 0; - $export[$index]['cigaretteBox'] = 0; - $export[$index]['tobaccoPouch'] = 0; - $export[$index]['papers_filters'] = 0; - $export[$index]['plastic_smoking_pk'] = 0; - $export[$index]['filters'] = 0; - $export[$index]['filterbox'] = 0; - $export[$index]['smokingOther'] = 0; - - $export[$index]['sweetWrappers'] = 0; - $export[$index]['paperFoodPackaging'] = 0; - $export[$index]['plasticFoodPackaging'] = 0; - $export[$index]['plasticCutlery'] = 0; - $export[$index]['crisp_small'] = 0; - $export[$index]['crisp_large'] = 0; - $export[$index]['styrofoam_plate'] = 0; - $export[$index]['napkins'] = 0; - $export[$index]['sauce_packet'] = 0; - $export[$index]['glass_jar'] = 0; - $export[$index]['glass_jar_lid'] = 0; - $export[$index]['foodOther'] = 0; - - $export[$index]['coffeeCups'] = 0; - $export[$index]['coffeeLids'] = 0; - $export[$index]['coffeeOther'] = 0; - - $export[$index]['beerCan'] = 0; - $export[$index]['beerBottle'] = 0; - $export[$index]['spiritBottle'] = 0; - $export[$index]['wineBottle'] = 0; - $export[$index]['brokenGlass'] = 0; - $export[$index]['paperCardAlcoholPackaging'] = 0; - $export[$index]['plasticAlcoholPackaging'] = 0; - $export[$index]['bottleTops'] = 0; - $export[$index]['alcoholOther'] = 0; - - $export[$index]['plasticWaterBottle'] = 0; - $export[$index]['fizzyDrinkBottle'] = 0; - $export[$index]['bottleLid'] = 0; - $export[$index]['bottleLabel'] = 0; - $export[$index]['tinCan'] = 0; - $export[$index]['sportsDrink'] = 0; - $export[$index]['straws'] = 0; - $export[$index]['plastic_cups'] = 0; - $export[$index]['plastic_cup_tops'] = 0; - $export[$index]['milk_bottle'] = 0; - $export[$index]['milk_carton'] = 0; - $export[$index]['paper_cups'] = 0; - $export[$index]['juice_cartons'] = 0; - $export[$index]['juice_bottles'] = 0; - $export[$index]['juice_packet'] = 0; - $export[$index]['ice_tea_bottles'] = 0; - $export[$index]['ice_tea_can'] = 0; - $export[$index]['energy_can'] = 0; - $export[$index]['softDrinkOther'] = 0; - - - $export[$index]['gloves'] = 0; - $export[$index]['facemasks'] = 0; - $export[$index]['condoms'] = 0; - $export[$index]['mental'] = 0; - $export[$index]['deodorant'] = 0; - $export[$index]['ear_swabs'] = 0; - $export[$index]['tooth_pick'] = 0; - $export[$index]['tooth_brush'] = 0; - $export[$index]['sanitaryOther'] = 0; - $export[$index]['dogshit'] = 0; - $export[$index]['Random_dump'] = 0; - $export[$index]['No_id_plastic'] = 0; - $export[$index]['Metal_object'] = 0; - $export[$index]['plastic_bags'] = 0; - $export[$index]['election_posters'] = 0; - $export[$index]['forsale_posters'] = 0; - $export[$index]['books'] = 0; - $export[$index]['magazines'] = 0; - $export[$index]['paper'] = 0; - $export[$index]['stationary'] = 0; - $export[$index]['washing_up'] = 0; - $export[$index]['hair_tie'] = 0; - $export[$index]['ear_plugs'] = 0; - $export[$index]['batteries'] = 0; - $export[$index]['elec_small'] = 0; - $export[$index]['elec_large'] = 0; - $export[$index]['Other_Unknown'] = 0; - - $export[$index]['microplastics'] = 0; - $export[$index]['mediumplastics'] = 0; - $export[$index]['macroplastics'] = 0; - $export[$index]['rope_small'] = 0; - $export[$index]['rope_medium'] = 0; - $export[$index]['rope_large'] = 0; - $export[$index]['fishing_gear_nets'] = 0; - $export[$index]['buoys'] = 0; - $export[$index]['degraded_plasticbottle'] = 0; - $export[$index]['degraded_plasticbag'] = 0; - $export[$index]['degraded_straws'] = 0; - $export[$index]['degraded_lighters'] = 0; - $export[$index]['baloons'] = 0; - $export[$index]['lego'] = 0; - $export[$index]['shotgun_cartridges'] = 0; - $export[$index]['coastal_other'] = 0; - - $export[$index]['art'] = 0; - - $export[$index]['adidas'] = 0; - $export[$index]['amazon'] = 0; - $export[$index]['aldi'] = 0; - $export[$index]['apple'] = 0; - $export[$index]['applegreen'] = 0; - $export[$index]['asahi'] = 0; - $export[$index]['avoca'] = 0; - - $export[$index]['ballygowan'] = 0; - $export[$index]['bewleys'] = 0; - $export[$index]['brambles'] = 0; - $export[$index]['budweiser'] = 0; - $export[$index]['bulmers'] = 0; - $export[$index]['burgerking'] = 0; - $export[$index]['butlers'] = 0; - - $export[$index]['cadburys'] = 0; - $export[$index]['cafe_nero'] = 0; - $export[$index]['camel'] = 0; - $export[$index]['carlsberg'] = 0; - $export[$index]['centra'] = 0; - $export[$index]['coke'] = 0; - $export[$index]['circlek'] = 0; - $export[$index]['coles'] = 0; - $export[$index]['colgate'] = 0; - $export[$index]['corona'] = 0; - $export[$index]['costa'] = 0; - - $export[$index]['doritos'] = 0; - $export[$index]['drpepper'] = 0; - $export[$index]['dunnes'] = 0; - $export[$index]['duracell'] = 0; - $export[$index]['durex'] = 0; - - $export[$index]['esquires'] = 0; - - $export[$index]['frank_and_honest'] = 0; - $export[$index]['fritolay'] = 0; - - $export[$index]['gatorade'] = 0; - $export[$index]['gillette'] = 0; - $export[$index]['guinness'] = 0; - - $export[$index]['haribo'] = 0; - $export[$index]['heineken'] = 0; - - $export[$index]['insomnia'] = 0; - - $export[$index]['kellogs'] = 0; - $export[$index]['kfc'] = 0; - - $export[$index]['lego'] = 0; - $export[$index]['lidl'] = 0; - $export[$index]['lindenvillage'] = 0; - $export[$index]['lolly_and_cookes'] = 0; - $export[$index]['loreal'] = 0; - $export[$index]['lucozade'] = 0; - - $export[$index]['nero'] = 0; - $export[$index]['nescafe'] = 0; - $export[$index]['nestle'] = 0; - - $export[$index]['marlboro'] = 0; - $export[$index]['mars'] = 0; - $export[$index]['mcdonalds'] = 0; - - $export[$index]['nike'] = 0; - - $export[$index]['obriens'] = 0; - - $export[$index]['pepsi'] = 0; - $export[$index]['powerade'] = 0; - - $export[$index]['redbull'] = 0; - $export[$index]['ribena'] = 0; - - $export[$index]['samsung'] = 0; - $export[$index]['sainsburys'] = 0; - $export[$index]['spar'] = 0; - $export[$index]['subway'] = 0; - $export[$index]['supermacs'] = 0; - $export[$index]['supervalu'] = 0; - $export[$index]['starbucks'] = 0; - - $export[$index]['tayto'] = 0; - $export[$index]['tesco'] = 0; - $export[$index]['thins'] = 0; - - $export[$index]['volvic'] = 0; - - $export[$index]['waitrose'] = 0; - $export[$index]['walkers'] = 0; - $export[$index]['woolworths'] = 0; - $export[$index]['wilde_and_greene'] = 0; - $export[$index]['wrigleys'] = 0; - - - if($photo['smoking_id']) { - $smoking = Smoking::find($photo['smoking_id']); - if($smoking['butts']) { - $export[$index]['cigaretteButts'] = $smoking['butts']; - } - if($smoking['lighters']) { - $export[$index]['lighters'] = $smoking['lighters']; - } - if($smoking['cigaretteBox']) { - $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; - } - if($smoking['tobaccoPouch']) { - $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; - } - if($smoking['skins']) { - $export[$index]['papers_filters'] = $smoking['skins']; - } - if($smoking['plastic']) { - $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; - } - if($smoking['filters']) { - $export[$index]['filters'] = $smoking['filters']; - } - if($smoking['filterbox']) { - $export[$index]['filterbox'] = $smoking['filterbox']; - } - if($smoking['smokingOther']) { - $export[$index]['smokingOther'] = $smoking['smokingOther']; - } - } - - if($photo['food_id']) { - $food = Food::find($photo['food_id']); - if($food['sweetWrappers']) { - $export[$index]['sweetWrappers'] = $food['sweetWrappers']; - } - if($food['paperFoodPackaging']) { - $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; - } - if($food['plasticFoodPackaging']) { - $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; - } - if($food['plasticCutlery']) { - $export[$index]['plasticCutlery'] = $food['plasticCutlery']; - } - if($food['crisp_small']) { - $export[$index]['crisp_small'] = $food['crisp_small']; - } - if($food['crisp_large']) { - $export[$index]['crisp_large'] = $food['crisp_large']; - } - if($food['styrofoam_plate']) { - $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; - } - if($food['napkins']) { - $export[$index]['napkins'] = $food['napkins']; - } - if($food['sauce_packet']) { - $export[$index]['sauce_packet'] = $food['sauce_packet']; - } - if($food['glass_jar']) { - $export[$index]['glass_jar'] = $food['glass_jar']; - } - if($food['glass_jar_lid']) { - $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; - } - if($food['foodOther']) { - $export[$index]['foodOther'] = $food['foodOther']; - } - } - - if($photo['coffee_id']) { - $coffee = Coffee::find($photo['coffee_id']); - if($coffee['coffeeCups']) { - $export[$index]['coffeeCups'] = $coffee['coffeeCups']; - } - if($coffee['coffeeLids']) { - $export[$index]['coffeeLids'] = $coffee['coffeeLids']; - } - if($coffee['coffeeOther']) { - $export[$index]['coffeeOther'] = $coffee['coffeeOther']; - } - } - - if($photo['alcohol_id']) { - $alcohol = Alcohol::find($photo['alcohol_id']); - if($alcohol['beerBottle']) { - $export[$index]['beerBottle'] = $alcohol['beerBottle']; - } - if($alcohol['spiritBottle']) { - $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; - } - if($alcohol['beerCan']) { - $export[$index]['beerCan'] = $alcohol['beerCan']; - } - if($alcohol['brokenGlass']) { - $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; - } - if($alcohol['paperCardAlcoholPackaging']) { - $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; - } - if($alcohol['plasticAlcoholPackaging']) { - $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; - } - if($alcohol['bottleTops']) { - $export[$index]['bottleTops'] = $alcohol['bottleTops']; - } - if($alcohol['wineBottle']) { - $export[$index]['wineBottle'] = $alcohol['wineBottle']; - } - if($alcohol['alcoholOther']) { - $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; - } - } - - if($photo["softdrinks_id"]) { - $softdrinks = SoftDrinks::find($photo["softdrinks_id"]); - if($softdrinks['waterBottle']) { - $export[$index]['plasticWaterBottle'] = $softdrinks["waterBottle"]; - } - if($softdrinks['fizzyDrinkBottle']) { - $export[$index]['fizzyDrinkBottle'] = $softdrinks["fizzyDrinkBottle"]; - } - if($softdrinks['bottleLid']) { - $export[$index]['bottleLid'] = $softdrinks["bottleLid"]; - } - if($softdrinks['bottleLabel']) { - $export[$index]['bottleLabel'] = $softdrinks["bottleLabel"]; - } - if($softdrinks['tinCan']) { - $export[$index]['tinCan'] = $softdrinks["tinCan"]; - } - if($softdrinks['sportsDrink']) { - $export[$index]['sportsDrink'] = $softdrinks["sportsDrink"]; - } - if($softdrinks['paper_cups']) { - $export[$index]['paper_cups'] = $softdrinks["paper_cups"]; - } - if($softdrinks['juice_cartons']) { - $export[$index]['juice_cartons'] = $softdrinks["juice_cartons"]; - } - if($softdrinks['juice_bottles']) { - $export[$index]['juice_bottles'] = $softdrinks["juice_bottles"]; - } - if($softdrinks['juice_packet']) { - $export[$index]['juice_packet'] = $softdrinks["juice_packet"]; - } - if($softdrinks['ice_tea_bottles']) { - $export[$index]['ice_tea_bottles'] = $softdrinks["ice_tea_bottles"]; - } - if($softdrinks['ice_tea_can']) { - $export[$index]['ice_tea_can'] = $softdrinks["ice_tea_can"]; - } - if($softdrinks['energy_can']) { - $export[$index]['energy_can'] = $softdrinks["energy_can"]; - } - if($softdrinks['softDrinkOther']) { - $export[$index]['softDrinkOther'] = $softdrinks["softDrinkOther"]; - } - } - - if($photo["sanitary_id"]){ - $sanitary = Sanitary::find($photo["sanitary_id"]); - if ($sanitary['gloves']) { - $export[$index]['gloves'] = $sanitary['gloves']; - } - if ($sanitary['facemasks']) { - $export[$index]['facemasks'] = $sanitary['facemasks']; - } - if($sanitary["condoms"]) { - $export[$index]["condoms"] = $sanitary["condoms"]; - } - if($sanitary["nappies"]) { - $export[$index]["nappies"] = $sanitary["nappies"]; - } - if($sanitary["menstral"]) { - $export[$index]["menstral"] = $sanitary["menstral"]; - } - if($sanitary["deodorant"]) { - $export[$index]["deodorant"] = $sanitary["deodorant"]; - } - if($sanitary["sanitaryOther"]) { - $export[$index]["sanitaryOther"] = $sanitary["sanitaryOther"]; - } - } - - if($photo['other_id']) { - $other = Other::find($photo["other_id"]); - if($other['dogshit']) { - $export[$index]["dogshit"] = $other['dogshit']; - } - if($other["dump"]) { - $export[$index]["Random_dump"] = $other["dump"]; - } - if($other["plastic"]) { - $export[$index]["No_id_plastic"] = $other["plastic"]; - } - if($other["metal"]) { - $export[$index]["Metal_object"] = $other["metal"]; - } - if($other["washing_up"]) { - $export[$index]["washing_up"] = $other["washing_up"]; - } - if($other["hair_tie"]) { - $export[$index]["hair_tie"] = $other["hair_tie"]; - } - if($other["ear_plugs"]) { - $export[$index]["ear_plugs"] = $other["ear_plugs"]; - } - if($other["other"]) { - $export[$index]["Unknown"] = $other["other"]; - } - } - - if($photo['coastal_id']) { - $coastal = Coastal::find($photo["coastal_id"]); - if($coastal['microplastics']) { - $export[$index]["microplastics"] = $coastal['microplastics']; - } - if($coastal['mediumplastics']) { - $export[$index]["mediumplastics"] = $coastal['mediumplastics']; - } - if($coastal['macroplastics']) { - $export[$index]['macroplastics'] = $coastal['macroplastics']; - } - if($coastal['rope_small']) { - $export[$index]['rope_small'] = $coastal['rope_small']; - } - if($coastal['rope_medium']) { - $export[$index]['rope_medium'] = $coastal['rope_medium']; - } - if($coastal['rope_large']) { - $export[$index]['rope_large'] = $coastal['rope_large']; - } - if($coastal['fishing_gear_nets']) { - $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; - } - if($coastal['buoys']) { - $export[$index]['buoys'] = $coastal['buoys']; - } - if($coastal['degraded_plasticbottle']) { - $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; - } - if($coastal['degraded_plasticbag']) { - $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; - } - if($coastal['degraded_straws']) { - $export[$index]['degraded_straws'] = $coastal['degraded_straws']; - } - if($coastal['degraded_lighters']) { - $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; - } - if($coastal['baloons']) { - $export[$index]['baloons'] = $coastal['baloons']; - } - if($coastal['lego']) { - $export[$index]['lego'] = $coastal['lego']; - } - if($coastal['shotgun_cartridges']) { - $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; - } - if($coastal['coastal_other']) { - $export[$index]['coastal_other']; - } - } - - if($photo["pathway_id"]) { - $pathway = Pathway::find($photo["pathway_id"]); - if($pathway["gutter"]) { - $export[$index]['gutter'] = $pathway["gutter"]; - } - if($pathway["gutter_long"]) { - $export[$index]['gutter_long'] = $pathway["gutter_long"]; - } - if($pathway["kerb_hole_small"]) { - $export[$index]['kerb_hole_small'] = $pathway["kerb_hole_small"]; - } - if($pathway["kerb_hole_large"]) { - $export[$index]['kerb_hole_large'] = $pathway["kerb_hole_large"]; - } - if($pathway["pathwayOther"]) { - $export[$index]['pathwayOther'] = $pathway["pathwayOther"]; - } - } - - // if($photo["art_id"]) { - // $art = Art::find($photo["art_id"]); - // if($art['item']) { - // $export[$index]['art'] = $art['item']; - // } - // } - - if($photo["brands_id"]) { - $brands = Brand::find($photo["brands_id"]); - if($brands["adidas"]) { - $export[$index]['adidas'] = $brands["adidas"]; - } - if($brands["amazon"]) { - $export[$index]['amazon'] = $brands["amazon"]; - } - if($brands["aldi"]) { - $export[$index]['aldi'] = $brands["aldi"]; - } - if($brands["apple"]) { - $export[$index]['apple'] = $brands["apple"]; - } - if($brands["applegreen"]) { - $export[$index]['applegreen'] = $brands["applegreen"]; - } - if($brands["asahi"]) { - $export[$index]['asahi'] = $brands["asahi"]; - } - if($brands["avoca"]) { - $export[$index]['avoca'] = $brands["avoca"]; - } - if($brands["ballygowan"]) { - $export[$index]['ballygowan'] = $brands["ballygowan"]; - } - if($brands["bewleys"]) { - $export[$index]['bewleys'] = $brands["bewleys"]; - } - if($brands["brambles"]) { - $export[$index]['brambles'] = $brands["brambles"]; - } - if($brands["budweiser"]) { - $export[$index]['budweiser'] = $brands["budweiser"]; - } - if($brands["bulmers"]) { - $export[$index]['bulmers'] = $brands["bulmers"]; - } - if($brands["burgerking"]) { - $export[$index]['burgerking'] = $brands["burgerking"]; - } - if($brands["butlers"]) { - $export[$index]['butlers'] = $brands["butlers"]; - } - - if($brands["cadburys"]) { - $export[$index]['cadburys'] = $brands["cadburys"]; - } - if($brands["cafe_nero"]) { - $export[$index]['cafe_nero'] = $brands["cafe_nero"]; - } - if($brands["camel"]) { - $export[$index]['camel'] = $brands["camel"]; - } - if($brands["carlsberg"]) { - $export[$index]['carlsberg'] = $brands["carlsberg"]; - } - if($brands["centra"]) { - $export[$index]['centra'] = $brands["centra"]; - } - if($brands["coke"]) { - $export[$index]['coke'] = $brands["coke"]; - } - if($brands["circlek"]) { - $export[$index]['circlek'] = $brands["circlek"]; - } - if($brands["coles"]) { - $export[$index]['coles'] = $brands["coles"]; - } - if($brands["colgate"]) { - $export[$index]['colgate'] = $brands["colgate"]; - } - if($brands["corona"]) { - $export[$index]['corona'] = $brands["corona"]; - } - if($brands["costa"]) { - $export[$index]['costa'] = $brands["costa"]; - } - - if($brands["doritos"]) { - $export[$index]['doritos'] = $brands["doritos"]; - } - if($brands["drpepper"]) { - $export[$index]['drpepper'] = $brands["drpepper"]; - } - if($brands["dunnes"]) { - $export[$index]['dunnes'] = $brands["dunnes"]; - } - if($brands["duracell"]) { - $export[$index]['duracell'] = $brands["duracell"]; - } - if($brands["durex"]) { - $export[$index]['durex'] = $brands["durex"]; - } - - if($brands["esquires"]) { - $export[$index]['esquires'] = $brands["esquires"]; - } - - if($brands["frank_and_honest"]) { - $export[$index]['frank_and_honest'] = $brands["frank_and_honest"]; - } - if($brands["fritolay"]) { - $export[$index]['fritolay'] = $brands["fritolay"]; - } - - if($brands["gatorade"]) { - $export[$index]['gatorade'] = $brands["gatorade"]; - } - if($brands["gillette"]) { - $export[$index]['gillette'] = $brands["gillette"]; - } - if($brands["guinness"]) { - $export[$index]['guinness'] = $brands["gillette"]; - } - - if($brands["haribo"]) { - $export[$index]['haribo'] = $brands["haribo"]; - } - if($brands["heineken"]) { - $export[$index]['heineken'] = $brands["heineken"]; - } - - if($brands["insomnia"]) { - $export[$index]['insomnia'] = $brands["insomnia"]; - } - - if($brands["kellogs"]) { - $export[$index]['kellogs'] = $brands["kellogs"]; - } - if($brands["kfc"]) { - $export[$index]['kfc'] = $brands["kfc"]; - } - - if($brands["lego"]) { - $export[$index]['lego'] = $brands["lego"]; - } - if($brands["lidl"]) { - $export[$index]['lidl'] = $brands["lidl"]; - } - if($brands["lindenvillage"]) { - $export[$index]['lindenvillage'] = $brands["lindenvillage"]; - } - if($brands["lolly_and_cookes"]) { - $export[$index]['lolly_and_cookes'] = $brands["lolly_and_cookes"]; - } - if($brands["loreal"]) { - $export[$index]['loreal'] = $brands["loreal"]; - } - if($brands["lucozade"]) { - $export[$index]['lucozade'] = $brands["lucozade"]; - } - - if($brands["marlboro"]) { - $export[$index]['marlboro'] = $brands["marlboro"]; - } - if($brands["mars"]) { - $export[$index]['mars'] = $brands["mars"]; - } - if($brands["mcdonalds"]) { - $export[$index]['mcdonalds'] = $brands["mcdonalds"]; - } - - if($brands["nero"]) { - $export[$index]['nero'] = $brands["nero"]; - } - if($brands["nescafe"]) { - $export[$index]['nescafe'] = $brands["nescafe"]; - } - if($brands["nestle"]) { - $export[$index]['nestle'] = $brands["nestle"]; - } - if($brands["nike"]) { - $export[$index]['nike'] = $brands["nike"]; - } - - if($brands["obriens"]) { - $export[$index]['obriens'] = $brands["obriens"]; - } - - if($brands["pepsi"]) { - $export[$index]['pepsi'] = $brands["pepsi"]; - } - if($brands["powerade"]) { - $export[$index]['powerade'] = $brands["powerade"]; - } - - if($brands["redbull"]) { - $export[$index]['redbull'] = $brands["redbull"]; - } - if($brands["ribena"]) { - $export[$index]['ribena'] = $brands["ribena"]; - } - - if($brands["samsung"]) { - $export[$index]['samsung'] = $brands["samsung"]; - } - if($brands["sainsburys"]) { - $export[$index]['sainsburys'] = $brands["sainsburys"]; - } - if($brands["spar"]) { - $export[$index]['spar'] = $brands["spar"]; - } - if($brands["stella"]) { - $export[$index]['stella'] = $brands["stella"]; - } - if($brands["subway"]) { - $export[$index]['subway'] = $brands["subway"]; - } - if($brands["supermacs"]) { - $export[$index]['supermacs'] = $brands["supermacs"]; - } - if($brands["supervale"]) { - $export[$index]['supervale'] = $brands["supervale"]; - } - if($brands["starbucks"]) { - $export[$index]['starbucks'] = $brands["starbucks"]; - } - - if($brands["tayto"]) { - $export[$index]['tayto'] = $brands["tayto"]; - } - if($brands["tesco"]) { - $export[$index]['tesco'] = $brands["tesco"]; - } - if($brands["thins"]) { - $export[$index]['thins'] = $brands["thins"]; - } - - if($brands["volvic"]) { - $export[$index]['volvic'] = $brands["volvic"]; - } - - if($brands["waitrose"]) { - $export[$index]['waitrose'] = $brands["waitrose"]; - } - if($brands["walkers"]) { - $export[$index]['walkers'] = $brands["walkers"]; - } - if($brands["woolworths"]) { - $export[$index]['woolworths'] = $brands["woolworths"]; - } - if($brands["wilde_and_greene"]) { - $export[$index]['wilde_and_greene'] = $brands["wilde_and_greene"]; - } - if($brands["wrigleys"]) { - $export[$index]['wrigleys'] = $brands["wrigleys"]; - } - } - } - // return $export; - $sheet->fromModel($export); - })->export('csv'); - // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); - }); - } - } + public function getDataByCity($country, $state, $city) + { + if ($city) { + // City only + // need to pass the variable down the chain + Excel::create('Open Litter Map', function ($excel) use ($city): void { + $excel->sheet('OLM', function ($sheet) use ($city): void { + + $theCity = City::where('city', $city)->first(); + $photos = Photo::where([ + ['city_id', $theCity->id], + ['verified', '>', 0], + ])->get(); + + $export = []; + foreach ($photos as $index => $photo) { + $index++; + $export[$index]['id'] = $index; + $export[$index]['verification'] = $photo->verified; + $export[$index]['phone'] = $photo->model; + $export[$index]['datetime'] = $photo->datetime; + $export[$index]['lat'] = $photo->lat; + $export[$index]['lon'] = $photo->lon; + $export[$index]['city'] = $photo->city; + $export[$index]['state'] = $photo->county; + $export[$index]['country'] = $photo->country; + $export[$index]['remaining_beta'] = $photo->remaining; + $export[$index]['address'] = $photo->display_name; + $export[$index]['total_litter'] = $photo->total_litter; + + $export[$index]['cigaretteButts'] = 0; + $export[$index]['lighters'] = 0; + $export[$index]['cigaretteBox'] = 0; + $export[$index]['tobaccoPouch'] = 0; + $export[$index]['papers_filters'] = 0; + $export[$index]['plastic_smoking_pk'] = 0; + $export[$index]['filters'] = 0; + $export[$index]['filterbox'] = 0; + $export[$index]['smokingOther'] = 0; + + $export[$index]['sweetWrappers'] = 0; + $export[$index]['paperFoodPackaging'] = 0; + $export[$index]['plasticFoodPackaging'] = 0; + $export[$index]['plasticCutlery'] = 0; + $export[$index]['crisp_small'] = 0; + $export[$index]['crisp_large'] = 0; + $export[$index]['styrofoam_plate'] = 0; + $export[$index]['napkins'] = 0; + $export[$index]['sauce_packet'] = 0; + $export[$index]['glass_jar'] = 0; + $export[$index]['glass_jar_lid'] = 0; + $export[$index]['foodOther'] = 0; + + $export[$index]['coffeeCups'] = 0; + $export[$index]['coffeeLids'] = 0; + $export[$index]['coffeeOther'] = 0; + + $export[$index]['beerCan'] = 0; + $export[$index]['beerBottle'] = 0; + $export[$index]['spiritBottle'] = 0; + $export[$index]['wineBottle'] = 0; + $export[$index]['brokenGlass'] = 0; + $export[$index]['paperCardAlcoholPackaging'] = 0; + $export[$index]['plasticAlcoholPackaging'] = 0; + $export[$index]['bottleTops'] = 0; + $export[$index]['alcoholOther'] = 0; + + $export[$index]['plasticWaterBottle'] = 0; + $export[$index]['fizzyDrinkBottle'] = 0; + $export[$index]['bottleLid'] = 0; + $export[$index]['bottleLabel'] = 0; + $export[$index]['tinCan'] = 0; + $export[$index]['sportsDrink'] = 0; + $export[$index]['straws'] = 0; + $export[$index]['plastic_cups'] = 0; + $export[$index]['plastic_cup_tops'] = 0; + $export[$index]['milk_bottle'] = 0; + $export[$index]['milk_carton'] = 0; + $export[$index]['paper_cups'] = 0; + $export[$index]['juice_cartons'] = 0; + $export[$index]['juice_bottles'] = 0; + $export[$index]['juice_packet'] = 0; + $export[$index]['ice_tea_bottles'] = 0; + $export[$index]['ice_tea_can'] = 0; + $export[$index]['energy_can'] = 0; + $export[$index]['softDrinkOther'] = 0; + + $export[$index]['gloves'] = 0; + $export[$index]['facemasks'] = 0; + $export[$index]['condoms'] = 0; + $export[$index]['mental'] = 0; + $export[$index]['deodorant'] = 0; + $export[$index]['ear_swabs'] = 0; + $export[$index]['tooth_pick'] = 0; + $export[$index]['tooth_brush'] = 0; + $export[$index]['sanitaryOther'] = 0; + $export[$index]['dogshit'] = 0; + $export[$index]['Random_dump'] = 0; + $export[$index]['No_id_plastic'] = 0; + $export[$index]['Metal_object'] = 0; + $export[$index]['plastic_bags'] = 0; + $export[$index]['election_posters'] = 0; + $export[$index]['forsale_posters'] = 0; + $export[$index]['books'] = 0; + $export[$index]['magazines'] = 0; + $export[$index]['paper'] = 0; + $export[$index]['stationary'] = 0; + $export[$index]['washing_up'] = 0; + $export[$index]['hair_tie'] = 0; + $export[$index]['ear_plugs'] = 0; + $export[$index]['batteries'] = 0; + $export[$index]['elec_small'] = 0; + $export[$index]['elec_large'] = 0; + $export[$index]['Other_Unknown'] = 0; + + $export[$index]['microplastics'] = 0; + $export[$index]['mediumplastics'] = 0; + $export[$index]['macroplastics'] = 0; + $export[$index]['rope_small'] = 0; + $export[$index]['rope_medium'] = 0; + $export[$index]['rope_large'] = 0; + $export[$index]['fishing_gear_nets'] = 0; + $export[$index]['buoys'] = 0; + $export[$index]['degraded_plasticbottle'] = 0; + $export[$index]['degraded_plasticbag'] = 0; + $export[$index]['degraded_straws'] = 0; + $export[$index]['degraded_lighters'] = 0; + $export[$index]['baloons'] = 0; + $export[$index]['lego'] = 0; + $export[$index]['shotgun_cartridges'] = 0; + $export[$index]['coastal_other'] = 0; + + $export[$index]['art'] = 0; + + $export[$index]['adidas'] = 0; + $export[$index]['amazon'] = 0; + $export[$index]['aldi'] = 0; + $export[$index]['apple'] = 0; + $export[$index]['applegreen'] = 0; + $export[$index]['asahi'] = 0; + $export[$index]['avoca'] = 0; + + $export[$index]['ballygowan'] = 0; + $export[$index]['bewleys'] = 0; + $export[$index]['brambles'] = 0; + $export[$index]['budweiser'] = 0; + $export[$index]['bulmers'] = 0; + $export[$index]['burgerking'] = 0; + $export[$index]['butlers'] = 0; + + $export[$index]['cadburys'] = 0; + $export[$index]['cafe_nero'] = 0; + $export[$index]['camel'] = 0; + $export[$index]['carlsberg'] = 0; + $export[$index]['centra'] = 0; + $export[$index]['coke'] = 0; + $export[$index]['circlek'] = 0; + $export[$index]['coles'] = 0; + $export[$index]['colgate'] = 0; + $export[$index]['corona'] = 0; + $export[$index]['costa'] = 0; + + $export[$index]['doritos'] = 0; + $export[$index]['drpepper'] = 0; + $export[$index]['dunnes'] = 0; + $export[$index]['duracell'] = 0; + $export[$index]['durex'] = 0; + + $export[$index]['esquires'] = 0; + + $export[$index]['frank_and_honest'] = 0; + $export[$index]['fritolay'] = 0; + + $export[$index]['gatorade'] = 0; + $export[$index]['gillette'] = 0; + $export[$index]['guinness'] = 0; + + $export[$index]['haribo'] = 0; + $export[$index]['heineken'] = 0; + + $export[$index]['insomnia'] = 0; + + $export[$index]['kellogs'] = 0; + $export[$index]['kfc'] = 0; + + $export[$index]['lego'] = 0; + $export[$index]['lidl'] = 0; + $export[$index]['lindenvillage'] = 0; + $export[$index]['lolly_and_cookes'] = 0; + $export[$index]['loreal'] = 0; + $export[$index]['lucozade'] = 0; + + $export[$index]['nero'] = 0; + $export[$index]['nescafe'] = 0; + $export[$index]['nestle'] = 0; + + $export[$index]['marlboro'] = 0; + $export[$index]['mars'] = 0; + $export[$index]['mcdonalds'] = 0; + + $export[$index]['nike'] = 0; + + $export[$index]['obriens'] = 0; + + $export[$index]['pepsi'] = 0; + $export[$index]['powerade'] = 0; + + $export[$index]['redbull'] = 0; + $export[$index]['ribena'] = 0; + + $export[$index]['samsung'] = 0; + $export[$index]['sainsburys'] = 0; + $export[$index]['spar'] = 0; + $export[$index]['subway'] = 0; + $export[$index]['supermacs'] = 0; + $export[$index]['supervalu'] = 0; + $export[$index]['starbucks'] = 0; + + $export[$index]['tayto'] = 0; + $export[$index]['tesco'] = 0; + $export[$index]['thins'] = 0; + + $export[$index]['volvic'] = 0; + + $export[$index]['waitrose'] = 0; + $export[$index]['walkers'] = 0; + $export[$index]['woolworths'] = 0; + $export[$index]['wilde_and_greene'] = 0; + $export[$index]['wrigleys'] = 0; + + if ($photo['smoking_id']) { + $smoking = Smoking::find($photo['smoking_id']); + if ($smoking['butts']) { + $export[$index]['cigaretteButts'] = $smoking['butts']; + } + if ($smoking['lighters']) { + $export[$index]['lighters'] = $smoking['lighters']; + } + if ($smoking['cigaretteBox']) { + $export[$index]['cigaretteBox'] = $smoking['cigaretteBox']; + } + if ($smoking['tobaccoPouch']) { + $export[$index]['tobaccoPouch'] = $smoking['tobaccoPouch']; + } + if ($smoking['skins']) { + $export[$index]['papers_filters'] = $smoking['skins']; + } + if ($smoking['plastic']) { + $export[$index]['plastic_smoking_pk'] = $smoking['plastic']; + } + if ($smoking['filters']) { + $export[$index]['filters'] = $smoking['filters']; + } + if ($smoking['filterbox']) { + $export[$index]['filterbox'] = $smoking['filterbox']; + } + if ($smoking['smokingOther']) { + $export[$index]['smokingOther'] = $smoking['smokingOther']; + } + } + + if ($photo['food_id']) { + $food = Food::find($photo['food_id']); + if ($food['sweetWrappers']) { + $export[$index]['sweetWrappers'] = $food['sweetWrappers']; + } + if ($food['paperFoodPackaging']) { + $export[$index]['paperFoodPackaging'] = $food['paperFoodPackaging']; + } + if ($food['plasticFoodPackaging']) { + $export[$index]['plasticFoodPackaging'] = $food['plasticFoodPackaging']; + } + if ($food['plasticCutlery']) { + $export[$index]['plasticCutlery'] = $food['plasticCutlery']; + } + if ($food['crisp_small']) { + $export[$index]['crisp_small'] = $food['crisp_small']; + } + if ($food['crisp_large']) { + $export[$index]['crisp_large'] = $food['crisp_large']; + } + if ($food['styrofoam_plate']) { + $export[$index]['styrofoam_plate'] = $food['styrofoam_plate']; + } + if ($food['napkins']) { + $export[$index]['napkins'] = $food['napkins']; + } + if ($food['sauce_packet']) { + $export[$index]['sauce_packet'] = $food['sauce_packet']; + } + if ($food['glass_jar']) { + $export[$index]['glass_jar'] = $food['glass_jar']; + } + if ($food['glass_jar_lid']) { + $export[$index]['glass_jar_lid'] = $food['glass_jar_lid']; + } + if ($food['foodOther']) { + $export[$index]['foodOther'] = $food['foodOther']; + } + } + + if ($photo['coffee_id']) { + $coffee = Coffee::find($photo['coffee_id']); + if ($coffee['coffeeCups']) { + $export[$index]['coffeeCups'] = $coffee['coffeeCups']; + } + if ($coffee['coffeeLids']) { + $export[$index]['coffeeLids'] = $coffee['coffeeLids']; + } + if ($coffee['coffeeOther']) { + $export[$index]['coffeeOther'] = $coffee['coffeeOther']; + } + } + + if ($photo['alcohol_id']) { + $alcohol = Alcohol::find($photo['alcohol_id']); + if ($alcohol['beerBottle']) { + $export[$index]['beerBottle'] = $alcohol['beerBottle']; + } + if ($alcohol['spiritBottle']) { + $export[$index]['spiritBottle'] = $alcohol['spiritBottle']; + } + if ($alcohol['beerCan']) { + $export[$index]['beerCan'] = $alcohol['beerCan']; + } + if ($alcohol['brokenGlass']) { + $export[$index]['brokenGlass_alcohol'] = $alcohol['brokenGlass']; + } + if ($alcohol['paperCardAlcoholPackaging']) { + $export[$index]['paperCardAlcoholPackaging'] = $alcohol['paperCardAlcoholPackaging']; + } + if ($alcohol['plasticAlcoholPackaging']) { + $export[$index]['plasticAlcoholPackaging'] = $alcohol['plasticAlcoholPackaging']; + } + if ($alcohol['bottleTops']) { + $export[$index]['bottleTops'] = $alcohol['bottleTops']; + } + if ($alcohol['wineBottle']) { + $export[$index]['wineBottle'] = $alcohol['wineBottle']; + } + if ($alcohol['alcoholOther']) { + $export[$index]['alcoholOther'] = $alcohol['alcoholOther']; + } + } + + if ($photo['softdrinks_id']) { + $softdrinks = SoftDrinks::find($photo['softdrinks_id']); + if ($softdrinks['waterBottle']) { + $export[$index]['plasticWaterBottle'] = $softdrinks['waterBottle']; + } + if ($softdrinks['fizzyDrinkBottle']) { + $export[$index]['fizzyDrinkBottle'] = $softdrinks['fizzyDrinkBottle']; + } + if ($softdrinks['bottleLid']) { + $export[$index]['bottleLid'] = $softdrinks['bottleLid']; + } + if ($softdrinks['bottleLabel']) { + $export[$index]['bottleLabel'] = $softdrinks['bottleLabel']; + } + if ($softdrinks['tinCan']) { + $export[$index]['tinCan'] = $softdrinks['tinCan']; + } + if ($softdrinks['sportsDrink']) { + $export[$index]['sportsDrink'] = $softdrinks['sportsDrink']; + } + if ($softdrinks['paper_cups']) { + $export[$index]['paper_cups'] = $softdrinks['paper_cups']; + } + if ($softdrinks['juice_cartons']) { + $export[$index]['juice_cartons'] = $softdrinks['juice_cartons']; + } + if ($softdrinks['juice_bottles']) { + $export[$index]['juice_bottles'] = $softdrinks['juice_bottles']; + } + if ($softdrinks['juice_packet']) { + $export[$index]['juice_packet'] = $softdrinks['juice_packet']; + } + if ($softdrinks['ice_tea_bottles']) { + $export[$index]['ice_tea_bottles'] = $softdrinks['ice_tea_bottles']; + } + if ($softdrinks['ice_tea_can']) { + $export[$index]['ice_tea_can'] = $softdrinks['ice_tea_can']; + } + if ($softdrinks['energy_can']) { + $export[$index]['energy_can'] = $softdrinks['energy_can']; + } + if ($softdrinks['softDrinkOther']) { + $export[$index]['softDrinkOther'] = $softdrinks['softDrinkOther']; + } + } + + if ($photo['sanitary_id']) { + $sanitary = Sanitary::find($photo['sanitary_id']); + if ($sanitary['gloves']) { + $export[$index]['gloves'] = $sanitary['gloves']; + } + if ($sanitary['facemasks']) { + $export[$index]['facemasks'] = $sanitary['facemasks']; + } + if ($sanitary['condoms']) { + $export[$index]['condoms'] = $sanitary['condoms']; + } + if ($sanitary['nappies']) { + $export[$index]['nappies'] = $sanitary['nappies']; + } + if ($sanitary['menstral']) { + $export[$index]['menstral'] = $sanitary['menstral']; + } + if ($sanitary['deodorant']) { + $export[$index]['deodorant'] = $sanitary['deodorant']; + } + if ($sanitary['sanitaryOther']) { + $export[$index]['sanitaryOther'] = $sanitary['sanitaryOther']; + } + } + + if ($photo['other_id']) { + $other = Other::find($photo['other_id']); + if ($other['dogshit']) { + $export[$index]['dogshit'] = $other['dogshit']; + } + if ($other['dump']) { + $export[$index]['Random_dump'] = $other['dump']; + } + if ($other['plastic']) { + $export[$index]['No_id_plastic'] = $other['plastic']; + } + if ($other['metal']) { + $export[$index]['Metal_object'] = $other['metal']; + } + if ($other['washing_up']) { + $export[$index]['washing_up'] = $other['washing_up']; + } + if ($other['hair_tie']) { + $export[$index]['hair_tie'] = $other['hair_tie']; + } + if ($other['ear_plugs']) { + $export[$index]['ear_plugs'] = $other['ear_plugs']; + } + if ($other['other']) { + $export[$index]['Unknown'] = $other['other']; + } + } + + if ($photo['coastal_id']) { + $coastal = Coastal::find($photo['coastal_id']); + if ($coastal['microplastics']) { + $export[$index]['microplastics'] = $coastal['microplastics']; + } + if ($coastal['mediumplastics']) { + $export[$index]['mediumplastics'] = $coastal['mediumplastics']; + } + if ($coastal['macroplastics']) { + $export[$index]['macroplastics'] = $coastal['macroplastics']; + } + if ($coastal['rope_small']) { + $export[$index]['rope_small'] = $coastal['rope_small']; + } + if ($coastal['rope_medium']) { + $export[$index]['rope_medium'] = $coastal['rope_medium']; + } + if ($coastal['rope_large']) { + $export[$index]['rope_large'] = $coastal['rope_large']; + } + if ($coastal['fishing_gear_nets']) { + $export[$index]['fishing_gear_nets'] = $coastal['fishing_gear_nets']; + } + if ($coastal['buoys']) { + $export[$index]['buoys'] = $coastal['buoys']; + } + if ($coastal['degraded_plasticbottle']) { + $export[$index]['degraded_plasticbottle'] = $coastal['degraded_plasticbottle']; + } + if ($coastal['degraded_plasticbag']) { + $export[$index]['degraded_plasticbag'] = $coastal['degraded_plasticbag']; + } + if ($coastal['degraded_straws']) { + $export[$index]['degraded_straws'] = $coastal['degraded_straws']; + } + if ($coastal['degraded_lighters']) { + $export[$index]['degraded_lighters'] = $coastal['degraded_lighters']; + } + if ($coastal['baloons']) { + $export[$index]['baloons'] = $coastal['baloons']; + } + if ($coastal['lego']) { + $export[$index]['lego'] = $coastal['lego']; + } + if ($coastal['shotgun_cartridges']) { + $export[$index]['shotgun_cartridges'] = $coastal['shotgun_cartridges']; + } + if ($coastal['coastal_other']) { + $export[$index]['coastal_other']; + } + } + + if ($photo['pathway_id']) { + $pathway = Pathway::find($photo['pathway_id']); + if ($pathway['gutter']) { + $export[$index]['gutter'] = $pathway['gutter']; + } + if ($pathway['gutter_long']) { + $export[$index]['gutter_long'] = $pathway['gutter_long']; + } + if ($pathway['kerb_hole_small']) { + $export[$index]['kerb_hole_small'] = $pathway['kerb_hole_small']; + } + if ($pathway['kerb_hole_large']) { + $export[$index]['kerb_hole_large'] = $pathway['kerb_hole_large']; + } + if ($pathway['pathwayOther']) { + $export[$index]['pathwayOther'] = $pathway['pathwayOther']; + } + } + + // if($photo["art_id"]) { + // $art = Art::find($photo["art_id"]); + // if($art['item']) { + // $export[$index]['art'] = $art['item']; + // } + // } + + if ($photo['brands_id']) { + $brands = Brand::find($photo['brands_id']); + if ($brands['adidas']) { + $export[$index]['adidas'] = $brands['adidas']; + } + if ($brands['amazon']) { + $export[$index]['amazon'] = $brands['amazon']; + } + if ($brands['aldi']) { + $export[$index]['aldi'] = $brands['aldi']; + } + if ($brands['apple']) { + $export[$index]['apple'] = $brands['apple']; + } + if ($brands['applegreen']) { + $export[$index]['applegreen'] = $brands['applegreen']; + } + if ($brands['asahi']) { + $export[$index]['asahi'] = $brands['asahi']; + } + if ($brands['avoca']) { + $export[$index]['avoca'] = $brands['avoca']; + } + if ($brands['ballygowan']) { + $export[$index]['ballygowan'] = $brands['ballygowan']; + } + if ($brands['bewleys']) { + $export[$index]['bewleys'] = $brands['bewleys']; + } + if ($brands['brambles']) { + $export[$index]['brambles'] = $brands['brambles']; + } + if ($brands['budweiser']) { + $export[$index]['budweiser'] = $brands['budweiser']; + } + if ($brands['bulmers']) { + $export[$index]['bulmers'] = $brands['bulmers']; + } + if ($brands['burgerking']) { + $export[$index]['burgerking'] = $brands['burgerking']; + } + if ($brands['butlers']) { + $export[$index]['butlers'] = $brands['butlers']; + } + + if ($brands['cadburys']) { + $export[$index]['cadburys'] = $brands['cadburys']; + } + if ($brands['cafe_nero']) { + $export[$index]['cafe_nero'] = $brands['cafe_nero']; + } + if ($brands['camel']) { + $export[$index]['camel'] = $brands['camel']; + } + if ($brands['carlsberg']) { + $export[$index]['carlsberg'] = $brands['carlsberg']; + } + if ($brands['centra']) { + $export[$index]['centra'] = $brands['centra']; + } + if ($brands['coke']) { + $export[$index]['coke'] = $brands['coke']; + } + if ($brands['circlek']) { + $export[$index]['circlek'] = $brands['circlek']; + } + if ($brands['coles']) { + $export[$index]['coles'] = $brands['coles']; + } + if ($brands['colgate']) { + $export[$index]['colgate'] = $brands['colgate']; + } + if ($brands['corona']) { + $export[$index]['corona'] = $brands['corona']; + } + if ($brands['costa']) { + $export[$index]['costa'] = $brands['costa']; + } + + if ($brands['doritos']) { + $export[$index]['doritos'] = $brands['doritos']; + } + if ($brands['drpepper']) { + $export[$index]['drpepper'] = $brands['drpepper']; + } + if ($brands['dunnes']) { + $export[$index]['dunnes'] = $brands['dunnes']; + } + if ($brands['duracell']) { + $export[$index]['duracell'] = $brands['duracell']; + } + if ($brands['durex']) { + $export[$index]['durex'] = $brands['durex']; + } + + if ($brands['esquires']) { + $export[$index]['esquires'] = $brands['esquires']; + } + + if ($brands['frank_and_honest']) { + $export[$index]['frank_and_honest'] = $brands['frank_and_honest']; + } + if ($brands['fritolay']) { + $export[$index]['fritolay'] = $brands['fritolay']; + } + + if ($brands['gatorade']) { + $export[$index]['gatorade'] = $brands['gatorade']; + } + if ($brands['gillette']) { + $export[$index]['gillette'] = $brands['gillette']; + } + if ($brands['guinness']) { + $export[$index]['guinness'] = $brands['gillette']; + } + + if ($brands['haribo']) { + $export[$index]['haribo'] = $brands['haribo']; + } + if ($brands['heineken']) { + $export[$index]['heineken'] = $brands['heineken']; + } + + if ($brands['insomnia']) { + $export[$index]['insomnia'] = $brands['insomnia']; + } + + if ($brands['kellogs']) { + $export[$index]['kellogs'] = $brands['kellogs']; + } + if ($brands['kfc']) { + $export[$index]['kfc'] = $brands['kfc']; + } + + if ($brands['lego']) { + $export[$index]['lego'] = $brands['lego']; + } + if ($brands['lidl']) { + $export[$index]['lidl'] = $brands['lidl']; + } + if ($brands['lindenvillage']) { + $export[$index]['lindenvillage'] = $brands['lindenvillage']; + } + if ($brands['lolly_and_cookes']) { + $export[$index]['lolly_and_cookes'] = $brands['lolly_and_cookes']; + } + if ($brands['loreal']) { + $export[$index]['loreal'] = $brands['loreal']; + } + if ($brands['lucozade']) { + $export[$index]['lucozade'] = $brands['lucozade']; + } + + if ($brands['marlboro']) { + $export[$index]['marlboro'] = $brands['marlboro']; + } + if ($brands['mars']) { + $export[$index]['mars'] = $brands['mars']; + } + if ($brands['mcdonalds']) { + $export[$index]['mcdonalds'] = $brands['mcdonalds']; + } + + if ($brands['nero']) { + $export[$index]['nero'] = $brands['nero']; + } + if ($brands['nescafe']) { + $export[$index]['nescafe'] = $brands['nescafe']; + } + if ($brands['nestle']) { + $export[$index]['nestle'] = $brands['nestle']; + } + if ($brands['nike']) { + $export[$index]['nike'] = $brands['nike']; + } + + if ($brands['obriens']) { + $export[$index]['obriens'] = $brands['obriens']; + } + + if ($brands['pepsi']) { + $export[$index]['pepsi'] = $brands['pepsi']; + } + if ($brands['powerade']) { + $export[$index]['powerade'] = $brands['powerade']; + } + + if ($brands['redbull']) { + $export[$index]['redbull'] = $brands['redbull']; + } + if ($brands['ribena']) { + $export[$index]['ribena'] = $brands['ribena']; + } + + if ($brands['samsung']) { + $export[$index]['samsung'] = $brands['samsung']; + } + if ($brands['sainsburys']) { + $export[$index]['sainsburys'] = $brands['sainsburys']; + } + if ($brands['spar']) { + $export[$index]['spar'] = $brands['spar']; + } + if ($brands['stella']) { + $export[$index]['stella'] = $brands['stella']; + } + if ($brands['subway']) { + $export[$index]['subway'] = $brands['subway']; + } + if ($brands['supermacs']) { + $export[$index]['supermacs'] = $brands['supermacs']; + } + if ($brands['supervale']) { + $export[$index]['supervale'] = $brands['supervale']; + } + if ($brands['starbucks']) { + $export[$index]['starbucks'] = $brands['starbucks']; + } + + if ($brands['tayto']) { + $export[$index]['tayto'] = $brands['tayto']; + } + if ($brands['tesco']) { + $export[$index]['tesco'] = $brands['tesco']; + } + if ($brands['thins']) { + $export[$index]['thins'] = $brands['thins']; + } + + if ($brands['volvic']) { + $export[$index]['volvic'] = $brands['volvic']; + } + + if ($brands['waitrose']) { + $export[$index]['waitrose'] = $brands['waitrose']; + } + if ($brands['walkers']) { + $export[$index]['walkers'] = $brands['walkers']; + } + if ($brands['woolworths']) { + $export[$index]['woolworths'] = $brands['woolworths']; + } + if ($brands['wilde_and_greene']) { + $export[$index]['wilde_and_greene'] = $brands['wilde_and_greene']; + } + if ($brands['wrigleys']) { + $export[$index]['wrigleys'] = $brands['wrigleys']; + } + } + } + // return $export; + $sheet->fromModel($export); + })->export('csv'); + // $excel->setCreator('OpenLitterMap')->setCompany('GeoTech Innovations Ltd.'); + }); + } + } } diff --git a/app/Http/Controllers/GlobalMap/GlobalMapController.php b/app/Http/Controllers/GlobalMap/GlobalMapController.php index 6c9330aad..454409ae2 100644 --- a/app/Http/Controllers/GlobalMap/GlobalMapController.php +++ b/app/Http/Controllers/GlobalMap/GlobalMapController.php @@ -2,10 +2,9 @@ namespace App\Http\Controllers\GlobalMap; +use App\Http\Controllers\Controller; use App\Models\Photo; use App\Traits\FilterPhotosByGeoHashTrait; - -use App\Http\Controllers\Controller; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; @@ -36,7 +35,7 @@ public function artData(): array ) ->where([ ['verified', '>=', 2], - ['art_id', '!=', null] + ['art_id', '!=', null], ]) ->with([ 'user:id,name,username,show_username_maps,show_name_maps,settings', @@ -51,8 +50,6 @@ public function artData(): array /** * Get photos point data at zoom levels 16 or above - * - * @return array */ public function index(): array { @@ -76,15 +73,14 @@ public function index(): array 'user.team:is_trusted', 'team:id,name', 'customTags:photo_id,tag', - 'adminVerificationLog.admin' => function ($q) { + 'adminVerificationLog.admin' => function ($q): void { $q->addSelect('id', 'show_name', 'show_username') ->addSelect(DB::raw('CASE WHEN show_name = 1 THEN name ELSE NULL END as name')) ->addSelect(DB::raw('CASE WHEN show_username = 1 THEN username ELSE NULL END as username')); - } + }, ]); - if (request()->fromDate || request()->toDate) - { + if (request()->fromDate || request()->toDate) { $startDate = request()->fromDate && Carbon::hasFormat(request()->fromDate, 'Y-m-d') ? Carbon::createFromFormat('Y-m-d', request()->fromDate)->startOfDay() : Carbon::create(2017); @@ -94,18 +90,15 @@ public function index(): array : now()->addDay(); $query->whereBetween('datetime', [$startDate, $endDate]); - } - else if (request()->year) - { + } elseif (request()->year) { $query->whereYear('datetime', request()->year); } - if (request()->username) - { - $query->whereHas('user', function ($q) { + if (request()->username) { + $query->whereHas('user', function ($q): void { $q->where([ 'users.show_username_maps' => 1, - 'users.username' => request()->username + 'users.username' => request()->username, ]); }); } diff --git a/app/Http/Controllers/History/GetPaginatedHistoryController.php b/app/Http/Controllers/History/GetPaginatedHistoryController.php index af44d9ebe..4cd77b066 100644 --- a/app/Http/Controllers/History/GetPaginatedHistoryController.php +++ b/app/Http/Controllers/History/GetPaginatedHistoryController.php @@ -2,11 +2,11 @@ namespace App\Http\Controllers\History; -use App\Models\Photo; +use App\Http\Controllers\Controller; use App\Models\CustomTag; -use Illuminate\Http\Request; +use App\Models\Photo; use Illuminate\Http\JsonResponse; -use App\Http\Controllers\Controller; +use Illuminate\Http\Request; use Illuminate\Pagination\Paginator; use Illuminate\Support\Facades\Auth; @@ -16,11 +16,8 @@ class GetPaginatedHistoryController extends Controller * Get a paginated response of all available verified data * * Todo - validate the request - * - * @param Request $request - * @return JsonResponse */ - public function __invoke (Request $request): JsonResponse + public function __invoke(Request $request): JsonResponse { // Default to page 1 if not provided $currentPage = $request->input('loadPage', 1); @@ -33,51 +30,50 @@ public function __invoke (Request $request): JsonResponse $query = Photo::query() - ->when($mobileAppUser, function ($q) use ($mobileAppUser) { + ->when($mobileAppUser, function ($q) use ($mobileAppUser): void { $q->where('user_id', $mobileAppUser->id); - }, function ($q) { + }, function ($q): void { $q->where('verified', '>=', 2); }) - ->when($request->filterCountry !== 'all', function ($q) use ($request) { + ->when($request->filterCountry !== 'all', function ($q) use ($request): void { $q->where('country_id', $request->filterCountry); }) - ->when($request->filterDateFrom, function ($q) use ($request) { + ->when($request->filterDateFrom, function ($q) use ($request): void { $q->whereDate('created_at', '>=', $request->filterDateFrom); }) - ->when($request->filterDateTo, function ($q) use ($request) { + ->when($request->filterDateTo, function ($q) use ($request): void { $q->whereDate('created_at', '<=', $request->filterDateTo); }) // Filter by tags: needs improvement to search by category, item, quantity // instead of looking at the result_string, we should be looking at the photos relationships - ->when($request->filterTag, function ($q) use ($request) { - $q->where('result_string', 'like', '%' . $request->filterTag . '%'); + ->when($request->filterTag, function ($q) use ($request): void { + $q->where('result_string', 'like', '%'.$request->filterTag.'%'); }) - ->when($request->filterCustomTag, function ($q) use ($request) { - $q->whereHas('customTags', function ($q) use ($request) { - $q->where('tag', 'like', '%' . $request->filterCustomTag . '%'); + ->when($request->filterCustomTag, function ($q) use ($request): void { + $q->whereHas('customTags', function ($q) use ($request): void { + $q->where('tag', 'like', '%'.$request->filterCustomTag.'%'); }); }); - $notInclude = CustomTag::notIncludeTags(); - $query->whereDoesntHave('customTags', function ($q) use ($notInclude) { + $query->whereDoesntHave('customTags', function ($q) use ($notInclude): void { $q->whereIn('tag', $notInclude); }); - $photos = $query->with(['customTags' => function ($query) use ($notInclude) { + $photos = $query->with(['customTags' => function ($query) use ($notInclude): void { $query->whereNotIn('tag', $notInclude); }]) - ->orderBy('id', 'desc') - ->paginate($request->paginationAmount); + ->orderBy('id', 'desc') + ->paginate($request->paginationAmount); return response()->json([ 'success' => true, - 'photos' => $photos + 'photos' => $photos, ]); } } diff --git a/app/Http/Controllers/TotalDataController.php b/app/Http/Controllers/TotalDataController.php index ff54670a2..ac2d478c7 100644 --- a/app/Http/Controllers/TotalDataController.php +++ b/app/Http/Controllers/TotalDataController.php @@ -2,25 +2,10 @@ namespace App\Http\Controllers; -use Auth; -use App\Models\Photo; -use App\Models\User\User; use App\Models\Litter\Categories\Smoking; -use App\Models\Litter\Categories\Alcohol; -use App\Models\Litter\Categories\Coffee; -use App\Models\Litter\Categories\Food; use App\Models\Litter\Categories\SoftDrinks; -use App\Models\Litter\Categories\Drugs; -use App\Models\Litter\Categories\Sanitary; -use App\Models\Litter\Categories\Other; -use App\Models\Litter\Categories\Coastal; -use App\Models\Litter\Categories\Pathway; -use App\Models\Litter\Categories\Art; -use App\Models\Litter\Categories\Brand; -use App\Models\Litter\Categories\TrashDog; -use DateTime; -use Carbon\Carbon; -use Illuminate\Http\Request; +use App\Models\Photo; +use Auth; use Excel; class TotalDataController extends Controller @@ -28,16 +13,12 @@ class TotalDataController extends Controller /** * Export some data for machine learning */ - public function getCSV () + public function getCSV() { - if ($user = Auth::user()) - { - if ($user->email == 'seanlynch@umail.ucc.ie') - { - Excel::create('cigarette_butts', function ($excel) - { - $excel->sheet('OLM', function ($sheet) - { + if ($user = Auth::user()) { + if ($user->email == 'seanlynch@umail.ucc.ie') { + Excel::create('cigarette_butts', function ($excel): void { + $excel->sheet('OLM', function ($sheet): void { $index = 0; $export = []; @@ -46,7 +27,7 @@ public function getCSV () $butts = Smoking::select('id') ->where([ ['id', '>', 984], - ['butts', '>', 0] + ['butts', '>', 0], ]) ->get() ->take(2500) @@ -55,17 +36,16 @@ public function getCSV () // Get photos that match the smoking_id column // eager load the cigarette_butt data again $cig_photos = Photo::select('id', 'smoking_id', 'filename') - ->whereIn('smoking_id', $butts) - ->with([ - 'smoking' => function ($a) { - $a->select('id', 'butts'); - } - ]) - ->get(); + ->whereIn('smoking_id', $butts) + ->with([ + 'smoking' => function ($a): void { + $a->select('id', 'butts'); + }, + ]) + ->get(); // Add to the CSV - foreach ($cig_photos as $photo) - { + foreach ($cig_photos as $photo) { $index++; $export[$index]['filename'] = $photo->filename; $export[$index]['photo_id'] = $photo->id; @@ -81,7 +61,7 @@ public function getCSV () $cig_boxes = Smoking::select('id') ->where([ ['id', '>', 984], - ['cigaretteBox', '>', 0] + ['cigaretteBox', '>', 0], ]) ->get() ->take(2500) @@ -90,15 +70,14 @@ public function getCSV () $cig_boxes_photos = Photo::select('id', 'smoking_id', 'filename') ->whereIn('smoking_id', $cig_boxes) ->with([ - 'smoking' => function ($a) { + 'smoking' => function ($a): void { $a->select('id', 'cigaretteBox'); - } + }, ]) ->get(); // Add to the CSV - foreach ($cig_boxes_photos as $photo) - { + foreach ($cig_boxes_photos as $photo) { $index++; $export[$index]['filename'] = $photo->filename; $export[$index]['photo_id'] = $photo->id; @@ -114,7 +93,7 @@ public function getCSV () $plastic_bottle_ids = SoftDrinks::select('id') ->where([ ['id', '>', 1462], - ['waterBottle', '>', 0] + ['waterBottle', '>', 0], ]) ->get() ->take(2500) @@ -123,15 +102,14 @@ public function getCSV () $plastic_bottle_photos = Photo::select('id', 'softdrinks_id', 'filename') ->whereIn('softdrinks_id', $plastic_bottle_ids) ->with([ - 'softdrinks' => function ($a) { + 'softdrinks' => function ($a): void { $a->select('id', 'waterBottle'); - } + }, ]) ->get(); // Add to the CSV - foreach ($plastic_bottle_photos as $photo) - { + foreach ($plastic_bottle_photos as $photo) { $index++; $export[$index]['filename'] = $photo->filename; $export[$index]['photo_id'] = $photo->id; @@ -147,7 +125,7 @@ public function getCSV () $cans_ids = SoftDrinks::select('id') ->where([ ['id', '>', 1462], - ['tinCan', '>', 0] + ['tinCan', '>', 0], ]) ->get() ->take(2500) @@ -156,15 +134,14 @@ public function getCSV () $tin_can_photos = Photo::select('id', 'softdrinks_id', 'filename') ->whereIn('softdrinks_id', $cans_ids) ->with([ - 'softdrinks' => function ($a) { + 'softdrinks' => function ($a): void { $a->select('id', 'tinCan'); - } + }, ]) ->get(); // Add to the CSV - foreach ($tin_can_photos as $photo) - { + foreach ($tin_can_photos as $photo) { $index++; $export[$index]['filename'] = $photo->filename; $export[$index]['photo_id'] = $photo->id; @@ -184,56 +161,54 @@ public function getCSV () } } + // /** + // * Return list of data for sean + // */ + // public function butts () + // { + + // return Photo::with([ + // 'smoking' => function ($a) { + // $a->select('id', 'butts', 'cigaretteBox'); + // }, + // 'softdrinks' => function ($b) { + // $b->select('id', 'waterBottle', 'fizzyDrinkBottle', 'tinCan', 'energy_can'); + // } + // ]) + // ->where([ + // ['filename', '!=', '/assets/verified.jpg'], + // 'verified' => 2, + // ['smoking_id', '!=', NULL], + // ])->select('id', 'filename', 'smoking_id')->get()->take(2500); + // } + // } -// /** -// * Return list of data for sean -// */ -// public function butts () -// { - -// return Photo::with([ -// 'smoking' => function ($a) { -// $a->select('id', 'butts', 'cigaretteBox'); -// }, -// 'softdrinks' => function ($b) { -// $b->select('id', 'waterBottle', 'fizzyDrinkBottle', 'tinCan', 'energy_can'); -// } -// ]) -// ->where([ -// ['filename', '!=', '/assets/verified.jpg'], -// 'verified' => 2, -// ['smoking_id', '!=', NULL], -// ])->select('id', 'filename', 'smoking_id')->get()->take(2500); -// } -// } - - /** - * Return list of data for Laurens - */ - public function laurens () - { - $user = Auth::user(); - - if ($user->email == 'seanlynch@umail.ucc.ie' || $user->email == 'bakker.laurens@gmail.com') { - - $data = Photo::with([ - 'softdrinks' => function($a) { - $a->select('id', 'waterBottle', 'fizzyDrinkBottle', 'tinCan'); - }, - 'brands' => function ($b) { - $b->select('id', 'coke', 'pepsi')->where('coke', '!=', null); - } - ]) - ->where([ - 'verified' => 2, - ['softdrinks_id', '!=', NULL], - ['brands_id', '!=', NULL] - ])->select('id', 'filename', 'softdrinks_id', 'brands_id')->get()->take(1000); - - return $data; - } - - return redirect()->to('/'); - } + /** + * Return list of data for Laurens + */ + public function laurens() + { + $user = Auth::user(); + + if ($user->email == 'seanlynch@umail.ucc.ie' || $user->email == 'bakker.laurens@gmail.com') { + + $data = Photo::with([ + 'softdrinks' => function ($a): void { + $a->select('id', 'waterBottle', 'fizzyDrinkBottle', 'tinCan'); + }, + 'brands' => function ($b): void { + $b->select('id', 'coke', 'pepsi')->where('coke', '!=', null); + }, + ]) + ->where([ + 'verified' => 2, + ['softdrinks_id', '!=', null], + ['brands_id', '!=', null], + ])->select('id', 'filename', 'softdrinks_id', 'brands_id')->get()->take(1000); + + return $data; + } + return redirect()->to('/'); + } } diff --git a/app/Http/Controllers/User/Photos/GetMyPhotosController.php b/app/Http/Controllers/User/Photos/GetMyPhotosController.php index 00e35f08b..a7ecfec66 100644 --- a/app/Http/Controllers/User/Photos/GetMyPhotosController.php +++ b/app/Http/Controllers/User/Photos/GetMyPhotosController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers\User\Photos; +use App\Http\Controllers\Controller; use App\Models\Photo; -use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; -use App\Http\Controllers\Controller; +use Illuminate\Http\Request; use Illuminate\Pagination\Paginator; use Illuminate\Support\Facades\Auth; @@ -14,11 +14,8 @@ class GetMyPhotosController extends Controller /** * Get the users photos to display on a paginated table * Optional filters - * - * @param Request $request - * @return JsonResponse */ - public function __invoke (Request $request): JsonResponse + public function __invoke(Request $request): JsonResponse { // Todo - validate the request @@ -43,14 +40,14 @@ public function __invoke (Request $request): JsonResponse // Filter by tags: needs improvement to search by category, item, quantity // instead of looking at the result_string, we should be looking at the photos relationships if ($request->filterTag) { - $query->where('result_string', 'like', '%' . $request->filterTag . '%'); + $query->where('result_string', 'like', '%'.$request->filterTag.'%'); } if ($request->filterCustomTag) { $customTag = $request->filterCustomTag; - $query->whereHas('customTags', function ($q) use ($customTag) { - $q->where('tag', 'like', '%' . $customTag . '%'); + $query->whereHas('customTags', function ($q) use ($customTag): void { + $q->where('tag', 'like', '%'.$customTag.'%'); }); } @@ -60,7 +57,7 @@ public function __invoke (Request $request): JsonResponse return response()->json([ 'success' => true, - 'photos' => $photos + 'photos' => $photos, ]); } } diff --git a/app/Http/Controllers/WebhookController.php b/app/Http/Controllers/WebhookController.php index 986663c51..84b48bb88 100644 --- a/app/Http/Controllers/WebhookController.php +++ b/app/Http/Controllers/WebhookController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers; use App\Models\User\User; -use App\Plan; use Exception; // use App\Billing\Payments; use Illuminate\Http\Request; @@ -17,13 +16,15 @@ class WebhookController extends Controller * Handle a Stripe webhook call. * Change "customer.created" to handleCustomerCreated */ - public function handleWebhook (Request $request) + public function handleWebhook(Request $request) { - $method = 'handle'.studly_case(str_replace('.', '_', $request->type)); + $method = 'handle'.\Illuminate\Support\Str::studly(str_replace('.', '_', $request->type)); - if (method_exists($this, $method)) return $this->{$method}($request->all()); - - else return $this->missingMethod(); + if (method_exists($this, $method)) { + return $this->{$method}($request->all()); + } else { + return $this->missingMethod(); + } } /** @@ -31,15 +32,13 @@ public function handleWebhook (Request $request) * * This happens second. * - * @param $request * @return string[] */ - protected function handleCustomerCreated ($request) + protected function handleCustomerCreated($request) { // \Log::info('handleCustomerCreated', $request); - if ($user = User::where('email', $request['data']['object']['email'])->first()) - { + if ($user = User::where('email', $request['data']['object']['email'])->first()) { $user->stripe_id = $request['data']['object']['id']; $user->save(); @@ -51,12 +50,11 @@ protected function handleCustomerCreated ($request) * Handle a successful payment * Not sure why this comes before customer.created, but this is first */ - protected function handleChargeSucceeded (array $payload) + protected function handleChargeSucceeded(array $payload) { // \Log::info(['handleChargeSucceeded', $payload]); - if ($user = User::where('email', $payload['data']['object']['billing_details']['email'])->first()) - { + if ($user = User::where('email', $payload['data']['object']['billing_details']['email'])->first()) { $user->payments()->create(['amount' => $payload['data']['object']['amount'], 'stripe_id' => $user->stripe_id]); } @@ -66,17 +64,18 @@ protected function handleChargeSucceeded (array $payload) /** * Third */ - protected function handleCustomerSubscriptionCreated (array $payload) + protected function handleCustomerSubscriptionCreated(array $payload) { // \Log::info(['handleSubscriptionCreated', $payload]); - if ($user = User::where('stripe_id', $payload['data']['object']['customer'])->first()) - { + if ($user = User::where('stripe_id', $payload['data']['object']['customer'])->first()) { $name = $payload['data']['object']['items']['data'][0]['plan']['nickname']; $sub_id = $payload['data']['object']['id']; // sub_id - $plan_id = $payload['data']['object']['items']['data'][0]['plan']['id']; + $plan_id = $payload['data']['object']['items']['data'][0]['plan']['id']; - if (is_null($name)) $name = $payload['data']['object']['items']['data'][0]['plan']['id']; + if (is_null($name)) { + $name = $payload['data']['object']['items']['data'][0]['plan']['id']; + } $user->subscriptions()->create([ 'name' => $name ?: '', // Startup, Advanced, Pro. @@ -85,7 +84,7 @@ protected function handleCustomerSubscriptionCreated (array $payload) 'quantity' => 1, 'ends_at' => now()->addMonths(1), 'stripe_active' => 1, - 'stripe_status' => 'active' + 'stripe_status' => 'active', ]); return ['status' => 'success']; @@ -99,17 +98,16 @@ protected function handleCustomerSubscriptionCreated (array $payload) /** * Handle a cancelled customer from a Stripe subscription. * - * @param array $payload * @return \Symfony\Component\HttpFoundation\Response */ - protected function handleCustomerSubscriptionDeleted (array $payload) + protected function handleCustomerSubscriptionDeleted(array $payload) { $user = $this->getUserByStripeId($payload['data']['object']['customer']); if ($user) { $user->subscriptions->filter(function ($subscription) use ($payload) { return $subscription->stripe_id === $payload['data']['object']['id']; - })->each(function ($subscription) { + })->each(function ($subscription): void { $subscription->markAsCancelled(); }); } @@ -123,9 +121,10 @@ protected function handleCustomerSubscriptionDeleted (array $payload) * @param string $stripeId * @return \Laravel\Cashier\Billable */ - protected function getUserByStripeId ($stripeId) + protected function getUserByStripeId($stripeId) { $model = getenv('STRIPE_MODEL') ?: config('services.stripe.model'); + return (new $model)->where('stripe_id', $stripeId)->first(); } @@ -135,7 +134,7 @@ protected function getUserByStripeId ($stripeId) * @param string $id * @return bool */ - protected function eventExistsOnStripe ($id) + protected function eventExistsOnStripe($id) { try { return ! is_null(StripeEvent::retrieve($id, config('services.stripe.secret'))); @@ -149,7 +148,7 @@ protected function eventExistsOnStripe ($id) * * @return bool */ - protected function isInTestingEnvironment () + protected function isInTestingEnvironment() { return getenv('CASHIER_ENV') === 'testing'; } @@ -157,10 +156,10 @@ protected function isInTestingEnvironment () /** * Handle calls to missing methods on the controller. * - * @param array $parameters + * @param array $parameters * @return mixed */ - public function missingMethod ($parameters = []) + public function missingMethod($parameters = []) { return new Response; } diff --git a/app/Http/Controllers/WorldCup/GetDataForWorldCupController.php b/app/Http/Controllers/WorldCup/GetDataForWorldCupController.php index 19723c803..e78dfa5d1 100644 --- a/app/Http/Controllers/WorldCup/GetDataForWorldCupController.php +++ b/app/Http/Controllers/WorldCup/GetDataForWorldCupController.php @@ -2,12 +2,11 @@ namespace App\Http\Controllers\WorldCup; -use App\Models\Littercoin; -use App\Models\Location\Country; use App\Helpers\Get\LocationHelper; -use App\Models\Leaderboard\Leaderboard; - use App\Http\Controllers\Controller; +use App\Models\Leaderboard\Leaderboard; +use App\Models\Littercoin; +use App\Models\Location\Country; use Illuminate\Support\Facades\Redis; class GetDataForWorldCupController extends Controller @@ -23,10 +22,8 @@ class GetDataForWorldCupController extends Controller * - total littercoin * * - Countries array - * - * @return array */ - public function __invoke (): array + public function __invoke(): array { $littercoin = Littercoin::count(); @@ -40,33 +37,32 @@ public function __invoke (): array * 4. Automate 'manual_verify => 1' */ $countries = Country::with([ - 'creator' => function ($q) { + 'creator' => function ($q): void { $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') ->where('show_name_createdby', true) ->orWhere('show_username_createdby', true); }, - 'lastUploader' => function ($q) { + 'lastUploader' => function ($q): void { $q->select('id', 'name', 'username', 'show_name_createdby', 'show_username_createdby', 'created_at', 'updated_at') ->where('show_name_createdby', true) ->orWhere('show_username_createdby', true); - } + }, ]) - ->where('manual_verify', true) - ->orderBy('country', 'asc') - ->get(); + ->where('manual_verify', true) + ->orderBy('country', 'asc') + ->get(); $total_litter = 0; $total_photos = 0; - foreach ($countries as $country) - { + foreach ($countries as $country) { // Get firstUploader (creator) and lastUploader // We should be loading this dynamically $country = LocationHelper::getCreatorInfo($country); // Get Leaderboard per country. Should load more and stop when there are 10-max as some users settings may be off. -// $leaderboardIds = Redis::zrevrange("xp.country.$country->id", 0, 9, 'withscores'); -// $country['leaderboard'] = Leaderboard::getLeadersByUserIds($leaderboardIds); + // $leaderboardIds = Redis::zrevrange("xp.country.$country->id", 0, 9, 'withscores'); + // $country['leaderboard'] = Leaderboard::getLeadersByUserIds($leaderboardIds); $country['leaderboard'] = []; // Total values @@ -96,38 +92,32 @@ public function __invoke (): array * See: GlobalLevels.php global_levels table */ // level 0 - if ($total_litter <= 1000) - { + if ($total_litter <= 1000) { $previousXp = 0; $nextXp = 1000; } // level 1 - target, 10,000 - else if ($total_litter <= 10000) - { + elseif ($total_litter <= 10000) { $previousXp = 1000; $nextXp = 10000; // 10,000 } // level 2 - target, 100,000 - else if ($total_litter <= 100000) - { + elseif ($total_litter <= 100000) { $previousXp = 10000; // 10,000 $nextXp = 100000; // 100,000 } // level 3 - target 250,000 - else if ($total_litter <= 250000) - { + elseif ($total_litter <= 250000) { $previousXp = 100000; // 100,000 $nextXp = 250000; // 250,000 } // level 4 500,000 - else if ($total_litter <= 500000) - { + elseif ($total_litter <= 500000) { $previousXp = 250000; // 250,000 $nextXp = 500000; // 500,000 } // level 5, 1M - else if ($total_litter <= 1000000) - { + elseif ($total_litter <= 1000000) { $previousXp = 500000; // 250,000 $nextXp = 1000000; // 500,000 } @@ -148,7 +138,7 @@ public function __invoke (): array 'previousXp' => $previousXp, 'nextXp' => $nextXp, 'littercoin' => $littercoin, - 'owed' => 0 + 'owed' => 0, ]; } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index abdc5c40f..5e56377d4 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -52,7 +52,7 @@ class Kernel extends HttpKernel * * @var array */ - protected $routeMiddleware = [ + protected $middlewareAliases = [ 'fw-block-blacklisted' => \PragmaRX\Firewall\Middleware\FirewallBlacklist::class, 'admin' => \App\Http\Middleware\IsAdmin::class, 'auth' => \App\Http\Middleware\Authenticate::class, diff --git a/app/Models/AdminVerificationLog.php b/app/Models/AdminVerificationLog.php index ef0e632da..27fff59af 100644 --- a/app/Models/AdminVerificationLog.php +++ b/app/Models/AdminVerificationLog.php @@ -12,15 +12,24 @@ class AdminVerificationLog extends Model protected $guarded = []; - protected $casts = [ - 'added_tags' => 'array', - 'removed_tags' => 'array' - ]; + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'added_tags' => 'array', + 'removed_tags' => 'array', + ]; + } /** * The user who updated the tags */ - public function admin () { + public function admin() + { return $this->belongsTo(User::class, 'admin_id', 'id'); } } diff --git a/app/Models/Photo.php b/app/Models/Photo.php index ef2706014..4c85b4ec8 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -10,11 +10,14 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; /** * @property Collection $customTags * @property User $user + * * @method Builder onlyFromUsersThatAllowTagging */ class Photo extends Model @@ -25,12 +28,20 @@ class Photo extends Model protected $appends = ['selected', 'picked_up']; - protected $casts = ['datetime']; + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return ['datetime']; + } /** * Create an Accessor that adds ['selected' => false] to each record */ - public function getSelectedAttribute () + public function getSelectedAttribute(): bool { return false; } @@ -38,23 +49,25 @@ public function getSelectedAttribute () /** * Wrapper around photo presence, for better readability */ - public function getPickedUpAttribute () + public function getPickedUpAttribute(): bool { - return !$this->remaining; + return ! $this->remaining; } /** * A photo can have many bounding boxes associated with it */ - public function boxes () + public function boxes(): HasMany { return $this->hasMany(Annotation::class); } /** * All Categories + * + * @return array */ - public static function categories () + public static function categories(): array { return [ 'smoking', @@ -77,7 +90,7 @@ public static function categories () /** * All Currently available Brands */ - public static function getBrands () + public static function getBrands(): array { return Brand::types(); } @@ -90,15 +103,15 @@ public static function getBrands () * - team * - total_categories */ - public function user () + public function user(): BelongsTo { - return $this->belongsTo(User::class, 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** * Team that uploaded the photo */ - public function team () + public function team(): BelongsTo { return $this->belongsTo(Team::class, 'team_id'); } @@ -108,21 +121,15 @@ public function team () * * Remove any keys with null values */ - public function tags (): array + public function tags(): array { $tags = []; - foreach ($this->categories() as $category) - { - if ($this->$category) - { - foreach ($this->$category->types() as $tag) - { - if (is_null($this->$category[$tag])) - { - unset ($this->$category[$tag]); - } - else - { + foreach ($this->categories() as $category) { + if ($this->$category) { + foreach ($this->$category->types() as $tag) { + if (is_null($this->$category[$tag])) { + unset($this->$category[$tag]); + } else { $tags[$category][$tag] = $this->$category[$tag]; } } @@ -135,18 +142,15 @@ public function tags (): array /** * Update and return the total amount of litter in a photo */ - public function total () + public function total(): void { $total = 0; - foreach ($this->categories() as $category) - { - if ($this->$category) - { + foreach ($this->categories() as $category) { + if ($this->$category) { // We dont want to include brands in total_litter // Increment total_litter when its not brands - if ($category !== 'brands') - { + if ($category !== 'brands') { $total += $this->$category->total(); } } @@ -163,14 +167,12 @@ public function total () * * eg: "smoking.butts 3, alcohol.beerBottles 4," */ - public function translate () + public function translate(): void { $result_string = ''; - foreach ($this->categories() as $category) - { - if ($this->$category) - { + foreach ($this->categories() as $category) { + if ($this->$category) { $result_string .= $this->$category->translate(); } } @@ -182,22 +184,22 @@ public function translate () /** * Location relationships */ - public function country () + public function country(): HasOne { - return $this->hasOne('App\Models\Location\Country'); + return $this->hasOne('App\Models\Location\Country'); } - public function state () + public function state(): HasOne { return $this->hasOne('App\Models\Location\State'); } - public function city () + public function city(): HasOne { - return $this->hasOne('App\Models\Location\City'); + return $this->hasOne('App\Models\Location\City'); } - public function adminVerificationLog() + public function adminVerificationLog(): HasOne { // Use hasOne or hasMany depending on your needs return $this->hasOne(AdminVerificationLog::class, 'photo_id'); @@ -206,77 +208,77 @@ public function adminVerificationLog() /** * Litter categories */ - public function smoking () + public function smoking(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Smoking', 'smoking_id', 'id'); + return $this->belongsTo('App\Models\Litter\Categories\Smoking', 'smoking_id', 'id'); } - public function food () + public function food(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Food', 'food_id', 'id'); + return $this->belongsTo('App\Models\Litter\Categories\Food', 'food_id', 'id'); } - public function coffee () + public function coffee(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Coffee', 'coffee_id', 'id'); + return $this->belongsTo('App\Models\Litter\Categories\Coffee', 'coffee_id', 'id'); } - public function softdrinks () + public function softdrinks(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\SoftDrinks', 'softdrinks_id', 'id'); - } + return $this->belongsTo('App\Models\Litter\Categories\SoftDrinks', 'softdrinks_id', 'id'); + } - public function alcohol () + public function alcohol(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Alcohol', 'alcohol_id', 'id'); - } + return $this->belongsTo('App\Models\Litter\Categories\Alcohol', 'alcohol_id', 'id'); + } - public function sanitary () + public function sanitary(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Sanitary', 'sanitary_id', 'id'); - } + return $this->belongsTo('App\Models\Litter\Categories\Sanitary', 'sanitary_id', 'id'); + } - public function dumping () + public function dumping(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Dumping', 'dumping_id', 'id'); } - public function other () + public function other(): BelongsTo { - return $this->belongsTo('App\Models\Litter\Categories\Other', 'other_id', 'id'); - } + return $this->belongsTo('App\Models\Litter\Categories\Other', 'other_id', 'id'); + } - public function industrial () + public function industrial(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Industrial', 'industrial_id', 'id'); } - public function coastal () + public function coastal(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Coastal', 'coastal_id', 'id'); } - public function art () + public function art(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Art', 'art_id', 'id'); } - public function brands () + public function brands(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Brand', 'brands_id', 'id'); } - public function trashdog () + public function trashdog(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\TrashDog', 'trashdog_id', 'id'); } - public function dogshit () + public function dogshit(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Dogshit', 'dogshit_id', 'id'); } - public function material () + public function material(): BelongsTo { return $this->belongsTo('App\Models\Litter\Categories\Material', 'material_id', 'id'); } @@ -290,9 +292,9 @@ public function customTags(): HasMany return $this->hasMany(CustomTag::class); } - public function scopeOnlyFromUsersThatAllowTagging(Builder $query) + public function scopeOnlyFromUsersThatAllowTagging(Builder $query): void { - $query->whereNotIn('user_id', function ($q) { + $query->whereNotIn('user_id', function ($q): void { $q->select('id') ->from('users') ->where('prevent_others_tagging_my_photos', true); diff --git a/app/Models/Teams/Team.php b/app/Models/Teams/Team.php index b05cd8f2d..1d72c934d 100644 --- a/app/Models/Teams/Team.php +++ b/app/Models/Teams/Team.php @@ -10,41 +10,48 @@ class Team extends Model use HasFactory; protected $fillable = [ - 'name', + 'name', 'type_id', 'type_name', - 'members', - 'images_remaining', - 'total_images', - 'total_litter', - 'leader', + 'members', + 'images_remaining', + 'total_images', + 'total_litter', + 'leader', 'created_by', 'identifier', 'leaderboards', - 'is_trusted' + 'is_trusted', ]; - protected $casts = [ - 'is_trusted' => 'boolean' - ]; + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'is_trusted' => 'boolean', + ]; + } /** * Relationships */ - public function users () + public function users() { - return $this->belongsToMany('App\Models\User\User'); + return $this->belongsToMany('App\Models\User\User'); } - public function leader () + public function leader() { - return $this->belongsTo('App\Models\User\User', 'leader'); + return $this->belongsTo('App\Models\User\User', 'leader'); } // double check this - public function photos () + public function photos() { return $this->hasManyThrough('App\Models\User\User', 'App\Models\Photo'); } - } diff --git a/app/Models/Teams/TeamType.php b/app/Models/Teams/TeamType.php index 153f2bb4a..b07e3ebac 100644 --- a/app/Models/Teams/TeamType.php +++ b/app/Models/Teams/TeamType.php @@ -9,7 +9,15 @@ class TeamType extends Model { use HasFactory; - protected $casts = [ - 'price' => 'integer' - ]; + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'price' => 'integer', + ]; + } } diff --git a/app/Models/User/User.php b/app/Models/User/User.php index 064f1b9f1..c328c11f2 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -2,29 +2,27 @@ namespace App\Models\User; -use App\Payment; -use App\Models\Photo; -use App\Models\CustomTag; -use App\Models\Teams\Team; -use App\Models\Littercoin; use App\Models\AI\Annotation; use App\Models\Cleanups\Cleanup; use App\Models\Cleanups\CleanupUser; - -use Laravel\Cashier\Billable; -use Laravel\Passport\HasApiTokens; -use Spatie\Permission\Traits\HasRoles; -use LaravelAndVueJS\Traits\LaravelPermissionToVueJS; - -use Illuminate\Support\Facades\Redis; -use Illuminate\Notifications\Notifiable; +use App\Models\CustomTag; +use App\Models\Littercoin; +use App\Models\Photo; +use App\Models\Teams\Team; +use App\Payment; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Redis; +use Laravel\Cashier\Billable; +use Laravel\Passport\HasApiTokens; +use LaravelAndVueJS\Traits\LaravelPermissionToVueJS; +use Spatie\Permission\Traits\HasRoles; /** * @property Collection | array $teams @@ -38,29 +36,29 @@ */ class User extends Authenticatable { - use Notifiable, Billable, HasApiTokens, HasRoles, LaravelPermissionToVueJS, HasFactory; + use Billable, HasApiTokens, HasFactory, HasRoles, LaravelPermissionToVueJS, Notifiable; /** * On creation, give a new user a 30 random string for email verification * Model event: * triggered automatically */ - public static function boot () + public static function boot() { // trigger the boot method of the Model Class that Eloquent models extend parent::boot(); // listen for model events // When a user is created, add tokens - static::creating(function($user) { - $user->token = str_random(30); + static::creating(function ($user): void { + $user->token = \Illuminate\Support\Str::random(30); }); - static::creating(function($user) { - $user->sub_token = str_random(30); + static::creating(function ($user): void { + $user->sub_token = \Illuminate\Support\Str::random(30); }); - static::addGlobalScope('photosCount', function($builder) { + static::addGlobalScope('photosCount', function ($builder): void { $builder->withCount('photos'); // photos_count }); } @@ -68,7 +66,7 @@ public static function boot () /** * Eager load by default */ - protected $with = ['team']; + protected $with = ['team']; /** * The attributes that are mass assignable. @@ -110,7 +108,7 @@ public static function boot () 'remaining_teams', 'photos_per_month', 'bbox_verification_count', - 'enable_admin_tagging' + 'enable_admin_tagging', ]; /** @@ -119,19 +117,11 @@ public static function boot () * @var array */ protected $hidden = [ - 'password', 'remember_token', 'role_id' + 'password', 'remember_token', 'role_id', ]; protected $guarded = [ - 'role_id' - ]; - - protected $casts = [ - 'show_name' => 'boolean', - 'show_username' => 'boolean', - 'verification_required' => 'boolean', - 'prevent_others_tagging_my_photos' => 'boolean', - 'settings' => 'array' + 'role_id', ]; protected $appends = [ @@ -141,7 +131,7 @@ public static function boot () 'picked_up', 'user_verification_count', 'littercoin_progress', - 'total_littercoin' + 'total_littercoin', ]; /** @@ -149,17 +139,15 @@ public static function boot () * * @return array */ - public function getTotalCategoriesAttribute () + public function getTotalCategoriesAttribute() { $categories = Photo::categories(); $totals = []; - foreach ($categories as $category) - { - if ($category !== "brands") - { - $totals[$category] = (int)Redis::hget("user:$this->id", $category); + foreach ($categories as $category) { + if ($category !== 'brands') { + $totals[$category] = (int) Redis::hget("user:$this->id", $category); } } @@ -172,16 +160,16 @@ public function getTotalCategoriesAttribute () */ public function getIsTrustedAttribute(): bool { - return !$this->verification_required || $this->team && $this->team->is_trusted; + return ! $this->verification_required || $this->team && $this->team->is_trusted; } /** * Wrapper around default setting for items_remaining, * for better readability */ - public function getPickedUpAttribute () + public function getPickedUpAttribute() { - return !$this->items_remaining; + return ! $this->items_remaining; } /** @@ -189,7 +177,7 @@ public function getPickedUpAttribute () * * @return int total number of tags */ - public function getTotalTagsAttribute () + public function getTotalTagsAttribute() { $totalBrands = (int) Redis::hget("user:{$this->id}", 'total_brands'); $totalLitter = (int) Redis::hget("user:{$this->id}", 'total_litter'); @@ -203,9 +191,9 @@ public function getTotalTagsAttribute () * * 0-100 */ - public function getUserVerificationCountAttribute () + public function getUserVerificationCountAttribute() { - return Redis::hget("user_verification_count", $this->id) ?? 0; + return Redis::hget('user_verification_count', $this->id) ?? 0; } /** @@ -217,13 +205,13 @@ public function getUserVerificationCountAttribute () */ public function getXpRedisAttribute() { - return (int) Redis::zscore("xp.users", $this->id); + return (int) Redis::zscore('xp.users', $this->id); } /** * Get this Users XP from the Global Leaderboard of All Users */ - public function getTodaysXpAttribute () + public function getTodaysXpAttribute() { $year = now()->year; $month = now()->month; @@ -232,7 +220,7 @@ public function getTodaysXpAttribute () return (int) Redis::zscore("leaderboard:users:$year:$month:$day", $this->id); } - public function getYesterdaysXpAttribute () + public function getYesterdaysXpAttribute() { $year = now()->subDays(1)->year; $month = now()->subDays(1)->month; @@ -241,7 +229,7 @@ public function getYesterdaysXpAttribute () return (int) Redis::zscore("leaderboard:users:$year:$month:$day", $this->id); } - public function getThisMonthsXpAttribute () + public function getThisMonthsXpAttribute() { $year = now()->year; $month = now()->month; @@ -249,7 +237,7 @@ public function getThisMonthsXpAttribute () return (int) Redis::zscore("leaderboard:users:$year:$month", $this->id); } - public function getLastMonthsXpAttribute () + public function getLastMonthsXpAttribute() { $year = now()->subMonths(1)->year; $month = now()->subMonths(1)->month; @@ -257,14 +245,14 @@ public function getLastMonthsXpAttribute () return (int) Redis::zscore("leaderboard:users:$year:$month", $this->id); } - public function getThisYearsXpAttribute () + public function getThisYearsXpAttribute() { $year = now()->year; return (int) Redis::zscore("leaderboard:users:$year", $this->id); } - public function getLastYearsXpAttribute () + public function getLastYearsXpAttribute() { $year = now()->year; @@ -276,57 +264,44 @@ public function getLastYearsXpAttribute () * * Here, we have to pass the locationType and locationId dynamically. */ - public function getXpWithParams ($param): int + public function getXpWithParams($param): int { $timeFilter = $param['timeFilter']; $locationType = $param['locationType']; $locationId = $param['locationId']; - if ($timeFilter === "today") - { + if ($timeFilter === 'today') { $year = now()->year; $month = now()->month; $day = now()->day; // country, state, city. not users return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year:$month:$day", $this->id); - } - else if ($timeFilter === "yesterday") - { + } elseif ($timeFilter === 'yesterday') { $year = now()->subDays(1)->year; $month = now()->subDays(1)->month; $day = now()->subDays(1)->day; return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year:$month:$day", $this->id); - } - else if ($timeFilter === "this-month") - { + } elseif ($timeFilter === 'this-month') { $year = now()->year; $month = now()->month; return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year:$month", $this->id); - } - else if ($timeFilter === "last-month") - { + } elseif ($timeFilter === 'last-month') { $year = now()->subMonths(1)->year; $month = now()->subMonths(1)->month; return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year:$month", $this->id); - } - else if ($timeFilter === "this-year") - { + } elseif ($timeFilter === 'this-year') { $year = now()->year; return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year", $this->id); - } - else if ($timeFilter === "last-year") - { + } elseif ($timeFilter === 'last-year') { $year = now()->year; return (int) Redis::zscore("leaderboard:$locationType:$locationId:$year", $this->id); - } - else if ($timeFilter === 'all-time') - { + } elseif ($timeFilter === 'all-time') { return (int) Redis::zscore("leaderboard:$locationType:$locationId:total", $this->id); } @@ -338,7 +313,7 @@ public function getXpWithParams ($param): int * * @return int total number of brand tags */ - public function getTotalBrandsRedisAttribute () + public function getTotalBrandsRedisAttribute() { return (int) Redis::hget("user:{$this->id}", 'total_brands'); } @@ -351,7 +326,7 @@ public function getPositionAttribute() /** * Return the users progress to earning their next Littercoin */ - public function getLittercoinProgressAttribute () + public function getLittercoinProgressAttribute() { return (int) Redis::hget("user:{$this->id}", 'littercoin_progress') ?? 0; } @@ -359,7 +334,7 @@ public function getLittercoinProgressAttribute () /** * Get the total number of Littercoin the user has earned */ - public function getTotalLittercoinAttribute () + public function getTotalLittercoinAttribute() { $count = $this->littercoin_allowance + $this->littercoin_owed; @@ -371,7 +346,7 @@ public function getTotalLittercoinAttribute () /** * Get all payments */ - public function payments (): HasMany + public function payments(): HasMany { return $this->hasMany(Payment::class); } @@ -379,7 +354,7 @@ public function payments (): HasMany /** * Get all photos */ - public function photos (): HasMany + public function photos(): HasMany { return $this->hasMany(Photo::class); } @@ -387,7 +362,7 @@ public function photos (): HasMany /** * A user can add many bounding boxes */ - public function boxes (): HasMany + public function boxes(): HasMany { return $this->hasMany(Annotation::class, 'added_by'); } @@ -395,7 +370,7 @@ public function boxes (): HasMany /** * A user can verify many bounding boxes */ - public function boxesVerified (): HasMany + public function boxesVerified(): HasMany { return $this->hasMany(Annotation::class, 'verified_by'); } @@ -405,7 +380,7 @@ public function boxesVerified (): HasMany * * return boolean */ - public function confirmEmail () + public function confirmEmail() { $this->verified = true; $this->token = null; @@ -419,7 +394,7 @@ public function confirmEmail () * * return void */ - public function setPasswordAttribute ($password) + public function setPasswordAttribute($password) { $this->attributes['password'] = bcrypt($password); } @@ -427,62 +402,62 @@ public function setPasswordAttribute ($password) /** * Has Many Through relationships */ - public function customTags (): HasManyThrough + public function customTags(): HasManyThrough { return $this->hasManyThrough(CustomTag::class, Photo::class); } - public function smoking () + public function smoking() { return $this->hasManyThrough('App\Smoking', 'App\Models\Photo'); } - public function alcohol () + public function alcohol() { return $this->hasManyThrough('App\Alcohol', 'App\Models\Photo'); } - public function coffee () + public function coffee() { return $this->hasManyThrough('App\Coffee', 'App\Models\Photo'); } - public function food () + public function food() { return $this->hasManyThrough('App\Food', 'App\Models\Photo'); } - public function softdrinks () + public function softdrinks() { return $this->hasManyThrough('App\SoftDrinks', 'App\Models\Photo'); } - public function drugs () + public function drugs() { return $this->hasManyThrough('App\Drugs', 'App\Models\Photo'); } - public function sanitary () + public function sanitary() { return $this->hasManyThrough('App\Sanitary', 'App\Models\Photo'); } - public function other () + public function other() { return $this->hasManyThrough('App\Other', 'App\Models\Photo'); } - public function coastal () + public function coastal() { return $this->hasManyThrough('App\Coastal', 'App\Models\Photo'); } - public function pathway () + public function pathway() { return $this->hasManyThrough('App\Pathway', 'App\Models\Photo'); } - public function art () + public function art() { return $this->hasManyThrough('App\Art', 'App\Models\Photo'); } @@ -492,7 +467,7 @@ public function art () * * @return BelongsTo */ - public function team () + public function team() { return $this->belongsTo(Team::class, 'active_team', 'id'); } @@ -502,7 +477,7 @@ public function team () * * Load extra columns on the pivot table */ - public function teams (): BelongsToMany + public function teams(): BelongsToMany { return $this->belongsToMany(Team::class) ->withTimestamps() @@ -532,7 +507,7 @@ public function isMemberOfTeam(int $teamId): bool * Load extra columns on the pivot table * ->withTimestamps(); */ - public function cleanups (): BelongsToMany + public function cleanups(): BelongsToMany { return $this->belongsToMany(Cleanup::class) ->using(CleanupUser::class); @@ -553,7 +528,7 @@ public function setting(string $name, $default = null) /** * Update one or more settings and save the model. */ - public function settings (array $revisions): self + public function settings(array $revisions): self { $this->settings = array_merge($this->settings ?? [], $revisions); $this->save(); @@ -572,4 +547,15 @@ public function getSocialLinksAttribute(): array 'reddit' => $this->setting('social_reddit'), ]); } + + protected function casts(): array + { + return [ + 'show_name' => 'boolean', + 'show_username' => 'boolean', + 'verification_required' => 'boolean', + 'prevent_others_tagging_my_photos' => 'boolean', + 'settings' => 'array', + ]; + } } diff --git a/app/Plan.php b/app/Plan.php index 04f38f40a..81bbfbe04 100644 --- a/app/Plan.php +++ b/app/Plan.php @@ -6,8 +6,15 @@ class Plan extends Model { - protected $casts = [ - 'price' => 'integer' - ]; - + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'price' => 'integer', + ]; + } } diff --git a/app/Traits/FilterClustersByGeohashTrait.php b/app/Traits/FilterClustersByGeohashTrait.php index 9ce797e34..cdac26e75 100644 --- a/app/Traits/FilterClustersByGeohashTrait.php +++ b/app/Traits/FilterClustersByGeohashTrait.php @@ -14,12 +14,10 @@ trait FilterClustersByGeohashTrait * * For a specific zoom level, we want to return the bounding box of the clusters + neighbours * - * @param Builder $query - * @param $zoom int -> zoom level of the browser - * @param $bbox array -> [west|left, south|bottom, east|right, north|top] - * @return Builder + * @param $zoom int -> zoom level of the browser + * @param $bbox array -> [west|left, south|bottom, east|right, north|top] */ - public function filterClustersByGeoHash (Builder $query, int $zoom, array $bbox): Builder + public function filterClustersByGeoHash(Builder $query, int $zoom, array $bbox): Builder { //$bbox = json_decode($bbox); @@ -38,18 +36,15 @@ public function filterClustersByGeoHash (Builder $query, int $zoom, array $bbox) return $query ->where('zoom', $zoom) - ->where(function ($q) use ($geos) { + ->where(function ($q) use ($geos): void { foreach ($geos as $geo) { - $q->orWhere('geohash', 'like', $geo . '%'); // starts with + $q->orWhere('geohash', 'like', $geo.'%'); // starts with } }); } /** * Converts the clusters into the format required by the map - * - * @param Collection $clusters - * @return array */ protected function getFeatures(Collection $clusters): array { @@ -58,13 +53,13 @@ protected function getFeatures(Collection $clusters): array 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [$cluster->lon, $cluster->lat] + 'coordinates' => [$cluster->lon, $cluster->lat], ], 'properties' => [ 'point_count' => $cluster->point_count, 'point_count_abbreviated' => $cluster->point_count_abbreviated, - 'cluster' => true - ] + 'cluster' => true, + ], ]; })->toArray(); } diff --git a/app/Traits/FilterPhotosByGeoHashTrait.php b/app/Traits/FilterPhotosByGeoHashTrait.php index 8439eabf5..f28db8771 100644 --- a/app/Traits/FilterPhotosByGeoHashTrait.php +++ b/app/Traits/FilterPhotosByGeoHashTrait.php @@ -3,7 +3,6 @@ namespace App\Traits; use App\Models\Photo; -use App\Models\User\User; use Illuminate\Database\Eloquent\Builder; trait FilterPhotosByGeoHashTrait @@ -15,13 +14,11 @@ trait FilterPhotosByGeoHashTrait * * For a specific zoom level, we want to return the bounding box of the clusters + neighbours * - * @param Builder $query - * @param array $bbox array -> [west|left, south|bottom, east|right, north|top] + * @param array $bbox array -> [west|left, south|bottom, east|right, north|top] * @param null layers - * * @return Builder $query */ - public function filterPhotosByGeoHash (Builder $query, array $bbox, $layers = null): Builder + public function filterPhotosByGeoHash(Builder $query, array $bbox, $layers = null): Builder { // get center of the bbox $center_lat = ($bbox['top'] + $bbox['bottom']) / 2; @@ -37,22 +34,18 @@ public function filterPhotosByGeoHash (Builder $query, array $bbox, $layers = nu $geos = array_values($this->neighbors($center_geohash)); // Build cluster query - $query->where(function ($q) use ($geos) - { + $query->where(function ($q) use ($geos): void { foreach ($geos as $geo) { - $q->orWhere('geohash', 'like', $geo . '%'); // starts with + $q->orWhere('geohash', 'like', $geo.'%'); // starts with } }); - if ($layers) - { - $query->where(function ($q) use ($layers) - { - foreach ($layers as $index => $layer) - { + if ($layers) { + $query->where(function ($q) use ($layers) { + foreach ($layers as $index => $layer) { ($index === 0) - ? $q->where($layer . "_id", '!=', null) - : $q->orWhere($layer . "_id", '!=', null); + ? $q->where($layer.'_id', '!=', null) + : $q->orWhere($layer.'_id', '!=', null); } return $q; @@ -64,15 +57,10 @@ public function filterPhotosByGeoHash (Builder $query, array $bbox, $layers = nu /** * Convert our photos object into a geojson array - * - * @param $photos - * - * @return array */ - protected function photosToGeojson ($photos): array + protected function photosToGeojson($photos): array { - $features = $photos->map(function (Photo $photo) - { + $features = $photos->map(function (Photo $photo) { $name = $photo->user->show_name_maps ? $photo->user->name : null; $username = $photo->user->show_username_maps ? $photo->user->username : null; $team = $photo->team ? $photo->team->name : null; @@ -86,7 +74,7 @@ protected function photosToGeojson ($photos): array 'type' => 'Feature', 'geometry' => [ 'type' => 'Point', - 'coordinates' => [$photo->lat, $photo->lon] + 'coordinates' => [$photo->lat, $photo->lon], ], 'properties' => [ 'photo_id' => $photo->id, @@ -101,23 +89,24 @@ protected function photosToGeojson ($photos): array 'picked_up' => $photo->picked_up, 'social' => $photo->user->social_links, 'custom_tags' => $photo->customTags->pluck('tag'), - 'admin' => $admin - ] + 'admin' => $admin, + ], ]; })->toArray(); return [ 'type' => 'FeatureCollection', - 'features' => $features + 'features' => $features, ]; } - protected function getDataForAdmin ($adminVerificationLog) { + protected function getDataForAdmin($adminVerificationLog) + { return [ 'name' => $adminVerificationLog->admin->show_name ? $adminVerificationLog->admin->name : null, 'username' => $adminVerificationLog->admin->show_username ? $adminVerificationLog->admin->username : null, 'created_at' => $adminVerificationLog->created_at, - 'removedTags' => $adminVerificationLog->removed_tags + 'removedTags' => $adminVerificationLog->removed_tags, ]; } } diff --git a/composer.json b/composer.json index 8c105f04b..658d1334c 100644 --- a/composer.json +++ b/composer.json @@ -42,10 +42,11 @@ "require-dev": { "barryvdh/laravel-debugbar": "^3.6", "coreproc/laravel-debugbar-git-info": "^0.1.1", - "spatie/laravel-ignition": "^2.0", + "driftingly/rector-laravel": "^1.2", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^8.1", - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^10.0", + "spatie/laravel-ignition": "^2.0" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index a18556bae..002840659 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "39b365307eec3b7a524e1b58cdc0e0fe", + "content-hash": "40fae535c7b7f79d1903500f7273c6c6", "packages": [ { "name": "abraham/twitteroauth", @@ -11103,6 +11103,41 @@ }, "time": "2020-06-25T05:51:08+00:00" }, + { + "name": "driftingly/rector-laravel", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/driftingly/rector-laravel.git", + "reference": "b55c3b374ba0eccdb9c5b1bc356749224ea13680" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/b55c3b374ba0eccdb9c5b1bc356749224ea13680", + "reference": "b55c3b374ba0eccdb9c5b1bc356749224ea13680", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "rector/rector": "^1.0" + }, + "type": "rector-extension", + "autoload": { + "psr-4": { + "RectorLaravel\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Rector upgrades rules for Laravel Framework", + "support": { + "issues": "https://github.com/driftingly/rector-laravel/issues", + "source": "https://github.com/driftingly/rector-laravel/tree/1.2.4" + }, + "time": "2024-09-12T12:55:41+00:00" + }, { "name": "filp/whoops", "version": "2.15.4", @@ -11651,6 +11686,64 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.12.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-09-26T12:45:22+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.16", @@ -12073,6 +12166,65 @@ ], "time": "2024-09-19T10:52:21+00:00" }, + { + "name": "rector/rector", + "version": "1.2.6", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "6ca85da28159dbd3bb36211c5104b7bc91278e99" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/6ca85da28159dbd3bb36211c5104b7bc91278e99", + "reference": "6ca85da28159dbd3bb36211c5104b7bc91278e99", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.12.5" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/1.2.6" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2024-10-03T08:56:44+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.1", diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..795876c51 --- /dev/null +++ b/rector.php @@ -0,0 +1,24 @@ +withPaths([ + __DIR__.'/app', + __DIR__.'/bootstrap', + __DIR__.'/config', + __DIR__.'/node_modules', + __DIR__.'/public', + __DIR__.'/resources', + __DIR__.'/routes', + __DIR__.'/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withSets([ + LaravelLevelSetList::UP_TO_LARAVEL_110, + ]) + ->withTypeCoverageLevel(0); diff --git a/routes/api.php b/routes/api.php index 937fb33c9..4621c89d2 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,12 +1,11 @@ 'v2', 'middleware' => 'auth:api'], function(){ +Route::group(['prefix' => 'v2', 'middleware' => 'auth:api'], function (): void { // Route::get('/user/setup-intent', 'API\UserController@getSetupIntent'); @@ -30,7 +29,7 @@ ->middleware('auth:api'); // Check if current token is valid -Route::post('/validate-token', function(Request $request) { +Route::post('/validate-token', function (Request $request) { return ['message' => 'valid']; })->middleware('auth:api'); @@ -112,7 +111,7 @@ Route::post('/littercoin/merchants', 'Merchants\BecomeAMerchantController'); // Teams -Route::prefix('/teams')->group(function () { +Route::prefix('/teams')->group(function (): void { Route::get('/members', 'API\TeamsController@members'); Route::get('/leaderboard', 'Teams\TeamsLeaderboardController@index')->middleware('auth:api'); Route::get('/list', 'API\TeamsController@list'); diff --git a/routes/console.php b/routes/console.php index da55196d4..69c09d991 100644 --- a/routes/console.php +++ b/routes/console.php @@ -14,6 +14,6 @@ | */ -Artisan::command('inspire', function () { +Artisan::command('inspire', function (): void { $this->comment(Inspiring::quote()); })->describe('Display an inspiring quote'); diff --git a/routes/web.php b/routes/web.php index 0a44d4d1b..6b984528f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -67,7 +67,7 @@ // "maps" was used before "world". We will keep this for now to keep old links active. // Todo - make this dynamic for wildcard routes prefixed by "/{lang}/maps" -Route::group(['middleware' => 'fw-block-blacklisted'], function () { +Route::group(['middleware' => 'fw-block-blacklisted'], function (): void { // these old routes are deprecated. Need to check if the functions are still in use. // Route::get('/maps/{country}', 'Location\LocationsController@getStates'); // Route::get('/maps/{country}/{state}', 'Location\LocationsController@getCities'); @@ -112,7 +112,7 @@ Route::get('upload', 'HomeController@index')->name('upload'); // Move more authenticated routes into this group instead of applying middleware on controllers -Route::group(['middleware' => 'auth'], function () { +Route::group(['middleware' => 'auth'], function (): void { // Upload the image from web // old route Route::post('/submit', 'Uploads\UploadPhotoController'); @@ -220,7 +220,7 @@ // The user can change their Security settings eg name, surname, username visiblity and toggle public profile Route::post('/settings/security', [ 'uses' => 'UsersController@updateSecurity', - 'as' => 'profile.settings.security' + 'as' => 'profile.settings.security', ]); // Update the users privacy eg toggle their anonmyity @@ -277,11 +277,11 @@ Route::get('/emails/unsubscribe/{token}', 'EmailSubController@unsubEmail'); Route::get('/unsubscribe/{token}', 'UsersController@unsubscribeEmail'); -Route::get('/terms', function() { +Route::get('/terms', function () { return view('pages.terms'); }); -Route::get('/privacy', function() { +Route::get('/privacy', function () { return view('pages.privacy'); }); @@ -307,7 +307,6 @@ ->name('password.reset') ->middleware('guest'); - /** PAYMENTS */ Route::get('/join/{plan?}', 'HomeController@index'); @@ -337,7 +336,7 @@ /** * ADMIN */ -Route::group(['prefix' => '/admin', 'middleware' => 'admin'], function () { +Route::group(['prefix' => '/admin', 'middleware' => 'admin'], function (): void { // route Route::get('photos', 'HomeController@index'); @@ -380,7 +379,7 @@ Route::post('/merchants/delete', 'Littercoin\Merchants\DeleteMerchantController'); }); -Route::group(['prefix' => '/bbox', 'middleware' => ['can_bbox']], function () { +Route::group(['prefix' => '/bbox', 'middleware' => ['can_bbox']], function (): void { // Add coordinates Route::get('/', 'HomeController@index'); diff --git a/tests/Feature/Teams/ListLeaderboardsTest.php b/tests/Feature/Teams/ListLeaderboardsTest.php index c5d94855e..58c85f54f 100644 --- a/tests/Feature/Teams/ListLeaderboardsTest.php +++ b/tests/Feature/Teams/ListLeaderboardsTest.php @@ -18,9 +18,8 @@ public static function routeDataProvider(): array } /** - * @param $route - * @param $guard * @dataProvider routeDataProvider + * * @return void */ public function test_it_can_list_the_global_teams_leaderboards($route, $guard) @@ -39,7 +38,7 @@ public function test_it_can_list_the_global_teams_leaderboards($route, $guard) ->getJson($route) ->assertOk() ->assertJsonCount(3) - ->assertJson(function (AssertableJson $json) { + ->assertJson(function (AssertableJson $json): void { $json->has('0.name'); $json->has('0.total_litter'); $json->has('0.total_images'); @@ -51,9 +50,8 @@ public function test_it_can_list_the_global_teams_leaderboards($route, $guard) } /** - * @param $route - * @param $guard * @dataProvider routeDataProvider + * * @return void */ public function test_it_does_not_include_teams_that_dont_want_to_be_in_leaderboards($route, $guard) diff --git a/tests/Feature/Teams/ListTeamMembersTest.php b/tests/Feature/Teams/ListTeamMembersTest.php index 5fc2d50cf..114d23df6 100644 --- a/tests/Feature/Teams/ListTeamMembersTest.php +++ b/tests/Feature/Teams/ListTeamMembersTest.php @@ -24,14 +24,14 @@ public function test_it_can_list_team_members($guard, $route) /** @var Team $team */ $team = Team::factory()->create(); $users = User::factory(3)->create(); - $users->each(function (User $user) use ($team) { + $users->each(function (User $user) use ($team): void { $user->teams()->attach($team); }); $otherTeam = Team::factory()->create(); $otherMember = User::factory()->create(); $otherMember->teams()->attach($otherTeam); - $response = $this->actingAs($users->first(), $guard)->getJson($route . '?team_id=' . $team->id); + $response = $this->actingAs($users->first(), $guard)->getJson($route.'?team_id='.$team->id); $response->assertOk(); $response->assertJsonFragment(['success' => true]); @@ -54,10 +54,10 @@ public function test_team_members_have_the_correct_data($guard, $route) $user = User::factory()->create(); $user->teams()->attach($team, [ 'show_name_leaderboards' => true, - 'show_username_leaderboards' => true + 'show_username_leaderboards' => true, ]); - $response = $this->actingAs($user, $guard)->getJson($route . '?team_id=' . $team->id); + $response = $this->actingAs($user, $guard)->getJson($route.'?team_id='.$team->id); $member = $response->json('result.data.0'); $this->assertEquals($user->id, $member['id']); @@ -79,10 +79,10 @@ public function test_it_hides_members_names_and_usernames_depending_on_their_set $user = User::factory()->create(); $user->teams()->attach($team, [ 'show_name_leaderboards' => false, - 'show_username_leaderboards' => false + 'show_username_leaderboards' => false, ]); - $response = $this->actingAs($user, $guard)->getJson($route . '?team_id=' . $team->id); + $response = $this->actingAs($user, $guard)->getJson($route.'?team_id='.$team->id); $member = $response->json('result.data.0'); $this->assertEmpty($member['name']); $this->assertEmpty($member['username']); @@ -101,7 +101,7 @@ public function test_only_members_of_a_team_can_view_its_members($guard, $route) /** @var User $nonMember */ $nonMember = User::factory()->create(); - $response = $this->actingAs($nonMember, $guard)->getJson($route . '?team_id=' . $team->id); + $response = $this->actingAs($nonMember, $guard)->getJson($route.'?team_id='.$team->id); $response->assertOk(); $response->assertJson(['success' => false, 'message' => 'not-a-member']);