Bumped Carbon version

This commit is contained in:
snipe 2019-11-21 13:14:18 -08:00
parent 8127fdc5bc
commit 5065164c40
4 changed files with 73 additions and 126 deletions

View file

@ -14,8 +14,7 @@ services:
# list any PHP version you want to test against # list any PHP version you want to test against
php: php:
- 7.1.3 - 7.1.8
- 7.1.4
- 7.2 - 7.2
- 7.3.0 - 7.3.0

View file

@ -2,15 +2,12 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Helpers\Helper; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Helpers\Helper;
use App\Models\Location;
use App\Http\Transformers\LocationsTransformer; use App\Http\Transformers\LocationsTransformer;
use App\Http\Transformers\SelectlistTransformer; 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 class LocationsController extends Controller
{ {
@ -29,7 +26,7 @@ class LocationsController extends Controller
'updated_at','manager_id','image', 'updated_at','manager_id','image',
'assigned_assets_count','users_count','assets_count','currency']; '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.id',
'locations.name', 'locations.name',
'locations.address', 'locations.address',
@ -112,7 +109,7 @@ class LocationsController extends Controller
public function show($id) public function show($id)
{ {
$this->authorize('view', Location::class); $this->authorize('view', Location::class);
$location = Location::with('parent', 'manager', 'children') $location = Location::with('parent', 'manager', 'childLocations')
->select([ ->select([
'locations.id', 'locations.id',
'locations.name', 'locations.name',
@ -149,13 +146,6 @@ class LocationsController extends Controller
{ {
$this->authorize('update', Location::class); $this->authorize('update', Location::class);
$location = Location::findOrFail($id); $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()); $location->fill($request->all());
if ($location->save()) { if ($location->save()) {
@ -191,71 +181,67 @@ class LocationsController extends Controller
/** /**
* Gets a paginated collection for the select2 menus * 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] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0.16] * @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer * @see \App\Http\Transformers\SelectlistTransformer
* *
*/ */
public function selectlist(Request $request) public function selectlist(Request $request, $selected_id = null)
{ {
$locations = Location::select([ $locations = Location::select([
'locations.id', 'locations.id',
'locations.name', 'locations.name',
'locations.parent_id',
'locations.image', '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); // // $location_options_array = Location::getLocationHierarchy($locations);
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []); // $location_options = Location::flattenLocationsArray($location_options_array);
// $location_options = array('' => 'Top Level') + $location_options;
//
// \Log::debug($location_options);
//return []; // Work here to take an argument and see whether we need to not include the current location ID
return (new SelectlistTransformer)->transformSelectlist($paginated_results); // 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);
} }
} }

View file

@ -43,6 +43,7 @@
"league/flysystem-sftp": "~1.0", "league/flysystem-sftp": "~1.0",
"maknz/slack": "^1.7", "maknz/slack": "^1.7",
"neitanod/forceutf8": "^2.0", "neitanod/forceutf8": "^2.0",
"nesbot/carbon": "2.26.0",
"paragonie/constant_time_encoding": "^1.0", "paragonie/constant_time_encoding": "^1.0",
"patchwork/utf8": "^1.3", "patchwork/utf8": "^1.3",
"phpdocumentor/reflection-docblock": "3.2.2", "phpdocumentor/reflection-docblock": "3.2.2",
@ -107,7 +108,7 @@
"optimize-autoloader": true, "optimize-autoloader": true,
"process-timeout": 3000, "process-timeout": 3000,
"platform": { "platform": {
"php": "7.1.3" "php": "7.1.8"
} }
} }
} }

85
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a7424df02e30f8e142e981584672875b", "content-hash": "6e13b351460917e5ede5ce8482687f1b",
"packages": [ "packages": [
{ {
"name": "adldap2/adldap2", "name": "adldap2/adldap2",
@ -2050,51 +2050,6 @@
"description": "A fast and easy to use slugger with full UTF-8 support.", "description": "A fast and easy to use slugger with full UTF-8 support.",
"time": "2015-04-12T19:57:10+00:00" "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", "name": "laravel/framework",
"version": "v5.8.35", "version": "v5.8.35",
@ -3270,34 +3225,36 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "1.39.1", "version": "2.26.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33" "reference": "e01ecc0b71168febb52ae1fdc1cfcc95428e604e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4be0c005164249208ce1b5ca633cd57bdd42ff33", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e01ecc0b71168febb52ae1fdc1cfcc95428e604e",
"reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33", "reference": "e01ecc0b71168febb52ae1fdc1cfcc95428e604e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"kylekatarnls/update-helper": "^1.1", "ext-json": "*",
"php": ">=5.3.9", "php": "^7.1.8 || ^8.0",
"symfony/translation": "~2.6 || ~3.0 || ~4.0" "symfony/translation": "^3.4 || ^4.0"
}, },
"require-dev": { "require-dev": {
"composer/composer": "^1.2", "friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
"friendsofphp/php-cs-fixer": "~2", "kylekatarnls/multi-tester": "^1.1",
"phpunit/phpunit": "^4.8.35 || ^5.7" "phpmd/phpmd": "dev-php-7.1-compatibility",
"phpstan/phpstan": "^0.11",
"phpunit/phpunit": "^7.5 || ^8.0",
"squizlabs/php_codesniffer": "^3.4"
}, },
"bin": [ "bin": [
"bin/upgrade-carbon" "bin/carbon"
], ],
"type": "library", "type": "library",
"extra": { "extra": {
"update-helper": "Carbon\\Upgrade",
"laravel": { "laravel": {
"providers": [ "providers": [
"Carbon\\Laravel\\ServiceProvider" "Carbon\\Laravel\\ServiceProvider"
@ -3306,7 +3263,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"": "src/" "Carbon\\": "src/Carbon/"
} }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -3318,16 +3275,20 @@
"name": "Brian Nesbitt", "name": "Brian Nesbitt",
"email": "brian@nesbot.com", "email": "brian@nesbot.com",
"homepage": "http://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", "homepage": "http://carbon.nesbot.com",
"keywords": [ "keywords": [
"date", "date",
"datetime", "datetime",
"time" "time"
], ],
"time": "2019-10-14T05:51:36+00:00" "time": "2019-10-21T21:32:25+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@ -9394,6 +9355,6 @@
}, },
"platform-dev": [], "platform-dev": [],
"platform-overrides": { "platform-overrides": {
"php": "7.1.3" "php": "7.1.8"
} }
} }