Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor entry() to parsedEntry() to avoid confusion #882

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function toArray($request)
'name' => $model->name,
'visibility_id' => (int) $model->visibility_id->value,
'entry' => $model->entry,
'entry_parsed' => $model->entry(),
'entry_parsed' => $model->parsedEntry(),
// 'is_pinned' => (bool) $this->is_pinned,
'position' => $model->position,
'settings' => $model->settings,
Expand Down
2 changes: 1 addition & 1 deletion app/Models/AttributeTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function hasVisibleAttributes($names = []): bool
* Attribute Templates have no entry field
* @return mixed|string
*/
public function entry()
public function parsedEntry()
{
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function preview(): string
return $this->excerpt();
}
if (!empty(strip_tags($this->entry))) {
return strip_tags(mb_substr($this->entry(), 0, 1000)) . ' ...';
return strip_tags(mb_substr($this->parsedEntry(), 0, 1000)) . ' ...';
}
return '';
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public function isHidden(): bool

/**
*/
public function entry()
public function parsedEntry()
{
return Mentions::mapAny($this);
}
Expand Down
7 changes: 0 additions & 7 deletions app/Models/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ public function entityTypeId(): int
return (int) config('entities.ids.conversation');
}

/**
*/
public function entry()
{
return '';
}

/**
*/
public function forCharacters(): bool
Expand Down
2 changes: 1 addition & 1 deletion app/Models/DiceRoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function entityTypeId(): int
/**
* @return mixed|string
*/
public function entry()
public function parsedEntry()
{
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function mappedPreview(): string
return (string)strip_tags($text);
}
}
return Str::limit(strip_tags($this->child->entry()), 500);
return Str::limit(strip_tags($this->child->parsedEntry()), 500);
}


Expand Down
12 changes: 7 additions & 5 deletions app/Models/EntityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use App\Models\Concerns\SortableTrait;
use App\Traits\VisibilityIDTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -15,6 +16,7 @@
* Class EntityEvent
* @package App\Models
*
* @property int $id
* @property int $entity_id
* @property int $calendar_id
* @property string $date
Expand All @@ -34,7 +36,7 @@
* @property EntityEvent|null $death
* @property EntityEventType|null $type
*/
class EntityEvent extends MiscModel
class EntityEvent extends Model
{
use Blameable;
use EntityEventScopes;
Expand All @@ -45,8 +47,8 @@ class EntityEvent extends MiscModel
/** @var string */
public $table = 'entity_events';

/** @var string|null Cached readable date */
protected string|null $readableDate = null;
/** @var string Cached readable date */
protected string $readableDate;

protected $fillable = [
'calendar_id',
Expand Down Expand Up @@ -85,7 +87,7 @@ public function calendar(): BelongsTo
return $this->belongsTo(Calendar::class, 'calendar_id');
}

public function entity()
public function entity(): BelongsTo
{
return $this->belongsTo(Entity::class, 'entity_id');
}
Expand All @@ -99,7 +101,7 @@ public function type(): BelongsTo
*/
public function readableDate(): string
{
if ($this->readableDate === null) {
if (!isset($this->readableDate)) {
// Replace month with real month, and year maybe
$months = $this->calendar->months();
$years = $this->calendar->years();
Expand Down
2 changes: 1 addition & 1 deletion app/Models/EntityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @property int $impersonated_by
* @property int $action
* @property int $post_id
* @property string|array $changes
* @property null|string|array $changes
* @property Entity|null $entity
* @property User|null $user
* @property User|null $impersonator
Expand Down
2 changes: 1 addition & 1 deletion app/Models/MiscModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function entityTypeSuggestion(int $take = 20): array

/**
*/
public function entry()
public function parsedEntry()
{
return Mentions::map($this);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/PluginVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ protected function abilities(Entity $entity): array
'name' => $abi->ability->name,
'slug' => $abi->ability->slug,
'type' => $abi->ability->type,
'entry' => $abi->ability->entry(),
'entry' => $abi->ability->parsedEntry(),
'charges' => $abi->ability->charges,
'used_charges' => $abi->charges,
'thumb' => '<img src="' . Avatar::entity($abi->ability->entity)->child($abi->ability)->size(40)->thumbnail() . '" class="ability-thumb"></i>',
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function copyTo(Entity $target)

/**
*/
public function entry()
public function parsedEntry()
{
return Mentions::mapPost($this);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/QuestElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function entity()

/**
*/
public function entry()
public function parsedEntry()
{
return Mentions::mapAny($this, 'description');
}
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Relations/EntityRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public function tags(): BelongsToMany
);
}

/**
* @return Collection|Tag[]
*/
public function tagsWithEntity(bool $excludeHidden = false): Collection
{
if (!isset($this->tagsWithEntity)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Models/TimelineElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getEntryForEditionAttribute()

/**
*/
public function entry()
public function parsedEntry()
{
return Mentions::mapAny($this);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Abilities/AbilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function add(EntityAbility $entityAbility): void
'type' => $parent->type,
'image' => Avatar::entity($parent->entity)->size(192)->thumbnail(),
'has_image' => !empty($parent->entity->image_path) || !empty($parent->entity->image),
'entry' => $parent->entry(),
'entry' => $parent->parsedEntry(),
'parent' => true,
'abilities' => [],
'url' => $parent->getLink(),
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Abilities/BaseAbilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function parseCharges(Ability $ability)
*/
protected function parseEntry(Ability $ability)
{
$entry = $ability->entry();
$entry = $ability->parsedEntry();
try {
return $this->mapAttributes($entry, false);
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion app/Services/MentionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ protected function replaceEntityMentions(): void
if ($field === 'entry') {
if ($this->enableEntryField) {
$this->lockEntryRendering();
$parsedTargetEntry = $entity->child->entry();
$parsedTargetEntry = $entity->child->parsedEntry();
$this->unlockEntryRendering();
} else {
$parsedTargetEntry = $entity->child->entry;
Expand Down
9 changes: 6 additions & 3 deletions app/Services/Submenus/AbilitySubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
namespace App\Services\Submenus;

use App\Facades\Module;
use App\Models\Ability;

class AbilitySubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
/** @var Ability $ability */
$ability = $this->model;
$items['second']['abilities'] = [
'name' => Module::plural($this->model->entityTypeId(), 'entities.abilities'),
'name' => Module::plural($ability->entityTypeId(), 'entities.abilities'),
'route' => 'abilities.abilities',
'count' => $this->model->descendants()->count()
'count' => $ability->descendants()->count()
];
$items['second']['entities'] = [
'name' => 'abilities.show.tabs.entities',
'route' => 'abilities.entities',
'count' => $this->model->entities()->count()
'count' => $ability->entities()->count()
];
return $items;
}
Expand Down
5 changes: 3 additions & 2 deletions app/Services/Submenus/BaseSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Submenus;

use App\Models\MiscModel;
use App\Traits\CampaignAware;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -10,9 +11,9 @@ class BaseSubmenu
use CampaignAware;

protected array $items;
protected Model $model;
protected Model|MiscModel $model;

public function model(Model $model): self
public function model(Model|MiscModel $model): self
{
$this->model = $model;
return $this;
Expand Down
6 changes: 5 additions & 1 deletion app/Services/Submenus/CalendarSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace App\Services\Submenus;

use App\Models\Calendar;

class CalendarSubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$count = $this->model->calendarEvents()->has('entity')->count();
/** @var Calendar $calendar */
$calendar = $this->model;
$count = $calendar->calendarEvents()->has('entity')->count();
$items = [];
if ($count > 0) {
$items['second']['events'] = [
Expand Down
11 changes: 7 additions & 4 deletions app/Services/Submenus/CharacterSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
namespace App\Services\Submenus;

use App\Facades\Module;
use App\Models\Character;

class CharacterSubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
$canEdit = auth()->check() && auth()->user()->can('update', $this->model);
/** @var Character $character */
$character = $this->model;
$canEdit = auth()->check() && auth()->user()->can('update', $character);

$items['second']['profile'] = [
'name' => 'entities/profile.show.tab_name',
'route' => 'entities.profile',
'entity' => true,

'button' => auth()->check() && auth()->user()->can('update', $this->model) ? [
'url' => $this->model->getLink('edit'),
'button' => auth()->check() && auth()->user()->can('update', $character) ? [
'url' => $character->getLink('edit'),
'icon' => 'fa-solid fa-pencil',
'tooltip' => __('crud.edit'),
] : null,
];

$count = $this->model->organisationMemberships()->has('organisation')->count();
$count = $character->organisationMemberships()->has('organisation')->count();
if ($this->campaign->enabled('organisations') && ($count > 0 || $canEdit)) {
$items['second']['organisations'] = [
'name' => Module::plural(config('entities.ids.organisation'), 'entities.organisations'),
Expand Down
7 changes: 5 additions & 2 deletions app/Services/Submenus/CreatureSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace App\Services\Submenus;

use App\Facades\Module;
use App\Models\Creature;

class CreatureSubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
$count = $this->model->descendants()->count();
/** @var Creature $creature */
$creature = $this->model;
$count = $creature->descendants()->count();
if ($count > 0) {
$items['second']['creatures'] = [
'name' => Module::plural($this->model->entityTypeId(), 'entities.creatures'),
'name' => Module::plural($creature->entityTypeId(), 'entities.creatures'),
'route' => 'creatures.creatures',
'count' => $count
];
Expand Down
7 changes: 5 additions & 2 deletions app/Services/Submenus/EventSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace App\Services\Submenus;

use App\Facades\Module;
use App\Models\Event;

class EventSubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
/** @var Event $event */
$event = $this->model;
$items['second']['events'] = [
'name' => Module::plural($this->model->entityTypeId(), 'entities.events'),
'name' => Module::plural($event->entityTypeId(), 'entities.events'),
'route' => 'events.events',
'count' => $this->model->descendants()->count()
'count' => $event->descendants()->count()
];
return $items;
}
Expand Down
7 changes: 5 additions & 2 deletions app/Services/Submenus/FamilySubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace App\Services\Submenus;

use App\Facades\Module;
use App\Models\Family;

class FamilySubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
/** @var Family $family */
$family = $this->model;
$items['second']['families'] = [
'name' => Module::plural($this->model->entityTypeId(), 'entities.families'),
'name' => Module::plural($family->entityTypeId(), 'entities.families'),
'route' => 'families.families',
'count' => $this->model->descendants()->count()
'count' => $family->descendants()->count()
];

if (config('services.stripe.enabled')) {
Expand Down
6 changes: 5 additions & 1 deletion app/Services/Submenus/ItemSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace App\Services\Submenus;

use App\Models\Item;

class ItemSubmenu extends BaseSubmenu implements EntitySubmenu
{
public function extra(): array
{
$items = [];
$inventoryCount = $this->model->inventories()->with('item')->has('entity')->count();
/** @var Item $item */
$item = $this->model;
$inventoryCount = $item->inventories()->with('item')->has('entity')->count();
if ($inventoryCount > 0) {
$items['second']['inventories'] = [
'name' => 'items.show.tabs.inventories',
Expand Down
Loading
Loading