Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/corowne/lorekeeper into …
Browse files Browse the repository at this point in the history
…extension/multiple-subtypes

# Conflicts:
#	composer.lock
  • Loading branch information
ScuffedNewt committed Mar 6, 2024
2 parents 560eb7d + 1e8c8bd commit 53579e4
Show file tree
Hide file tree
Showing 89 changed files with 1,724 additions and 982 deletions.
36 changes: 18 additions & 18 deletions app/Helpers/AssetHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ function parseAssetData($array) {
* Distributes the assets in an assets array to the given recipient (user).
* Loot tables will be rolled before distribution.
*
* @param array $assets
* @param \App\Models\User\User $sender
* @param \App\Models\User\User $recipient
* @param string $logType
* @param string $data
* @param array $assets
* @param App\Models\User\User $sender
* @param App\Models\User\User $recipient
* @param string $logType
* @param string $data
*
* @return array
*/
Expand All @@ -296,35 +296,35 @@ function fillUserAssets($assets, $sender, $recipient, $logType, $data) {

foreach ($assets as $key => $contents) {
if ($key == 'items' && count($contents)) {
$service = new \App\Services\InventoryManager;
$service = new App\Services\InventoryManager;
foreach ($contents as $asset) {
if (!$service->creditItem($sender, $recipient, $logType, $data, $asset['asset'], $asset['quantity'])) {
return false;
}
}
} elseif ($key == 'currencies' && count($contents)) {
$service = new \App\Services\CurrencyManager;
$service = new App\Services\CurrencyManager;
foreach ($contents as $asset) {
if (!$service->creditCurrency($sender, $recipient, $logType, $data['data'], $asset['asset'], $asset['quantity'])) {
return false;
}
}
} elseif ($key == 'raffle_tickets' && count($contents)) {
$service = new \App\Services\RaffleManager;
$service = new App\Services\RaffleManager;
foreach ($contents as $asset) {
if (!$service->addTicket($recipient, $asset['asset'], $asset['quantity'])) {
return false;
}
}
} elseif ($key == 'user_items' && count($contents)) {
$service = new \App\Services\InventoryManager;
$service = new App\Services\InventoryManager;
foreach ($contents as $asset) {
if (!$service->moveStack($sender, $recipient, $logType, $data, $asset['asset'])) {
return false;
}
}
} elseif ($key == 'characters' && count($contents)) {
$service = new \App\Services\CharacterManager;
$service = new App\Services\CharacterManager;
foreach ($contents as $asset) {
if (!$service->moveCharacter($asset['asset'], $recipient, $data, $asset['quantity'], $logType)) {
return false;
Expand All @@ -340,12 +340,12 @@ function fillUserAssets($assets, $sender, $recipient, $logType, $data) {
* Distributes the assets in an assets array to the given recipient (character).
* Loot tables will be rolled before distribution.
*
* @param array $assets
* @param \App\Models\User\User $sender
* @param \App\Models\Character\Character $recipient
* @param string $logType
* @param string $data
* @param mixed|null $submitter
* @param array $assets
* @param App\Models\User\User $sender
* @param App\Models\Character\Character $recipient
* @param string $logType
* @param string $data
* @param mixed|null $submitter
*
* @return array
*/
Expand All @@ -366,14 +366,14 @@ function fillCharacterAssets($assets, $sender, $recipient, $logType, $data, $sub

foreach ($assets as $key => $contents) {
if ($key == 'currencies' && count($contents)) {
$service = new \App\Services\CurrencyManager;
$service = new App\Services\CurrencyManager;
foreach ($contents as $asset) {
if (!$service->creditCurrency($sender, ($asset['asset']->is_character_owned ? $recipient : $item_recipient), $logType, $data['data'], $asset['asset'], $asset['quantity'])) {
return false;
}
}
} elseif ($key == 'items' && count($contents)) {
$service = new \App\Services\InventoryManager;
$service = new App\Services\InventoryManager;
foreach ($contents as $asset) {
if (!$service->creditItem($sender, (($asset['asset']->category && $asset['asset']->category->is_character_owned) ? $recipient : $item_recipient), $logType, $data, $asset['asset'], $asset['quantity'])) {
return false;
Expand Down
20 changes: 10 additions & 10 deletions app/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function breadcrumbs($links) {
/**
* Formats the timestamp to a standard format.
*
* @param \Illuminate\Support\Carbon\Carbon $timestamp
* @param mixed $showTime
* @param Illuminate\Support\Carbon\Carbon $timestamp
* @param mixed $showTime
*
* @return string
*/
Expand Down Expand Up @@ -160,7 +160,7 @@ function parseUsers($text, &$users) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$user = \App\Models\User\User::where('name', $match)->first();
$user = App\Models\User\User::where('name', $match)->first();
if ($user) {
$users[] = $user;
$text = preg_replace('/\B@'.$match.'/', $user->displayName, $text);
Expand All @@ -187,7 +187,7 @@ function parseUsersAndAvatars($text, &$users) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$user = \App\Models\User\User::where('name', $match)->first();
$user = App\Models\User\User::where('name', $match)->first();
if ($user) {
$users[] = $user;
$text = preg_replace('/\B%'.$match.'/', '<a href="'.$user->url.'"><img src="'.$user->avatarUrl.'" style="width:70px; height:70px; border-radius:50%; " alt="'.$user->name.'\'s Avatar"></a>'.$user->displayName, $text);
Expand All @@ -214,7 +214,7 @@ function parseUserIDs($text, &$users) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$user = \App\Models\User\User::where('id', $match)->first();
$user = App\Models\User\User::where('id', $match)->first();
if ($user) {
$users[] = $user;
$text = preg_replace('/\[user='.$match.'\]/', $user->displayName, $text);
Expand All @@ -241,7 +241,7 @@ function parseUserIDsForAvatars($text, &$users) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$user = \App\Models\User\User::where('id', $match)->first();
$user = App\Models\User\User::where('id', $match)->first();
if ($user) {
$users[] = $user;
$text = preg_replace('/\[userav='.$match.'\]/', '<a href="'.$user->url.'"><img src="'.$user->avatarUrl.'" style="width:70px; height:70px; border-radius:50%; " alt="'.$user->name.'\'s Avatar"></a>', $text);
Expand All @@ -268,7 +268,7 @@ function parseCharacters($text, &$characters) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$character = \App\Models\Character\Character::where('slug', $match)->first();
$character = App\Models\Character\Character::where('slug', $match)->first();
if ($character) {
$characters[] = $character;
$text = preg_replace('/\[character='.$match.'\]/', $character->displayName, $text);
Expand All @@ -295,7 +295,7 @@ function parseCharacterThumbs($text, &$characters) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$character = \App\Models\Character\Character::where('slug', $match)->first();
$character = App\Models\Character\Character::where('slug', $match)->first();
if ($character) {
$characters[] = $character;
$text = preg_replace('/\[charthumb='.$match.'\]/', '<a href="'.$character->url.'"><img class="img-thumbnail" alt="Thumbnail of '.$character->fullName.'" data-toggle="tooltip" title="'.$character->fullName.'" src="'.$character->image->thumbnailUrl.'"></a>', $text);
Expand All @@ -322,7 +322,7 @@ function parseGalleryThumbs($text, &$submissions) {
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$submission = \App\Models\Gallery\GallerySubmission::where('id', $match)->first();
$submission = App\Models\Gallery\GallerySubmission::where('id', $match)->first();
if ($submission) {
$submissions[] = $submission;
$text = preg_replace('/\[thumb='.$match.'\]/', '<a href="'.$submission->url.'" data-toggle="tooltip" title="'.$submission->displayTitle.' by '.nl2br(htmlentities($submission->creditsPlain)).(isset($submission->content_warning) ? '<br/><strong>Content Warning:</strong> '.nl2br(htmlentities($submission->content_warning)) : '').'">'.view('widgets._gallery_thumb', ['submission' => $submission]).'</a>', $text);
Expand Down Expand Up @@ -374,7 +374,7 @@ function checkAlias($url, $failOnError = true) {
}
}
if ((!isset($matches[0]) || $matches[0] == []) && $failOnError) {
throw new \Exception('This URL is from an invalid site. Please provide a URL for a user profile from a site used for authentication.');
throw new Exception('This URL is from an invalid site. Please provide a URL for a user profile from a site used for authentication.');
}

// and 2. if it contains an alias associated with a user on-site.
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Admin/Data/CurrencyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function getEditCurrency($id) {
}

return view('admin.currencies.create_edit_currency', [
'currency' => $currency,
'currency' => $currency,
'currencies' => Currency::where('id', '!=', $id)->get()->sortBy('name')->pluck('name', 'id'),
]);
}

Expand All @@ -73,6 +74,7 @@ public function postCreateEditCurrency(Request $request, CurrencyService $servic
'name', 'abbreviation', 'description',
'is_displayed', 'allow_user_to_user', 'allow_user_to_character', 'allow_character_to_user',
'icon', 'image', 'remove_icon', 'remove_image',
'conversion_id', 'rate',
]);
if ($id && $service->updateCurrency(Currency::find($id), $data, Auth::user())) {
flash('Currency updated successfully.')->success();
Expand Down
60 changes: 53 additions & 7 deletions app/Http/Controllers/Admin/Data/FeatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,75 @@ public function postSortFeatureCategory(Request $request, FeatureService $servic
*/
public function getFeatureIndex(Request $request) {
$query = Feature::query();
$data = $request->only(['rarity_id', 'feature_category_id', 'species_id', 'subtype_id', 'name']);
$data = $request->only(['rarity_id', 'feature_category_id', 'species_id', 'subtype_id', 'name', 'sort']);
if (isset($data['rarity_id']) && $data['rarity_id'] != 'none') {
$query->where('rarity_id', $data['rarity_id']);
}
if (isset($data['feature_category_id']) && $data['feature_category_id'] != 'none') {
$query->where('feature_category_id', $data['feature_category_id']);
if ($data['feature_category_id'] == 'withoutOption') {
$query->whereNull('feature_category_id');
} else {
$query->where('feature_category_id', $data['feature_category_id']);
}
}
if (isset($data['species_id']) && $data['species_id'] != 'none') {
$query->where('species_id', $data['species_id']);
if ($data['species_id'] == 'withoutOption') {
$query->whereNull('species_id');
} else {
$query->where('species_id', $data['species_id']);
}
}
if (isset($data['subtype_id']) && $data['subtype_id'] != 'none') {
$query->where('subtype_id', $data['subtype_id']);
if ($data['subtype_id'] == 'withoutOption') {
$query->whereNull('subtype_id');
} else {
$query->where('subtype_id', $data['subtype_id']);
}
}
if (isset($data['name'])) {
$query->where('name', 'LIKE', '%'.$data['name'].'%');
}

if (isset($data['sort'])) {
switch ($data['sort']) {
case 'alpha':
$query->sortAlphabetical();
break;
case 'alpha-reverse':
$query->sortAlphabetical(true);
break;
case 'category':
$query->sortCategory();
break;
case 'rarity':
$query->sortRarity();
break;
case 'rarity-reverse':
$query->sortRarity(true);
break;
case 'species':
$query->sortSpecies();
break;
case 'subtypes':
$query->sortSubtype();
break;
case 'newest':
$query->sortNewest();
break;
case 'oldest':
$query->sortOldest();
break;
}
} else {
$query->sortOldest();
}

return view('admin.features.features', [
'features' => $query->paginate(20)->appends($request->query()),
'rarities' => ['none' => 'Any Rarity'] + Rarity::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'specieses' => ['none' => 'Any Species'] + Species::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'subtypes' => ['none' => 'Any Subtype'] + Subtype::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'categories' => ['none' => 'Any Category'] + FeatureCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'specieses' => ['none' => 'Any Species'] + ['withoutOption' => 'Without Species'] + Species::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'subtypes' => ['none' => 'Any Subtype'] + ['withoutOption' => 'Without Subtype'] + Subtype::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'categories' => ['none' => 'Any Category'] + ['withoutOption' => 'Without Category'] + FeatureCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function postRegisterWithDriver(LinkService $service, Request $request, $
/**
* Create a new user instance after a valid registration.
*
* @return \App\Models\User\User
* @return User
*/
protected function create(array $data) {
DB::beginTransaction();
Expand Down
53 changes: 52 additions & 1 deletion app/Http/Controllers/Users/BankController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function getIndex() {
return view('home.bank', [
'currencyOptions' => Currency::where('allow_user_to_user', 1)->where('is_user_owned', 1)->whereIn('id', UserCurrency::where('user_id', Auth::user()->id)->pluck('currency_id')->toArray())->orderBy('sort_user', 'DESC')->pluck('name', 'id')->toArray(),
'userOptions' => User::visible()->where('id', '!=', Auth::user()->id)->orderBy('name')->pluck('name', 'id')->toArray(),

// only get currency with currency_conversions relationship
'convertOptions' => Currency::where('is_user_owned', 1)->whereHas('conversions')->orderBy('sort_user', 'DESC')->pluck('name', 'id')->toArray(),
]);
}

Expand All @@ -51,4 +52,54 @@ public function postTransfer(Request $request, CurrencyManager $service) {

return redirect()->back();
}

/**
* Gets the currency conversion form for the user.
*
* @param mixed $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function getConvertCurrency($id) {
$currency = Currency::where('is_user_owned', 1)->where('id', $id)->first();
$convertOptions = Currency::whereIn('id', $currency->conversions->pluck('conversion_id')->toArray())->orderBy('sort_user', 'DESC')->pluck('name', 'id')->toArray();

return view('home._bank_convert', [
'convertOptions' => $convertOptions,
]);
}

/**
* Gets the currency conversion rate for the user.
*
* @param mixed $currency_id
* @param mixed $conversion_id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function getConvertCurrencyRate($currency_id, $conversion_id) {
$currency = Currency::where('is_user_owned', 1)->where('id', $currency_id)->first();

return $currency->conversions()->where('conversion_id', $conversion_id)->first()->ratio();
}

/**
* Converts currency from one type to another.
*
* @param App\Services\CurrencyManager $service
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postConvertCurrency(Request $request, CurrencyManager $service) {
$data = $request->only(['currency_id', 'conversion_id', 'quantity']);
if ($service->convertCurrency(Currency::find($data['currency_id']), Currency::find($data['conversion_id']), $data['quantity'], Auth::user())) {
flash('Currency converted successfully.')->success();
} else {
foreach ($service->errors()->getMessages()['error'] as $error) {
flash($error)->error();
}
}

return redirect()->back();
}
}
Loading

0 comments on commit 53579e4

Please sign in to comment.