Skip to content

Commit

Permalink
Bug(Visual Trait Index): Hidden Traits were still showing when they s…
Browse files Browse the repository at this point in the history
…houldn't
  • Loading branch information
AW0005 committed Feb 7, 2024
1 parent 1762a80 commit c8ea950
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/Models/Feature/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public function scopeSortOldest($query) {
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeVisible($query, $withHidden = 0) {
if ($withHidden) {
public function scopeVisible($query, $user = null) {
if ($user && $user->hasPower('edit_data')) {
return $query;
}

Expand Down Expand Up @@ -297,14 +297,15 @@ public function getAdminPowerAttribute() {
**********************************************************************************************/

public static function getDropdownItems($withHidden = 0) {
$visibleOnly = 1;
if ($withHidden) {
$visibleOnly = 0;
}

if (config('lorekeeper.extensions.organised_traits_dropdown')) {
$visibleOnly = 1;
if ($withHidden) {
$visibleOnly = 0;
}
$sorted_feature_categories = collect(FeatureCategory::all()->where('is_visible', '>=', $visibleOnly)->sortBy('sort')->pluck('name')->toArray());

$grouped = self::visible($withHidden)->select('name', 'id', 'feature_category_id')->with('category')->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)->toArray();
$grouped = self::where('is_visible', '>=', $visibleOnly)->select('name', 'id', 'feature_category_id')->with('category')->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)->toArray();
if (isset($grouped[''])) {
if (!$sorted_feature_categories->contains('Miscellaneous')) {
$sorted_feature_categories->push('Miscellaneous');
Expand All @@ -327,7 +328,7 @@ public static function getDropdownItems($withHidden = 0) {

return $features_by_category;
} else {
return self::visible($withHidden)->orderBy('name')->pluck('name', 'id')->toArray();
return self::where('is_visible', '>=', $visibleOnly)->orderBy('name')->pluck('name', 'id')->toArray();
}
}
}

0 comments on commit c8ea950

Please sign in to comment.