From 5065164c40db1295b730d1b3f0104b79e3be5f12 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 21 Nov 2019 13:14:18 -0800 Subject: [PATCH] Bumped Carbon version --- .travis.yml | 3 +- .../Controllers/Api/LocationsController.php | 108 ++++++++---------- composer.json | 3 +- composer.lock | 85 ++++---------- 4 files changed, 73 insertions(+), 126 deletions(-) diff --git a/.travis.yml b/.travis.yml index f112d46807..75c7c2245c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,7 @@ services: # list any PHP version you want to test against php: - - 7.1.3 - - 7.1.4 + - 7.1.8 - 7.2 - 7.3.0 diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 03ef65095d..11a35cd05a 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -2,15 +2,12 @@ namespace App\Http\Controllers\Api; -use App\Helpers\Helper; +use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use App\Helpers\Helper; +use App\Models\Location; use App\Http\Transformers\LocationsTransformer; use App\Http\Transformers\SelectlistTransformer; -use App\Models\Location; -use Illuminate\Pagination\LengthAwarePaginator; -use Illuminate\Support\Collection; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Storage; class LocationsController extends Controller { @@ -29,7 +26,7 @@ class LocationsController extends Controller 'updated_at','manager_id','image', 'assigned_assets_count','users_count','assets_count','currency']; - $locations = Location::with('parent', 'manager', 'children')->select([ + $locations = Location::with('parent', 'manager', 'childLocations')->select([ 'locations.id', 'locations.name', 'locations.address', @@ -112,7 +109,7 @@ class LocationsController extends Controller public function show($id) { $this->authorize('view', Location::class); - $location = Location::with('parent', 'manager', 'children') + $location = Location::with('parent', 'manager', 'childLocations') ->select([ 'locations.id', 'locations.name', @@ -149,13 +146,6 @@ class LocationsController extends Controller { $this->authorize('update', Location::class); $location = Location::findOrFail($id); - - if ($request->input('parent_id') == $id) { - - return response()->json(Helper::formatStandardApiResponse('error', null, 'A location cannot be its own parent. Please select a different parent ID.')); - } - - $location->fill($request->all()); if ($location->save()) { @@ -191,71 +181,67 @@ class LocationsController extends Controller /** * Gets a paginated collection for the select2 menus * - * This is handled slightly differently as of ~4.7.8-pre, as - * we have to do some recursive magic to get the hierarchy to display - * properly when looking at the parent/child relationship in the - * rich menus. - * - * This means we can't use the normal pagination that we use elsewhere - * in our selectlists, since we have to get the full set before we can - * determine which location is parent/child/grandchild, etc. - * - * This also means that hierarchy display gets a little funky when people - * use the Select2 search functionality, but there's not much we can do about - * that right now. - * - * As a result, instead of paginating as part of the query, we have to grab - * the entire data set, and then invoke a paginator manually and pass that - * through to the SelectListTransformer. - * - * Many thanks to @uberbrady for the help getting this working better. - * Recursion still sucks, but I guess he doesn't have to get in the - * sea... this time. - * * @author [A. Gianotto] [] * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer * */ - public function selectlist(Request $request) + public function selectlist(Request $request, $selected_id = null) { + + $locations = Location::select([ 'locations.id', 'locations.name', - 'locations.parent_id', 'locations.image', - ]); + ])->orderBy('name', 'ASC')->paginate(50)->map(function ($location) { + return $location->groupBy('parent_id') + ->map(function ($parentName) { + return $parentName->map(function ($parent) { + return $parent->game_types->groupBy('parent_id'); + }); + }); + }); - $page = 1; - if ($request->filled('page')) { - $page = $request->input('page'); - } - if ($request->filled('search')) { - \Log::debug('Searching... '); - $locations = $locations->where('locations.name', 'LIKE', '%'.$request->input('search').'%'); - } - $locations = $locations->orderBy('name', 'ASC')->get(); +// $locations = Location::select([ +// 'locations.id', +// 'locations.name', +// 'locations.image', +// ]); +// +// if ($request->filled('search')) { +// $locations = $locations->where('locations.name', 'LIKE', '%'.$request->get('search').'%'); +// } +// +// +// $locations = $locations->groupBy(function ($locations) { +// return $locations->parent_id; +// })->orderBy('name', 'ASC')->paginate(50); - $locations_with_children = []; - foreach ($locations as $location) { - $location->use_text = $location->name; - $location->use_image = ($location->image) ? Storage::disk('public')->url('locations/'.$location->image, $location->image): null; - } - $locations_with_children[$location->parent_id][] = $location; - } - $location_options = Location::indenter($locations_with_children); - $locations_formatted = new Collection($location_options); - $paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []); +// // $location_options_array = Location::getLocationHierarchy($locations); +// $location_options = Location::flattenLocationsArray($location_options_array); +// $location_options = array('' => 'Top Level') + $location_options; +// +// \Log::debug($location_options); - //return []; - return (new SelectlistTransformer)->transformSelectlist($paginated_results); + // Work here to take an argument and see whether we need to not include the current location ID + // so that a location can't be its own parent + + // Loop through and set some custom properties for the transformer to use. + // This lets us have more flexibility in special cases like assets, where + // they may not have a ->name value but we want to display something anyway +// foreach ($location_options as $location) { +// $location->use_text = $location->name; +// $location->use_image = ($location->image) ? url('/').'/uploads/locations/'.$location->image : null; +// } + + return (new SelectlistTransformer)->transformSelectlist($locations); } - } diff --git a/composer.json b/composer.json index 5d0c26bd9b..03cf6c9e97 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "league/flysystem-sftp": "~1.0", "maknz/slack": "^1.7", "neitanod/forceutf8": "^2.0", + "nesbot/carbon": "2.26.0", "paragonie/constant_time_encoding": "^1.0", "patchwork/utf8": "^1.3", "phpdocumentor/reflection-docblock": "3.2.2", @@ -107,7 +108,7 @@ "optimize-autoloader": true, "process-timeout": 3000, "platform": { - "php": "7.1.3" + "php": "7.1.8" } } } diff --git a/composer.lock b/composer.lock index e408c609da..b6cfc07b38 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "a7424df02e30f8e142e981584672875b", + "content-hash": "6e13b351460917e5ede5ce8482687f1b", "packages": [ { "name": "adldap2/adldap2", @@ -2050,51 +2050,6 @@ "description": "A fast and easy to use slugger with full UTF-8 support.", "time": "2015-04-12T19:57:10+00:00" }, - { - "name": "kylekatarnls/update-helper", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/kylekatarnls/update-helper.git", - "reference": "5786fa188e0361b9adf9e8199d7280d1b2db165e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kylekatarnls/update-helper/zipball/5786fa188e0361b9adf9e8199d7280d1b2db165e", - "reference": "5786fa188e0361b9adf9e8199d7280d1b2db165e", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0.0", - "php": ">=5.3.0" - }, - "require-dev": { - "codeclimate/php-test-reporter": "dev-master", - "composer/composer": "2.0.x-dev || ^2.0.0-dev", - "phpunit/phpunit": ">=4.8.35 <6.0" - }, - "type": "composer-plugin", - "extra": { - "class": "UpdateHelper\\ComposerPlugin" - }, - "autoload": { - "psr-0": { - "UpdateHelper\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kyle", - "email": "kylekatarnls@gmail.com" - } - ], - "description": "Update helper", - "time": "2019-07-29T11:03:54+00:00" - }, { "name": "laravel/framework", "version": "v5.8.35", @@ -3270,34 +3225,36 @@ }, { "name": "nesbot/carbon", - "version": "1.39.1", + "version": "2.26.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33" + "reference": "e01ecc0b71168febb52ae1fdc1cfcc95428e604e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4be0c005164249208ce1b5ca633cd57bdd42ff33", - "reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e01ecc0b71168febb52ae1fdc1cfcc95428e604e", + "reference": "e01ecc0b71168febb52ae1fdc1cfcc95428e604e", "shasum": "" }, "require": { - "kylekatarnls/update-helper": "^1.1", - "php": ">=5.3.9", - "symfony/translation": "~2.6 || ~3.0 || ~4.0" + "ext-json": "*", + "php": "^7.1.8 || ^8.0", + "symfony/translation": "^3.4 || ^4.0" }, "require-dev": { - "composer/composer": "^1.2", - "friendsofphp/php-cs-fixer": "~2", - "phpunit/phpunit": "^4.8.35 || ^5.7" + "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "kylekatarnls/multi-tester": "^1.1", + "phpmd/phpmd": "dev-php-7.1-compatibility", + "phpstan/phpstan": "^0.11", + "phpunit/phpunit": "^7.5 || ^8.0", + "squizlabs/php_codesniffer": "^3.4" }, "bin": [ - "bin/upgrade-carbon" + "bin/carbon" ], "type": "library", "extra": { - "update-helper": "Carbon\\Upgrade", "laravel": { "providers": [ "Carbon\\Laravel\\ServiceProvider" @@ -3306,7 +3263,7 @@ }, "autoload": { "psr-4": { - "": "src/" + "Carbon\\": "src/Carbon/" } }, "notification-url": "https://packagist.org/downloads/", @@ -3318,16 +3275,20 @@ "name": "Brian Nesbitt", "email": "brian@nesbot.com", "homepage": "http://nesbot.com" + }, + { + "name": "kylekatarnls", + "homepage": "http://github.com/kylekatarnls" } ], - "description": "A simple API extension for DateTime.", + "description": "An API extension for DateTime that supports 281 different languages.", "homepage": "http://carbon.nesbot.com", "keywords": [ "date", "datetime", "time" ], - "time": "2019-10-14T05:51:36+00:00" + "time": "2019-10-21T21:32:25+00:00" }, { "name": "nikic/php-parser", @@ -9394,6 +9355,6 @@ }, "platform-dev": [], "platform-overrides": { - "php": "7.1.3" + "php": "7.1.8" } }