98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\Post;
|
|
use Illuminate\Support\Facades\App;
|
|
use Livewire\Component;
|
|
|
|
class AccountUsageInfoModal extends Component
|
|
{
|
|
public $show = false;
|
|
public $post = null;
|
|
public $image = null;
|
|
public $imageCaption = null;
|
|
public $imageOwner = null;
|
|
public $fallbackTitle;
|
|
public $fallbackDescription;
|
|
|
|
protected $listeners = ['openAccountUsageInfoModal' => 'open'];
|
|
|
|
public function mount()
|
|
{
|
|
$this->fallbackTitle = __('Account usage');
|
|
$this->fallbackDescription = __('The account usage bar provides a visual representation of your currency holdings, similar to a disk space bar but for money. It displays both the amount of currency you currently possess and the maximum limit of your account.');
|
|
}
|
|
|
|
public function open()
|
|
{
|
|
$this->show = true;
|
|
$this->loadPost();
|
|
}
|
|
|
|
public function loadPost()
|
|
{
|
|
$locale = App::getLocale();
|
|
|
|
$this->post = Post::with([
|
|
'category',
|
|
'media',
|
|
'translations' => function ($query) use ($locale) {
|
|
$query->where('locale', $locale)
|
|
->orderBy('created_at', 'desc')
|
|
->limit(3);
|
|
}
|
|
])
|
|
->whereHas('category', function ($query) {
|
|
$query->where('type', 'SiteContents\AccountUsage\Info');
|
|
})
|
|
->whereHas('translations', function ($query) use ($locale) {
|
|
$query->where('locale', $locale)
|
|
->whereDate('from', '<=', now())
|
|
->where(function ($query) {
|
|
$query->whereDate('till', '>', now())->orWhereNull('till');
|
|
})
|
|
->orderBy('updated_at', 'desc');
|
|
})
|
|
->orderBy('created_at', 'desc')
|
|
->limit(3)
|
|
->first();
|
|
|
|
if ($this->post && $this->post->hasMedia('posts')) {
|
|
$this->image = $this->post->getFirstMediaUrl('posts', 'half_hero');
|
|
$mediaItem = $this->post->getFirstMedia('posts');
|
|
if ($mediaItem) {
|
|
// Get owner
|
|
$this->imageOwner = $mediaItem->getCustomProperty('owner');
|
|
|
|
// Try to get caption for current locale
|
|
$this->imageCaption = $mediaItem->getCustomProperty('caption-' . $locale);
|
|
|
|
// If not found, try fallback locales
|
|
if (!$this->imageCaption) {
|
|
$fallbackLocales = ['en', 'nl', 'de', 'es', 'fr'];
|
|
foreach ($fallbackLocales as $fallbackLocale) {
|
|
$this->imageCaption = $mediaItem->getCustomProperty('caption-' . $fallbackLocale);
|
|
if ($this->imageCaption) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
$this->show = false;
|
|
$this->image = null;
|
|
$this->imageCaption = null;
|
|
$this->imageOwner = null;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.account-usage-info-modal');
|
|
}
|
|
}
|