94 lines
4.7 KiB
PHP
94 lines
4.7 KiB
PHP
<?php
|
|
|
|
use humhub\modules\animal_management\models\Animal;
|
|
use humhub\modules\animal_management\helpers\DateDisplayHelper;
|
|
use humhub\modules\animal_management\models\AnimalMedicalVisit;
|
|
use humhub\modules\content\components\ContentContainerActiveRecord;
|
|
use yii\helpers\Html;
|
|
|
|
/* @var Animal $animal */
|
|
/* @var ContentContainerActiveRecord $contentContainer */
|
|
/* @var AnimalMedicalVisit|null $lastMedical */
|
|
/* @var string $imageUrl */
|
|
/* @var array $tileFields */
|
|
/* @var bool $showMedicalIcon */
|
|
|
|
$showMedicalIcon = isset($showMedicalIcon) ? (bool)$showMedicalIcon : true;
|
|
$imageUrl = trim((string)$imageUrl);
|
|
$hasImage = $imageUrl !== '' && (preg_match('/^https?:\/\//i', $imageUrl) || substr($imageUrl, 0, 1) === '/');
|
|
|
|
$statusLabel = Animal::statusOptions()[$animal->status] ?? (string)$animal->status;
|
|
$fieldMap = [
|
|
'name' => (string)$animal->getDisplayName(),
|
|
'species' => (string)$animal->species,
|
|
'breed' => (string)$animal->breed,
|
|
'sex' => (string)$animal->sex,
|
|
'status' => (string)$statusLabel,
|
|
'location_name' => (string)$animal->location_name,
|
|
'animal_uid' => (string)$animal->animal_uid,
|
|
'public_summary' => trim((string)$animal->public_summary),
|
|
'last_medical' => $lastMedical instanceof AnimalMedicalVisit ? DateDisplayHelper::format((string)$lastMedical->visit_at) : '',
|
|
];
|
|
|
|
$tileFields = is_array($tileFields) ? $tileFields : [];
|
|
$selectedMeta = [];
|
|
foreach ($tileFields as $fieldKey) {
|
|
$fieldKey = trim((string)$fieldKey);
|
|
if ($fieldKey === '' || $fieldKey === 'name' || !array_key_exists($fieldKey, $fieldMap)) {
|
|
continue;
|
|
}
|
|
|
|
$value = trim((string)$fieldMap[$fieldKey]);
|
|
if ($value === '') {
|
|
continue;
|
|
}
|
|
|
|
$selectedMeta[] = $value;
|
|
}
|
|
|
|
$summaryText = trim((string)$fieldMap['public_summary']);
|
|
if ($summaryText !== '') {
|
|
$summaryText = substr($summaryText, 0, 160) . (strlen($summaryText) > 160 ? '...' : '');
|
|
}
|
|
|
|
$animalViewUrl = $contentContainer->createUrl('/animal_management/animals/view', ['id' => $animal->id]);
|
|
$medicalUrl = $contentContainer->createUrl('/animal_management/animals/medical-visits', ['id' => $animal->id]);
|
|
?>
|
|
|
|
<div class="panel panel-default" style="margin-bottom:0;overflow:hidden;border-radius:12px;border:0;box-shadow:0 8px 24px rgba(15,23,42,0.14);">
|
|
<div style="display:block;position:relative;aspect-ratio:4 / 3;background:#d8dee8;">
|
|
<a href="<?= Html::encode($animalViewUrl) ?>" aria-label="<?= Html::encode($animal->getDisplayName()) ?>" style="position:absolute;inset:0;z-index:1;"></a>
|
|
<?php if ($hasImage): ?>
|
|
<img src="<?= Html::encode($imageUrl) ?>" alt="<?= Html::encode($animal->getDisplayName()) ?>" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;">
|
|
<?php endif; ?>
|
|
<div style="position:absolute;inset:0;background:linear-gradient(180deg, rgba(7,10,16,0.05) 0%, rgba(7,10,16,0.62) 58%, rgba(7,10,16,0.78) 100%);"></div>
|
|
|
|
<div style="position:absolute;left:12px;right:12px;bottom:12px;z-index:2;color:#fff;pointer-events:none;">
|
|
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:6px;">
|
|
<span style="font-size:20px;font-weight:700;line-height:1.15;text-shadow:0 2px 8px rgba(0,0,0,0.4);color:#fff;">
|
|
<?= Html::encode($animal->getDisplayName()) ?>
|
|
</span>
|
|
<?php if ($showMedicalIcon): ?>
|
|
<a href="<?= Html::encode($medicalUrl) ?>" class="btn btn-xs btn-default" title="<?= Yii::t('AnimalManagementModule.base', 'Medical Visits') ?>" aria-label="<?= Yii::t('AnimalManagementModule.base', 'Medical Visits') ?>" style="border-radius:999px;padding:6px 8px;background:rgba(255,255,255,0.92);border:0;position:relative;z-index:3;pointer-events:auto;">
|
|
<i class="fa fa-heartbeat"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php if (!empty($selectedMeta)): ?>
|
|
<div style="display:flex;gap:6px;flex-wrap:wrap;margin-bottom:6px;">
|
|
<?php foreach ($selectedMeta as $metaValue): ?>
|
|
<span style="display:inline-block;background:rgba(15,23,42,0.58);border:1px solid rgba(255,255,255,0.28);padding:2px 8px;border-radius:999px;font-size:12px;">
|
|
<?= Html::encode($metaValue) ?>
|
|
</span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($summaryText !== ''): ?>
|
|
<div style="font-size:12px;line-height:1.35;color:rgba(255,255,255,0.92);text-shadow:0 1px 4px rgba(0,0,0,0.5);">
|
|
<?= Html::encode($summaryText) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|