diff --git a/app/Console/Commands/CheckPetDrops.php b/app/Console/Commands/CheckPetDrops.php index 18b115dd88..55207709f4 100644 --- a/app/Console/Commands/CheckPetDrops.php +++ b/app/Console/Commands/CheckPetDrops.php @@ -2,15 +2,11 @@ namespace App\Console\Commands; -use DB; -use Carbon\Carbon; use App\Models\Pet\PetDrop; - +use Carbon\Carbon; use Illuminate\Console\Command; -use App\Services\NewsService; -class CheckPetDrops extends Command -{ +class CheckPetDrops extends Command { /** * The name and signature of the console command. * @@ -27,11 +23,8 @@ class CheckPetDrops extends Command /** * Create a new command instance. - * - * @return void */ - public function __construct() - { + public function __construct() { parent::__construct(); } @@ -40,18 +33,17 @@ public function __construct() * * @return mixed */ - public function handle() - { + public function handle() { // $updateDrops = PetDrop::requiresUpdate()->get(); foreach ($updateDrops as $drop) { - if((!isset($drop->dropData->cap) || $drop->dropData->cap == 0) || $drop->drops_available < $drop->dropData->cap) { + if ((!isset($drop->dropData->cap) || $drop->dropData->cap == 0) || $drop->drops_available < $drop->dropData->cap) { $drop->update([ 'drops_available' => $drop->drops_available += 1, - 'next_day' => Carbon::now()->add( + 'next_day' => Carbon::now()->add( $drop->dropData->frequency, $drop->dropData->interval, - )->startOf($drop->dropData->interval) + )->startOf($drop->dropData->interval), ]); } } diff --git a/app/Console/Commands/RestockShops.php b/app/Console/Commands/RestockShops.php index e410167a67..e1c6a4ddd4 100644 --- a/app/Console/Commands/RestockShops.php +++ b/app/Console/Commands/RestockShops.php @@ -2,10 +2,10 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use Carbon\Carbon; -class RestockShops extends Command -{ +use Illuminate\Console\Command; + +class RestockShops extends Command { /** * The name and signature of the console command. * @@ -22,11 +22,8 @@ class RestockShops extends Command /** * Create a new command instance. - * - * @return void */ - public function __construct() - { + public function __construct() { parent::__construct(); } @@ -35,26 +32,25 @@ public function __construct() * * @return int */ - public function handle() - { + public function handle() { $stocks = \App\Models\Shop\ShopStock::where('is_limited_stock', 1)->where('restock', 1)->get(); - foreach($stocks as $stock) { - if($stock->restock_interval == 1) { + foreach ($stocks as $stock) { + if ($stock->restock_interval == 1) { $stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity; $stock->save(); - } elseif($stock->restock_interval == 2) { + } elseif ($stock->restock_interval == 2) { // check if it's start of week $now = Carbon::now(); $day = $now->dayOfWeek; - if($day == 1) { + if ($day == 1) { $stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity; $stock->save(); } - } elseif($stock->restock_interval == 3) { + } elseif ($stock->restock_interval == 3) { // check if it's start of month $now = Carbon::now(); $day = $now->day; - if($day == 1) { + if ($day == 1) { $stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity; $stock->save(); } diff --git a/app/Console/Commands/UpdatePets.php b/app/Console/Commands/UpdatePets.php index 3914f85282..7d76782a53 100644 --- a/app/Console/Commands/UpdatePets.php +++ b/app/Console/Commands/UpdatePets.php @@ -2,13 +2,11 @@ namespace App\Console\Commands; +use File; use Illuminate\Console\Command; use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\Storage; -use File; -class UpdatePets extends Command -{ +class UpdatePets extends Command { /** * The name and signature of the console command. * @@ -25,11 +23,8 @@ class UpdatePets extends Command /** * Create a new command instance. - * - * @return void */ - public function __construct() - { + public function __construct() { parent::__construct(); } @@ -38,28 +33,26 @@ public function __construct() * * @return mixed */ - public function handle() - { + public function handle() { // add new col // check if col exists if (Schema::hasTable('pet_variant_drop_data')) { $this->info('Already updated tables, updating data.'); - } - else { - Schema::table('pet_drop_data', function($table) { + } else { + Schema::table('pet_drop_data', function ($table) { $table->string('name')->default('drop'); $table->integer('frequency'); $table->string('interval')->default('Hour'); $table->integer('cap')->default(null)->nullable(); $table->boolean('override')->default(false); }); - Schema::table('pet_categories', function($table) { + Schema::table('pet_categories', function ($table) { $table->integer('limit')->default(null)->nullable(); }); - Schema::table('pets', function($table) { + Schema::table('pets', function ($table) { $table->integer('limit')->default(null)->nullable(); }); - Schema::create('pet_variant_drop_data', function($table) { + Schema::create('pet_variant_drop_data', function ($table) { $table->increments('id'); $table->integer('variant_id')->unsigned(); $table->json('data')->default(null)->nullable(); @@ -69,52 +62,51 @@ public function handle() // convert old data $drop_data = \App\Models\Pet\PetDropData::all(); - foreach($drop_data as $drop) { + foreach ($drop_data as $drop) { // check if 'assets' offset exists on $drop->data, if it does continue if (isset($drop->data['assets'])) { - $this->line('Skipping drop data for pet: ' . $drop->pet->name . '...'); + $this->line('Skipping drop data for pet: '.$drop->pet->name.'...'); } else { - $this->line('Converting drop data for pet: ' . $drop->pet->name . '...'); + $this->line('Converting drop data for pet: '.$drop->pet->name.'...'); $drop->name = $drop->data['drop_name']; $drop->frequency = $drop->data['frequency']['frequency']; $drop->interval = $drop->data['frequency']['interval']; $drop->cap = $drop->data['cap']; $this->convertItems($drop, $drop->data['items']); - $this->info('Converted drop data for pet: ' . $drop->pet->name . '.'); + $this->info('Converted drop data for pet: '.$drop->pet->name.'.'); } } // update variant images to use ID instead of name $variants = \App\Models\Pet\PetVariant::all(); - foreach($variants as $variant) { - $this->line('Updating variant image for variant: ' . $variant->variant_name . '...'); + foreach ($variants as $variant) { + $this->line('Updating variant image for variant: '.$variant->variant_name.'...'); // rename image - $old_image = $variant->imageDirectory . '/' . $variant->pet_id .'-'. $variant->variant_name .'-image.png'; + $old_image = $variant->imageDirectory.'/'.$variant->pet_id.'-'.$variant->variant_name.'-image.png'; // rename - if(File::exists(public_path($old_image))) { - $new_image = $variant->imageDirectory . '/' . $variant->pet_id .'-variant-'. $variant->id .'-image.png'; + if (File::exists(public_path($old_image))) { + $new_image = $variant->imageDirectory.'/'.$variant->pet_id.'-variant-'.$variant->id.'-image.png'; File::move(public_path($old_image), public_path($new_image)); } } } private function convertItems($drop, $data) { - foreach($data as $key => $group) { - $this->line('Converting group: ' . $key . '...'); + foreach ($data as $key => $group) { + $this->line('Converting group: '.$key.'...'); // if it's the base pet, put it on the data table - if($key == "pet") { + if ($key == 'pet') { $assets = []; - foreach($group as $name => $item) { + foreach ($group as $name => $item) { $assets[strtolower($name)]['items'][$item['item_id']] = [ 'min_quantity' => $item['min'], 'max_quantity' => $item['max'], ]; } $drop->data = ['assets' => $assets]; - } - else { + } else { $assets = []; - foreach($group as $name => $item) { + foreach ($group as $name => $item) { $assets[strtolower($name)]['items'][$item['item_id']] = [ 'min_quantity' => $item['min'], 'max_quantity' => $item['max'], @@ -123,7 +115,7 @@ private function convertItems($drop, $data) { // if not "pet" we create a PetVariantDropData entry with the data \App\Models\Pet\PetVariantDropData::create([ 'variant_id' => $key, - 'data' => json_encode(['assets' => $assets]), + 'data' => json_encode(['assets' => $assets]), ]); } } diff --git a/app/Console/Commands/update_timed_stock.php b/app/Console/Commands/update_timed_stock.php index 17c2042fec..3166424e06 100644 --- a/app/Console/Commands/update_timed_stock.php +++ b/app/Console/Commands/update_timed_stock.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use App\Models\Shop\ShopStock; use App\Models\Shop\Shop; +use App\Models\Shop\ShopStock; use Carbon\Carbon; +use Illuminate\Console\Command; -class update_timed_stock extends Command -{ +class update_timed_stock extends Command { /** * The name and signature of the console command. * @@ -25,11 +24,8 @@ class update_timed_stock extends Command /** * Create a new command instance. - * - * @return void */ - public function __construct() - { + public function __construct() { parent::__construct(); } @@ -38,33 +34,32 @@ public function __construct() * * @return int */ - public function handle() - { + public function handle() { $hidestock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 1)->where('start_at', '<=', Carbon::now())->where('end_at', '<=', Carbon::now())->orWhere('is_timed_stock', 1)->where('is_visible', 1)->whereNull('start_at')->where('end_at', '<=', Carbon::now())->get(); $showstock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 0)->where('start_at', '<=', Carbon::now())->where('end_at', '>=', Carbon::now())->orWhere('is_timed_stock', 1)->where('is_visible', 0)->where('start_at', '<=', Carbon::now())->whereNull('end_at')->get(); //set stock that should be active to active - foreach($showstock as $showstock) { + foreach ($showstock as $showstock) { $showstock->is_visible = 1; $showstock->save(); - } + } //hide stock that should be hidden now - foreach($hidestock as $hidestock) { - $hidestock->is_visible = 0; - $hidestock->save(); - } + foreach ($hidestock as $hidestock) { + $hidestock->is_visible = 0; + $hidestock->save(); + } //also activate or deactivate the shops $hideshop = Shop::where('is_timed_shop', 1)->where('is_active', 1)->where('start_at', '<=', Carbon::now())->where('end_at', '<=', Carbon::now())->orWhere('is_timed_shop', 1)->where('is_active', 0)->whereNull('start_at')->where('end_at', '>=', Carbon::now())->get(); $showshop = Shop::where('is_timed_shop', 1)->where('is_active', 0)->where('start_at', '<=', Carbon::now())->where('end_at', '>=', Carbon::now())->orWhere('is_timed_shop', 1)->where('is_active', 0)->where('start_at', '<=', Carbon::now())->whereNull('end_at')->get(); //set shop that should be active to active - foreach($showshop as $showshop) { + foreach ($showshop as $showshop) { $showshop->is_active = 1; $showshop->save(); - } + } //hide shop that should be hidden now - foreach($hideshop as $hideshop) { - $hideshop->is_active = 0; - $hideshop->save(); - } + foreach ($hideshop as $hideshop) { + $hideshop->is_active = 0; + $hideshop->save(); + } } } diff --git a/app/Helpers/AssetHelpers.php b/app/Helpers/AssetHelpers.php index 30b8e153c8..3c0778faac 100644 --- a/app/Helpers/AssetHelpers.php +++ b/app/Helpers/AssetHelpers.php @@ -106,8 +106,11 @@ function getAssetModelString($type, $namespaced = true) { break; case 'pets': case 'pet': - if($namespaced) return '\App\Models\Pet\Pet'; - else return 'Pet'; + if ($namespaced) { + return '\App\Models\Pet\Pet'; + } else { + return 'Pet'; + } break; case 'raffle_tickets': @@ -239,15 +242,20 @@ function getDataReadyAssets($array, $isCharacter = false) { * Adds an asset to the given array. * If the asset already exists, it adds to the quantity. * - * @param array $array - * @param mixed $asset - * @param int $quantity + * @param array $array + * @param mixed $asset + * @param mixed $min_quantity + * @param mixed $max_quantity */ -function addDropAsset(&$array, $asset, $min_quantity = 1, $max_quantity = 1) -{ - if(!$asset) return; - if(isset($array[$asset->assetType][$asset->id])) return; - else $array[$asset->assetType][$asset->id] = ['asset' => $asset, 'min_quantity' => $min_quantity, 'max_quantity' => $max_quantity]; +function addDropAsset(&$array, $asset, $min_quantity = 1, $max_quantity = 1) { + if (!$asset) { + return; + } + if (isset($array[$asset->assetType][$asset->id])) { + return; + } else { + $array[$asset->assetType][$asset->id] = ['asset' => $asset, 'min_quantity' => $min_quantity, 'max_quantity' => $max_quantity]; + } } /** @@ -255,24 +263,22 @@ function addDropAsset(&$array, $asset, $min_quantity = 1, $max_quantity = 1) * where each asset is listed in [id => quantity] format. * json_encode this and store in the data attribute. * - * @param array $array - * @param bool $isCharacter + * @param array $array + * * @return array */ -function getDataReadyDropAssets($array) -{ +function getDataReadyDropAssets($array) { $result = []; - foreach($array as $group => $types) - { + foreach ($array as $group => $types) { $result[$group] = []; - foreach($types as $type => $key) - { - if($type && !isset($result[$group][$type])) $result[$group][$type] = []; - foreach($key as $assetId => $assetData) - { + foreach ($types as $type => $key) { + if ($type && !isset($result[$group][$type])) { + $result[$group][$type] = []; + } + foreach ($key as $assetId => $assetData) { $result[$group][$type][$assetId] = [ 'min_quantity' => $assetData['min_quantity'], - 'max_quantity' => $assetData['max_quantity'] + 'max_quantity' => $assetData['max_quantity'], ]; } if (empty($result[$group][$type])) { @@ -280,6 +286,7 @@ function getDataReadyDropAssets($array) } } } + return $result; } @@ -299,11 +306,11 @@ function parseDropAssetData($array) { foreach ($types as $type => $contents) { $model = getAssetModelString($type); if ($model) { - foreach($contents as $id => $data) { + foreach ($contents as $id => $data) { $result[$group][$type][$id] = [ - 'asset' => $model::find($id), + 'asset' => $model::find($id), 'min_quantity' => $data['min_quantity'], - 'max_quantity' => $data['max_quantity'] + 'max_quantity' => $data['max_quantity'], ]; } } @@ -377,10 +384,12 @@ function fillUserAssets($assets, $sender, $recipient, $logType, $data) { return false; } } - } elseif($key == 'pets' && count($contents)) { + } elseif ($key == 'pets' && count($contents)) { $service = new \App\Services\PetManager; - foreach($contents as $asset) { - if(!$service->creditPet($sender, $recipient, $logType, $data, $asset['asset'], $asset['quantity'])) return false; + foreach ($contents as $asset) { + if (!$service->creditPet($sender, $recipient, $logType, $data, $asset['asset'], $asset['quantity'])) { + return false; + } } } elseif ($key == 'raffle_tickets' && count($contents)) { $service = new \App\Services\RaffleManager; @@ -461,17 +470,20 @@ function fillCharacterAssets($assets, $sender, $recipient, $logType, $data, $sub /** * Creates a rewards string from an asset array. * - * @param array $array + * @param array $array + * * @return string */ -function createRewardsString($array) -{ +function createRewardsString($array) { $string = []; - foreach($array as $key => $contents) - { - foreach($contents as $asset) - $string[] = $asset['asset']->displayName . ' x'.$asset['quantity']; + foreach ($array as $key => $contents) { + foreach ($contents as $asset) { + $string[] = $asset['asset']->displayName.' x'.$asset['quantity']; + } } - if (!count ($string)) return; - return implode(', ', array_slice($string, 0, count($string) - 1)) . (count($string) > 2 ? ', and ' : ' and ') . end($string); + if (!count($string)) { + return; + } + + return implode(', ', array_slice($string, 0, count($string) - 1)).(count($string) > 2 ? ', and ' : ' and ').end($string); } diff --git a/app/Http/Controllers/Admin/Data/LootTableController.php b/app/Http/Controllers/Admin/Data/LootTableController.php index 75aa8da947..6c1128d0b6 100644 --- a/app/Http/Controllers/Admin/Data/LootTableController.php +++ b/app/Http/Controllers/Admin/Data/LootTableController.php @@ -5,9 +5,9 @@ use App\Http\Controllers\Controller; use App\Models\Currency\Currency; use App\Models\Item\Item; -use App\Models\Pet\Pet; use App\Models\Item\ItemCategory; use App\Models\Loot\LootTable; +use App\Models\Pet\Pet; use App\Services\LootService; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Admin/Data/PetController.php b/app/Http/Controllers/Admin/Data/PetController.php index bbd3700b19..2352352a6f 100644 --- a/app/Http/Controllers/Admin/Data/PetController.php +++ b/app/Http/Controllers/Admin/Data/PetController.php @@ -2,26 +2,21 @@ namespace App\Http\Controllers\Admin\Data; -use Illuminate\Http\Request; - -use Auth; - -use App\Models\Pet\PetCategory; +use App\Http\Controllers\Controller; +use App\Models\Item\Item; use App\Models\Pet\Pet; -use App\Models\Pet\PetVariant; -use App\Models\Pet\PetEvolution; +use App\Models\Pet\PetCategory; use App\Models\Pet\PetDropData; +use App\Models\Pet\PetEvolution; +use App\Models\Pet\PetVariant; use App\Models\Pet\PetVariantDropData; -use App\Services\PetService; -use App\Services\PetDropService; use App\Models\User\UserPet; +use App\Services\PetDropService; +use App\Services\PetService; +use Auth; +use Illuminate\Http\Request; -use App\Models\Item\Item; - -use App\Http\Controllers\Controller; - -class PetController extends Controller -{ +class PetController extends Controller { /* |-------------------------------------------------------------------------- | Admin / Pet Controller @@ -42,10 +37,9 @@ class PetController extends Controller * * @return \Illuminate\Contracts\Support\Renderable */ - public function getIndex() - { + public function getIndex() { return view('admin.pets.pet_categories', [ - 'categories' => PetCategory::orderBy('sort', 'DESC')->get() + 'categories' => PetCategory::orderBy('sort', 'DESC')->get(), ]); } @@ -54,64 +48,68 @@ public function getIndex() * * @return \Illuminate\Contracts\Support\Renderable */ - public function getCreatePetCategory() - { + public function getCreatePetCategory() { return view('admin.pets.create_edit_pet_category', [ - 'category' => new PetCategory + 'category' => new PetCategory, ]); } /** * Shows the edit pet category page. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getEditPetCategory($id) - { + public function getEditPetCategory($id) { $category = PetCategory::find($id); - if(!$category) abort(404); + if (!$category) { + abort(404); + } + return view('admin.pets.create_edit_pet_category', [ - 'category' => $category + 'category' => $category, ]); } /** * Creates or edits an pet category. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int|null $id + * @param App\Services\PetService $service + * @param int|null $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postCreateEditPetCategory(Request $request, PetService $service, $id = null) - { + public function postCreateEditPetCategory(Request $request, PetService $service, $id = null) { $id ? $request->validate(PetCategory::$updateRules) : $request->validate(PetCategory::$createRules); $data = $request->only([ - 'name', 'description', 'image', 'remove_image', 'allow_attach', 'limit' + 'name', 'description', 'image', 'remove_image', 'allow_attach', 'limit', ]); - if($id && $service->updatePetCategory(PetCategory::find($id), $data, Auth::user())) { + if ($id && $service->updatePetCategory(PetCategory::find($id), $data, Auth::user())) { flash('Category updated successfully.')->success(); - } - else if (!$id && $category = $service->createPetCategory($data, Auth::user())) { + } elseif (!$id && $category = $service->createPetCategory($data, Auth::user())) { flash('Category created successfully.')->success(); + return redirect()->to('admin/data/pet-categories/edit/'.$category->id); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Gets the pet category deletion modal. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getDeletePetCategory($id) - { + public function getDeletePetCategory($id) { $category = PetCategory::find($id); + return view('admin.pets._delete_pet_category', [ 'category' => $category, ]); @@ -120,37 +118,39 @@ public function getDeletePetCategory($id) /** * Deletes an pet category. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int $id + * @param App\Services\PetService $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDeletePetCategory(Request $request, PetService $service, $id) - { - if($id && $service->deletePetCategory(PetCategory::find($id))) { + public function postDeletePetCategory(Request $request, PetService $service, $id) { + if ($id && $service->deletePetCategory(PetCategory::find($id))) { flash('Category deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/pet-categories'); } /** * Sorts pet categories. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service + * @param App\Services\PetService $service + * * @return \Illuminate\Http\RedirectResponse */ - public function postSortPetCategory(Request $request, PetService $service) - { - if($service->sortPetCategory($request->get('sort'))) { + public function postSortPetCategory(Request $request, PetService $service) { + if ($service->sortPetCategory($request->get('sort'))) { flash('Category order updated successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } @@ -163,20 +163,21 @@ public function postSortPetCategory(Request $request, PetService $service) /** * Shows the pet index. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\Support\Renderable */ - public function getPetIndex(Request $request) - { + public function getPetIndex(Request $request) { $query = Pet::query(); $data = $request->only(['pet_category_id', 'name']); - if(isset($data['pet_category_id']) && $data['pet_category_id'] != 'none') + if (isset($data['pet_category_id']) && $data['pet_category_id'] != 'none') { $query->where('pet_category_id', $data['pet_category_id']); - if(isset($data['name'])) + } + if (isset($data['name'])) { $query->where('name', 'LIKE', '%'.$data['name'].'%'); + } + return view('admin.pets.pets', [ 'pets' => $query->paginate(20)->appends($request->query()), - 'categories' => ['none' => 'Any Category'] + PetCategory::orderBy('name', 'DESC')->pluck('name', 'id')->toArray() + 'categories' => ['none' => 'Any Category'] + PetCategory::orderBy('name', 'DESC')->pluck('name', 'id')->toArray(), ]); } @@ -185,66 +186,70 @@ public function getPetIndex(Request $request) * * @return \Illuminate\Contracts\Support\Renderable */ - public function getCreatePet() - { + public function getCreatePet() { return view('admin.pets.create_edit_pet', [ 'pet' => new Pet, - 'categories' => ['none' => 'No category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray() + 'categories' => ['none' => 'No category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(), ]); } /** * Shows the edit pet page. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getEditPet($id) - { + public function getEditPet($id) { $pet = Pet::find($id); - if(!$pet) abort(404); + if (!$pet) { + abort(404); + } + return view('admin.pets.create_edit_pet', [ 'pet' => $pet, - 'categories' => ['none' => 'No category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray() + 'categories' => ['none' => 'No category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(), ]); } /** * Creates or edits an pet. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int|null $id + * @param App\Services\PetService $service + * @param int|null $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postCreateEditPet(Request $request, PetService $service, $id = null) - { + public function postCreateEditPet(Request $request, PetService $service, $id = null) { $id ? $request->validate(Pet::$updateRules) : $request->validate(Pet::$createRules); $data = $request->only([ - 'name', 'allow_transfer', 'pet_category_id', 'description', 'image', 'remove_image', 'limit' + 'name', 'allow_transfer', 'pet_category_id', 'description', 'image', 'remove_image', 'limit', ]); - if($id && $service->updatePet(Pet::find($id), $data, Auth::user())) { + if ($id && $service->updatePet(Pet::find($id), $data, Auth::user())) { flash('Pet updated successfully.')->success(); - } - else if (!$id && $pet = $service->createPet($data, Auth::user())) { + } elseif (!$id && $pet = $service->createPet($data, Auth::user())) { flash('Pet created successfully.')->success(); + return redirect()->to('admin/data/pets/edit/'.$pet->id); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Gets the pet deletion modal. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getDeletePet($id) - { + public function getDeletePet($id) { $pet = Pet::find($id); + return view('admin.pets._delete_pet', [ 'pet' => $pet, ]); @@ -253,19 +258,20 @@ public function getDeletePet($id) /** * Creates or edits an pet. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int $id + * @param App\Services\PetService $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDeletePet(Request $request, PetService $service, $id) - { - if($id && $service->deletePet(Pet::find($id))) { + public function postDeletePet(Request $request, PetService $service, $id) { + if ($id && $service->deletePet(Pet::find($id))) { flash('Pet deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/pets'); } @@ -277,9 +283,11 @@ public function postDeletePet(Request $request, PetService $service, $id) /** * Gets the create / edit pet variant page. + * + * @param mixed $pet_id + * @param mixed|null $id */ - public function getCreateEditVariant($pet_id, $id = null) - { + public function getCreateEditVariant($pet_id, $id = null) { return view('admin.pets._create_edit_pet_variant', [ 'pet' => Pet::find($pet_id), 'variant' => $id ? PetVariant::find($id) : new PetVariant, @@ -287,25 +295,26 @@ public function getCreateEditVariant($pet_id, $id = null) } /** - * Edits pet variants + * Edits pet variants. + * + * @param App\Services\PetService $service + * @param int $id + * @param mixed $pet_id * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int $id * @return \Illuminate\Http\RedirectResponse */ - public function postCreateEditVariant(Request $request, PetService $service, $pet_id, $id = null) - { + public function postCreateEditVariant(Request $request, PetService $service, $pet_id, $id = null) { $data = $request->only(['variant_name', 'variant_image', 'remove_image', 'delete']); - if($id && $service->editVariant(PetVariant::findOrFail($id), $data)) { + if ($id && $service->editVariant(PetVariant::findOrFail($id), $data)) { // we dont flash in case we are deleting the variant - } - else if (!$id && $service->createVariant(Pet::find($pet_id), $data)) { + } elseif (!$id && $service->createVariant(Pet::find($pet_id), $data)) { flash('Variant created successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } @@ -317,39 +326,41 @@ public function postCreateEditVariant(Request $request, PetService $service, $pe /** * Gets the create / edit pet evolution page. + * + * @param mixed $pet_id + * @param mixed|null $id */ - public function getCreateEditEvolution($pet_id, $id = null) - { + public function getCreateEditEvolution($pet_id, $id = null) { return view('admin.pets._create_edit_pet_evolution', [ - 'pet' => Pet::find($pet_id), + 'pet' => Pet::find($pet_id), 'evolution' => $id ? PetEvolution::find($id) : new PetEvolution, ]); } /** - * Edits pet evolutions + * Edits pet evolutions. + * + * @param App\Services\PetService $service + * @param int $id + * @param mixed $pet_id * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetService $service - * @param int $id * @return \Illuminate\Http\RedirectResponse */ - public function postCreateEditEvolution(Request $request, PetService $service, $pet_id, $id = null) - { + public function postCreateEditEvolution(Request $request, PetService $service, $pet_id, $id = null) { $data = $request->only(['evolution_name', 'evolution_image', 'evolution_stage', 'delete', 'variant_id', 'variant_image']); - if($id && $service->editEvolution(PetEvolution::findOrFail($id), $data)) { + if ($id && $service->editEvolution(PetEvolution::findOrFail($id), $data)) { // we dont flash in case we are deleting the evolution - } - else if (!$id && $service->createEvolution(Pet::find($pet_id), $data)) { + } elseif (!$id && $service->createEvolution(Pet::find($pet_id), $data)) { flash('Evolution created successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } - /********************************************************************************************** PET DROPS @@ -359,25 +370,31 @@ public function postCreateEditEvolution(Request $request, PetService $service, $ /** * Edits pet drops. * - * @param \Illuminate\Http\Request $request - * @param string $slug + * @param mixed $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postEditPetDrop(Request $request, $id) - { - if(!Auth::check()) abort(404); + public function postEditPetDrop(Request $request, $id) { + if (!Auth::check()) { + abort(404); + } $this->user_pet = UserPet::where('id', $id)->first(); - if(!$this->user_pet) abort(404); + if (!$this->user_pet) { + abort(404); + } $drops = $this->user_pet->drops; - if(!$request['drops_available']) $request['drops_available'] = 0; + if (!$request['drops_available']) { + $request['drops_available'] = 0; + } if ($drops->update(['parameters' => $request['parameters'], 'drops_available' => $request['drops_available']])) { flash('Pet drops updated successfully.')->success(); + return redirect()->to($this->user_pet->pageUrl(Auth::user()->id)); - } - else { + } else { flash('Failed to update pet drops.')->error(); } + return redirect()->back()->withInput(); } @@ -386,10 +403,9 @@ public function postEditPetDrop(Request $request, $id) * * @return \Illuminate\Contracts\Support\Renderable */ - public function getDropIndex() - { + public function getDropIndex() { return view('admin.pets.pet_drops', [ - 'drops' => PetDropData::orderBy('pet_id', 'ASC')->paginate(20) + 'drops' => PetDropData::orderBy('pet_id', 'ASC')->paginate(20), ]); } @@ -398,10 +414,10 @@ public function getDropIndex() * * @return \Illuminate\Contracts\Support\Renderable */ - public function getCreateDrop() - { + public function getCreateDrop() { // get pets without drop relation $pets = Pet::orderBy('name', 'DESC')->whereDoesntHave('dropData')->pluck('name', 'id')->toArray(); + return view('admin.pets.create_edit_drop', [ 'drop' => new PetDropData, 'pets' => $pets, @@ -412,59 +428,64 @@ public function getCreateDrop() /** * Shows the edit pet drop data page. * - * @param int $id + * @param mixed $pet_id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getEditDrop($pet_id) - { + public function getEditDrop($pet_id) { $pet = Pet::findOrFail($pet_id); $petDrop = $pet->dropData; - if (!$petDrop) abort(404); + if (!$petDrop) { + abort(404); + } + return view('admin.pets.create_edit_drop', [ 'drop' => $petDrop, 'pets' => Pet::orderBy('name', 'DESC')->pluck('name', 'id')->toArray(), 'variants' => PetVariant::orderBy('variant_name', 'DESC')->pluck('variant_name', 'id')->toArray(), - 'items' => Item::orderBy('name')->pluck('name', 'id') + 'items' => Item::orderBy('name')->pluck('name', 'id'), ]); } /** * Creates or edits pet drop data. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetDropService $service - * @param int|null $id + * @param App\Services\PetDropService $service + * @param mixed|null $pet_id + * * @return \Illuminate\Http\RedirectResponse */ - public function postCreateEditDrop(Request $request, PetDropService $service, $pet_id = null) - { + public function postCreateEditDrop(Request $request, PetDropService $service, $pet_id = null) { // $id ? $request->validate(PetDropData::$updateRules) : $request->validate(PetDropData::$createRules); $data = $request->only([ 'pet_id', 'label', 'weight', 'drop_frequency', 'drop_interval', 'is_active', 'item_id', 'drop_name', 'is_active', 'cap', 'rewardable_type', 'rewardable_id', 'min_quantity', 'max_quantity', 'override', ]); - if($pet_id && $service->updatePetDrop(Pet::find($pet_id)->dropData, $data, Auth::user())) { + if ($pet_id && $service->updatePetDrop(Pet::find($pet_id)->dropData, $data, Auth::user())) { flash('Pet drop updated successfully.')->success(); - } - else if (!$pet_id && $drop = $service->createPetDrop($data, Auth::user())) { + } elseif (!$pet_id && $drop = $service->createPetDrop($data, Auth::user())) { flash('Pet drop created successfully.')->success(); + return redirect()->to('admin/data/pets/drops/edit/'.$drop->pet_id); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Gets the pet drop data deletion modal. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getDeleteDrop($id) - { + public function getDeleteDrop($id) { $drop = PetDropData::find($id); + return view('admin.pets._delete_drop', [ 'drop' => $drop, ]); @@ -473,27 +494,29 @@ public function getDeleteDrop($id) /** * Deletes a drop. * - * @param \Illuminate\Http\Request $request - * @param App\Services\SpeciesService $service - * @param int $id + * @param App\Services\SpeciesService $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDeleteDrop(Request $request, SpeciesService $service, $id) - { - if($id && $service->deleteDropData(PetDropData::find($id))) { + public function postDeleteDrop(Request $request, SpeciesService $service, $id) { + if ($id && $service->deleteDropData(PetDropData::find($id))) { flash('Drop data deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/pets/drops'); } /** - * returns widget based on id + * returns widget based on id. + * + * @param mixed $id */ - public function getDropWidget($id) - { + public function getDropWidget($id) { return view('admin.pets._drop_widget', [ 'drop' => PetDropData::find($id), ]); @@ -507,9 +530,10 @@ public function getDropWidget($id) /** * Gets the pet drop variant creation modal. + * + * @param mixed $pet_id */ - public function getCreateVariantDrop($pet_id) - { + public function getCreateVariantDrop($pet_id) { return view('admin.pets._create_edit_pet_variant_drop', [ 'pet' => Pet::findOrFail($pet_id), 'variants' => PetVariant::where('pet_id', $pet_id)->orderBy('variant_name', 'DESC')->pluck('variant_name', 'id')->toArray(), @@ -519,9 +543,11 @@ public function getCreateVariantDrop($pet_id) /** * Gets the pet drop variant edit modal. + * + * @param mixed $pet_id + * @param mixed $variant_id */ - public function getEditVariantDrop($pet_id, $variant_id) - { + public function getEditVariantDrop($pet_id, $variant_id) { $variant = PetVariant::findOrFail($variant_id); return view('admin.pets._create_edit_pet_variant_drop', [ @@ -534,9 +560,11 @@ public function getEditVariantDrop($pet_id, $variant_id) /** * Creates or edits a pet drop variant. + * + * @param mixed $pet_id + * @param mixed|null $variant_id */ - public function postCreateEditVariantDrop(Request $request, PetDropService $service, $pet_id, $variant_id = null) - { + public function postCreateEditVariantDrop(Request $request, PetDropService $service, $pet_id, $variant_id = null) { $data = $request->only([ 'variant_id', 'rewardable_type', 'rewardable_id', 'min_quantity', 'max_quantity', ]); @@ -544,25 +572,30 @@ public function postCreateEditVariantDrop(Request $request, PetDropService $serv $variant = PetVariant::find($variant_id); $pet = Pet::findOrFail($pet_id); - if($variant_id && $service->editPetVariantDrop($variant->dropData, $data)) { + if ($variant_id && $service->editPetVariantDrop($variant->dropData, $data)) { flash('Pet variant drop edited successfully.')->success(); - } - else if (!$variant_id && $drop = $service->createPetVariantDrop($data)) { + } elseif (!$variant_id && $drop = $service->createPetVariantDrop($data)) { flash('Pet variant drop created successfully.')->success(); + return redirect()->to('admin/data/pets/drops/edit/'.$pet->id); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/pets/drops/edit/'.$pet->id); } /** * Gets the pet drop variant deletion modal. + * + * @param mixed $pet_id + * @param mixed $variant_id */ - public function getDeleteVariantDrop($pet_id, $variant_id) - { + public function getDeleteVariantDrop($pet_id, $variant_id) { $variant = PetVariant::findOrFail($variant_id); + return view('admin.pets._delete_pet_variant_drop', [ 'pet' => Pet::findOrFail($pet_id), 'variant' => $variant, @@ -572,16 +605,20 @@ public function getDeleteVariantDrop($pet_id, $variant_id) /** * Deletes a pet drop variant. + * + * @param mixed $pet_id + * @param mixed $variant_id */ - public function postDeleteVariantDrop(Request $request, PetDropService $service, $pet_id, $variant_id) - { + public function postDeleteVariantDrop(Request $request, PetDropService $service, $pet_id, $variant_id) { $variant = PetVariant::findOrFail($variant_id); - if($variant_id && $service->deletePetVariantDrop($variant->dropData)) { + if ($variant_id && $service->deletePetVariantDrop($variant->dropData)) { flash('Pet variant drop deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/pets/drops/edit/'.$pet_id); } } diff --git a/app/Http/Controllers/Admin/Data/ShopController.php b/app/Http/Controllers/Admin/Data/ShopController.php index e91a8e2c36..32c96b8c0b 100644 --- a/app/Http/Controllers/Admin/Data/ShopController.php +++ b/app/Http/Controllers/Admin/Data/ShopController.php @@ -9,9 +9,9 @@ use App\Models\Shop\Shop; use App\Models\Shop\ShopStock; use App\Services\ShopService; -use Log; use Auth; use Illuminate\Http\Request; +use Log; class ShopController extends Controller { /* @@ -39,15 +39,15 @@ public function getIndex() { * * @return \Illuminate\Contracts\Support\Renderable */ - public function getCreateShop() - { + public function getCreateShop() { // get all items where they have a tag 'coupon' - $coupons = Item::whereHas('tags', function($query) { + $coupons = Item::whereHas('tags', function ($query) { $query->where('tag', 'coupon')->where('is_active', 1); })->orderBy('name')->pluck('name', 'id'); + return view('admin.shops.create_edit_shop', [ - 'shop' => new Shop, - 'items' => Item::orderBy('name')->pluck('name', 'id'), + 'shop' => new Shop, + 'items' => Item::orderBy('name')->pluck('name', 'id'), 'coupons' => $coupons, ]); } @@ -61,19 +61,21 @@ public function getCreateShop() */ public function getEditShop($id) { $shop = Shop::find($id); - if(!$shop) abort(404); + if (!$shop) { + abort(404); + } // get all items where they have a tag 'coupon' - $coupons = Item::released()->whereHas('tags', function($query) { + $coupons = Item::released()->whereHas('tags', function ($query) { $query->where('tag', 'coupon'); })->orderBy('name')->pluck('name', 'id'); return view('admin.shops.create_edit_shop', [ - 'shop' => $shop, - 'items' => Item::orderBy('name')->pluck('name', 'id'), - 'pets' => Pet::orderBy('name')->pluck('name', 'id'), + 'shop' => $shop, + 'items' => Item::orderBy('name')->pluck('name', 'id'), + 'pets' => Pet::orderBy('name')->pluck('name', 'id'), 'currencies' => Currency::orderBy('name')->pluck('name', 'id'), - 'coupons' => $coupons, + 'coupons' => $coupons, ]); } @@ -88,7 +90,7 @@ public function getEditShop($id) { public function postCreateEditShop(Request $request, ShopService $service, $id = null) { $id ? $request->validate(Shop::$updateRules) : $request->validate(Shop::$createRules); $data = $request->only([ - 'name', 'description', 'image', 'remove_image', 'is_active', 'is_staff', 'use_coupons', 'is_fto', 'allowed_coupons', 'is_timed_shop', 'start_at', 'end_at' + 'name', 'description', 'image', 'remove_image', 'is_active', 'is_staff', 'use_coupons', 'is_fto', 'allowed_coupons', 'is_timed_shop', 'start_at', 'end_at', ]); if ($id && $service->updateShop(Shop::find($id), $data, Auth::user())) { flash('Shop updated successfully.')->success(); @@ -106,48 +108,56 @@ public function postCreateEditShop(Request $request, ShopService $service, $id = } /** - * loads the create stock modal + * loads the create stock modal. + * + * @param mixed $id */ - public function getCreateShopStock($id) - { + public function getCreateShopStock($id) { $shop = Shop::find($id); - if(!$shop) abort(404); + if (!$shop) { + abort(404); + } return view('admin.shops._stock_modal', [ - 'shop' => $shop, + 'shop' => $shop, 'currencies' => Currency::orderBy('name')->pluck('name', 'id'), - 'stock' => new ShopStock + 'stock' => new ShopStock, ]); } /** - * loads the edit stock modal + * loads the edit stock modal. + * + * @param mixed $id */ - public function getEditShopStock($id) - { + public function getEditShopStock($id) { $stock = ShopStock::find($id); - if(!$stock) abort(404); + if (!$stock) { + abort(404); + } return view('admin.shops._stock_modal', [ - 'shop' => $stock->shop, - 'stock' => $stock, + 'shop' => $stock->shop, + 'stock' => $stock, 'currencies' => Currency::orderBy('name')->pluck('name', 'id'), - 'items' => Item::orderBy('name')->pluck('name', 'id'), + 'items' => Item::orderBy('name')->pluck('name', 'id'), ]); } /** * gets stock of a certain type. */ - public function getShopStockType(Request $request) - { + public function getShopStockType(Request $request) { $type = $request->input('type'); - if (!$type) return null; + if (!$type) { + return null; + } // get base modal from type using asset helper $model = getAssetModelString(strtolower($type)); log::info([$model, $type]); + return view('admin.shops._stock_item', [ - 'items' => $model::orderBy('name')->pluck('name', 'id') + 'items' => $model::orderBy('name')->pluck('name', 'id'), ]); } @@ -159,35 +169,36 @@ public function getShopStockType(Request $request) * * @return \Illuminate\Http\RedirectResponse */ - public function postEditShopStock(Request $request, ShopService $service, $id) - { + public function postEditShopStock(Request $request, ShopService $service, $id) { $data = $request->only([ 'shop_id', 'item_id', 'currency_id', 'cost', 'use_user_bank', 'use_character_bank', 'is_limited_stock', 'quantity', 'purchase_limit', 'purchase_limit_timeframe', 'is_fto', 'stock_type', 'is_visible', - 'restock', 'restock_quantity', 'restock_interval', 'range', 'disallow_transfer', 'is_timed_stock', 'start_at', 'end_at' + 'restock', 'restock_quantity', 'restock_interval', 'range', 'disallow_transfer', 'is_timed_stock', 'start_at', 'end_at', ]); - if($service->editShopStock(ShopStock::find($id), $data, Auth::user())) { + if ($service->editShopStock(ShopStock::find($id), $data, Auth::user())) { flash('Shop stock updated successfully.')->success(); + return redirect()->back(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Edits a shop's stock. * - * @param \Illuminate\Http\Request $request - * @param App\Services\ShopService $service - * @param int $id + * @param App\Services\ShopService $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postCreateShopStock(Request $request, ShopService $service, $id) - { + public function postCreateShopStock(Request $request, ShopService $service, $id) { $data = $request->only([ 'shop_id', 'item_id', 'currency_id', 'cost', 'use_user_bank', 'use_character_bank', 'is_limited_stock', 'quantity', 'purchase_limit', 'purchase_limit_timeframe', 'is_fto', 'stock_type', 'is_visible', - 'restock', 'restock_quantity', 'restock_interval', 'range', 'is_timed_stock', 'start_at', 'end_at' + 'restock', 'restock_quantity', 'restock_interval', 'range', 'is_timed_stock', 'start_at', 'end_at', ]); if ($service->updateShopStock(Shop::find($id), $data, Auth::user())) { flash('Shop stock updated successfully.')->success(); @@ -205,12 +216,13 @@ public function postCreateShopStock(Request $request, ShopService $service, $id) /** * Gets the stock deletion modal. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getDeleteShopStock($id) - { + public function getDeleteShopStock($id) { $stock = ShopStock::find($id); + return view('admin.shops._delete_stock', [ 'stock' => $stock, ]); @@ -219,21 +231,22 @@ public function getDeleteShopStock($id) /** * Deletes a stock. * - * @param \Illuminate\Http\Request $request - * @param App\Services\StockService $service - * @param int $id + * @param App\Services\StockService $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDeleteShopStock(Request $request, ShopService $service, $id) - { + public function postDeleteShopStock(Request $request, ShopService $service, $id) { $stock = ShopStock::find($id); $shop = $stock->shop; - if($id && $service->deleteStock($stock)) { + if ($id && $service->deleteStock($stock)) { flash('Stock deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->to('admin/data/shops/edit/'.$shop->id); } @@ -291,19 +304,19 @@ public function postSortShop(Request $request, ShopService $service) { return redirect()->back(); } - public function postRestrictShop(Request $request, ShopService $service, $id) - { + public function postRestrictShop(Request $request, ShopService $service, $id) { $data = $request->only([ - 'item_id', 'is_restricted' + 'item_id', 'is_restricted', ]); - if($service->restrictShop($data, $id)) { + if ($service->restrictShop($data, $id)) { flash('Shop limits updated successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } - } diff --git a/app/Http/Controllers/Admin/SubmissionController.php b/app/Http/Controllers/Admin/SubmissionController.php index b4a80cfd74..63ef403293 100644 --- a/app/Http/Controllers/Admin/SubmissionController.php +++ b/app/Http/Controllers/Admin/SubmissionController.php @@ -3,12 +3,11 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; -use App\Models\Item\Item; use App\Models\Currency\Currency; +use App\Models\Item\Item; use App\Models\Loot\LootTable; -use App\Models\Raffle\Raffle; -use App\Models\Pet\Pet; use App\Models\Prompt\PromptCategory; +use App\Models\Raffle\Raffle; use App\Models\Submission\Submission; use App\Services\SubmissionManager; use Auth; diff --git a/app/Http/Controllers/Admin/Users/GrantController.php b/app/Http/Controllers/Admin/Users/GrantController.php index c38f05562c..8bdf2fdd54 100644 --- a/app/Http/Controllers/Admin/Users/GrantController.php +++ b/app/Http/Controllers/Admin/Users/GrantController.php @@ -89,30 +89,30 @@ public function postItems(Request $request, InventoryManager $service) { * * @return \Illuminate\Contracts\Support\Renderable */ - public function getPets() - { + public function getPets() { return view('admin.grants.pets', [ 'users' => User::orderBy('id')->pluck('name', 'id'), - 'pets' => Pet::orderBy('name')->pluck('name', 'id') + 'pets' => Pet::orderBy('name')->pluck('name', 'id'), ]); } /** * Grants or removes pets from multiple users. * - * @param \Illuminate\Http\Request $request - * @param App\Services\InvenntoryManager $service + * @param App\Services\InvenntoryManager $service + * * @return \Illuminate\Http\RedirectResponse */ - public function postPets(Request $request, PetManager $service) - { + public function postPets(Request $request, PetManager $service) { $data = $request->only(['names', 'pet_ids', 'quantities', 'data', 'disallow_transfer', 'notes']); - if($service->grantPets($data, Auth::user())) { + if ($service->grantPets($data, Auth::user())) { flash('Pets granted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 3c9b919395..5b1d8d1405 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -4,10 +4,11 @@ use App\Models\Currency\Currency; use App\Models\Item\Item; -use App\Models\Item\ItemTag; use App\Models\Item\ItemCategory; +use App\Models\Item\ItemTag; +use App\Models\Pet\Pet; +use App\Models\Pet\PetCategory; use App\Models\Shop\Shop; -use App\Models\Shop\ShopLimit; use App\Models\Shop\ShopLog; use App\Models\Shop\ShopStock; use App\Models\User\UserItem; @@ -15,9 +16,6 @@ use Auth; use Illuminate\Http\Request; -use App\Models\Pet\Pet; -use App\Models\Pet\PetCategory; - class ShopController extends Controller { /* |-------------------------------------------------------------------------- @@ -46,43 +44,51 @@ public function getIndex() { * * @return \Illuminate\Contracts\Support\Renderable */ - public function getShop($id) - { + public function getShop($id) { $categories = ItemCategory::orderBy('sort', 'DESC')->get(); $petCategories = PetCategory::orderBy('sort', 'DESC')->get(); $shop = Shop::where('id', $id)->where('is_active', 1)->first(); - if(!$shop) abort(404); + if (!$shop) { + abort(404); + } - if($shop->is_staff) { - if(!Auth::check()) abort(404); - if(!Auth::user()->isStaff) abort(404); + if ($shop->is_staff) { + if (!Auth::check()) { + abort(404); + } + if (!Auth::user()->isStaff) { + abort(404); + } } - if($shop->is_restricted) { - if(!Auth::check()) { + if ($shop->is_restricted) { + if (!Auth::check()) { flash('You must be logged in to enter this shop.')->error(); + return redirect()->to('/shops'); } - foreach($shop->limits as $limit) - { + foreach ($shop->limits as $limit) { $item = $limit->item_id; $check = UserItem::where('item_id', $item)->where('user_id', auth::user()->id)->where('count', '>', 0)->first(); - if(!$check) { - flash('You require a ' . $limit->item->name . ' to enter this store.')->error(); - return redirect()->to('/shops'); + if (!$check) { + flash('You require a '.$limit->item->name.' to enter this store.')->error(); + + return redirect()->to('/shops'); } } } - if($shop->is_fto) { - if(!Auth::check()) { + if ($shop->is_fto) { + if (!Auth::check()) { flash('You must be logged in to enter this shop.')->error(); + return redirect()->to('/shops'); } - if(!Auth::user()->settings->is_fto && !Auth::user()->isStaff) { + if (!Auth::user()->settings->is_fto && !Auth::user()->isStaff) { flash('You must be a FTO to enter this shop.')->error(); + return redirect()->to('/shops'); } } @@ -90,7 +96,7 @@ public function getShop($id) // get all types of stock in the shop $stock_types = ShopStock::where('shop_id', $shop->id)->pluck('stock_type')->unique(); $stocks = []; - foreach($stock_types as $type) { + foreach ($stock_types as $type) { // get the model for the stock type (item, pet, etc) $type = strtolower($type); $model = getAssetModelString($type); @@ -116,10 +122,10 @@ public function getShop($id) } return view('shops.shop', [ - 'shop' => $shop, - 'stocks' => $stocks, - 'shops' => Shop::where('is_active', 1)->orderBy('sort', 'DESC')->get(), - 'currencies' => Currency::whereIn('id', ShopStock::where('shop_id', $shop->id)->pluck('currency_id')->toArray())->get()->keyBy('id') + 'shop' => $shop, + 'stocks' => $stocks, + 'shops' => Shop::where('is_active', 1)->orderBy('sort', 'DESC')->get(), + 'currencies' => Currency::whereIn('id', ShopStock::where('shop_id', $shop->id)->pluck('currency_id')->toArray())->get()->keyBy('id'), ]); } @@ -135,7 +141,9 @@ public function getShop($id) public function getShopStock(ShopManager $service, $id, $stockId) { $shop = Shop::where('id', $id)->where('is_active', 1)->first(); $stock = ShopStock::where('id', $stockId)->where('shop_id', $id)->first(); - if(!$shop) abort(404); + if (!$shop) { + abort(404); + } $user = Auth::user(); $quantityLimit = 0; @@ -148,27 +156,26 @@ public function getShopStock(ShopManager $service, $id, $stockId) { $userOwned = UserItem::where('user_id', $user->id)->where('item_id', $stock->item->id)->where('count', '>', 0)->get(); } - if($shop->use_coupons) { + if ($shop->use_coupons) { $couponId = ItemTag::where('tag', 'coupon')->where('is_active', 1); // Removed get() $itemIds = $couponId->pluck('item_id'); // Could be combined with above // get rid of any itemIds that are not in allowed_coupons - if($shop->allowed_coupons && count(json_decode($shop->allowed_coupons, 1))) { - $itemIds = $itemIds->filter(function($itemId) use ($shop) { + if ($shop->allowed_coupons && count(json_decode($shop->allowed_coupons, 1))) { + $itemIds = $itemIds->filter(function ($itemId) use ($shop) { return in_array($itemId, json_decode($shop->allowed_coupons, 1)); }); } $check = UserItem::with('item')->whereIn('item_id', $itemIds)->where('user_id', auth::user()->id)->where('count', '>', 0)->get()->pluck('item.name', 'id'); - } - else { + } else { $check = null; } return view('shops._stock_modal', [ - 'shop' => $shop, - 'stock' => $stock, - 'userCoupons' => $check, - 'quantityLimit' => $quantityLimit, - 'userPurchaseCount' => $userPurchaseCount, + 'shop' => $shop, + 'stock' => $stock, + 'userCoupons' => $check, + 'quantityLimit' => $quantityLimit, + 'userPurchaseCount' => $userPurchaseCount, 'purchaseLimitReached' => $purchaseLimitReached, 'userOwned' => $user ? $userOwned : null, ]); @@ -183,7 +190,7 @@ public function getShopStock(ShopManager $service, $id, $stockId) { */ public function postBuy(Request $request, ShopManager $service) { $request->validate(ShopLog::$createRules); - if($service->buyStock($request->only(['stock_id', 'shop_id', 'slug', 'bank', 'quantity', 'use_coupon', 'coupon']), Auth::user())) { + if ($service->buyStock($request->only(['stock_id', 'shop_id', 'slug', 'bank', 'quantity', 'use_coupon', 'coupon']), Auth::user())) { flash('Successfully purchased item.')->success(); } else { foreach ($service->errors()->getMessages()['error'] as $error) { diff --git a/app/Http/Controllers/Users/PetController.php b/app/Http/Controllers/Users/PetController.php index eb0ea6fabb..002ceb42d1 100644 --- a/app/Http/Controllers/Users/PetController.php +++ b/app/Http/Controllers/Users/PetController.php @@ -2,27 +2,21 @@ namespace App\Http\Controllers\Users; -use Illuminate\Http\Request; - -use DB; -use Auth; -use App\Models\User\User; -use App\Models\User\UserPet; +use App\Http\Controllers\Controller; +use App\Models\Character\Character; +use App\Models\Item\ItemTag; use App\Models\Pet\Pet; -use App\Models\Pet\PetDrop; use App\Models\Pet\PetCategory; -use App\Models\Pet\PetLog; -use App\Models\Item\ItemTag; +use App\Models\Pet\PetDrop; +use App\Models\User\User; use App\Models\User\UserItem; -use App\Services\PetManager; +use App\Models\User\UserPet; use App\Services\PetDropService; +use App\Services\PetManager; +use Auth; +use Illuminate\Http\Request; -use App\Models\Character\Character; - -use App\Http\Controllers\Controller; - -class PetController extends Controller -{ +class PetController extends Controller { /* |-------------------------------------------------------------------------- | Pet Controller @@ -37,15 +31,15 @@ class PetController extends Controller * * @return \Illuminate\Contracts\Support\Renderable */ - public function getIndex() - { + public function getIndex() { $categories = PetCategory::orderBy('sort', 'DESC')->get(); $pets = count($categories) ? Auth::user()->pets()->orderByRaw('FIELD(pet_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')->orderBy('pet_name')->get()->groupBy('pet_category_id') : Auth::user()->pets()->orderBy('pet_name')->get()->groupBy('pet_category_id'); + return view('home.pets', [ - 'categories' => $categories->keyBy('id'), - 'pets' => $pets, - 'userOptions' => User::visible()->where('id', '!=', Auth::user()->id)->orderBy('name')->pluck('name', 'id')->toArray(), - 'user' => Auth::user(), + 'categories' => $categories->keyBy('id'), + 'pets' => $pets, + 'userOptions' => User::visible()->where('id', '!=', Auth::user()->id)->orderBy('name')->pluck('name', 'id')->toArray(), + 'user' => Auth::user(), 'userCreditOptions' => ['' => 'Select User'] + User::visible()->orderBy('name')->get()->pluck('verified_name', 'id')->toArray(), ]); } @@ -53,26 +47,26 @@ public function getIndex() /** * Shows the pet stack modal. * - * @param \Illuminate\Http\Request $request - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getStack(Request $request, $id) - { + public function getStack(Request $request, $id) { $stack = UserPet::withTrashed()->where('id', $id)->with('pet')->first(); $chara = Character::myo()->where('user_id', $stack->user_id)->pluck('slug', 'id'); - $readOnly = $request->get('read_only') ? : ((Auth::check() && $stack && !$stack->deleted_at && ($stack->user_id == Auth::user()->id || Auth::user()->hasPower('edit_inventories'))) ? 0 : 1); + $readOnly = $request->get('read_only') ?: ((Auth::check() && $stack && !$stack->deleted_at && ($stack->user_id == Auth::user()->id || Auth::user()->hasPower('edit_inventories'))) ? 0 : 1); $tags = ItemTag::where('tag', 'splice')->where('is_active', 1)->pluck('item_id'); $splices = UserItem::where('user_id', $stack->user_id)->whereIn('item_id', $tags)->where('count', '>', 0)->with('item')->get()->pluck('item.name', 'id'); + return view('home._pet_stack', [ - 'stack' => $stack, - 'chara' => $chara, - 'user' => Auth::user(), - 'userOptions' => ['' => 'Select User'] + User::visible()->where('id', '!=', $stack ? $stack->user_id : 0)->orderBy('name')->get()->pluck('verified_name', 'id')->toArray(), - 'readOnly' => $readOnly, - 'splices' => $splices, + 'stack' => $stack, + 'chara' => $chara, + 'user' => Auth::user(), + 'userOptions' => ['' => 'Select User'] + User::visible()->where('id', '!=', $stack ? $stack->user_id : 0)->orderBy('name')->get()->pluck('verified_name', 'id')->toArray(), + 'readOnly' => $readOnly, + 'splices' => $splices, 'userCreditOptions' => ['' => 'Select User'] + User::visible()->orderBy('name')->get()->pluck('verified_name', 'id')->toArray(), ]); } @@ -80,141 +74,155 @@ public function getStack(Request $request, $id) /** * Transfers an pet stack to another user. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetManager $service - * @param int $id + * @param App\Services\PetManager $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postTransfer(Request $request, PetManager $service, $id) - { - if($service->transferStack(Auth::user(), User::visible()->where('id', $request->get('user_id'))->first(), UserPet::where('id', $id)->first())) { + public function postTransfer(Request $request, PetManager $service, $id) { + if ($service->transferStack(Auth::user(), User::visible()->where('id', $request->get('user_id'))->first(), UserPet::where('id', $id)->first())) { flash('Pet transferred successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Deletes an pet stack. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetManager $service - * @param int $id + * @param App\Services\PetManager $service + * @param int $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDelete(Request $request, PetManager $service, $id) - { - if($service->deleteStack(Auth::user(), UserPet::where('id', $id)->first())) { + public function postDelete(Request $request, PetManager $service, $id) { + if ($service->deleteStack(Auth::user(), UserPet::where('id', $id)->first())) { flash('Pet deleted successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Names an pet. * - * @param \Illuminate\Http\Request $request - * @param App\Services\CharacterManager $service + * @param App\Services\CharacterManager $service + * @param mixed $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postName(Request $request, PetManager $service, $id) - { - if($service->nameStack(UserPet::find($id), $request->get('name'))) { + public function postName(Request $request, PetManager $service, $id) { + if ($service->nameStack(UserPet::find($id), $request->get('name'))) { flash('Pet named successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Attaches an pet. * - * @param \Illuminate\Http\Request $request - * @param App\Services\CharacterManager $service + * @param App\Services\CharacterManager $service + * @param mixed $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postAttach(Request $request, PetManager $service, $id) - { - if($service->attachStack(UserPet::find($id), $request->get('id'))) { + public function postAttach(Request $request, PetManager $service, $id) { + if ($service->attachStack(UserPet::find($id), $request->get('id'))) { flash('Pet attached successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Detaches an pet. * - * @param \Illuminate\Http\Request $request - * @param App\Services\CharacterManager $service + * @param App\Services\CharacterManager $service + * @param mixed $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postDetach(Request $request, PetManager $service, $id) - { - if($service->detachStack(UserPet::find($id))) { + public function postDetach(Request $request, PetManager $service, $id) { + if ($service->detachStack(UserPet::find($id))) { flash('Pet detached successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** - * Changes variant + * Changes variant. + * + * @param App\Services\CharacterManager $service + * @param mixed $id + * @param mixed $isStaff * - * @param \Illuminate\Http\Request $request - * @param App\Services\CharacterManager $service * @return \Illuminate\Http\RedirectResponse */ - public function postVariant(Request $request, PetManager $service, $id, $isStaff = false) - { + public function postVariant(Request $request, PetManager $service, $id, $isStaff = false) { $pet = UserPet::find($id); - if($service->editVariant($request->input('variant_id'), $pet, $request->input('stack_id'), $request->input('is_staff'))) { + if ($service->editVariant($request->input('variant_id'), $pet, $request->input('stack_id'), $request->input('is_staff'))) { flash('Pet variant changed successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** - * Changes evolution + * Changes evolution. + * + * @param App\Services\CharacterManager $service + * @param mixed $id + * @param mixed $isStaff * - * @param \Illuminate\Http\Request $request - * @param App\Services\CharacterManager $service * @return \Illuminate\Http\RedirectResponse */ - public function postEvolution(Request $request, PetManager $service, $id, $isStaff = false) - { + public function postEvolution(Request $request, PetManager $service, $id, $isStaff = false) { $pet = UserPet::find($id); - if($service->editEvolution($request->input('evolution_id'), $pet, $request->input('stack_id'), $request->input('is_staff'))) { + if ($service->editEvolution($request->input('evolution_id'), $pet, $request->input('stack_id'), $request->input('is_staff'))) { flash('Pet evolution changed successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** * Shows the pet selection widget. * - * @param int $id + * @param int $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getSelector($id) - { + public function getSelector($id) { return view('widgets._pet_select', [ 'user' => Auth::user(), ]); @@ -223,108 +231,125 @@ public function getSelector($id) /** * Shows a pet's indiviudal page. * - * @param string $slug + * @param mixed $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getPetPage($id) - { + public function getPetPage($id) { $pet = UserPet::findOrFail($id); $user = $pet->user; $tags = ItemTag::where('tag', 'splice')->where('is_active', 1)->pluck('item_id'); $splices = UserItem::where('user_id', $user->id)->whereIn('item_id', $tags)->where('count', '>', 0)->with('item')->get()->pluck('item.name', 'id'); + return view('user.pet', [ - 'user' => $user, - 'pet' => $pet, - 'drops' => $pet->drops, + 'user' => $user, + 'pet' => $pet, + 'drops' => $pet->drops, 'userOptions' => User::where('id', '!=', $user->id)->orderBy('name')->pluck('name', 'id')->toArray(), - 'logs' => $user->getPetLogs(), - 'splices' => $splices, + 'logs' => $user->getPetLogs(), + 'splices' => $splices, ]); } /** * Claims pet drops. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetDropService $service - * @param string $slug + * @param App\Services\PetDropService $service + * @param mixed $id + * * @return \Illuminate\Http\RedirectResponse */ - public function postClaimPetDrops(PetDropService $service, $id) - { + public function postClaimPetDrops(PetDropService $service, $id) { $pet = UserPet::findOrFail($id); - if(!Auth::check() || $pet->user_id != Auth::user()->id) abort(404); - if(!$pet->drops) abort(404); - if($service->claimPetDrops($pet)) { - flash('Drops claimed successfully.')->success(); + if (!Auth::check() || $pet->user_id != Auth::user()->id) { + abort(404); } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); + if (!$pet->drops) { + abort(404); } + if ($service->claimPetDrops($pet)) { + flash('Drops claimed successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } + } + return redirect()->back(); } /** * Claims pet drops. * - * @param \Illuminate\Http\Request $request - * @param App\Services\PetDropService $service - * @param string $slug + * @param App\Services\PetDropService $service + * * @return \Illuminate\Http\RedirectResponse */ - public function postClaimAllPetDrops(PetDropService $service) - { + public function postClaimAllPetDrops(PetDropService $service) { $user_pet_ids = UserPet::where('user_id', Auth::user()->id)->pluck('id'); $pet_drops = PetDrop::whereIn('user_pet_id', $user_pet_ids)->where('drops_available', '>', 0)->pluck('user_pet_id'); $pets = UserPet::whereIn('id', $pet_drops)->get(); $rewards = createAssetsArray(); - foreach($pets as $pet) { - if($assets = $service->claimPetDrops($pet, false)) { + foreach ($pets as $pet) { + if ($assets = $service->claimPetDrops($pet, false)) { $rewards = mergeAssetsArrays($rewards, $assets); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } } - if(createRewardsString($rewards)) flash("You received: " . createRewardsString($rewards))->info(); - else flash('No drops to claim.')->info(); + if (createRewardsString($rewards)) { + flash('You received: '.createRewardsString($rewards))->info(); + } else { + flash('No drops to claim.')->info(); + } flash('Drops claimed successfully.')->success(); + return redirect()->back(); -} + } /** - * Post custom image + * Post custom image. + * + * @param mixed $id */ - public function postCustomImage($id, Request $request, PetManager $service) - { + public function postCustomImage($id, Request $request, PetManager $service) { $pet = UserPet::findOrFail($id); $data = $request->only(['image', 'remove_image', 'artist_id', 'artist_url', 'remove_credit']); - if(!Auth::user()->isStaff) abort(404); + if (!Auth::user()->isStaff) { + abort(404); + } - if($service->editCustomImage($pet, $data)) { + if ($service->editCustomImage($pet, $data)) { flash('Pet image updated successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } /** - * Unique image + * Unique image. + * + * @param mixed $id */ - public function postDescription($id, Request $request, PetManager $service) - { + public function postDescription($id, Request $request, PetManager $service) { $pet = UserPet::findOrFail($id); - if($service->editCustomImageDescription($pet, $request->only(['description']))) { + if ($service->editCustomImageDescription($pet, $request->only(['description']))) { flash('Pet custom image description updated successfully.')->success(); + } else { + foreach ($service->errors()->getMessages()['error'] as $error) { + flash($error)->error(); + } } - else { - foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); - } + return redirect()->back(); } } diff --git a/app/Http/Controllers/Users/UserController.php b/app/Http/Controllers/Users/UserController.php index d03ee35c9e..6855e94aa6 100644 --- a/app/Http/Controllers/Users/UserController.php +++ b/app/Http/Controllers/Users/UserController.php @@ -12,12 +12,11 @@ use App\Models\Gallery\GallerySubmission; use App\Models\Item\Item; use App\Models\Item\ItemCategory; -use App\Models\User\UserPet; use App\Models\Pet\Pet; use App\Models\Pet\PetCategory; -use App\Models\Pet\PetLog; use App\Models\User\User; use App\Models\User\UserCurrency; +use App\Models\User\UserPet; use Auth; use Illuminate\Http\Request; use Illuminate\Support\Facades\View; @@ -227,38 +226,40 @@ public function getUserInventory($name) { /** * Shows a user's pets. * - * @param string $name + * @param string $name + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getUserPets($name) - { + public function getUserPets($name) { $categories = PetCategory::orderBy('sort', 'DESC')->get(); $pets = count($categories) ? $this->user->pets()->orderByRaw('FIELD(pet_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')->orderBy('name')->orderBy('updated_at')->get()->groupBy('pet_category_id') : $this->user->pets()->orderBy('name')->orderBy('updated_at')->get()->groupBy('pet_category_id'); + return view('user.pets', [ - 'user' => $this->user, - 'categories' => $categories->keyBy('id'), - 'pets' => $pets, + 'user' => $this->user, + 'categories' => $categories->keyBy('id'), + 'pets' => $pets, 'userOptions' => User::where('id', '!=', $this->user->id)->orderBy('name')->pluck('name', 'id')->toArray(), - 'user' => $this->user, - 'logs' => $this->user->getPetLogs() + 'user' => $this->user, + 'logs' => $this->user->getPetLogs(), ]); } /** * Shows a user's pets. * - * @param string $name + * @param string $name + * @param mixed $id + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getUserPet($name, $id) - { + public function getUserPet($name, $id) { $pet = UserPet::findOrFail($id); return view('user.pet', [ - 'user' => $this->user, - 'pet' => $pet, + 'user' => $this->user, + 'pet' => $pet, 'userOptions' => User::where('id', '!=', $this->user->id)->orderBy('name')->pluck('name', 'id')->toArray(), - 'logs' => $this->user->getPetLogs() + 'logs' => $this->user->getPetLogs(), ]); } @@ -313,18 +314,19 @@ public function getUserItemLogs($name) { ]); } - /** + /** * Shows a user's pet logs. * - * @param string $name + * @param string $name + * * @return \Illuminate\Contracts\Support\Renderable */ - public function getUserPetLogs($name) - { + public function getUserPetLogs($name) { $user = $this->user; + return view('user.pet_logs', [ 'user' => $this->user, - 'logs' => $this->user->getPetLogs(0) + 'logs' => $this->user->getPetLogs(0), ]); } diff --git a/app/Http/Controllers/WorldController.php b/app/Http/Controllers/WorldController.php index 1f1ac01ceb..0e31feaa4f 100644 --- a/app/Http/Controllers/WorldController.php +++ b/app/Http/Controllers/WorldController.php @@ -7,14 +7,14 @@ use App\Models\Feature\FeatureCategory; use App\Models\Item\Item; use App\Models\Item\ItemCategory; +use App\Models\Pet\Pet; +use App\Models\Pet\PetCategory; use App\Models\Rarity; use App\Models\Shop\Shop; use App\Models\Shop\ShopStock; use App\Models\Species\Species; use App\Models\Species\Subtype; use App\Models\User\User; -use App\Models\Pet\PetCategory; -use App\Models\Pet\Pet; use Auth; use Config; use Illuminate\Http\Request; @@ -382,10 +382,13 @@ public function getItem($id) { 'name' => $item->displayName, 'description' => $item->parsed_description, 'categories' => $categories->keyBy('id'), - 'shops' => Shop::where(function($shops) { - if(Auth::check() && Auth::user()->isStaff) return $shops; - return $shops->where('is_staff', 0); - })->whereIn('id', ShopStock::where('item_id', $item->id)->pluck('shop_id')->unique()->toArray())->orderBy('sort', 'DESC')->get() + 'shops' => Shop::where(function ($shops) { + if (Auth::check() && Auth::user()->isStaff) { + return $shops; + } + + return $shops->where('is_staff', 0); + })->whereIn('id', ShopStock::where('item_id', $item->id)->pluck('shop_id')->unique()->toArray())->orderBy('sort', 'DESC')->get(), ]); } @@ -409,14 +412,15 @@ public function getCharacterCategories(Request $request) { /** * Shows the pet categories page. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\Support\Renderable */ - public function getPetCategories(Request $request) - { + public function getPetCategories(Request $request) { $query = PetCategory::query(); $name = $request->get('name'); - if($name) $query->where('name', 'LIKE', '%'.$name.'%'); + if ($name) { + $query->where('name', 'LIKE', '%'.$name.'%'); + } + return view('world.pet_categories', [ 'categories' => $query->orderBy('sort', 'DESC')->paginate(20)->appends($request->query()), ]); @@ -425,21 +429,20 @@ public function getPetCategories(Request $request) /** * Shows the pets page. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\Support\Renderable */ - public function getPets(Request $request) - { + public function getPets(Request $request) { $query = Pet::with('category'); $data = $request->only(['pet_category_id', 'name', 'sort']); - if(isset($data['pet_category_id']) && $data['pet_category_id'] != 'none') + if (isset($data['pet_category_id']) && $data['pet_category_id'] != 'none') { $query->where('pet_category_id', $data['pet_category_id']); - if(isset($data['name'])) + } + if (isset($data['name'])) { $query->where('name', 'LIKE', '%'.$data['name'].'%'); + } - if(isset($data['sort'])) - { - switch($data['sort']) { + if (isset($data['sort'])) { + switch ($data['sort']) { case 'alpha': $query->sortAlphabetical(); break; @@ -456,22 +459,24 @@ public function getPets(Request $request) $query->sortOldest(); break; } + } else { + $query->sortCategory(); } - else $query->sortCategory(); return view('world.pets', [ - 'pets' => $query->paginate(20)->appends($request->query()), - 'categories' => ['none' => 'Any Category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray() + 'pets' => $query->paginate(20)->appends($request->query()), + 'categories' => ['none' => 'Any Category'] + PetCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(), ]); } /** * Gets a specific pet page. * + * @param mixed $id */ - public function getPet($id) - { + public function getPet($id) { $pet = Pet::with('category')->findOrFail($id); + return view('world.pet_page', [ 'pet' => $pet, ]); diff --git a/app/Models/Character/Character.php b/app/Models/Character/Character.php index db23a614ed..6a3b73165c 100644 --- a/app/Models/Character/Character.php +++ b/app/Models/Character/Character.php @@ -172,11 +172,10 @@ public function rarity() { return $this->belongsTo('App\Models\Rarity', 'rarity_id'); } - public function pets() - { + public function pets() { return $this->hasMany('App\Models\User\UserPet', 'chara_id'); } - + /** * Get the character's associated gallery submissions. */ diff --git a/app/Models/Pet/Pet.php b/app/Models/Pet/Pet.php index b6ffad8ccf..99bc5cd536 100644 --- a/app/Models/Pet/Pet.php +++ b/app/Models/Pet/Pet.php @@ -2,21 +2,18 @@ namespace App\Models\Pet; -use Config; -use DB; use App\Models\Model; -use App\Models\Pet\PetCategory; use App\Models\User\UserPet; +use DB; -class Pet extends Model -{ +class Pet extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'pet_category_id', 'name', 'has_image', 'description', 'parsed_description', 'allow_transfer', 'limit', 'evolution_stage' + 'pet_category_id', 'name', 'has_image', 'description', 'parsed_description', 'allow_transfer', 'limit', 'evolution_stage', ]; /** @@ -33,9 +30,9 @@ class Pet extends Model */ public static $createRules = [ 'pet_category_id' => 'nullable', - 'name' => 'required|unique:pets|between:3,25', - 'description' => 'nullable', - 'image' => 'mimes:png', + 'name' => 'required|unique:pets|between:3,25', + 'description' => 'nullable', + 'image' => 'mimes:png', ]; /** @@ -45,9 +42,9 @@ class Pet extends Model */ public static $updateRules = [ 'pet_category_id' => 'nullable', - 'name' => 'required|between:3,25', - 'description' => 'nullable', - 'image' => 'mimes:png', + 'name' => 'required|between:3,25', + 'description' => 'nullable', + 'image' => 'mimes:png', ]; /********************************************************************************************** @@ -59,32 +56,28 @@ class Pet extends Model /** * Get the category the pet belongs to. */ - public function category() - { + public function category() { return $this->belongsTo('App\Models\Pet\PetCategory', 'pet_category_id'); } /** - * get all the pet variants + * get all the pet variants. */ - public function variants() - { + public function variants() { return $this->hasMany('App\Models\Pet\PetVariant', 'pet_id'); } /** - * get the pets evolutions + * get the pets evolutions. */ - public function evolutions() - { + public function evolutions() { return $this->hasMany('App\Models\Pet\PetEvolution', 'pet_id'); } /** * Get the drop data associated with this species. */ - public function dropData() - { + public function dropData() { return $this->hasOne('App\Models\Pet\PetDropData'); } @@ -97,46 +90,47 @@ public function dropData() /** * Scope a query to sort pets in alphabetical order. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param bool $reverse + * @param \Illuminate\Database\Eloquent\Builder $query + * @param bool $reverse + * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeSortAlphabetical($query, $reverse = false) - { + public function scopeSortAlphabetical($query, $reverse = false) { return $query->orderBy('name', $reverse ? 'DESC' : 'ASC'); } /** * Scope a query to sort pets in category order. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query + * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeSortCategory($query) - { + public function scopeSortCategory($query) { $ids = PetCategory::orderBy('sort', 'DESC')->pluck('id')->toArray(); + return count($ids) ? $query->orderByRaw(DB::raw('FIELD(pet_category_id, '.implode(',', $ids).')')) : $query; } /** * Scope a query to sort pets by newest first. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query + * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeSortNewest($query) - { + public function scopeSortNewest($query) { return $query->orderBy('id', 'DESC'); } /** * Scope a query to sort features oldest first. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query + * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeSortOldest($query) - { + public function scopeSortOldest($query) { return $query->orderBy('id'); } @@ -151,8 +145,7 @@ public function scopeSortOldest($query) * * @return string */ - public function getDisplayNameAttribute() - { + public function getDisplayNameAttribute() { return ''.$this->name.''; } @@ -161,8 +154,7 @@ public function getDisplayNameAttribute() * * @return string */ - public function getImageDirectoryAttribute() - { + public function getImageDirectoryAttribute() { return 'images/data/pets'; } @@ -171,9 +163,8 @@ public function getImageDirectoryAttribute() * * @return string */ - public function getImageFileNameAttribute() - { - return $this->id . '-image.png'; + public function getImageFileNameAttribute() { + return $this->id.'-image.png'; } /** @@ -181,8 +172,7 @@ public function getImageFileNameAttribute() * * @return string */ - public function getImagePathAttribute() - { + public function getImagePathAttribute() { return public_path($this->imageDirectory); } @@ -191,10 +181,12 @@ public function getImagePathAttribute() * * @return string */ - public function getImageUrlAttribute() - { - if (!$this->has_image) return null; - return asset($this->imageDirectory . '/' . $this->imageFileName); + public function getImageUrlAttribute() { + if (!$this->has_image) { + return null; + } + + return asset($this->imageDirectory.'/'.$this->imageFileName); } /** @@ -202,8 +194,7 @@ public function getImageUrlAttribute() * * @return string */ - public function getUrlAttribute() - { + public function getUrlAttribute() { return url('world/pets?name='.$this->name); } @@ -212,8 +203,7 @@ public function getUrlAttribute() * * @return string */ - public function getIdUrlAttribute() - { + public function getIdUrlAttribute() { return url('world/pets/'.$this->id); } @@ -222,36 +212,50 @@ public function getIdUrlAttribute() * * @return string */ - public function getAssetTypeAttribute() - { + public function getAssetTypeAttribute() { return 'pets'; } /** - * returns the variant image for the pet + * returns the variant image for the pet. + * + * @param mixed|null $id */ - public function VariantImage($id = null) - { - if(!$id) return $this->imageUrl; + public function VariantImage($id = null) { + if (!$id) { + return $this->imageUrl; + } $userpet = UserPet::find($id); - if (!$userpet) return $this->imageUrl; + if (!$userpet) { + return $this->imageUrl; + } // custom image takes prescendence over all other images - else if ($userpet->has_image) return $userpet->imageUrl; + elseif ($userpet->has_image) { + return $userpet->imageUrl; + } // check if there is an evolution and variant - else if ($userpet->evolution_id && $userpet->variant_id) return $userpet->evolution->variantImageUrl($userpet->variant_id); + elseif ($userpet->evolution_id && $userpet->variant_id) { + return $userpet->evolution->variantImageUrl($userpet->variant_id); + } // evolution > variant - else if ($userpet->evolution_id) return $userpet->evolution->imageUrl; - else if ($userpet->variant_id) return $userpet->variant->imageUrl; + elseif ($userpet->evolution_id) { + return $userpet->evolution->imageUrl; + } elseif ($userpet->variant_id) { + return $userpet->variant->imageUrl; + } + //default return $this->imageUrl; } - public function VariantName($id = null) - { - if(!$id || !$this->variants() ) return ''; - else return $this->variants()->where('id', $id)->first()->variant_name; + public function VariantName($id = null) { + if (!$id || !$this->variants()) { + return ''; + } else { + return $this->variants()->where('id', $id)->first()->variant_name; + } } /** @@ -259,9 +263,11 @@ public function VariantName($id = null) * * @return string */ - public function getHasDropsAttribute() - { - if($this->dropData) return 1; - else return 0; + public function getHasDropsAttribute() { + if ($this->dropData) { + return 1; + } else { + return 0; + } } } diff --git a/app/Models/Pet/PetCategory.php b/app/Models/Pet/PetCategory.php index ebfe58cb39..58e30918cc 100644 --- a/app/Models/Pet/PetCategory.php +++ b/app/Models/Pet/PetCategory.php @@ -2,11 +2,9 @@ namespace App\Models\Pet; -use Config; use App\Models\Model; -class PetCategory extends Model -{ +class PetCategory extends Model { /** * The attributes that are mass assignable. * @@ -29,9 +27,9 @@ class PetCategory extends Model * @var array */ public static $createRules = [ - 'name' => 'required|unique:pet_categories|between:3,25', + 'name' => 'required|unique:pet_categories|between:3,25', 'description' => 'nullable', - 'image' => 'mimes:png', + 'image' => 'mimes:png', ]; /** @@ -40,9 +38,9 @@ class PetCategory extends Model * @var array */ public static $updateRules = [ - 'name' => 'required|between:3,25', + 'name' => 'required|between:3,25', 'description' => 'nullable', - 'image' => 'mimes:png', + 'image' => 'mimes:png', ]; /********************************************************************************************** @@ -56,8 +54,7 @@ class PetCategory extends Model * * @return string */ - public function getDisplayNameAttribute() - { + public function getDisplayNameAttribute() { return ''.$this->name.''; } @@ -66,8 +63,7 @@ public function getDisplayNameAttribute() * * @return string */ - public function getImageDirectoryAttribute() - { + public function getImageDirectoryAttribute() { return 'images/data/pet-categories'; } @@ -76,9 +72,8 @@ public function getImageDirectoryAttribute() * * @return string */ - public function getCategoryImageFileNameAttribute() - { - return $this->id . '-image.png'; + public function getCategoryImageFileNameAttribute() { + return $this->id.'-image.png'; } /** @@ -86,8 +81,7 @@ public function getCategoryImageFileNameAttribute() * * @return string */ - public function getCategoryImagePathAttribute() - { + public function getCategoryImagePathAttribute() { return public_path($this->imageDirectory); } @@ -96,10 +90,12 @@ public function getCategoryImagePathAttribute() * * @return string */ - public function getCategoryImageUrlAttribute() - { - if (!$this->has_image) return null; - return asset($this->imageDirectory . '/' . $this->categoryImageFileName); + public function getCategoryImageUrlAttribute() { + if (!$this->has_image) { + return null; + } + + return asset($this->imageDirectory.'/'.$this->categoryImageFileName); } /** @@ -107,8 +103,7 @@ public function getCategoryImageUrlAttribute() * * @return string */ - public function getUrlAttribute() - { + public function getUrlAttribute() { return url('world/pet-categories?name='.$this->name); } @@ -117,8 +112,7 @@ public function getUrlAttribute() * * @return string */ - public function getSearchUrlAttribute() - { + public function getSearchUrlAttribute() { return url('world/pets?pet_category_id='.$this->id); } } diff --git a/app/Models/Pet/PetDrop.php b/app/Models/Pet/PetDrop.php index 4b298766e3..1340993964 100644 --- a/app/Models/Pet/PetDrop.php +++ b/app/Models/Pet/PetDrop.php @@ -2,29 +2,19 @@ namespace App\Models\Pet; -use Config; -use DB; -use Carbon\Carbon; -use Notifications; use App\Models\Model; - use App\Models\User\User; use App\Models\User\UserPet; -use App\Models\Pet\Pet; -use App\Models\Pet\PetDropData; -use App\Models\Item\Item; -use App\Models\Item\ItemLog; - -class PetDrop extends Model -{ +use Carbon\Carbon; +class PetDrop extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'drop_id', 'user_pet_id', 'parameters', 'drops_available', 'next_day' + 'drop_id', 'user_pet_id', 'parameters', 'drops_available', 'next_day', ]; /** @@ -50,16 +40,14 @@ class PetDrop extends Model /** * Get the associated user pet. */ - public function user_pet() - { + public function user_pet() { return $this->belongsTo('App\Models\User\UserPet', 'user_pet_id'); } /** * Get the category the user pet belongs to. */ - public function dropData() - { + public function dropData() { return $this->belongsTo('App\Models\Pet\PetDropData', 'drop_id'); } @@ -72,11 +60,11 @@ public function dropData() /** * Scope a query to only include drops that require updating. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query + * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeRequiresUpdate($query) - { + public function scopeRequiresUpdate($query) { return $query->whereNotIn('user_pet_id', UserPet::pluck('pet_id')->toArray())->whereIn('drop_id', PetDropData::where('is_active', 1)->pluck('id')->toArray())->where('next_day', '<', Carbon::now()); } @@ -88,12 +76,13 @@ public function scopeRequiresUpdate($query) /** * Get the display of the group a user pet belongs to, so long as the species has more than one. - * */ - public function getGroupAttribute() - { - if(count($this->dropData->parameters) > 1) return ' ('.$this->parameters.')'; - else return null; + public function getGroupAttribute() { + if (count($this->dropData->parameters) > 1) { + return ' ('.$this->parameters.')'; + } else { + return null; + } } /********************************************************************************************** @@ -105,18 +94,18 @@ public function getGroupAttribute() /** * Create drop info for a user pet. * - * @param int $id + * @param int $id + * @param mixed|null $parameters */ - public function createDrop($id, $parameters = null) - { + public function createDrop($id, $parameters = null) { $user_pet = UserPet::find($id); $dropData = $user_pet->pet->dropData; $drop = $this->create([ - 'drop_id' => $dropData->id, - 'user_pet_id' => $id, - 'parameters' => $parameters ? $parameters : $dropData->rollParameters(), + 'drop_id' => $dropData->id, + 'user_pet_id' => $id, + 'parameters' => $parameters ? $parameters : $dropData->rollParameters(), 'drops_available' => 0, - 'next_day' => Carbon::now()->add($dropData->frequency, $dropData->interval)->startOf($dropData->interval), + 'next_day' => Carbon::now()->add($dropData->frequency, $dropData->interval)->startOf($dropData->interval), ]); } } diff --git a/app/Models/Pet/PetDropData.php b/app/Models/Pet/PetDropData.php index 2f01dfba5e..932ad46bb2 100644 --- a/app/Models/Pet/PetDropData.php +++ b/app/Models/Pet/PetDropData.php @@ -2,27 +2,9 @@ namespace App\Models\Pet; -use Config; -use DB; -use Carbon\Carbon; -use Notifications; use App\Models\Model; -use App\Models\Species\Species; -use App\Models\Species\Subtype; -use App\Models\Character\Character; - -use App\Models\User\UserPet; -use App\Models\Pet\Pet; -use App\Models\Pet\PetVariant; -use App\Models\Pet\PetDrop; - -use App\Models\Currency\Currency; -use App\Models\Item\Item; - -class PetDropData extends Model -{ - +class PetDropData extends Model { /** * The attributes that are mass assignable. * @@ -45,9 +27,9 @@ class PetDropData extends Model * @var array */ public static $createRules = [ - 'pet_id' => 'required|unique:pet_drop_data', + 'pet_id' => 'required|unique:pet_drop_data', 'drop_frequency' => 'required', - 'drop_interval' => 'required' + 'drop_interval' => 'required', ]; /** @@ -57,7 +39,7 @@ class PetDropData extends Model */ public static $updateRules = [ 'drop_frequency' => 'required', - 'drop_interval' => 'required' + 'drop_interval' => 'required', ]; /********************************************************************************************** @@ -69,24 +51,21 @@ class PetDropData extends Model /** * Get the pet to which the data pertains. */ - public function pet() - { + public function pet() { return $this->belongsTo('App\Models\Pet\Pet', 'pet_id'); } /** * Get the pet to which the data pertains. */ - public function user_pet() - { + public function user_pet() { return $this->belongsTo('App\Models\Pet\Pet', 'pet_id'); } /** * Get any pet drops using this data. */ - public function petDrops() - { + public function petDrops() { return $this->hasMany('App\Models\Pet\PetDrop', 'drop_id'); } @@ -101,8 +80,7 @@ public function petDrops() * * @return array */ - public function getUrlAttribute() - { + public function getUrlAttribute() { return url('admin/data/pets/drops/edit/'.$this->pet_id); } @@ -111,10 +89,12 @@ public function getUrlAttribute() * * @return array */ - public function getParametersAttribute() - { - if(isset($this->attributes['parameters'])) return json_decode($this->attributes['parameters'], true); - else return null; + public function getParametersAttribute() { + if (isset($this->attributes['parameters'])) { + return json_decode($this->attributes['parameters'], true); + } else { + return null; + } } /** @@ -122,9 +102,11 @@ public function getParametersAttribute() * * @return array */ - public function getParameterArrayAttribute() - { - foreach($this->parameters as $parameter=>$weight) $paramArray[$parameter] = $parameter; + public function getParameterArrayAttribute() { + foreach ($this->parameters as $parameter=>$weight) { + $paramArray[$parameter] = $parameter; + } + return $paramArray; } @@ -133,10 +115,12 @@ public function getParameterArrayAttribute() * * @return array */ - public function getDataAttribute() - { - if(isset($this->attributes['data'])) return json_decode($this->attributes['data'], true); - else return null; + public function getDataAttribute() { + if (isset($this->attributes['data'])) { + return json_decode($this->attributes['data'], true); + } else { + return null; + } } /** @@ -144,8 +128,7 @@ public function getDataAttribute() * * @return array */ - public function getIsActiveAttribute() - { + public function getIsActiveAttribute() { return $this->attributes['is_active']; } @@ -154,9 +137,8 @@ public function getIsActiveAttribute() * * @return array */ - public function getCapAttribute() - { - return isset($this->data['cap']) ? $this->data['cap'] : null; + public function getCapAttribute() { + return $this->data['cap'] ?? null; } /********************************************************************************************** @@ -170,37 +152,40 @@ public function getCapAttribute() * * @return string */ - public function rollParameters() - { + public function rollParameters() { $parameters = $this->parameters; $totalWeight = 0; - foreach($parameters as $parameter=>$weight) $totalWeight += $weight; + foreach ($parameters as $parameter=>$weight) { + $totalWeight += $weight; + } - for($i = 0; $i < 1; $i++) - { + for ($i = 0; $i < 1; $i++) { $roll = mt_rand(0, $totalWeight - 1); $result = null; $prev = null; $count = 0; - foreach($parameters as $parameter=>$weight) - { + foreach ($parameters as $parameter=>$weight) { $count += $weight; - if($roll < $count) - { + if ($roll < $count) { $result = $parameter; break; } $prev = $parameter; } - if(!$result) $result = $prev; + if (!$result) { + $result = $prev; + } } + return $result; } /** * Get the rewards for the submission/claim. * + * @param mixed $namespace + * * @return array */ public function Rewards($namespace = false) { @@ -215,13 +200,15 @@ public function Rewards($namespace = false) { 'rewardable_type' => $class, 'rewardable_id' => $id, 'min_quantity' => $asset['min_quantity'], - 'max_quantity' => $asset['max_quantity'] + 'max_quantity' => $asset['max_quantity'], ]; } } } + return $rewards; } + return null; } } diff --git a/app/Models/Pet/PetEvolution.php b/app/Models/Pet/PetEvolution.php index ff2877bfea..1588036772 100644 --- a/app/Models/Pet/PetEvolution.php +++ b/app/Models/Pet/PetEvolution.php @@ -5,30 +5,29 @@ use App\Models\Model; use File; -class PetEvolution extends Model -{ +class PetEvolution extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'pet_id', 'evolution_name', 'evolution_stage' + 'pet_id', 'evolution_name', 'evolution_stage', ]; /** - * Whether the model contains timestamps to be saved and updated. + * The table associated with the model. * * @var string */ - public $timestamps = false; + protected $table = 'pet_evolutions'; /** - * The table associated with the model. + * Whether the model contains timestamps to be saved and updated. * * @var string */ - protected $table = 'pet_evolutions'; + public $timestamps = false; /********************************************************************************************** @@ -39,8 +38,7 @@ class PetEvolution extends Model /** * Get the pet associated with this pet stack. */ - public function pet() - { + public function pet() { return $this->belongsTo('App\Models\Pet\Pet'); } @@ -55,8 +53,7 @@ public function pet() * * @return string */ - public function getDisplayNameAttribute() - { + public function getDisplayNameAttribute() { return ''.$this->name.' '.$this->pet->name.''; } @@ -65,8 +62,7 @@ public function getDisplayNameAttribute() * * @return string */ - public function getImageDirectoryAttribute() - { + public function getImageDirectoryAttribute() { return 'images/data/pets/evolutions'; } @@ -75,9 +71,8 @@ public function getImageDirectoryAttribute() * * @return string */ - public function getImageFileNameAttribute() - { - return $this->pet_id .'-evolution-'. $this->id .'-image.png'; + public function getImageFileNameAttribute() { + return $this->pet_id.'-evolution-'.$this->id.'-image.png'; } /** @@ -85,8 +80,7 @@ public function getImageFileNameAttribute() * * @return string */ - public function getImagePathAttribute() - { + public function getImagePathAttribute() { return public_path($this->imageDirectory); } @@ -95,9 +89,8 @@ public function getImagePathAttribute() * * @return string */ - public function getImageUrlAttribute() - { - return asset($this->imageDirectory . '/' . $this->imageFileName); + public function getImageUrlAttribute() { + return asset($this->imageDirectory.'/'.$this->imageFileName); } /********************************************************************************************** @@ -111,19 +104,19 @@ public function getImageUrlAttribute() * * @return string */ - public function getVariantImageDirectoryAttribute() - { + public function getVariantImageDirectoryAttribute() { return 'images/data/pets/evolutions'; } /** * Gets the file name of the model's variant image. * + * @param mixed $id + * * @return string */ - public function variantImageFileName($id) - { - return $this->pet_id .'-evolution-'. $this->id .'-variant-'. $id .'-image.png'; + public function variantImageFileName($id) { + return $this->pet_id.'-evolution-'.$this->id.'-variant-'.$id.'-image.png'; } /** @@ -131,26 +124,27 @@ public function variantImageFileName($id) * * @return string */ - public function getVariantImagePathAttribute() - { + public function getVariantImagePathAttribute() { return public_path($this->variantImageDirectory); } /** * Gets the URL of the model's variant image. * + * @param mixed $id + * * @return string */ - public function variantImageUrl($id) - { - return asset($this->variantImageDirectory . '/' . $this->variantImageFileName($id)); + public function variantImageUrl($id) { + return asset($this->variantImageDirectory.'/'.$this->variantImageFileName($id)); } /** - * checks if variant image file exists + * checks if variant image file exists. + * + * @param mixed $id */ - public function variantImageExists($id) - { - return File::exists($this->variantImagePath . '/' . $this->variantImageFileName($id)); + public function variantImageExists($id) { + return File::exists($this->variantImagePath.'/'.$this->variantImageFileName($id)); } } diff --git a/app/Models/Pet/PetLog.php b/app/Models/Pet/PetLog.php index 2a3a29b8e5..6e181ef44f 100644 --- a/app/Models/Pet/PetLog.php +++ b/app/Models/Pet/PetLog.php @@ -2,20 +2,18 @@ namespace App\Models\Pet; -use Config; use App\Models\Model; -class PetLog extends Model -{ +class PetLog extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'sender_id', 'recipient_id', + 'sender_id', 'recipient_id', 'log', 'log_type', 'data', - 'pet_id', 'quantity', 'stack_id' + 'pet_id', 'quantity', 'stack_id', ]; /** @@ -33,7 +31,7 @@ class PetLog extends Model public $timestamps = true; /********************************************************************************************** - + RELATIONS **********************************************************************************************/ @@ -41,24 +39,21 @@ class PetLog extends Model /** * Get the user who initiated the logged action. */ - public function sender() - { + public function sender() { return $this->belongsTo('App\Models\User\User', 'sender_id'); } /** * Get the user who received the logged action. */ - public function recipient() - { + public function recipient() { return $this->belongsTo('App\Models\User\User', 'recipient_id'); } /** * Get the pet that is the target of the action. */ - public function pet() - { + public function pet() { return $this->belongsTo('App\Models\Pet\Pet'); } } diff --git a/app/Models/Pet/PetVariant.php b/app/Models/Pet/PetVariant.php index 470591d199..db2910d28d 100644 --- a/app/Models/Pet/PetVariant.php +++ b/app/Models/Pet/PetVariant.php @@ -4,30 +4,29 @@ use App\Models\Model; -class PetVariant extends Model -{ +class PetVariant extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'pet_id', 'variant_name', 'has_image' + 'pet_id', 'variant_name', 'has_image', ]; /** - * Whether the model contains timestamps to be saved and updated. + * The table associated with the model. * * @var string */ - public $timestamps = false; + protected $table = 'pet_variants'; /** - * The table associated with the model. + * Whether the model contains timestamps to be saved and updated. * * @var string */ - protected $table = 'pet_variants'; + public $timestamps = false; /********************************************************************************************** @@ -38,16 +37,14 @@ class PetVariant extends Model /** * Get the pet associated with this pet stack. */ - public function pet() - { + public function pet() { return $this->belongsTo('App\Models\Pet\Pet'); } /** - * gets the variants drop data + * gets the variants drop data. */ - public function dropData() - { + public function dropData() { return $this->hasOne('App\Models\Pet\PetVariantDropData', 'variant_id'); } @@ -62,8 +59,7 @@ public function dropData() * * @return string */ - public function getDisplayNameAttribute() - { + public function getDisplayNameAttribute() { return ''.$this->name.' '.$this->pet->name.''; } @@ -72,8 +68,7 @@ public function getDisplayNameAttribute() * * @return string */ - public function getImageDirectoryAttribute() - { + public function getImageDirectoryAttribute() { return 'images/data/pets'; } @@ -82,9 +77,8 @@ public function getImageDirectoryAttribute() * * @return string */ - public function getImageFileNameAttribute() - { - return $this->pet_id .'-variant-'. $this->id .'-image.png'; + public function getImageFileNameAttribute() { + return $this->pet_id.'-variant-'.$this->id.'-image.png'; } /** @@ -92,8 +86,7 @@ public function getImageFileNameAttribute() * * @return string */ - public function getImagePathAttribute() - { + public function getImagePathAttribute() { return public_path($this->imageDirectory); } @@ -102,9 +95,11 @@ public function getImagePathAttribute() * * @return string */ - public function getImageUrlAttribute() - { - if (!$this->has_image) return null; - return asset($this->imageDirectory . '/' . $this->imageFileName); + public function getImageUrlAttribute() { + if (!$this->has_image) { + return null; + } + + return asset($this->imageDirectory.'/'.$this->imageFileName); } } diff --git a/app/Models/Pet/PetVariantDropData.php b/app/Models/Pet/PetVariantDropData.php index be70dfeea3..d6b6f5e261 100644 --- a/app/Models/Pet/PetVariantDropData.php +++ b/app/Models/Pet/PetVariantDropData.php @@ -2,19 +2,16 @@ namespace App\Models\Pet; -use Config; use App\Models\Model; -class PetVariantDropData extends Model -{ - +class PetVariantDropData extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'pet_drop_data_id', 'variant_id', 'data' + 'pet_drop_data_id', 'variant_id', 'data', ]; /** @@ -30,9 +27,9 @@ class PetVariantDropData extends Model * @var array */ public static $createRules = [ - 'variant_id' => 'required|unique:pet_variant_drop_data', + 'variant_id' => 'required|unique:pet_variant_drop_data', 'drop_frequency' => 'required', - 'drop_interval' => 'required' + 'drop_interval' => 'required', ]; /** @@ -42,7 +39,7 @@ class PetVariantDropData extends Model */ public static $updateRules = [ 'drop_frequency' => 'required', - 'drop_interval' => 'required' + 'drop_interval' => 'required', ]; /********************************************************************************************** @@ -54,16 +51,14 @@ class PetVariantDropData extends Model /** * Get the pet to which the data pertains. */ - public function variant() - { + public function variant() { return $this->belongsTo('App\Models\Pet\PetVariant', 'variant_id'); } /** * Get any pet drops using this data. */ - public function petDrops() - { + public function petDrops() { return $this->hasMany('App\Models\Pet\PetDrop', 'drop_id'); } @@ -78,8 +73,7 @@ public function petDrops() * * @return array */ - public function getUrlAttribute() - { + public function getUrlAttribute() { return url('admin/data/pets/drops/edit/'.$this->pet->id.'/variants/'.$this->variant_id); } @@ -88,10 +82,12 @@ public function getUrlAttribute() * * @return array */ - public function getParametersAttribute() - { - if(isset($this->attributes['parameters'])) return json_decode($this->attributes['parameters'], true); - else return null; + public function getParametersAttribute() { + if (isset($this->attributes['parameters'])) { + return json_decode($this->attributes['parameters'], true); + } else { + return null; + } } /** @@ -99,9 +95,11 @@ public function getParametersAttribute() * * @return array */ - public function getParameterArrayAttribute() - { - foreach($this->parameters as $parameter=>$weight) $paramArray[$parameter] = $parameter; + public function getParameterArrayAttribute() { + foreach ($this->parameters as $parameter=>$weight) { + $paramArray[$parameter] = $parameter; + } + return $paramArray; } @@ -110,10 +108,12 @@ public function getParameterArrayAttribute() * * @return array */ - public function getDataAttribute() - { - if(isset($this->attributes['data'])) return json_decode($this->attributes['data'], true); - else return null; + public function getDataAttribute() { + if (isset($this->attributes['data'])) { + return json_decode($this->attributes['data'], true); + } else { + return null; + } } /** @@ -121,8 +121,7 @@ public function getDataAttribute() * * @return array */ - public function getIsActiveAttribute() - { + public function getIsActiveAttribute() { return $this->attributes['is_active']; } @@ -131,9 +130,8 @@ public function getIsActiveAttribute() * * @return array */ - public function getCapAttribute() - { - return isset($this->data['cap']) ? $this->data['cap'] : null; + public function getCapAttribute() { + return $this->data['cap'] ?? null; } /********************************************************************************************** @@ -147,37 +145,40 @@ public function getCapAttribute() * * @return string */ - public function rollParameters() - { + public function rollParameters() { $parameters = $this->parameters; $totalWeight = 0; - foreach($parameters as $parameter=>$weight) $totalWeight += $weight; + foreach ($parameters as $parameter=>$weight) { + $totalWeight += $weight; + } - for($i = 0; $i < 1; $i++) - { + for ($i = 0; $i < 1; $i++) { $roll = mt_rand(0, $totalWeight - 1); $result = null; $prev = null; $count = 0; - foreach($parameters as $parameter=>$weight) - { + foreach ($parameters as $parameter=>$weight) { $count += $weight; - if($roll < $count) - { + if ($roll < $count) { $result = $parameter; break; } $prev = $parameter; } - if(!$result) $result = $prev; + if (!$result) { + $result = $prev; + } } + return $result; } /** * Get the rewards for the submission/claim. * + * @param mixed $namespace + * * @return array */ public function Rewards($namespace = false) { @@ -192,29 +193,34 @@ public function Rewards($namespace = false) { 'rewardable_type' => $class, 'rewardable_id' => $id, 'min_quantity' => $asset['min_quantity'], - 'max_quantity' => $asset['max_quantity'] + 'max_quantity' => $asset['max_quantity'], ]; } } } + return $rewards; } + return null; } /** - * gets the rewards as a comma-seperated string + * gets the rewards as a comma-seperated string. */ - public function rewardString() - { + public function rewardString() { $string = []; - foreach($this->rewards(true) as $label => $reward_values) { - foreach($reward_values as $reward) { + foreach ($this->rewards(true) as $label => $reward_values) { + foreach ($reward_values as $reward) { $reward_object = $reward->rewardable_type::find($reward->rewardable_id); - if( $reward->min_quantity == $reward->max_quantity) $string[$label][] = $reward_object->displayname . ' ('. $reward->min_quantity .')'; - else $string[$label][] = $reward_object->displayname . ' ('. $reward->min_quantity . '-' . $reward->max_quantity .')'; + if ($reward->min_quantity == $reward->max_quantity) { + $string[$label][] = $reward_object->displayname.' ('.$reward->min_quantity.')'; + } else { + $string[$label][] = $reward_object->displayname.' ('.$reward->min_quantity.'-'.$reward->max_quantity.')'; + } } } + return $string; } } diff --git a/app/Models/Prompt/PromptReward.php b/app/Models/Prompt/PromptReward.php index 68df08f482..14877ca2b2 100644 --- a/app/Models/Prompt/PromptReward.php +++ b/app/Models/Prompt/PromptReward.php @@ -64,10 +64,10 @@ public function reward() { break; case 'Pet': return $this->belongsTo('App\Models\Pet\Pet', 'rewardable_id'); - break; + break; case 'Raffle': return $this->belongsTo('App\Models\Raffle\Raffle', 'rewardable_id'); - break; + break; } return null; diff --git a/app/Models/Shop/Shop.php b/app/Models/Shop/Shop.php index 014349b63f..fd67a93b3e 100644 --- a/app/Models/Shop/Shop.php +++ b/app/Models/Shop/Shop.php @@ -11,7 +11,7 @@ class Shop extends Model { * @var array */ protected $fillable = [ - 'name', 'sort', 'has_image', 'description', 'parsed_description', 'is_active', 'is_staff', 'use_coupons', 'is_restricted', 'is_fto', 'allowed_coupons', 'is_timed_shop', 'start_at', 'end_at' + 'name', 'sort', 'has_image', 'description', 'parsed_description', 'is_active', 'is_staff', 'use_coupons', 'is_restricted', 'is_fto', 'allowed_coupons', 'is_timed_shop', 'start_at', 'end_at', ]; /** @@ -56,20 +56,22 @@ public function stock() { /** * Get the shop stock as items for display purposes. + * + * @param mixed|null $model + * @param mixed|null $type */ - public function displayStock($model=null, $type=null) - { + public function displayStock($model = null, $type = null) { if (!$model || !$type) { return $this->belongsToMany('App\Models\Item\Item', 'shop_stock')->where('stock_type', 'Item')->withPivot('item_id', 'currency_id', 'cost', 'use_user_bank', 'use_character_bank', 'is_limited_stock', 'quantity', 'purchase_limit', 'id')->wherePivot('is_visible', 1); } + return $this->belongsToMany($model, 'shop_stock', 'shop_id', 'item_id')->where('stock_type', $type)->withPivot('item_id', 'currency_id', 'cost', 'use_user_bank', 'use_character_bank', 'is_limited_stock', 'quantity', 'purchase_limit', 'id')->wherePivot('is_visible', 1); } /** * Get the required items / assets to enter the shop. */ - public function limits() - { + public function limits() { return $this->hasMany('App\Models\Shop\ShopLimit', 'shop_id'); } @@ -144,13 +146,15 @@ public function getUrlAttribute() { **********************************************************************************************/ /** - * Gets all the coupons useable in the shop + * Gets all the coupons useable in the shop. */ - public function getAllAllowedCouponsAttribute() - { - if(!$this->use_coupons || !$this->allowed_coupons) return; + public function getAllAllowedCouponsAttribute() { + if (!$this->use_coupons || !$this->allowed_coupons) { + return; + } // Get the coupons from the id in allowed_coupons $coupons = \App\Models\Item\Item::whereIn('id', json_decode($this->allowed_coupons, 1))->get(); + return $coupons; } diff --git a/app/Models/Shop/ShopLimit.php b/app/Models/Shop/ShopLimit.php index ef7f02dc1a..d1d033d958 100644 --- a/app/Models/Shop/ShopLimit.php +++ b/app/Models/Shop/ShopLimit.php @@ -2,18 +2,16 @@ namespace App\Models\Shop; -use Config; use App\Models\Model; -class ShopLimit extends Model -{ +class ShopLimit extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'shop_id', 'item_id' + 'shop_id', 'item_id', ]; /** @@ -24,14 +22,12 @@ class ShopLimit extends Model protected $table = 'shop_limits'; /********************************************************************************************** - + RELATIONS **********************************************************************************************/ - public function item() - { + public function item() { return $this->belongsTo('App\Models\Item\Item', 'item_id'); } - -} \ No newline at end of file +} diff --git a/app/Models/Shop/ShopLog.php b/app/Models/Shop/ShopLog.php index 6b5d69f65a..4200b62d49 100644 --- a/app/Models/Shop/ShopLog.php +++ b/app/Models/Shop/ShopLog.php @@ -90,8 +90,7 @@ public function currency() { * * @return string */ - public function getItemDataAttribute() - { - return 'Purchased from '.$this->shop->name.' by '.($this->character_id ? $this->character->slug . ' (owned by ' . $this->user->name . ')' : $this->user->displayName) . ' for ' . (int)$this->cost . ' ' . $this->currency->name . '.'; + public function getItemDataAttribute() { + return 'Purchased from '.$this->shop->name.' by '.($this->character_id ? $this->character->slug.' (owned by '.$this->user->name.')' : $this->user->displayName).' for '.(int) $this->cost.' '.$this->currency->name.'.'; } } diff --git a/app/Models/Shop/ShopStock.php b/app/Models/Shop/ShopStock.php index 15476c6fda..f63e809360 100644 --- a/app/Models/Shop/ShopStock.php +++ b/app/Models/Shop/ShopStock.php @@ -12,7 +12,7 @@ class ShopStock extends Model { */ protected $fillable = [ 'shop_id', 'item_id', 'currency_id', 'cost', 'use_user_bank', 'use_character_bank', 'is_limited_stock', 'quantity', 'sort', 'purchase_limit', 'purchase_limit_timeframe', 'is_fto', 'stock_type', 'is_visible', - 'restock', 'restock_quantity', 'restock_interval', 'range', 'disallow_transfer','is_timed_stock', 'start_at', 'end_at' + 'restock', 'restock_quantity', 'restock_interval', 'range', 'disallow_transfer', 'is_timed_stock', 'start_at', 'end_at', ]; /** @@ -40,9 +40,9 @@ class ShopStock extends Model { /** * Get the item being stocked. */ - public function item() - { + public function item() { $model = getAssetModelString(strtolower($this->stock_type)); + return $this->belongsTo($model); } @@ -60,22 +60,21 @@ public function currency() { return $this->belongsTo('App\Models\Currency\Currency'); } - /* * Gets the current date associated to the current stocks purchase limit timeframe */ public function getPurchaseLimitDateAttribute() { - switch($this->purchase_limit_timeframe) { - case "yearly": + switch ($this->purchase_limit_timeframe) { + case 'yearly': $date = strtotime('January 1st'); break; - case "monthly": + case 'monthly': $date = strtotime('midnight first day of this month'); break; - case "weekly": + case 'weekly': $date = strtotime('last sunday'); break; - case "daily": + case 'daily': $date = strtotime('midnight'); break; default: @@ -92,18 +91,18 @@ public function getPurchaseLimitDateAttribute() { **********************************************************************************************/ /** - * Scopes active stock + * Scopes active stock. + * + * @param mixed $query */ - public function scopeActive($query) - { + public function scopeActive($query) { return $query->where('is_visible', 1); } /** - * Makes the cost an integer for display + * Makes the cost an integer for display. */ - public function getDisplayCostAttribute() - { - return (int)$this->cost; + public function getDisplayCostAttribute() { + return (int) $this->cost; } } diff --git a/app/Models/User/User.php b/app/Models/User/User.php index e423c68452..4fe3a92305 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -160,12 +160,10 @@ public function items() { /** * Get the user's pets. */ - public function pets() - { + public function pets() { return $this->belongsToMany('App\Models\Pet\Pet', 'user_pets')->withPivot('data', 'updated_at', 'id', 'variant_id', 'chara_id', 'pet_name', 'has_image', 'evolution_id')->whereNull('user_pets.deleted_at'); } - /** * Get all of the user's gallery submissions. */ @@ -534,19 +532,22 @@ public function getItemLogs($limit = 10) { /** * Get the user's pet logs. * - * @param int $limit - * @return \Illuminate\Support\Collection|\Illuminate\Pagination\LengthAwarePaginator + * @param int $limit + * + * @return \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection */ - public function getPetLogs($limit = 10) - { + public function getPetLogs($limit = 10) { $user = $this; - $query = PetLog::with('sender')->with('recipient')->with('pet')->where(function($query) use ($user) { + $query = PetLog::with('sender')->with('recipient')->with('pet')->where(function ($query) use ($user) { $query->where('sender_id', $user->id)->whereNotIn('log_type', ['Staff Grant', 'Staff Removal']); - })->orWhere(function($query) use ($user) { + })->orWhere(function ($query) use ($user) { $query->where('recipient_id', $user->id); })->orderBy('id', 'DESC'); - if($limit) return $query->take($limit)->get(); - else return $query->paginate(30); + if ($limit) { + return $query->take($limit)->get(); + } else { + return $query->paginate(30); + } } /** diff --git a/app/Models/User/UserPet.php b/app/Models/User/UserPet.php index eed3eaad65..0bf329dca1 100644 --- a/app/Models/User/UserPet.php +++ b/app/Models/User/UserPet.php @@ -3,11 +3,10 @@ namespace App\Models\User; use App\Models\Model; -use Illuminate\Database\Eloquent\SoftDeletes; use App\Models\Pet\PetDrop; +use Illuminate\Database\Eloquent\SoftDeletes; -class UserPet extends Model -{ +class UserPet extends Model { use SoftDeletes; /** @@ -17,22 +16,22 @@ class UserPet extends Model */ protected $fillable = [ 'data', 'pet_id', 'user_id', 'attached_at', 'pet_name', 'has_image', 'artist_url', 'artist_id', 'description', - 'evolution_id' + 'evolution_id', ]; /** - * Whether the model contains timestamps to be saved and updated. + * The table associated with the model. * * @var string */ - public $timestamps = true; + protected $table = 'user_pets'; /** - * The table associated with the model. + * Whether the model contains timestamps to be saved and updated. * * @var string */ - protected $table = 'user_pets'; + public $timestamps = true; /********************************************************************************************** @@ -43,66 +42,61 @@ class UserPet extends Model /** * Get the user who owns the stack. */ - public function user() - { + public function user() { return $this->belongsTo('App\Models\User\User'); } /** * Get the pet associated with this pet stack. */ - public function pet() - { + public function pet() { return $this->belongsTo('App\Models\Pet\Pet'); } /** * Get the character associated with this pet stack. */ - public function character() - { + public function character() { return $this->belongsTo('App\Models\Character\Character', 'chara_id'); } /** * Get the variant associated with this pet stack. */ - public function variant() - { - return $this->belongsTo('App\Models\Pet\PetVariant','variant_id'); + public function variant() { + return $this->belongsTo('App\Models\Pet\PetVariant', 'variant_id'); } /** * Get the evolution associated with this pet stack. */ - public function evolution() - { - return $this->belongsTo('App\Models\Pet\PetEvolution','evolution_id'); + public function evolution() { + return $this->belongsTo('App\Models\Pet\PetEvolution', 'evolution_id'); } /** * Get the pet's pet drop data. */ - public function drops() - { - if(!$this->pet->dropData) return $this->belongsTo('App\Models\Loot\Loot', 'rewardable_id', 'loot_table_id')->whereNull('loot_table_id'); - if(!PetDrop::where('user_pet_id', $this->id)->first()) { + public function drops() { + if (!$this->pet->dropData) { + return $this->belongsTo('App\Models\Loot\Loot', 'rewardable_id', 'loot_table_id')->whereNull('loot_table_id'); + } + if (!PetDrop::where('user_pet_id', $this->id)->first()) { $drop = new PetDrop; $drop->createDrop($this->id); - } - elseif(!PetDrop::where('user_pet_id', $this->id)->where('drop_id', $this->pet->dropData->id)->first()) { + } elseif (!PetDrop::where('user_pet_id', $this->id)->where('drop_id', $this->pet->dropData->id)->first()) { PetDrop::where('user_pet_id', $this->id)->delete; $drop = new PetDrop; $drop->createDrop($this->id); } + return $this->hasOne('App\Models\Pet\PetDrop', 'user_pet_id'); } /** * Get the user that drew the pet art. */ - public function artist() - { + public function artist() { return $this->belongsTo('App\Models\User\User', 'artist_id'); } @@ -117,8 +111,7 @@ public function artist() * * @return array */ - public function getDataAttribute() - { + public function getDataAttribute() { return json_decode($this->attributes['data'], true); } @@ -127,9 +120,11 @@ public function getDataAttribute() * * @return array */ - public function getIsTransferrableAttribute() - { - if(!isset($this->data['disallow_transfer']) && $this->pet->allow_transfer) return true; + public function getIsTransferrableAttribute() { + if (!isset($this->data['disallow_transfer']) && $this->pet->allow_transfer) { + return true; + } + return false; } @@ -138,8 +133,7 @@ public function getIsTransferrableAttribute() * * @return string */ - public function getAssetTypeAttribute() - { + public function getAssetTypeAttribute() { return 'user_pets'; } @@ -148,8 +142,7 @@ public function getAssetTypeAttribute() * * @return string */ - public function getImageDirectoryAttribute() - { + public function getImageDirectoryAttribute() { return 'images/data/user-pets'; } @@ -158,9 +151,8 @@ public function getImageDirectoryAttribute() * * @return string */ - public function getImageFileNameAttribute() - { - return $this->id . '-image.png'; + public function getImageFileNameAttribute() { + return $this->id.'-image.png'; } /** @@ -168,8 +160,7 @@ public function getImageFileNameAttribute() * * @return string */ - public function getImagePathAttribute() - { + public function getImagePathAttribute() { return public_path($this->imageDirectory); } @@ -178,10 +169,12 @@ public function getImagePathAttribute() * * @return string */ - public function getImageUrlAttribute() - { - if (!$this->has_image) return null; - return asset($this->imageDirectory . '/' . $this->imageFileName); + public function getImageUrlAttribute() { + if (!$this->has_image) { + return null; + } + + return asset($this->imageDirectory.'/'.$this->imageFileName); } /** @@ -189,24 +182,22 @@ public function getImageUrlAttribute() * * @return string */ - public function getPetArtistAttribute() - { - if(!$this->artist_url && !$this->artist_id) return null; + public function getPetArtistAttribute() { + if (!$this->artist_url && !$this->artist_id) { + return null; + } // Check to see if the artist exists on site $artist = checkAlias($this->artist_url, false); - if(is_object($artist)) { + if (is_object($artist)) { $this->artist_id = $artist->id; $this->artist_url = null; $this->save(); } - if($this->artist_id) - { + if ($this->artist_id) { return $this->artist->displayName; - } - else if ($this->artist_url) - { + } elseif ($this->artist_url) { return prettyProfileLink($this->artist_url); } } @@ -220,30 +211,36 @@ public function getPetArtistAttribute() /** * Get the url for the pet's custom page. * + * @param mixed|null $id + * * @return array */ - public function pageUrl($id = null) - { - if($id && $this->user_id == $id) return url('pets/view/' . $this->id); - return url('user/'. $this->user->name . '/pets/' . $this->id); + public function pageUrl($id = null) { + if ($id && $this->user_id == $id) { + return url('pets/view/'.$this->id); + } + + return url('user/'.$this->user->name.'/pets/'.$this->id); } /** - * gets all drops this pet is eligible for + * gets all drops this pet is eligible for. */ - public function getAvailableDropsAttribute() - { - if(!$this->pet->dropData) return null; + public function getAvailableDropsAttribute() { + if (!$this->pet->dropData) { + return null; + } $rewards = []; // otherwise return base rewards + variant rewards - if($this->variant_id) { - if($this->variant->dropData) { + if ($this->variant_id) { + if ($this->variant->dropData) { $rewards[] = $this->variant->dropData; } } - if(!$this->pet->dropData->override) { + if (!$this->pet->dropData->override) { $rewards[] = $this->pet->dropData; } + return $rewards; } } diff --git a/app/Services/Item/CouponService.php b/app/Services/Item/CouponService.php index df25b6ad20..9c538de007 100644 --- a/app/Services/Item/CouponService.php +++ b/app/Services/Item/CouponService.php @@ -1,70 +1,63 @@ -data['discount']) ? $tag->data['discount'] : null; - $couponData['infinite'] = isset($tag->data['infinite']) ? $tag->data['infinite'] : null; + $couponData['discount'] = $tag->data['discount'] ?? null; + $couponData['infinite'] = $tag->data['infinite'] ?? null; return $couponData; - } /** * Processes the data attribute of the tag and returns it in the preferred format. * - * @param string $tag - * @param array $data + * @param string $tag + * @param array $data + * * @return bool */ - public function updateData($tag, $data) - { + public function updateData($tag, $data) { DB::beginTransaction(); try { - if(!isset($data['infinite'])) $data['infinite'] = 0; + if (!isset($data['infinite'])) { + $data['infinite'] = 0; + } $coupon['discount'] = $data['discount']; $coupon['infinite'] = $data['infinite']; $tag->update(['data' => json_encode($coupon)]); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } -} \ No newline at end of file +} diff --git a/app/Services/Item/RareCandyService.php b/app/Services/Item/RareCandyService.php index 207b9b79c3..ede1276ee3 100644 --- a/app/Services/Item/RareCandyService.php +++ b/app/Services/Item/RareCandyService.php @@ -1,19 +1,12 @@ -commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } - /** * Acts upon the item when used from the inventory. * - * @param \App\Models\User\UserItem $stacks - * @param \App\Models\User\User $user - * @param array $data + * @param \App\Models\User\UserItem $stacks + * @param \App\Models\User\User $user + * @param array $data + * * @return bool */ - public function act($stacks, $user, $data) - { + public function act($stacks, $user, $data) { DB::beginTransaction(); try { - - return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } } diff --git a/app/Services/Item/SpliceService.php b/app/Services/Item/SpliceService.php index db02f9fc87..5ccae1ba3d 100644 --- a/app/Services/Item/SpliceService.php +++ b/app/Services/Item/SpliceService.php @@ -1,19 +1,12 @@ -commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } - /** * Acts upon the item when used from the inventory. * - * @param \App\Models\User\UserItem $stacks - * @param \App\Models\User\User $user - * @param array $data + * @param \App\Models\User\UserItem $stacks + * @param \App\Models\User\User $user + * @param array $data + * * @return bool */ - public function act($stacks, $user, $data) - { + public function act($stacks, $user, $data) { DB::beginTransaction(); try { - - return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } } diff --git a/app/Services/PetDropService.php b/app/Services/PetDropService.php index d9789158e2..9a7283de55 100644 --- a/app/Services/PetDropService.php +++ b/app/Services/PetDropService.php @@ -1,23 +1,19 @@ - $param) $paramData[$param] = $data['weight'][$key]; + foreach ($data['label'] as $key => $param) { + $paramData[$param] = $data['weight'][$key]; + } $drop = PetDropData::create([ - 'pet_id' => $data['pet_id'], + 'pet_id' => $data['pet_id'], 'parameters' => json_encode($paramData), - 'frequency' => $data['drop_frequency'], - 'interval' => $data['drop_interval'], - 'is_active' => $data['is_active'] ?? 0, - 'cap' => $data['drop_cap'] ?? 0, - 'name' => $data['drop_name'] ?? 'drop', - 'override' => $data['override'] ?? 0 + 'frequency' => $data['drop_frequency'], + 'interval' => $data['drop_interval'], + 'is_active' => $data['is_active'] ?? 0, + 'cap' => $data['drop_cap'] ?? 0, + 'name' => $data['drop_name'] ?? 'drop', + 'override' => $data['override'] ?? 0, ]); return $this->commitReturn($drop); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Updates pet drop data. * - * @param \App\Models\Pet\PetDropData $drop - * @param array $data - * @return bool|\App\Models\Pet\PetDropData + * @param \App\Models\Pet\PetDropData $drop + * @param array $data + * + * @return \App\Models\Pet\PetDropData|bool */ - public function updatePetDrop($drop, $data) - { + public function updatePetDrop($drop, $data) { DB::beginTransaction(); try { @@ -85,39 +86,42 @@ public function updatePetDrop($drop, $data) // Collect parameter data and encode it $paramData = []; - foreach($data['label'] as $key => $param) $paramData[$param] = $data['weight'][$key]; + foreach ($data['label'] as $key => $param) { + $paramData[$param] = $data['weight'][$key]; + } - $data['rewardable_type'] = $data['rewardable_type'] ?? null; - $data['rewardable_id'] = $data['rewardable_id'] ?? null; - $data['min_quantity'] = $data['min_quantity'] ?? null; - $data['max_quantity'] = $data['max_quantity'] ?? null; + $data['rewardable_type'] ??= null; + $data['rewardable_id'] ??= null; + $data['min_quantity'] ??= null; + $data['max_quantity'] ??= null; $drop->update([ 'parameters' => json_encode($paramData), - 'frequency' => $data['drop_frequency'], - 'interval' => $data['drop_interval'], - 'is_active' => $data['is_active'] ?? 0, - 'name' => $data['drop_name'] ?? 'drop', - 'cap' => $data['cap'] ?? null, - 'data' => $this->populateAssetData($data['rewardable_type'], $data['rewardable_id'], $data['min_quantity'], $data['max_quantity']), - 'override' => $data['override'] ?? 0 + 'frequency' => $data['drop_frequency'], + 'interval' => $data['drop_interval'], + 'is_active' => $data['is_active'] ?? 0, + 'name' => $data['drop_name'] ?? 'drop', + 'cap' => $data['cap'] ?? null, + 'data' => $this->populateAssetData($data['rewardable_type'], $data['rewardable_id'], $data['min_quantity'], $data['max_quantity']), + 'override' => $data['override'] ?? 0, ]); return $this->commitReturn($drop); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Deletes pet drop data. * - * @param \App\Models\Pet\PetDropData $drop + * @param \App\Models\Pet\PetDropData $drop + * * @return bool */ - public function deletePetDrop($drop) - { + public function deletePetDrop($drop) { DB::beginTransaction(); try { @@ -126,8 +130,8 @@ public function deletePetDrop($drop) $variants = $drop->pet->variants()->has('dropData')->get(); // Delete variant drop data - if($variants->count()) { - foreach($variants as $variant) { + if ($variants->count()) { + foreach ($variants as $variant) { $variant->dropData()->delete(); } } @@ -135,13 +139,13 @@ public function deletePetDrop($drop) $drop->delete(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } - /********************************************************************************************** PET VARIANT DROPS @@ -149,20 +153,23 @@ public function deletePetDrop($drop) **********************************************************************************************/ /** - * Creates a pet variant drop + * Creates a pet variant drop. + * + * @param mixed $data */ - public function createPetVariantDrop($data) - { + public function createPetVariantDrop($data) { DB::beginTransaction(); try { - $data['rewardable_type'] = $data['rewardable_type'] ?? null; - $data['rewardable_id'] = $data['rewardable_id'] ?? null; - $data['min_quantity'] = $data['min_quantity'] ?? null; - $data['max_quantity'] = $data['max_quantity'] ?? null; + $data['rewardable_type'] ??= null; + $data['rewardable_id'] ??= null; + $data['min_quantity'] ??= null; + $data['max_quantity'] ??= null; // check if drop data with this variant id exists - if(PetVariantDropData::where('variant_id', $data['variant_id'])->exists()) throw new \Exception('This pet variant already has drop data. Consider editing the existing data instead.'); + if (PetVariantDropData::where('variant_id', $data['variant_id'])->exists()) { + throw new \Exception('This pet variant already has drop data. Consider editing the existing data instead.'); + } PetVariantDropData::create([ 'variant_id' => $data['variant_id'], @@ -170,52 +177,56 @@ public function createPetVariantDrop($data) ]); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * Edits a pet variant drop + * Edits a pet variant drop. + * + * @param mixed $drop + * @param mixed $data */ - public function editPetVariantDrop($drop, $data) - { + public function editPetVariantDrop($drop, $data) { DB::beginTransaction(); try { - - $data['rewardable_type'] = $data['rewardable_type'] ?? null; - $data['rewardable_id'] = $data['rewardable_id'] ?? null; - $data['min_quantity'] = $data['min_quantity'] ?? null; - $data['max_quantity'] = $data['max_quantity'] ?? null; + $data['rewardable_type'] ??= null; + $data['rewardable_id'] ??= null; + $data['min_quantity'] ??= null; + $data['max_quantity'] ??= null; $drop->update([ 'data' => $this->populateAssetData($data['rewardable_type'], $data['rewardable_id'], $data['min_quantity'], $data['max_quantity']), ]); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * Deletes a pet variant drop + * Deletes a pet variant drop. + * + * @param mixed $drop */ - public function deletePetVariantDrop($drop) - { + public function deletePetVariantDrop($drop) { DB::beginTransaction(); try { - $drop->delete(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } @@ -231,24 +242,27 @@ public function deletePetVariantDrop($drop) /** * Claim pet drops and credit user the items from the drop. * - * @param \App\Models\User\UserPet $pet + * @param mixed $flash + * * @return bool */ - public function claimPetDrops(UserPet $pet, $flash = true) - { + public function claimPetDrops(UserPet $pet, $flash = true) { DB::beginTransaction(); try { - - if(!$pet->drops->drops_available) throw new \Exception('This pet doesn\'t have any available drops.'); - if(!$pet->drops->dropData->isActive) throw new \Exception('Drops are not currently active for this pet.'); + if (!$pet->drops->drops_available) { + throw new \Exception('This pet doesn\'t have any available drops.'); + } + if (!$pet->drops->dropData->isActive) { + throw new \Exception('Drops are not currently active for this pet.'); + } $rewards = createAssetsArray(); // these are handled like prompt rewards for ($i = 0; $i < $pet->drops->drops_available; $i++) { - foreach($pet->availableDrops as $drops) { - if(isset($drops->rewards(false)[strtolower($pet->drops->parameters)])) { - foreach($drops->rewards(false)[strtolower($pet->drops->parameters)] as $data) { + foreach ($pet->availableDrops as $drops) { + if (isset($drops->rewards(false)[strtolower($pet->drops->parameters)])) { + foreach ($drops->rewards(false)[strtolower($pet->drops->parameters)] as $data) { // get object switch ($data->rewardable_type) { case 'Item': @@ -274,31 +288,41 @@ public function claimPetDrops(UserPet $pet, $flash = true) } } } - if(!$final_rewards = fillUserAssets($rewards, null, $pet->user, 'Pet Drop', [ - 'data' => 'Collected from '.($pet->pet_name ? $pet->pet_name.' the '.$pet->pet->name : $pet->pet->name ), - 'notes' => 'Collected ' . format_date(Carbon::now()) - ])) throw new \Exception("Failed to distribute drops."); + if (!$final_rewards = fillUserAssets($rewards, null, $pet->user, 'Pet Drop', [ + 'data' => 'Collected from '.($pet->pet_name ? $pet->pet_name.' the '.$pet->pet->name : $pet->pet->name), + 'notes' => 'Collected '.format_date(Carbon::now()), + ])) { + throw new \Exception('Failed to distribute drops.'); + } - if ($flash) flash("You received: " . createRewardsString($final_rewards))->info(); + if ($flash) { + flash('You received: '.createRewardsString($final_rewards))->info(); + } // Clear the number of available drops $pet->drops->update(['drops_available' => 0]); return $this->commitReturn($rewards); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Creates pet drop and pet variant drop data. + * + * @param mixed $rewardable_type + * @param mixed $rewardable_id + * @param mixed $min_quantity + * @param mixed $max_quantity */ private function populateAssetData($rewardable_type, $rewardable_id, $min_quantity, $max_quantity) { $assets = []; if (isset($rewardable_type) && $rewardable_type) { foreach ($rewardable_type as $group => $types) { - foreach($types as $key=>$type) { + foreach ($types as $key=>$type) { if (!isset($assets[$group])) { $assets[$group] = createAssetsArray(); } @@ -324,7 +348,7 @@ private function populateAssetData($rewardable_type, $rewardable_id, $min_quanti } } } + return ['assets' => getDataReadyDropAssets($assets)]; } - } diff --git a/app/Services/PetManager.php b/app/Services/PetManager.php index a4a69534b3..71da7fd63d 100644 --- a/app/Services/PetManager.php +++ b/app/Services/PetManager.php @@ -1,24 +1,19 @@ -creditPet($staff, $user, 'Staff Grant', Arr::only($data, ['data', 'disallow_transfer', 'notes']), $pet, $keyed_quantities[$pet->id])) - { + foreach ($users as $user) { + foreach ($pets as $pet) { + if ($this->creditPet($staff, $user, 'Staff Grant', Arr::only($data, ['data', 'disallow_transfer', 'notes']), $pet, $keyed_quantities[$pet->id])) { Notifications::create('PET_GRANT', $user, [ - 'pet_name' => $pet->name, + 'pet_name' => $pet->name, 'pet_quantity' => $keyed_quantities[$pet->id], - 'sender_url' => $staff->url, - 'sender_name' => $staff->name + 'sender_url' => $staff->url, + 'sender_name' => $staff->name, ]); - } - else - { - throw new \Exception("Failed to credit pets to ".$user->name."."); + } else { + throw new \Exception('Failed to credit pets to '.$user->name.'.'); } } } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Transfers an pet stack between users. * - * @param \App\Models\User\User $sender - * @param \App\Models\User\User $recipient - * @param \App\Models\User\UserPet $stack + * @param \App\Models\User\User $sender + * @param \App\Models\User\User $recipient + * @param \App\Models\User\UserPet $stack + * * @return bool */ - public function transferStack($sender, $recipient, $stack) - { + public function transferStack($sender, $recipient, $stack) { DB::beginTransaction(); try { - if(!$sender->hasAlias) throw new \Exception("Your deviantART account must be verified before you can perform this action."); - if(!$stack) throw new \Exception("Invalid pet selected."); - if($stack->user_id != $sender->id && !$sender->hasPower('edit_inventories')) throw new \Exception("You do not own this pet."); - if($stack->user_id == $recipient->id) throw new \Exception("Cannot send an pet to the pet's owner."); - if(!$recipient) throw new \Exception("Invalid recipient selected."); - if(!$recipient->hasAlias) throw new \Exception("Cannot transfer pets to a non-verified member."); - if($recipient->is_banned) throw new \Exception("Cannot transfer pets to a banned member."); - if((!$stack->pet->allow_transfer || isset($stack->data['disallow_transfer'])) && !$sender->hasPower('edit_inventories')) throw new \Exception("This pet cannot be transferred."); + if (!$sender->hasAlias) { + throw new \Exception('Your deviantART account must be verified before you can perform this action.'); + } + if (!$stack) { + throw new \Exception('Invalid pet selected.'); + } + if ($stack->user_id != $sender->id && !$sender->hasPower('edit_inventories')) { + throw new \Exception('You do not own this pet.'); + } + if ($stack->user_id == $recipient->id) { + throw new \Exception("Cannot send an pet to the pet's owner."); + } + if (!$recipient) { + throw new \Exception('Invalid recipient selected.'); + } + if (!$recipient->hasAlias) { + throw new \Exception('Cannot transfer pets to a non-verified member.'); + } + if ($recipient->is_banned) { + throw new \Exception('Cannot transfer pets to a banned member.'); + } + if ((!$stack->pet->allow_transfer || isset($stack->data['disallow_transfer'])) && !$sender->hasPower('edit_inventories')) { + throw new \Exception('This pet cannot be transferred.'); + } $oldUser = $stack->user; - if($this->moveStack($stack->user, $recipient, ($stack->user_id == $sender->id ? 'User Transfer' : 'Staff Transfer'), ['data' => ($stack->user_id != $sender->id ? 'Transferred by '.$sender->displayName : '')], $stack)) - { + if ($this->moveStack($stack->user, $recipient, ($stack->user_id == $sender->id ? 'User Transfer' : 'Staff Transfer'), ['data' => ($stack->user_id != $sender->id ? 'Transferred by '.$sender->displayName : '')], $stack)) { Notifications::create('PET_TRANSFER', $recipient, [ - 'pet_name' => $stack->pet->name, + 'pet_name' => $stack->pet->name, 'pet_quantity' => 1, - 'sender_url' => $sender->url, - 'sender_name' => $sender->name + 'sender_url' => $sender->url, + 'sender_name' => $sender->name, ]); - if($stack->user_id != $sender->id) + if ($stack->user_id != $sender->id) { Notifications::create('FORCED_PET_TRANSFER', $oldUser, [ - 'pet_name' => $stack->pet->name, + 'pet_name' => $stack->pet->name, 'pet_quantity' => 1, - 'sender_url' => $sender->url, - 'sender_name' => $sender->name + 'sender_url' => $sender->url, + 'sender_name' => $sender->name, ]); + } + return $this->commitReturn(true); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Deletes an pet stack. * - * @param \App\Models\User\User $user - * @param \App\Models\User\UserPet $stack + * @param \App\Models\User\User $user + * @param \App\Models\User\UserPet $stack + * * @return bool */ - public function deleteStack($user, $stack) - { + public function deleteStack($user, $stack) { DB::beginTransaction(); try { - if(!$user->hasAlias) throw new \Exception("Your deviantART account must be verified before you can perform this action."); - if(!$stack) throw new \Exception("Invalid pet selected."); - if($stack->user_id != $user->id && !$user->hasPower('edit_inventories')) throw new \Exception("You do not own this pet."); + if (!$user->hasAlias) { + throw new \Exception('Your deviantART account must be verified before you can perform this action.'); + } + if (!$stack) { + throw new \Exception('Invalid pet selected.'); + } + if ($stack->user_id != $user->id && !$user->hasPower('edit_inventories')) { + throw new \Exception('You do not own this pet.'); + } $oldUser = $stack->user; - if($this->debitStack($stack->user, ($stack->user_id == $user->id ? 'User Deleted' : 'Staff Deleted'), ['data' => ($stack->user_id != $user->id ? 'Deleted by '.$user->displayName : '')], $stack)) - { - if($stack->user_id != $user->id) + if ($this->debitStack($stack->user, ($stack->user_id == $user->id ? 'User Deleted' : 'Staff Deleted'), ['data' => ($stack->user_id != $user->id ? 'Deleted by '.$user->displayName : '')], $stack)) { + if ($stack->user_id != $user->id) { Notifications::create('PET_REMOVAL', $oldUser, [ - 'pet_name' => $stack->pet->name, + 'pet_name' => $stack->pet->name, 'pet_quantity' => 1, - 'sender_url' => $user->url, - 'sender_name' => $user->name + 'sender_url' => $user->url, + 'sender_name' => $user->name, ]); + } + return $this->commitReturn(true); } - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Names a pet stack. * - * @param \App\Models\User\User $owner * @param \App\Models\User\UserPet - * @param int $quantities + * @param mixed $pet + * @param mixed $name + * * @return bool */ - public function nameStack($pet, $name) - { + public function nameStack($pet, $name) { DB::beginTransaction(); try { - $user = Auth::user(); - if(!$user->hasAlias) throw new \Exception("Your deviantART account must be verified before you can perform this action."); - if(!$pet) throw new \Exception("An invalid pet was selected."); - if($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) throw new \Exception("You do not own this pet."); + $user = Auth::user(); + if (!$user->hasAlias) { + throw new \Exception('Your deviantART account must be verified before you can perform this action.'); + } + if (!$pet) { + throw new \Exception('An invalid pet was selected.'); + } + if ($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) { + throw new \Exception('You do not own this pet.'); + } - $pet['pet_name'] = $name; - $pet->save(); + $pet['pet_name'] = $name; + $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * attaches a pet stack. * - * @param \App\Models\User\User $owner - * @param \App\Models\User\UserPet $stacks - * @param int $quantities + * @param mixed $pet + * @param mixed $id + * * @return bool */ - public function attachStack($pet, $id) - { + public function attachStack($pet, $id) { DB::beginTransaction(); try { - // First, check user permissions - $user = Auth::user(); - if(!$user->hasAlias) throw new \Exception("Your deviantART account must be verified before you can perform this action."); - - // Next, why bother checking everything else if the pet isn't even attachable? Also determine if the user is the owner of the pet/has permission to attach. - if(!$pet) throw new \Exception("An invalid pet was selected."); - if($pet->pet->category && !$pet->pet->category->allow_attach) throw new \Exception("This pet is in a category that cannot be attached to a character."); - if($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) throw new \Exception("You do not own this pet."); - - // Next, check if the character the pet is being attached to is valid and the user has permission to attach the pet to that character. - if($id == NULL) throw new \Exception("No character selected."); - $character = Character::find($id); - if(!$character) throw new \Exception("An invalid character was selected."); - if($character->user_id !== $user->id && !$user->hasPower('edit_inventories'))throw new \Exception("You do not own this character."); - - // Finally, compare character and limits based on pet and pet category. - $allPets = $character->pets; - if($pet->pet->category){ - $petCategory = $pet->pet->category; - $categoryLimit = $petCategory->limit; - $categoryCount = 0; - foreach($allPets as $p) { - if($p->pet->pet_category_id == $petCategory->id) $categoryCount++; + // First, check user permissions + $user = Auth::user(); + if (!$user->hasAlias) { + throw new \Exception('Your deviantART account must be verified before you can perform this action.'); + } + + // Next, why bother checking everything else if the pet isn't even attachable? Also determine if the user is the owner of the pet/has permission to attach. + if (!$pet) { + throw new \Exception('An invalid pet was selected.'); + } + if ($pet->pet->category && !$pet->pet->category->allow_attach) { + throw new \Exception('This pet is in a category that cannot be attached to a character.'); + } + if ($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) { + throw new \Exception('You do not own this pet.'); + } + + // Next, check if the character the pet is being attached to is valid and the user has permission to attach the pet to that character. + if ($id == null) { + throw new \Exception('No character selected.'); + } + $character = Character::find($id); + if (!$character) { + throw new \Exception('An invalid character was selected.'); + } + if ($character->user_id !== $user->id && !$user->hasPower('edit_inventories')) { + throw new \Exception('You do not own this character.'); + } + + // Finally, compare character and limits based on pet and pet category. + $allPets = $character->pets; + if ($pet->pet->category) { + $petCategory = $pet->pet->category; + $categoryLimit = $petCategory->limit; + $categoryCount = 0; + foreach ($allPets as $p) { + if ($p->pet->pet_category_id == $petCategory->id) { + $categoryCount++; } - if($categoryLimit && $categoryCount >= $categoryLimit) throw new \Exception("This character has reached the limit of pets in this category."); } - if($pet->pet->limit){ - $petLimit = $pet->pet->limit; - $petCount = 0; - foreach($allPets as $p) { - if($p->pet_id == $pet->pet->id) $petCount++; + if ($categoryLimit && $categoryCount >= $categoryLimit) { + throw new \Exception('This character has reached the limit of pets in this category.'); + } + } + if ($pet->pet->limit) { + $petLimit = $pet->pet->limit; + $petCount = 0; + foreach ($allPets as $p) { + if ($p->pet_id == $pet->pet->id) { + $petCount++; } - if($petLimit && $petCount >= $petLimit) throw new \Exception("This character has reached the limit of this pet."); } + if ($petLimit && $petCount >= $petLimit) { + throw new \Exception('This character has reached the limit of this pet.'); + } + } - // If all checks pass, attach the pet to the character. - $pet['chara_id'] = $character->id; - $pet['attached_at'] = Carbon::now(); - $pet->save(); + // If all checks pass, attach the pet to the character. + $pet['chara_id'] = $character->id; + $pet['attached_at'] = Carbon::now(); + $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * detaches a pet stack. * + * @param mixed $pet */ - public function detachStack($pet) - { + public function detachStack($pet) { DB::beginTransaction(); try { - $user = Auth::user(); - if(!$user->hasAlias) throw new \Exception("Your deviantART account must be verified before you can perform this action."); - if(!$pet) throw new \Exception("An invalid pet was selected."); - if($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) throw new \Exception("You do not own this pet."); + $user = Auth::user(); + if (!$user->hasAlias) { + throw new \Exception('Your deviantART account must be verified before you can perform this action.'); + } + if (!$pet) { + throw new \Exception('An invalid pet was selected.'); + } + if ($pet->user_id != $user->id && !$user->hasPower('edit_inventories')) { + throw new \Exception('You do not own this pet.'); + } - $pet['chara_id'] = null; - $pet->save(); + $pet['chara_id'] = null; + $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * edits variant + * edits variant. + * + * @param mixed $id + * @param mixed $pet + * @param mixed $stack_id + * @param mixed $isStaff */ - public function editVariant($id, $pet, $stack_id, $isStaff = false) - { + public function editVariant($id, $pet, $stack_id, $isStaff = false) { DB::beginTransaction(); try { - if (!$isStaff || !Auth::user()->isStaff) { - if (!$stack_id) throw new \Exception("No item selected."); - - // check if user has item - $item = UserItem::find($stack_id); - $invman = new InventoryManager; - if(!$invman->debitStack($pet->user, 'Used to change pet variant', ['data' => 'Used to change '.$pet->pet->name.' variant'], $item, 1)) { - throw new \Exception("Could not debit item."); - } + if (!$isStaff || !Auth::user()->isStaff) { + if (!$stack_id) { + throw new \Exception('No item selected.'); } - // else logAdminAction($pet->user, 'Pet Variant Changed', ['pet' => $pet->id, 'variant' => $id]); // for when develop is merged - $pet['variant_id'] = $id; - $pet->save(); + // check if user has item + $item = UserItem::find($stack_id); + $invman = new InventoryManager; + if (!$invman->debitStack($pet->user, 'Used to change pet variant', ['data' => 'Used to change '.$pet->pet->name.' variant'], $item, 1)) { + throw new \Exception('Could not debit item.'); + } + } + // else logAdminAction($pet->user, 'Pet Variant Changed', ['pet' => $pet->id, 'variant' => $id]); // for when develop is merged + + $pet['variant_id'] = $id; + $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * edits evolution + * edits evolution. + * + * @param mixed $id + * @param mixed $pet + * @param mixed $stack_id + * @param mixed $isStaff */ - public function editEvolution($id, $pet, $stack_id, $isStaff = false) - { + public function editEvolution($id, $pet, $stack_id, $isStaff = false) { DB::beginTransaction(); try { - if (!$isStaff || !Auth::user()->isStaff) { - if (!$stack_id) throw new \Exception("No item selected."); - - // check if user has item - $item = UserItem::find($stack_id); - $invman = new InventoryManager; - if(!$invman->debitStack($pet->user, 'Used to change pet evolution', ['data' => 'Used to change '.$pet->pet->name.' evolution'], $item, 1)) { - throw new \Exception("Could not debit item."); - } + if (!$isStaff || !Auth::user()->isStaff) { + if (!$stack_id) { + throw new \Exception('No item selected.'); } - // else logAdminAction($pet->user, 'Pet Evolution Changed', ['pet' => $pet->id, 'evolution' => $id]); // for when develop is merged - $pet['evolution_id'] = $id; - $pet->save(); + // check if user has item + $item = UserItem::find($stack_id); + $invman = new InventoryManager; + if (!$invman->debitStack($pet->user, 'Used to change pet evolution', ['data' => 'Used to change '.$pet->pet->name.' evolution'], $item, 1)) { + throw new \Exception('Could not debit item.'); + } + } + // else logAdminAction($pet->user, 'Pet Evolution Changed', ['pet' => $pet->id, 'evolution' => $id]); // for when develop is merged + + $pet['evolution_id'] = $id; + $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * Edits the custom variant image on a user pet stack + * Edits the custom variant image on a user pet stack. * + * @param mixed $pet + * @param mixed $data */ - public function editCustomImage($pet, $data) - { + public function editCustomImage($pet, $data) { DB::beginTransaction(); try { - $data['has_image'] = 1; - $image = null; - if(isset($data['remove_image'])) - { - if($pet && $pet->has_image && $data['remove_image']) - { - $data['has_image'] = 0; - if (file_exists($pet->imagePath . '/' . $pet->imageFileName)) - $this->deleteImage($pet->imagePath, $pet->imageFileName); - } - unset($data['remove_image']); - unset($data['image']); + $data['has_image'] = 1; + $image = null; + if (isset($data['remove_image'])) { + if ($pet && $pet->has_image && $data['remove_image']) { $data['has_image'] = 0; + if (file_exists($pet->imagePath.'/'.$pet->imageFileName)) { + $this->deleteImage($pet->imagePath, $pet->imageFileName); + } } + unset($data['remove_image']); + unset($data['image']); + $data['has_image'] = 0; + } - if(isset($data['image']) && $data['image']) { - $image = $data['image']; - unset($data['image']); - $data['has_image'] = 1; - } + if (isset($data['image']) && $data['image']) { + $image = $data['image']; + unset($data['image']); + $data['has_image'] = 1; + } - $data['artist_id'] = (isset($data['remove_credit']) && $data['remove_credit']) ? null : ($data['artist_id'] ?? null); - $data['artist_url'] = (isset($data['remove_credit']) && $data['remove_credit']) ? null : ($data['artist_url'] ?? null); + $data['artist_id'] = (isset($data['remove_credit']) && $data['remove_credit']) ? null : ($data['artist_id'] ?? null); + $data['artist_url'] = (isset($data['remove_credit']) && $data['remove_credit']) ? null : ($data['artist_url'] ?? null); - $pet->update($data); + $pet->update($data); - if ($pet) $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + if ($pet) { + $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * change pet's description + * change pet's description. + * + * @param mixed $pet + * @param mixed $data */ - public function editCustomImageDescription($pet, $data) - { + public function editCustomImageDescription($pet, $data) { DB::beginTransaction(); try { - $pet->description = parse($data['description']); $pet->save(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Credits an pet to a user. * - * @param \App\Models\User\User $sender - * @param \App\Models\User\User $recipient - * @param string $type - * @param array $data - * @param \App\Models\Pet\Pet $pet - * @param int $quantity + * @param \App\Models\User\User $sender + * @param \App\Models\User\User $recipient + * @param string $type + * @param array $data + * @param \App\Models\Pet\Pet $pet + * @param int $quantity + * * @return bool */ - public function creditPet($sender, $recipient, $type, $data, $pet, $quantity) - { + public function creditPet($sender, $recipient, $type, $data, $pet, $quantity) { DB::beginTransaction(); try { - for($i = 0; $i < $quantity; $i++) $user_pet = UserPet::create(['user_id' => $recipient->id, 'pet_id' => $pet->id, 'data' => json_encode($data)]); + for ($i = 0; $i < $quantity; $i++) { + $user_pet = UserPet::create(['user_id' => $recipient->id, 'pet_id' => $pet->id, 'data' => json_encode($data)]); + } // Create drop information for the character, if relevant - if($pet->pet && $pet->pet->dropData) { + if ($pet->pet && $pet->pet->dropData) { $drop = new PetDrop; - if($drop->createDrop($user_pet->id, null)) throw new \Exception('Failed to create pet drop.'); + if ($drop->createDrop($user_pet->id, null)) { + throw new \Exception('Failed to create pet drop.'); + } + } + if ($type && !$this->createLog($sender ? $sender->id : null, $recipient->id, null, $type, $data['data'], $pet->id, $quantity)) { + throw new \Exception('Failed to create log.'); } - if($type && !$this->createLog($sender ? $sender->id : null, $recipient->id, null, $type, $data['data'], $pet->id, $quantity)) throw new \Exception("Failed to create log."); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Moves an pet stack from one user to another. * - * @param \App\Models\User\User $sender - * @param \App\Models\User\User $recipient - * @param string $type - * @param array $data - * @param \App\Models\User\UserPet $pet + * @param \App\Models\User\User $sender + * @param \App\Models\User\User $recipient + * @param string $type + * @param array $data + * @param mixed $stack + * * @return bool */ - public function moveStack($sender, $recipient, $type, $data, $stack) - { + public function moveStack($sender, $recipient, $type, $data, $stack) { DB::beginTransaction(); try { $stack->user_id = $recipient->id; $stack->save(); - if($type && !$this->createLog($sender ? $sender->id : null, $recipient->id, $stack->id, $type, $data['data'], $stack->pet_id, 1)) throw new \Exception("Failed to create log."); + if ($type && !$this->createLog($sender ? $sender->id : null, $recipient->id, $stack->id, $type, $data['data'], $stack->pet_id, 1)) { + throw new \Exception('Failed to create log.'); + } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Debits an pet from a user. * - * @param \App\Models\User\User $user - * @param string $type - * @param array $data - * @param \App\Models\Pet\UserPet $stack + * @param \App\Models\User\User $user + * @param string $type + * @param array $data + * @param \App\Models\Pet\UserPet $stack + * * @return bool */ - public function debitStack($user, $type, $data, $stack) - { + public function debitStack($user, $type, $data, $stack) { DB::beginTransaction(); try { $stack->delete(); - if($type && !$this->createLog($user ? $user->id : null, null, $stack->id, $type, $data['data'], $stack->pet_id, 1)) throw new \Exception("Failed to create log."); + if ($type && !$this->createLog($user ? $user->id : null, null, $stack->id, $type, $data['data'], $stack->pet_id, 1)) { + throw new \Exception('Failed to create log.'); + } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Creates an inventory log. * - * @param int $senderId - * @param int $recipientId - * @param int $stackId - * @param string $type - * @param string $data - * @param int $quantity - * @return int + * @param int $senderId + * @param int $recipientId + * @param int $stackId + * @param string $type + * @param string $data + * @param int $quantity + * @param mixed $petId + * + * @return int */ - public function createLog($senderId, $recipientId, $stackId, $type, $data, $petId, $quantity) - { + public function createLog($senderId, $recipientId, $stackId, $type, $data, $petId, $quantity) { return DB::table('user_pets_log')->insert( [ - 'sender_id' => $senderId, + 'sender_id' => $senderId, 'recipient_id' => $recipientId, - 'stack_id' => $stackId, - 'log' => $type . ($data ? ' (' . $data . ')' : ''), - 'log_type' => $type, - 'data' => $data, // this should be just a string - 'pet_id' => $petId, - 'quantity' => $quantity, - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() + 'stack_id' => $stackId, + 'log' => $type.($data ? ' ('.$data.')' : ''), + 'log_type' => $type, + 'data' => $data, // this should be just a string + 'pet_id' => $petId, + 'quantity' => $quantity, + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), ] ); } diff --git a/app/Services/PetService.php b/app/Services/PetService.php index d2a1738fd1..877f749baf 100644 --- a/app/Services/PetService.php +++ b/app/Services/PetService.php @@ -1,18 +1,15 @@ -populateCategoryData($data); $image = null; - if(isset($data['image']) && $data['image']) { + if (isset($data['image']) && $data['image']) { $data['has_image'] = 1; $image = $data['image']; unset($data['image']); + } else { + $data['has_image'] = 0; } - else $data['has_image'] = 0; $category = PetCategory::create($data); - if ($image) $this->handleImage($image, $category->categoryImagePath, $category->categoryImageFileName); + if ($image) { + $this->handleImage($image, $category->categoryImagePath, $category->categoryImageFileName); + } return $this->commitReturn($category); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Update a category. * - * @param \App\Models\Pet\PetCategory $category - * @param array $data - * @param \App\Models\User\User $user + * @param \App\Models\Pet\PetCategory $category + * @param array $data + * @param \App\Models\User\User $user + * * @return \App\Models\Pet\PetCategory|bool */ - public function updatePetCategory($category, $data, $user) - { + public function updatePetCategory($category, $data, $user) { DB::beginTransaction(); try { // More specific validation - if(PetCategory::where('name', $data['name'])->where('id', '!=', $category->id)->exists()) throw new \Exception("The name has already been taken."); + if (PetCategory::where('name', $data['name'])->where('id', '!=', $category->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } $data = $this->populateCategoryData($data, $category); $image = null; - if(isset($data['image']) && $data['image']) { + if (isset($data['image']) && $data['image']) { $data['has_image'] = 1; $image = $data['image']; unset($data['image']); @@ -89,62 +91,70 @@ public function updatePetCategory($category, $data, $user) $category->update($data); - if ($category) $this->handleImage($image, $category->categoryImagePath, $category->categoryImageFileName); + if ($category) { + $this->handleImage($image, $category->categoryImagePath, $category->categoryImageFileName); + } return $this->commitReturn($category); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } - /** * Delete a category. * - * @param \App\Models\Pet\PetCategory $category + * @param \App\Models\Pet\PetCategory $category + * * @return bool */ - public function deletePetCategory($category) - { + public function deletePetCategory($category) { DB::beginTransaction(); try { // Check first if the category is currently in use - if(Pet::where('pet_category_id', $category->id)->exists()) throw new \Exception("An pet with this category exists. Please change its category first."); + if (Pet::where('pet_category_id', $category->id)->exists()) { + throw new \Exception('An pet with this category exists. Please change its category first.'); + } - if($category->has_image) $this->deleteImage($category->categoryImagePath, $category->categoryImageFileName); + if ($category->has_image) { + $this->deleteImage($category->categoryImagePath, $category->categoryImageFileName); + } $category->delete(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Sorts category order. * - * @param string $data + * @param string $data + * * @return bool */ - public function sortPetCategory($data) - { + public function sortPetCategory($data) { DB::beginTransaction(); try { // explode the sort array and reverse it since the order is inverted $sort = array_reverse(explode(',', $data)); - foreach($sort as $key => $s) { + foreach ($sort as $key => $s) { PetCategory::where('id', $s)->update(['sort' => $key]); } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } @@ -157,63 +167,77 @@ public function sortPetCategory($data) /** * Creates a new pet. * - * @param array $data - * @param \App\Models\User\User $user - * @return bool|\App\Models\Pet\Pet + * @param array $data + * @param \App\Models\User\User $user + * + * @return \App\Models\Pet\Pet|bool */ - public function createPet($data, $user) - { + public function createPet($data, $user) { DB::beginTransaction(); try { - if(isset($data['pet_category_id']) && $data['pet_category_id'] == 'none') $data['pet_category_id'] = null; + if (isset($data['pet_category_id']) && $data['pet_category_id'] == 'none') { + $data['pet_category_id'] = null; + } - if((isset($data['pet_category_id']) && $data['pet_category_id']) && !PetCategory::where('id', $data['pet_category_id'])->exists()) throw new \Exception("The selected pet category is invalid."); + if ((isset($data['pet_category_id']) && $data['pet_category_id']) && !PetCategory::where('id', $data['pet_category_id'])->exists()) { + throw new \Exception('The selected pet category is invalid.'); + } $data = $this->populateData($data); $image = null; - if(isset($data['image']) && $data['image']) { + if (isset($data['image']) && $data['image']) { $data['has_image'] = 1; $image = $data['image']; unset($data['image']); + } else { + $data['has_image'] = 0; } - else $data['has_image'] = 0; $pet = Pet::create($data); - if ($image) $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + if ($image) { + $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + } return $this->commitReturn($pet); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Updates an pet. * - * @param \App\Models\Pet\Pet $pet - * @param array $data - * @param \App\Models\User\User $user - * @return bool|\App\Models\Pet\Pet + * @param \App\Models\Pet\Pet $pet + * @param array $data + * @param \App\Models\User\User $user + * + * @return \App\Models\Pet\Pet|bool */ - public function updatePet($pet, $data, $user) - { + public function updatePet($pet, $data, $user) { DB::beginTransaction(); try { - if(isset($data['pet_category_id']) && $data['pet_category_id'] == 'none') $data['pet_category_id'] = null; + if (isset($data['pet_category_id']) && $data['pet_category_id'] == 'none') { + $data['pet_category_id'] = null; + } // More specific validation - if(Pet::where('name', $data['name'])->where('id', '!=', $pet->id)->exists()) throw new \Exception("The name has already been taken."); - if((isset($data['pet_category_id']) && $data['pet_category_id']) && !PetCategory::where('id', $data['pet_category_id'])->exists()) throw new \Exception("The selected pet category is invalid."); + if (Pet::where('name', $data['name'])->where('id', '!=', $pet->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } + if ((isset($data['pet_category_id']) && $data['pet_category_id']) && !PetCategory::where('id', $data['pet_category_id'])->exists()) { + throw new \Exception('The selected pet category is invalid.'); + } $data = $this->populateData($data); $image = null; - if(isset($data['image']) && $data['image']) { + if (isset($data['image']) && $data['image']) { $data['has_image'] = 1; $image = $data['image']; unset($data['image']); @@ -221,35 +245,48 @@ public function updatePet($pet, $data, $user) $pet->update($data); - if ($pet) $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + if ($pet) { + $this->handleImage($image, $pet->imagePath, $pet->imageFileName); + } return $this->commitReturn($pet); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Deletes an pet. * - * @param \App\Models\Pet\Pet $pet + * @param \App\Models\Pet\Pet $pet + * * @return bool */ - public function deletePet($pet) - { + public function deletePet($pet) { DB::beginTransaction(); try { // Check first if the pet is currently owned or if some other site feature uses it - if(DB::table('user_pets')->where('pet_id', $pet->id)->where('count', '>', 0)->where('deleted_at', '!=', null)->exists()) throw new \Exception("At least one user currently owns this pet. Please remove the pet(s) before deleting it."); - if(DB::table('loots')->where('rewardable_type', 'Pet')->where('rewardable_id', $pet->id)->exists()) throw new \Exception("A loot table currently distributes this pet as a potential reward. Please remove the pet before deleting it."); - if(DB::table('prompt_rewards')->where('rewardable_type', 'Pet')->where('rewardable_id', $pet->id)->exists()) throw new \Exception("A prompt currently distributes this pet as a reward. Please remove the pet before deleting it."); - if(DB::table('user_pets_logs')->where('pet_id', $pet->id)->exists()) throw new \Exception("At least one log currently has this pet. Please remove the log(s) before deleting it."); - if(DB::table('shop_stock')->where('item_id', $pet->id)->where('stock_type', 'Pet')->exists()) throw new \Exception("A shop currently stocks this pet. Please remove the pet before deleting it."); + if (DB::table('user_pets')->where('pet_id', $pet->id)->where('count', '>', 0)->where('deleted_at', '!=', null)->exists()) { + throw new \Exception('At least one user currently owns this pet. Please remove the pet(s) before deleting it.'); + } + if (DB::table('loots')->where('rewardable_type', 'Pet')->where('rewardable_id', $pet->id)->exists()) { + throw new \Exception('A loot table currently distributes this pet as a potential reward. Please remove the pet before deleting it.'); + } + if (DB::table('prompt_rewards')->where('rewardable_type', 'Pet')->where('rewardable_id', $pet->id)->exists()) { + throw new \Exception('A prompt currently distributes this pet as a reward. Please remove the pet before deleting it.'); + } + if (DB::table('user_pets_logs')->where('pet_id', $pet->id)->exists()) { + throw new \Exception('At least one log currently has this pet. Please remove the log(s) before deleting it.'); + } + if (DB::table('shop_stock')->where('item_id', $pet->id)->where('stock_type', 'Pet')->exists()) { + throw new \Exception('A shop currently stocks this pet. Please remove the pet before deleting it.'); + } // Delete character drops and drop data if they exist - if($pet->dropData->exists()) { + if ($pet->dropData->exists()) { $pet->dropData->petDrops()->delete(); $pet->dropData->delete(); } @@ -257,9 +294,10 @@ public function deletePet($pet) $pet->delete(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } @@ -270,54 +308,62 @@ public function deletePet($pet) **********************************************************************************************/ /** - * Creates a new variant for a pet + * Creates a new variant for a pet. + * + * @param mixed $pet + * @param mixed $data */ - public function createVariant($pet, $data) - { + public function createVariant($pet, $data) { DB::beginTransaction(); try { - // check name is unique - if(PetVariant::where('variant_name', $data['variant_name'])->where('pet_id', $pet->id)->exists()) throw new \Exception("The name has already been taken."); + if (PetVariant::where('variant_name', $data['variant_name'])->where('pet_id', $pet->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } $image = null; - if(isset($data['variant_image']) && $data['variant_image']) { + if (isset($data['variant_image']) && $data['variant_image']) { $data['has_image'] = 1; $image = $data['variant_image']; unset($data['variant_image']); + } else { + $data['has_image'] = 0; } - else $data['has_image'] = 0; $data['pet_id'] = $pet->id; $variant = PetVariant::create($data); - if ($image) $this->handleImage($image, $variant->imagePath, $variant->imageFileName); + if ($image) { + $this->handleImage($image, $variant->imagePath, $variant->imageFileName); + } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * Edits the variants on a pet + * Edits the variants on a pet. + * + * @param mixed $variant + * @param mixed $data */ - public function editVariant($variant, $data) - { + public function editVariant($variant, $data) { DB::beginTransaction(); try { - // check name is unique - if(PetVariant::where('variant_name', $data['variant_name'])->where('pet_id', $variant->pet->id)->where('id', '!=', $variant->id)->exists()) throw new \Exception("The name has already been taken."); + if (PetVariant::where('variant_name', $data['variant_name'])->where('pet_id', $variant->pet->id)->where('id', '!=', $variant->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } - if(isset($data['remove_image'])) - { - if($variant && $variant->has_image && $data['remove_image']) - { + if (isset($data['remove_image'])) { + if ($variant && $variant->has_image && $data['remove_image']) { $data['has_image'] = 0; $this->deleteImage($variant->imagePath, $variant->imageFileName); } @@ -325,7 +371,7 @@ public function editVariant($variant, $data) } $image = null; - if(isset($data['variant_image']) && $data['variant_image']) { + if (isset($data['variant_image']) && $data['variant_image']) { $data['has_image'] = 1; $image = $data['variant_image']; unset($data['variant_image']); @@ -333,89 +379,35 @@ public function editVariant($variant, $data) $variant->update([ 'variant_name' => $data['variant_name'], - 'has_image' => isset($data['has_image']) ? $data['has_image'] : $variant->has_image, + 'has_image' => $data['has_image'] ?? $variant->has_image, ]); - if ($image) $this->handleImage($image, $variant->imagePath, $variant->imageFileName); + if ($image) { + $this->handleImage($image, $variant->imagePath, $variant->imageFileName); + } if (isset($data['delete']) && $data['delete']) { // check that no user pets exist with this variant before deleting - if(UserPet::where('variant_id', $variant->id)->exists()) throw new \Exception("At least one user pet currently is this variant. Please remove the pet(s) before deleting it."); + if (UserPet::where('variant_id', $variant->id)->exists()) { + throw new \Exception('At least one user pet currently is this variant. Please remove the pet(s) before deleting it.'); + } // delete image - if ($variant->has_image) $this->deleteImage($variant->imagePath, $variant->imageFileName); + if ($variant->has_image) { + $this->deleteImage($variant->imagePath, $variant->imageFileName); + } $variant->delete(); flash('Variant deleted successfully.')->success(); - } - else { + } else { flash('Variant updated successfully.')->success(); } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } - return $this->rollbackReturn(false); - } - - /** - * Handle category data. - * - * @param array $data - * @param \App\Models\Pet\PetCategory|null $category - * @return array - */ - private function populateCategoryData($data, $category = null) - { - if(isset($data['description']) && $data['description']) $data['parsed_description'] = parse($data['description']); - - if(!isset($data['allow_attach'])) { - $data['allow_attach'] = 0; - $data['limit'] = null; - } - // If attachments are allowed, but no limit is set, set it to null. - if(isset($data['allow_attach']) && $data['allow_attach'] && !isset($data['limit'])) $data['limit'] = null; - - if(isset($data['remove_image'])) - { - if($category && $category->has_image && $data['remove_image']) - { - $data['has_image'] = 0; - $this->deleteImage($category->categoryImagePath, $category->categoryImageFileName); - } - unset($data['remove_image']); - } - - return $data; - } - - /** - * Processes user input for creating/updating an pet. - * - * @param array $data - * @param \App\Models\Pet\Pet $pet - * @return array - */ - private function populateData($data, $pet = null) - { - if(isset($data['description']) && $data['description']) $data['parsed_description'] = parse($data['description']); - - // If attachments are allowed, but no limit is set, set it to null. - if(isset($data['allow_attach']) && $data['allow_attach'] && !isset($data['limit'])) $data['limit'] = null; - - if(!isset($data['allow_transfer'])) $data['allow_transfer'] = 0; - - if(isset($data['remove_image'])) - { - if($pet && $pet->has_image && $data['remove_image']) - { - $data['has_image'] = 0; - $this->deleteImage($pet->imagePath, $pet->imageFileName); - } - unset($data['remove_image']); - } - return $data; + return $this->rollbackReturn(false); } /********************************************************************************************** @@ -425,19 +417,25 @@ private function populateData($data, $pet = null) **********************************************************************************************/ /** - * Creates a pet evolution + * Creates a pet evolution. + * + * @param mixed $pet + * @param mixed $data */ - public function createEvolution($pet, $data) - { + public function createEvolution($pet, $data) { DB::beginTransaction(); try { - if (!isset($data['evolution_name']) || !$data['evolution_name']) throw new \Exception("Please enter a valid evolution name."); + if (!isset($data['evolution_name']) || !$data['evolution_name']) { + throw new \Exception('Please enter a valid evolution name.'); + } // check name is unique - if(PetEvolution::where('evolution_name', $data['evolution_name'])->where('pet_id', $pet->id)->exists()) throw new \Exception("The name has already been taken."); + if (PetEvolution::where('evolution_name', $data['evolution_name'])->where('pet_id', $pet->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } $image = null; - if(isset($data['evolution_image']) && $data['evolution_image']) { + if (isset($data['evolution_image']) && $data['evolution_image']) { $data['has_image'] = 1; $image = $data['evolution_image']; unset($data['evolution_image']); @@ -445,33 +443,46 @@ public function createEvolution($pet, $data) $data['pet_id'] = $pet->id; - if (!$image) throw new \Exception("Please upload an image for this evolution."); + if (!$image) { + throw new \Exception('Please upload an image for this evolution.'); + } $evolution = PetEvolution::create($data); - if ($image) $this->handleImage($image, $evolution->imagePath, $evolution->imageFileName); + if ($image) { + $this->handleImage($image, $evolution->imagePath, $evolution->imageFileName); + } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** - * Edits the evolutions on a pet + * Edits the evolutions on a pet. + * + * @param mixed $evolution + * @param mixed $data */ - public function editEvolution($evolution, $data) - { + public function editEvolution($evolution, $data) { DB::beginTransaction(); try { - if (!isset($data['evolution_name']) || !$data['evolution_name']) throw new \Exception("Please enter a valid evolution name."); - if(PetEvolution::where('evolution_name', $data['evolution_name'])->where('pet_id', $evolution->pet->id)->where('id', '!=', $evolution->id)->exists()) throw new \Exception("The name has already been taken."); - if(!isset($data['evolution_stage']) || !$data['evolution_stage']) throw new \Exception("Please enter a valid evolution stage."); + if (!isset($data['evolution_name']) || !$data['evolution_name']) { + throw new \Exception('Please enter a valid evolution name.'); + } + if (PetEvolution::where('evolution_name', $data['evolution_name'])->where('pet_id', $evolution->pet->id)->where('id', '!=', $evolution->id)->exists()) { + throw new \Exception('The name has already been taken.'); + } + if (!isset($data['evolution_stage']) || !$data['evolution_stage']) { + throw new \Exception('Please enter a valid evolution stage.'); + } $image = null; - if(isset($data['evolution_image']) && $data['evolution_image']) { + if (isset($data['evolution_image']) && $data['evolution_image']) { $image = $data['evolution_image']; unset($data['evolution_image']); } @@ -481,48 +492,119 @@ public function editEvolution($evolution, $data) 'evolution_stage' => $data['evolution_stage'], ]); - if ($image) $this->handleImage($image, $evolution->imagePath, $evolution->imageFileName); + if ($image) { + $this->handleImage($image, $evolution->imagePath, $evolution->imageFileName); + } // variant images - if(isset($data['variant_id']) && $data['variant_id']) { - foreach($data['variant_id'] as $key => $variant_id) { + if (isset($data['variant_id']) && $data['variant_id']) { + foreach ($data['variant_id'] as $key => $variant_id) { $variant = PetVariant::find($variant_id); - if($variant) { + if ($variant) { $variant_image = null; - if(isset($data['variant_image'][$key]) && $data['variant_image'][$key]) { + if (isset($data['variant_image'][$key]) && $data['variant_image'][$key]) { $variant_image = $data['variant_image'][$key]; unset($data['variant_image'][$key]); } - if ($variant_image) $this->handleImage($variant_image, $evolution->variantImageDirectory, $evolution->variantImageFileName($variant->id)); + if ($variant_image) { + $this->handleImage($variant_image, $evolution->variantImageDirectory, $evolution->variantImageFileName($variant->id)); + } } } } if (isset($data['delete']) && $data['delete']) { // check that no user pets exist with this evolution before deleting - if(UserPet::where('evolution_id', $evolution->id)->exists()) throw new \Exception("At least one user pet currently is this evolution. Please remove the pet(s) before deleting it."); + if (UserPet::where('evolution_id', $evolution->id)->exists()) { + throw new \Exception('At least one user pet currently is this evolution. Please remove the pet(s) before deleting it.'); + } // delete image $this->deleteImage($evolution->imagePath, $evolution->imageFileName); // delete all variant images - foreach($evolution->pet->variants as $variant) { + foreach ($evolution->pet->variants as $variant) { // check if file exists - if($evolution->variantImageExists($variant->id)) - { + if ($evolution->variantImageExists($variant->id)) { $this->deleteImage($evolution->variantImageDirectory, $evolution->variantImageFileName($variant->id)); } } $evolution->delete(); flash('Evolution deleted successfully.')->success(); - } - else { + } else { flash('Evolution updated successfully.')->success(); } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } + + /** + * Handle category data. + * + * @param array $data + * @param \App\Models\Pet\PetCategory|null $category + * + * @return array + */ + private function populateCategoryData($data, $category = null) { + if (isset($data['description']) && $data['description']) { + $data['parsed_description'] = parse($data['description']); + } + + if (!isset($data['allow_attach'])) { + $data['allow_attach'] = 0; + $data['limit'] = null; + } + // If attachments are allowed, but no limit is set, set it to null. + if (isset($data['allow_attach']) && $data['allow_attach'] && !isset($data['limit'])) { + $data['limit'] = null; + } + + if (isset($data['remove_image'])) { + if ($category && $category->has_image && $data['remove_image']) { + $data['has_image'] = 0; + $this->deleteImage($category->categoryImagePath, $category->categoryImageFileName); + } + unset($data['remove_image']); + } + + return $data; + } + + /** + * Processes user input for creating/updating an pet. + * + * @param array $data + * @param \App\Models\Pet\Pet $pet + * + * @return array + */ + private function populateData($data, $pet = null) { + if (isset($data['description']) && $data['description']) { + $data['parsed_description'] = parse($data['description']); + } + + // If attachments are allowed, but no limit is set, set it to null. + if (isset($data['allow_attach']) && $data['allow_attach'] && !isset($data['limit'])) { + $data['limit'] = null; + } + + if (!isset($data['allow_transfer'])) { + $data['allow_transfer'] = 0; + } + + if (isset($data['remove_image'])) { + if ($pet && $pet->has_image && $data['remove_image']) { + $data['has_image'] = 0; + $this->deleteImage($pet->imagePath, $pet->imageFileName); + } + unset($data['remove_image']); + } + + return $data; + } } diff --git a/app/Services/ShopManager.php b/app/Services/ShopManager.php index fcf1ae333a..8dbc0b78dd 100644 --- a/app/Services/ShopManager.php +++ b/app/Services/ShopManager.php @@ -3,12 +3,11 @@ namespace App\Services; use App\Models\Character\Character; +use App\Models\Item\Item; use App\Models\Shop\Shop; use App\Models\Shop\ShopLog; -use App\Models\User\UserItem; -use App\Models\Item\Item; -use App\Models\Item\ItemTag; use App\Models\Shop\ShopStock; +use App\Models\User\UserItem; use Config; use DB; @@ -47,7 +46,9 @@ public function buyStock($data, $user) { // Check that the stock exists and belongs to the shop $shopStock = ShopStock::where('id', $data['stock_id'])->where('shop_id', $data['shop_id'])->with('currency')->first(); - if(!$shopStock) throw new \Exception("Invalid item selected."); + if (!$shopStock) { + throw new \Exception('Invalid item selected.'); + } // Check if the item has a quantity, and if it does, check there is enough stock remaining if ($shopStock->is_limited_stock && $shopStock->quantity < $quantity) { @@ -59,47 +60,54 @@ public function buyStock($data, $user) { throw new \Exception('You have already purchased the maximum amount of this item you can buy.'); } - - if(isset($data['use_coupon'])) { + if (isset($data['use_coupon'])) { // check if the the stock is limited stock - if($shopStock->is_limited_stock && !Settings::get('limited_stock_coupon_settings')) throw new \Exception('Sorry! You can\'t use coupons on limited stock items'); + if ($shopStock->is_limited_stock && !Settings::get('limited_stock_coupon_settings')) { + throw new \Exception('Sorry! You can\'t use coupons on limited stock items'); + } - if(!isset($data['coupon'])) throw new \Exception('Please select a coupon to use.'); + if (!isset($data['coupon'])) { + throw new \Exception('Please select a coupon to use.'); + } // finding the users tag $userItem = UserItem::find($data['coupon']); // check if the item id is inside allowed_coupons - if($shop->allowed_coupons && count(json_decode($shop->allowed_coupons, 1)) > 0 && !in_array($userItem->item_id, json_decode($shop->allowed_coupons, 1))) throw new \Exception('Sorry! You can\'t use this coupon.'); + if ($shop->allowed_coupons && count(json_decode($shop->allowed_coupons, 1)) > 0 && !in_array($userItem->item_id, json_decode($shop->allowed_coupons, 1))) { + throw new \Exception('Sorry! You can\'t use this coupon.'); + } // finding bought item $item = Item::find($userItem->item_id); $tag = $item->tags()->where('tag', 'Coupon')->first(); $coupon = $tag->data; - if(!$coupon['discount']) throw new \Exception('No discount amount set, please contact a site admin before trying to purchase again.'); + if (!$coupon['discount']) { + throw new \Exception('No discount amount set, please contact a site admin before trying to purchase again.'); + } // if the coupon isn't infinite kill it - if(!$coupon['infinite']) { - if(!(new InventoryManager)->debitStack($user, 'Coupon Used', ['data' => 'Coupon used in purchase of ' . $shopStock->item->name . ' from ' . $shop->name], $userItem, 1)) throw new \Exception("Failed to remove coupon."); + if (!$coupon['infinite']) { + if (!(new InventoryManager)->debitStack($user, 'Coupon Used', ['data' => 'Coupon used in purchase of '.$shopStock->item->name.' from '.$shop->name], $userItem, 1)) { + throw new \Exception('Failed to remove coupon.'); + } } - if(!Settings::get('coupon_settings')) { + if (!Settings::get('coupon_settings')) { $minus = ($coupon['discount'] / 100) * ($shopStock->displayCost * $quantity); $base = ($shopStock->displayCost * $quantity); - if($base <= 0) { - throw new \Exception("Cannot use a coupon on an item that is free."); - } + if ($base <= 0) { + throw new \Exception('Cannot use a coupon on an item that is free.'); + } $new = $base - $minus; - $total_cost = round($new); - } - else { + $total_cost = round($new); + } else { $minus = ($coupon['discount'] / 100) * ($shopStock->displayCost); $base = ($shopStock->displayCost * $quantity); - if($base <= 0) { - throw new \Exception("Cannot use a coupon on an item that is free."); - } + if ($base <= 0) { + throw new \Exception('Cannot use a coupon on an item that is free.'); + } $new = $base - $minus; - $total_cost = round($new); + $total_cost = round($new); } - } - else { + } else { $total_cost = $shopStock->displayCost * $quantity; } @@ -146,26 +154,28 @@ public function buyStock($data, $user) { // Add a purchase log $shopLog = ShopLog::create([ - 'shop_id' => $shop->id, + 'shop_id' => $shop->id, 'character_id' => $character ? $character->id : null, - 'user_id' => $user->id, - 'currency_id' => $shopStock->currency->id, - 'cost' => isset($data['use_coupon']) ? $total_cost : $shopStock->cost, - 'item_id' => $shopStock->item_id, - 'quantity' => $quantity + 'user_id' => $user->id, + 'currency_id' => $shopStock->currency->id, + 'cost' => isset($data['use_coupon']) ? $total_cost : $shopStock->cost, + 'item_id' => $shopStock->item_id, + 'quantity' => $quantity, ]); // Give the user the item, noting down 1. whose currency was used (user or character) 2. who purchased it 3. which shop it was purchased from $assets = createAssetsArray(); addAsset($assets, $shopStock->item, $quantity); - if(!fillUserAssets($assets, null, $user, 'Shop Purchase', [ - 'data' => $shopLog->itemData, - 'notes' => 'Purchased ' . format_date($shopLog->created_at) - ])) throw new \Exception("Failed to purchase item."); + if (!fillUserAssets($assets, null, $user, 'Shop Purchase', [ + 'data' => $shopLog->itemData, + 'notes' => 'Purchased '.format_date($shopLog->created_at), + ])) { + throw new \Exception('Failed to purchase item.'); + } return $this->commitReturn($shop); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } @@ -196,11 +206,10 @@ public function checkPurchaseLimitReached($shopStock, $user) { * * @return int */ - public function checkUserPurchases($shopStock, $user) - { + public function checkUserPurchases($shopStock, $user) { $date = $shopStock->purchaseLimitDate; $shopQuery = ShopLog::where('shop_id', $shopStock->shop_id)->where('cost', $shopStock->cost)->where('item_id', $shopStock->item_id)->where('user_id', $user->id); - $shopQuery = isset($date) ? $shopQuery->where('created_at', '>=', date("Y-m-d H:i:s", $date)) : $shopQuery; + $shopQuery = isset($date) ? $shopQuery->where('created_at', '>=', date('Y-m-d H:i:s', $date)) : $shopQuery; return $shopQuery->sum('quantity'); } diff --git a/app/Services/ShopService.php b/app/Services/ShopService.php index 842ef1d9fd..301d20b675 100644 --- a/app/Services/ShopService.php +++ b/app/Services/ShopService.php @@ -4,7 +4,6 @@ use App\Models\Shop\Shop; use App\Models\Shop\ShopLimit; -use App\Models\Shop\ShopStock; use DB; class ShopService extends Service { @@ -118,130 +117,110 @@ public function updateShopStock($shop, $data, $user) { DB::beginTransaction(); try { - if(!$data['stock_type']) throw new \Exception("Please select a stock type."); - if(!$data['item_id']) throw new \Exception("You must select an item."); + if (!$data['stock_type']) { + throw new \Exception('Please select a stock type.'); + } + if (!$data['item_id']) { + throw new \Exception('You must select an item.'); + } $shop->stock()->create([ - 'shop_id' => $shop->id, - 'item_id' => $data['item_id'], - 'currency_id' => $data['currency_id'], - 'cost' => $data['cost'], - 'use_user_bank' => isset($data['use_user_bank']), - 'use_character_bank' => isset($data['use_character_bank']), - 'is_fto' => isset($data['is_fto']), - 'is_limited_stock' => isset($data['is_limited_stock']), - 'quantity' => isset($data['is_limited_stock']) ? $data['quantity'] : 0, - 'purchase_limit' => isset($data['purchase_limit']) ? $data['purchase_limit'] : 0, + 'shop_id' => $shop->id, + 'item_id' => $data['item_id'], + 'currency_id' => $data['currency_id'], + 'cost' => $data['cost'], + 'use_user_bank' => isset($data['use_user_bank']), + 'use_character_bank' => isset($data['use_character_bank']), + 'is_fto' => isset($data['is_fto']), + 'is_limited_stock' => isset($data['is_limited_stock']), + 'quantity' => isset($data['is_limited_stock']) ? $data['quantity'] : 0, + 'purchase_limit' => $data['purchase_limit'] ?? 0, 'purchase_limit_timeframe' => isset($data['purchase_limit']) ? $data['purchase_limit_timeframe'] : null, - 'stock_type' => $data['stock_type'], - 'is_visible' => isset($data['is_visible']) ? $data['is_visible'] : 0, - 'restock' => isset($data['restock']) ? $data['restock'] : 0, - 'restock_quantity' => isset($data['restock']) && isset($data['quantity']) ? $data['quantity'] : 1, - 'restock_interval' => isset($data['restock_interval']) ? $data['restock_interval'] : 2, - 'range' => isset($data['range']) ? $data['range'] : 0, - 'is_timed_stock' => isset($data['is_timed_stock']), - 'start_at' => $data['start_at'], - 'end_at' => $data['end_at'], + 'stock_type' => $data['stock_type'], + 'is_visible' => $data['is_visible'] ?? 0, + 'restock' => $data['restock'] ?? 0, + 'restock_quantity' => isset($data['restock']) && isset($data['quantity']) ? $data['quantity'] : 1, + 'restock_interval' => $data['restock_interval'] ?? 2, + 'range' => $data['range'] ?? 0, + 'is_timed_stock' => isset($data['is_timed_stock']), + 'start_at' => $data['start_at'], + 'end_at' => $data['end_at'], ]); return $this->commitReturn($shop); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } /** * Updates shop stock. * - * @param \App\Models\Shop\Shop $shop - * @param array $data - * @param \App\Models\User\User $user - * @return bool|\App\Models\Shop\Shop + * @param array $data + * @param \App\Models\User\User $user + * @param mixed $stock + * + * @return \App\Models\Shop\Shop|bool */ - public function editShopStock($stock, $data, $user) - { + public function editShopStock($stock, $data, $user) { DB::beginTransaction(); try { - if(!$data['stock_type']) throw new \Exception("Please select a stock type."); - if(!$data['item_id']) throw new \Exception("You must select an item."); + if (!$data['stock_type']) { + throw new \Exception('Please select a stock type.'); + } + if (!$data['item_id']) { + throw new \Exception('You must select an item.'); + } $stock->update([ - 'shop_id' => $stock->shop->id, - 'item_id' => $data['item_id'], - 'currency_id' => $data['currency_id'], - 'cost' => $data['cost'], - 'use_user_bank' => isset($data['use_user_bank']), - 'use_character_bank' => isset($data['use_character_bank']), - 'is_fto' => isset($data['is_fto']), - 'is_limited_stock' => isset($data['is_limited_stock']), - 'quantity' => isset($data['is_limited_stock']) ? $data['quantity'] : 0, - 'purchase_limit' => $data['purchase_limit'], + 'shop_id' => $stock->shop->id, + 'item_id' => $data['item_id'], + 'currency_id' => $data['currency_id'], + 'cost' => $data['cost'], + 'use_user_bank' => isset($data['use_user_bank']), + 'use_character_bank' => isset($data['use_character_bank']), + 'is_fto' => isset($data['is_fto']), + 'is_limited_stock' => isset($data['is_limited_stock']), + 'quantity' => isset($data['is_limited_stock']) ? $data['quantity'] : 0, + 'purchase_limit' => $data['purchase_limit'], 'purchase_limit_timeframe' => $data['purchase_limit_timeframe'], - 'stock_type' => $data['stock_type'], - 'is_visible' => isset($data['is_visible']) ? $data['is_visible'] : 0, - 'restock' => isset($data['restock']) ? $data['restock'] : 0, - 'restock_quantity' => isset($data['restock']) && isset($data['quantity']) ? $data['quantity'] : 1, - 'restock_interval' => isset($data['restock_interval']) ? $data['restock_interval'] : 2, - 'range' => isset($data['range']) ? $data['range'] : 0, - 'disallow_transfer' => isset($data['disallow_transfer']) ? $data['disallow_transfer'] : 0, - 'is_timed_stock' => isset($data['is_timed_stock']), - 'start_at' => $data['start_at'], - 'end_at' => $data['end_at'], + 'stock_type' => $data['stock_type'], + 'is_visible' => $data['is_visible'] ?? 0, + 'restock' => $data['restock'] ?? 0, + 'restock_quantity' => isset($data['restock']) && isset($data['quantity']) ? $data['quantity'] : 1, + 'restock_interval' => $data['restock_interval'] ?? 2, + 'range' => $data['range'] ?? 0, + 'disallow_transfer' => $data['disallow_transfer'] ?? 0, + 'is_timed_stock' => isset($data['is_timed_stock']), + 'start_at' => $data['start_at'], + 'end_at' => $data['end_at'], ]); return $this->commitReturn($stock); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } - public function deleteStock($stock) - { + public function deleteStock($stock) { DB::beginTransaction(); try { - $stock->delete(); return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } return $this->rollbackReturn(false); } - /** - * Processes user input for creating/updating a shop. - * - * @param array $data - * @param \App\Models\Shop\Shop $shop - * @return array - */ - private function populateShopData($data, $shop = null) - { - if(isset($data['description']) && $data['description']) $data['parsed_description'] = parse($data['description']); - $data['is_active'] = isset($data['is_active']); - $data['is_staff'] = isset($data['is_staff']); - $data['use_coupons'] = isset($data['use_coupons']); - $data['allowed_coupons'] = isset($data['allowed_coupons']) ? $data['allowed_coupons'] : null; - - if(isset($data['remove_image'])) - { - if($shop && $shop->has_image && $data['remove_image']) - { - $data['has_image'] = 0; - $this->deleteImage($shop->shopImagePath, $shop->shopImageFileName); - } - unset($data['remove_image']); - } - - return $data; - } - /** * Deletes a shop. * @@ -295,12 +274,13 @@ public function sortShop($data) { return $this->rollbackReturn(false); } - public function restrictShop($data, $id) - { + public function restrictShop($data, $id) { DB::beginTransaction(); try { - if(!isset($data['is_restricted'])) $data['is_restricted'] = 0; + if (!isset($data['is_restricted'])) { + $data['is_restricted'] = 0; + } $shop = Shop::find($id); $shop->is_restricted = $data['is_restricted']; @@ -308,20 +288,48 @@ public function restrictShop($data, $id) $shop->limits()->delete(); - if(isset($data['item_id'])) { - foreach($data['item_id'] as $key => $type) - { + if (isset($data['item_id'])) { + foreach ($data['item_id'] as $key => $type) { ShopLimit::create([ 'shop_id' => $shop->id, - 'item_id' => $type, + 'item_id' => $type, ]); } } return $this->commitReturn(true); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->setError('error', $e->getMessage()); } + return $this->rollbackReturn(false); } + + /** + * Processes user input for creating/updating a shop. + * + * @param array $data + * @param \App\Models\Shop\Shop $shop + * + * @return array + */ + private function populateShopData($data, $shop = null) { + if (isset($data['description']) && $data['description']) { + $data['parsed_description'] = parse($data['description']); + } + $data['is_active'] = isset($data['is_active']); + $data['is_staff'] = isset($data['is_staff']); + $data['use_coupons'] = isset($data['use_coupons']); + $data['allowed_coupons'] ??= null; + + if (isset($data['remove_image'])) { + if ($shop && $shop->has_image && $data['remove_image']) { + $data['has_image'] = 0; + $this->deleteImage($shop->shopImagePath, $shop->shopImageFileName); + } + unset($data['remove_image']); + } + + return $data; + } } diff --git a/app/Services/SubmissionManager.php b/app/Services/SubmissionManager.php index cc773ae3cf..e6e38891a0 100644 --- a/app/Services/SubmissionManager.php +++ b/app/Services/SubmissionManager.php @@ -6,8 +6,8 @@ use App\Models\Currency\Currency; use App\Models\Item\Item; use App\Models\Loot\LootTable; -use App\Models\Prompt\Prompt; use App\Models\Pet\Pet; +use App\Models\Prompt\Prompt; use App\Models\Raffle\Raffle; use App\Models\Submission\Submission; use App\Models\Submission\SubmissionCharacter; diff --git a/config/lorekeeper/admin_sidebar.php b/config/lorekeeper/admin_sidebar.php index 9da8dea0ba..8cb4f7fea3 100644 --- a/config/lorekeeper/admin_sidebar.php +++ b/config/lorekeeper/admin_sidebar.php @@ -104,9 +104,9 @@ ], [ 'name' => 'Pet Grants', - 'url' => 'admin/grants/pets' + 'url' => 'admin/grants/pets', ], - ] + ], ], 'Masterlist' => [ 'power' => 'manage_characters', @@ -190,9 +190,9 @@ ], [ 'name' => 'Pets', - 'url' => 'admin/data/pets' + 'url' => 'admin/data/pets', ], - ] + ], ], 'Raffles' => [ 'power' => 'manage_raffles', diff --git a/config/lorekeeper/extension_tracker.php b/config/lorekeeper/extension_tracker.php index b0b2b80fbd..432adf5e52 100644 --- a/config/lorekeeper/extension_tracker.php +++ b/config/lorekeeper/extension_tracker.php @@ -1,4 +1,5 @@ [ - 'key' => 'shop_features', + 'key' => 'shop_features', 'wiki_key' => 'Shop_Features', 'creators' => json_encode([ 'Newt' => 'https://github.com/ne-wt/', diff --git a/config/lorekeeper/item_tags.php b/config/lorekeeper/item_tags.php index 55e9315cc9..a64c88c622 100644 --- a/config/lorekeeper/item_tags.php +++ b/config/lorekeeper/item_tags.php @@ -26,22 +26,22 @@ ], 'splice' => [ - 'name' => 'Splice', - 'text_color' => '#ffffff', - 'background_color' => '#a69bc6' + 'name' => 'Splice', + 'text_color' => '#ffffff', + 'background_color' => '#a69bc6', ], // pokemon ftw // if you want to change this, just edit the 'name' part. 'rare_candy' => [ - 'name' => 'Rare Candy', - 'text_color' => '#ffffff', - 'background_color' => '#96afdb' + 'name' => 'Rare Candy', + 'text_color' => '#ffffff', + 'background_color' => '#96afdb', ], 'coupon' => [ - 'name' => 'Coupon', - 'text_color' => '#ffffff', - 'background_color' => '#ff5ca8' + 'name' => 'Coupon', + 'text_color' => '#ffffff', + 'background_color' => '#ff5ca8', ], ]; diff --git a/config/lorekeeper/notifications.php b/config/lorekeeper/notifications.php index 6e1bb06b42..883bba7683 100644 --- a/config/lorekeeper/notifications.php +++ b/config/lorekeeper/notifications.php @@ -333,27 +333,27 @@ ], // PET_REMOVAL 241 => [ - 'name' => 'Pet Removal', + 'name' => 'Pet Removal', 'message' => '{pet_name} (×{pet_quantity}) was removed from your inventory by {sender_name}. (View Inventory)', - 'url' => 'pets' + 'url' => 'pets', ], // PET_TRANSFER 242 => [ - 'name' => 'Pet Transfer', + 'name' => 'Pet Transfer', 'message' => 'You have received {pet_name} (×{pet_quantity}) from {sender_name}. (View Inventory)', - 'url' => 'pets' + 'url' => 'pets', ], // FORCED_PET_TRANSFER 243 => [ - 'name' => 'Forced Pet Transfer', + 'name' => 'Forced Pet Transfer', 'message' => '{pet_name} (×{pet_quantity}) was transferred out of your inventory by {sender_name}. (View Inventory)', - 'url' => 'pets' + 'url' => 'pets', ], // PET_GRANT 244 => [ - 'name' => 'Pet Grant', + 'name' => 'Pet Grant', 'message' => 'You have received a staff grant of {pet_name} (×{pet_quantity}) from {sender_name}. (View Inventory)', - 'url' => 'pets' + 'url' => 'pets', ], // CHARACTER_ITEM_GRANT 501 => [ diff --git a/database/migrations/2020_11_07_120635_add_pet_tables.php b/database/migrations/2020_11_07_120635_add_pet_tables.php index 1273266b99..da03d1fde3 100644 --- a/database/migrations/2020_11_07_120635_add_pet_tables.php +++ b/database/migrations/2020_11_07_120635_add_pet_tables.php @@ -1,18 +1,14 @@ engine = 'InnoDB'; $table->increments('id'); @@ -53,7 +49,7 @@ public function up() $table->foreign('user_id')->references('id')->on('users'); }); - Schema::create('user_pets_log', function(Blueprint $table) { + Schema::create('user_pets_log', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('pet_id')->unsigned(); @@ -61,8 +57,8 @@ public function up() $table->integer('sender_id')->unsigned()->nullable(); $table->integer('recipient_id')->unsigned()->nullable(); - $table->string('log'); - $table->string('log_type'); + $table->string('log'); + $table->string('log_type'); $table->string('data', 1024)->nullable(); $table->timestamps(); @@ -78,14 +74,11 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('user_pets_log'); Schema::dropIfExists('user_pets'); Schema::dropIfExists('pets'); Schema::dropIfExists('pet_categories'); } -} \ No newline at end of file +} diff --git a/database/migrations/2020_11_10_183745_add_pet_names.php b/database/migrations/2020_11_10_183745_add_pet_names.php index 1062e5de55..7006312e41 100644 --- a/database/migrations/2020_11_10_183745_add_pet_names.php +++ b/database/migrations/2020_11_10_183745_add_pet_names.php @@ -1,18 +1,14 @@ boolean('is_staff')->default(0); @@ -23,11 +19,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // schema::table('shops', function (Blueprint $table) { $table->dropColumn('is_staff'); diff --git a/database/migrations/2020_11_19_205400_add_shop_restriction_table.php b/database/migrations/2020_11_19_205400_add_shop_restriction_table.php index 5c5182e908..66ab2e5614 100644 --- a/database/migrations/2020_11_19_205400_add_shop_restriction_table.php +++ b/database/migrations/2020_11_19_205400_add_shop_restriction_table.php @@ -1,18 +1,14 @@ increments('id'); @@ -23,11 +19,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // schema::dropIfExists('shop_limits'); } diff --git a/database/migrations/2020_11_26_161652_add_fto_shops.php b/database/migrations/2020_11_26_161652_add_fto_shops.php index e5abaec371..bf0378d053 100644 --- a/database/migrations/2020_11_26_161652_add_fto_shops.php +++ b/database/migrations/2020_11_26_161652_add_fto_shops.php @@ -1,41 +1,34 @@ boolean('is_fto')->default(0); }); - Schema::table('shop_stock', function (Blueprint $table){ + Schema::table('shop_stock', function (Blueprint $table) { $table->boolean('is_fto')->default(0); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // schema::table('shops', function (Blueprint $table) { $table->dropColumn('is_fto'); }); - - Schema::table('shop_stock', function (Blueprint $table){ + + Schema::table('shop_stock', function (Blueprint $table) { $table->dropColumn('is_fto'); }); } diff --git a/database/migrations/2020_11_28_114556_add_chara_table_for_pets.php b/database/migrations/2020_11_28_114556_add_chara_table_for_pets.php index d69500621b..5b30a0a47a 100644 --- a/database/migrations/2020_11_28_114556_add_chara_table_for_pets.php +++ b/database/migrations/2020_11_28_114556_add_chara_table_for_pets.php @@ -1,18 +1,14 @@ integer('chara_id')->nullable()->default(null); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::table('user_pets', function (Blueprint $table) { $table->dropColumn('chara_id'); diff --git a/database/migrations/2021_06_01_163339_add_pet_changes.php b/database/migrations/2021_06_01_163339_add_pet_changes.php index 59bdf52e0a..a09421d5c1 100644 --- a/database/migrations/2021_06_01_163339_add_pet_changes.php +++ b/database/migrations/2021_06_01_163339_add_pet_changes.php @@ -1,49 +1,42 @@ boolean('allow_attach')->default(1); }); - Schema::table('user_pets', function (Blueprint $table) { + Schema::table('user_pets', function (Blueprint $table) { $table->timestamp('attached_at')->nullable()->default(null); $table->integer('variant_id')->nullable()->default(null); }); - Schema::create('pet_variants', function (Blueprint $table) { + Schema::create('pet_variants', function (Blueprint $table) { $table->id(); $table->integer('pet_id'); $table->string('variant_name'); - $table->boolean('has_image')->default(0); + $table->boolean('has_image')->default(0); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // - Schema::table('pet_categories', function (Blueprint $table) { + Schema::table('pet_categories', function (Blueprint $table) { $table->dropColumn('allow_attach'); }); - Schema::table('user_pets', function (Blueprint $table) { + Schema::table('user_pets', function (Blueprint $table) { $table->dropColumn('attached_at'); $table->dropColumn('variant_id'); }); diff --git a/database/migrations/2021_09_02_193957_add_shop_stock_type.php b/database/migrations/2021_09_02_193957_add_shop_stock_type.php index 48c8b5d72d..946e8e1233 100644 --- a/database/migrations/2021_09_02_193957_add_shop_stock_type.php +++ b/database/migrations/2021_09_02_193957_add_shop_stock_type.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddShopStockType extends Migration -{ +class AddShopStockType extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { // Schema::table('shop_stock', function (Blueprint $table) { $table->string('stock_type')->default('Item'); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::table('shop_stock', function (Blueprint $table) { $table->dropColumn('stock_type'); diff --git a/database/migrations/2021_10_13_185131_make_shop_cost_float.php b/database/migrations/2021_10_13_185131_make_shop_cost_float.php index c22ee8fa15..3c362d4b77 100644 --- a/database/migrations/2021_10_13_185131_make_shop_cost_float.php +++ b/database/migrations/2021_10_13_185131_make_shop_cost_float.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class MakeShopCostFloat extends Migration -{ +class MakeShopCostFloat extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { // Schema::table('shop_stock', function (Blueprint $table) { $table->float('cost')->change(); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::table('shop_stock', function (Blueprint $table) { $table->integer('cost')->change(); diff --git a/database/migrations/2021_10_14_044223_make_shop_log_float.php b/database/migrations/2021_10_14_044223_make_shop_log_float.php index 3a0795bb9e..93e6a77cab 100644 --- a/database/migrations/2021_10_14_044223_make_shop_log_float.php +++ b/database/migrations/2021_10_14_044223_make_shop_log_float.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class MakeShopLogFloat extends Migration -{ +class MakeShopLogFloat extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { // Schema::table('shop_log', function (Blueprint $table) { $table->float('cost')->change(); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::table('shop_log', function (Blueprint $table) { $table->integer('cost')->change(); diff --git a/database/migrations/2021_12_15_102154_add_visble_to_stock.php b/database/migrations/2021_12_15_102154_add_visble_to_stock.php index 11fcbf8721..2592ff0694 100644 --- a/database/migrations/2021_12_15_102154_add_visble_to_stock.php +++ b/database/migrations/2021_12_15_102154_add_visble_to_stock.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddVisbleToStock extends Migration -{ +class AddVisbleToStock extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('shop_stock', function (Blueprint $table) { // $table->boolean('is_visible')->default(true); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('shop_stock', function (Blueprint $table) { // $table->dropColumn('is_visible'); diff --git a/database/migrations/2021_12_22_181141_add_pet_drop_tables.php b/database/migrations/2021_12_22_181141_add_pet_drop_tables.php index 4fb4812c85..fcc5dc0465 100644 --- a/database/migrations/2021_12_22_181141_add_pet_drop_tables.php +++ b/database/migrations/2021_12_22_181141_add_pet_drop_tables.php @@ -1,18 +1,14 @@ engine = 'InnoDB'; @@ -42,17 +38,13 @@ public function up() // Timestamp at which next drop becomes available $table->timestamp('next_day')->nullable()->default(null); - }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::dropIfExists('pet_drop_data'); Schema::dropIfExists('pet_drops'); diff --git a/database/migrations/2022_02_06_131334_add_restock_to_shop_stock.php b/database/migrations/2022_02_06_131334_add_restock_to_shop_stock.php index 0788458308..3f354eb38b 100644 --- a/database/migrations/2022_02_06_131334_add_restock_to_shop_stock.php +++ b/database/migrations/2022_02_06_131334_add_restock_to_shop_stock.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddRestockToShopStock extends Migration -{ +class AddRestockToShopStock extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('shop_stock', function (Blueprint $table) { // $table->boolean('restock')->default(false); @@ -24,11 +20,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('shop_stock', function (Blueprint $table) { // $table->dropColumn('restock'); diff --git a/database/migrations/2022_03_01_094114_add_disallow_transfer_option_to_shop_stock.php b/database/migrations/2022_03_01_094114_add_disallow_transfer_option_to_shop_stock.php index 85e69aacb5..2150e8d1fd 100644 --- a/database/migrations/2022_03_01_094114_add_disallow_transfer_option_to_shop_stock.php +++ b/database/migrations/2022_03_01_094114_add_disallow_transfer_option_to_shop_stock.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddDisallowTransferOptionToShopStock extends Migration -{ +class AddDisallowTransferOptionToShopStock extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('shop_stock', function (Blueprint $table) { // $table->boolean('disallow_transfer')->default(false); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('shop_stock', function (Blueprint $table) { // $table->dropColumn('disallow_transfer'); diff --git a/database/migrations/2022_03_17_123003_add_allowed_coupons_to_shops.php b/database/migrations/2022_03_17_123003_add_allowed_coupons_to_shops.php index 7c6c151bbb..1903f62663 100644 --- a/database/migrations/2022_03_17_123003_add_allowed_coupons_to_shops.php +++ b/database/migrations/2022_03_17_123003_add_allowed_coupons_to_shops.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddAllowedCouponsToShops extends Migration -{ +class AddAllowedCouponsToShops extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('shops', function (Blueprint $table) { // $table->string('allowed_coupons')->nullable()->default(null); @@ -21,11 +17,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('shops', function (Blueprint $table) { // $table->dropColumn('allowed_coupons'); diff --git a/database/migrations/2022_05_16_211400_add_purchase_limit_timeframe_to_shop_stock.php b/database/migrations/2022_05_16_211400_add_purchase_limit_timeframe_to_shop_stock.php index ced26775c5..c12fdbe564 100644 --- a/database/migrations/2022_05_16_211400_add_purchase_limit_timeframe_to_shop_stock.php +++ b/database/migrations/2022_05_16_211400_add_purchase_limit_timeframe_to_shop_stock.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddPurchaseLimitTimeframeToShopStock extends Migration -{ +class AddPurchaseLimitTimeframeToShopStock extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('shop_stock', function (Blueprint $table) { $table->text('purchase_limit_timeframe')->nullable()->default(null); }); @@ -20,11 +16,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('shop_stock', function (Blueprint $table) { $table->dropColumn('purchase_limit_timeframe'); }); diff --git a/database/migrations/2023_03_07_002536_add_timed_stock.php b/database/migrations/2023_03_07_002536_add_timed_stock.php index f1514c2e5c..18e5afaa97 100644 --- a/database/migrations/2023_03_07_002536_add_timed_stock.php +++ b/database/migrations/2023_03_07_002536_add_timed_stock.php @@ -4,31 +4,24 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddTimedStock extends Migration -{ +class AddTimedStock extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { - Schema::table('shop_stock', function (Blueprint $table){ - $table->boolean('is_timed_stock')->default(false); - $table->timestamps(); - $table->timestamp('start_at')->nullable()->default(null); - $table->timestamp('end_at')->nullable()->default(null); + public function up() { + Schema::table('shop_stock', function (Blueprint $table) { + $table->boolean('is_timed_stock')->default(false); + $table->timestamps(); + $table->timestamp('start_at')->nullable()->default(null); + $table->timestamp('end_at')->nullable()->default(null); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { - Schema::table('shop_stock', function (Blueprint $table){ + public function down() { + Schema::table('shop_stock', function (Blueprint $table) { $table->dropColumn('is_timed_stock'); $table->dropColumn('start_at'); $table->dropColumn('start_at'); diff --git a/database/migrations/2023_03_07_144637_add_timed_shop.php b/database/migrations/2023_03_07_144637_add_timed_shop.php index 218666f92b..099fc0769f 100644 --- a/database/migrations/2023_03_07_144637_add_timed_shop.php +++ b/database/migrations/2023_03_07_144637_add_timed_shop.php @@ -4,31 +4,24 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddTimedShop extends Migration -{ +class AddTimedShop extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { - Schema::table('shops', function (Blueprint $table){ + public function up() { + Schema::table('shops', function (Blueprint $table) { $table->boolean('is_timed_shop')->default(false); $table->timestamps(); $table->timestamp('start_at')->nullable()->default(null); $table->timestamp('end_at')->nullable()->default(null); - }); + }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { - Schema::table('shops', function (Blueprint $table){ + public function down() { + Schema::table('shops', function (Blueprint $table) { $table->dropColumn('is_timed_shop'); $table->dropColumn('start_at'); $table->dropColumn('start_at'); diff --git a/database/migrations/2023_07_27_202333_add_custom_pet_tables.php b/database/migrations/2023_07_27_202333_add_custom_pet_tables.php index 8213a5aca2..d60e19ce8d 100644 --- a/database/migrations/2023_07_27_202333_add_custom_pet_tables.php +++ b/database/migrations/2023_07_27_202333_add_custom_pet_tables.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddCustomPetTables extends Migration -{ +class AddCustomPetTables extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::table('user_pets', function (Blueprint $table) { $table->boolean('has_image')->default(0); $table->text('description')->nullable()->default(null); @@ -23,11 +19,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::table('user_pets', function (Blueprint $table) { $table->dropColumn('has_image'); $table->dropColumn('description'); diff --git a/database/migrations/2023_10_19_144923_create_pet_evolutions.php b/database/migrations/2023_10_19_144923_create_pet_evolutions.php index 932beab8f7..4c70101feb 100644 --- a/database/migrations/2023_10_19_144923_create_pet_evolutions.php +++ b/database/migrations/2023_10_19_144923_create_pet_evolutions.php @@ -4,15 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreatePetEvolutions extends Migration -{ +class CreatePetEvolutions extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() - { + public function up() { Schema::create('pet_evolutions', function (Blueprint $table) { $table->id(); $table->integer('pet_id'); @@ -28,11 +24,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { Schema::dropIfExists('pet_evolutions'); Schema::table('user_pets', function (Blueprint $table) { $table->dropColumn('evolution_id'); diff --git a/database/migrations/database/migrations/2021_12_22_181141_add_pet_drop_tables.php b/database/migrations/database/migrations/2021_12_22_181141_add_pet_drop_tables.php index 06b802c08e..e8e925ee6a 100644 --- a/database/migrations/database/migrations/2021_12_22_181141_add_pet_drop_tables.php +++ b/database/migrations/database/migrations/2021_12_22_181141_add_pet_drop_tables.php @@ -1,18 +1,14 @@ engine = 'InnoDB'; @@ -43,17 +39,13 @@ public function up() // Timestamp at which next drop becomes available $table->timestamp('next_day')->nullable()->default(null); - }); } /** * Reverse the migrations. - * - * @return void */ - public function down() - { + public function down() { // Schema::dropIfExists('pet_drop_data'); Schema::dropIfExists('pet_drops'); diff --git a/routes/lorekeeper/admin.php b/routes/lorekeeper/admin.php index fdf5a00123..6b3adc7f43 100644 --- a/routes/lorekeeper/admin.php +++ b/routes/lorekeeper/admin.php @@ -161,7 +161,7 @@ Route::get('items/tag/{id}', 'ItemController@getAddItemTag'); Route::post('items/tag/{id}', 'ItemController@postAddItemTag'); - # PETS + // PETS Route::get('pet-categories', 'PetController@getIndex'); Route::get('pet-categories/create', 'PetController@getCreatePetCategory'); Route::get('pet-categories/edit/{id}', 'PetController@getEditPetCategory'); @@ -208,7 +208,7 @@ Route::get('pets/drops/edit/{pet_id}/variants/delete/{variant_id}', 'PetController@getDeleteVariantDrop'); Route::post('pets/drops/edit/{pet_id}/variants/delete/{variant_id}', 'PetController@postDeleteVariantDrop'); - # SHOPS + // SHOPS Route::get('shops', 'ShopController@getIndex'); Route::get('shops/create', 'ShopController@getCreateShop'); Route::get('shops/edit/{id}', 'ShopController@getEditShop'); @@ -218,7 +218,7 @@ Route::post('shops/delete/{id}', 'ShopController@postDeleteShop'); Route::post('shops/sort', 'ShopController@postSortShop'); Route::post('shops/restrictions/{id}', 'ShopController@postRestrictShop'); - # stock + // stock // create Route::get('shops/stock/{id}', 'ShopController@getCreateShopStock'); Route::post('shops/stock/{id}', 'ShopController@postCreateShopStock'); @@ -353,8 +353,8 @@ Route::get('item-search', 'GrantController@getItemSearch'); }); -# PETS -Route::group(['prefix' => 'pets', 'middleware' => 'power:edit_inventories'], function() { +// PETS +Route::group(['prefix' => 'pets', 'middleware' => 'power:edit_inventories'], function () { Route::post('pet/{id}', 'Data\PetController@postEditPetDrop'); }); diff --git a/routes/lorekeeper/members.php b/routes/lorekeeper/members.php index 53519bd17c..73d683e46f 100644 --- a/routes/lorekeeper/members.php +++ b/routes/lorekeeper/members.php @@ -59,7 +59,7 @@ Route::get('selector', 'InventoryController@getSelector'); }); -Route::group(['prefix' => 'pets', 'namespace' => 'Users'], function() { +Route::group(['prefix' => 'pets', 'namespace' => 'Users'], function () { Route::get('/', 'PetController@getIndex'); Route::post('transfer/{id}', 'PetController@postTransfer'); Route::post('delete/{id}', 'PetController@postDelete');