284 lines
18 KiB
PHP
284 lines
18 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\animal_management\models\AnimalTransfer;
|
|
use humhub\modules\space\models\Space;
|
|
use humhub\widgets\Button;
|
|
use yii\helpers\Html;
|
|
|
|
/* @var Animal[] $animals */
|
|
/* @var AnimalTransfer[] $incomingTransfers */
|
|
/* @var AnimalTransfer[] $outgoingTransfers */
|
|
/* @var string $queryValue */
|
|
/* @var string $statusFilter */
|
|
/* @var string $speciesFilter */
|
|
/* @var string $viewMode */
|
|
/* @var string $sortKey */
|
|
/* @var string $sortDirection */
|
|
/* @var array $availableColumns */
|
|
/* @var array $selectedColumns */
|
|
/* @var array $speciesOptions */
|
|
/* @var array<int, AnimalMedicalVisit> $latestMedicalVisitByAnimal */
|
|
/* @var array<int, string> $animalImageUrls */
|
|
/* @var array<int, string> $transferAnimalImageUrls */
|
|
/* @var array $tileFields */
|
|
/* @var array<int, array> $tileFieldOverrides */
|
|
/* @var Space $space */
|
|
/* @var bool $canManage */
|
|
|
|
$currentParams = [
|
|
'q' => $queryValue,
|
|
'status' => $statusFilter,
|
|
'species' => $speciesFilter,
|
|
'view' => $viewMode,
|
|
'sort' => $sortKey,
|
|
'direction' => $sortDirection,
|
|
'cols' => $selectedColumns,
|
|
];
|
|
|
|
$buildUrl = static function (array $overrides) use ($space, $currentParams): string {
|
|
$params = array_merge($currentParams, $overrides);
|
|
return $space->createUrl('/animal_management/animals/index', $params);
|
|
};
|
|
|
|
$sortUrl = static function (string $column) use ($buildUrl, $sortKey, $sortDirection): string {
|
|
$nextDirection = ($sortKey === $column && $sortDirection === 'asc') ? 'desc' : 'asc';
|
|
return $buildUrl(['sort' => $column, 'direction' => $nextDirection, 'view' => 'table']);
|
|
};
|
|
?>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading" style="display:flex;justify-content:space-between;align-items:center;">
|
|
<span><?= Yii::t('AnimalManagementModule.base', '<strong>Animals</strong>') ?></span>
|
|
<span style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
|
|
<?= Html::a('<i class="fa fa-th-large"></i>', $buildUrl(['view' => 'tiles']), [
|
|
'class' => 'btn btn-default btn-sm' . ($viewMode === 'tiles' ? ' active' : ''),
|
|
'title' => Yii::t('AnimalManagementModule.base', 'Tile View'),
|
|
'aria-label' => Yii::t('AnimalManagementModule.base', 'Tile View'),
|
|
]) ?>
|
|
<?= Html::a('<i class="fa fa-table"></i>', $buildUrl(['view' => 'table']), [
|
|
'class' => 'btn btn-default btn-sm' . ($viewMode === 'table' ? ' active' : ''),
|
|
'title' => Yii::t('AnimalManagementModule.base', 'Table View'),
|
|
'aria-label' => Yii::t('AnimalManagementModule.base', 'Table View'),
|
|
]) ?>
|
|
<?php if ($canManage): ?>
|
|
<?= Html::a('<i class="fa fa-plus"></i> ' . Yii::t('AnimalManagementModule.base', 'Intake'), $space->createUrl('/animal_management/animals/create'), [
|
|
'class' => 'btn btn-primary btn-sm',
|
|
'title' => Yii::t('AnimalManagementModule.base', 'Intake'),
|
|
'aria-label' => Yii::t('AnimalManagementModule.base', 'Intake'),
|
|
]) ?>
|
|
<?php endif; ?>
|
|
</span>
|
|
</div>
|
|
|
|
<div class="panel-body">
|
|
<form method="get" action="<?= Html::encode($space->createUrl('/animal_management/animals/index')) ?>" class="form-inline" style="margin-bottom:12px;display:flex;gap:8px;flex-wrap:wrap;">
|
|
<input type="hidden" name="view" value="<?= Html::encode($viewMode) ?>">
|
|
<input type="hidden" name="sort" value="<?= Html::encode($sortKey) ?>">
|
|
<input type="hidden" name="direction" value="<?= Html::encode($sortDirection) ?>">
|
|
<?php foreach ($selectedColumns as $col): ?>
|
|
<input type="hidden" name="cols[]" value="<?= Html::encode($col) ?>">
|
|
<?php endforeach; ?>
|
|
|
|
<div class="form-group" style="flex:1;min-width:260px;">
|
|
<input type="text" class="form-control" style="width:100%;" name="q" value="<?= Html::encode($queryValue) ?>" placeholder="<?= Yii::t('AnimalManagementModule.base', 'Search by name, species, ID, or breed') ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<?= Html::dropDownList('status', $statusFilter, ['' => Yii::t('AnimalManagementModule.base', 'All Statuses')] + Animal::statusOptions(), ['class' => 'form-control']) ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<?php $speciesDropDown = ['' => Yii::t('AnimalManagementModule.base', 'All Species')]; ?>
|
|
<?php foreach ($speciesOptions as $speciesOption): ?>
|
|
<?php $speciesDropDown[$speciesOption] = $speciesOption; ?>
|
|
<?php endforeach; ?>
|
|
<?= Html::dropDownList('species', $speciesFilter, $speciesDropDown, ['class' => 'form-control']) ?>
|
|
</div>
|
|
<button type="submit" class="btn btn-default"><?= Yii::t('AnimalManagementModule.base', 'Apply') ?></button>
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Reset'))->link($space->createUrl('/animal_management/animals/index', ['view' => $viewMode])) ?>
|
|
</form>
|
|
|
|
<?php if ($viewMode === 'table'): ?>
|
|
<details style="margin-bottom:12px;">
|
|
<summary style="cursor:pointer;"><?= Yii::t('AnimalManagementModule.base', 'Show/Hide Columns') ?></summary>
|
|
<form method="get" action="<?= Html::encode($space->createUrl('/animal_management/animals/index')) ?>" style="margin-top:8px;display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
|
|
<input type="hidden" name="view" value="table">
|
|
<input type="hidden" name="q" value="<?= Html::encode($queryValue) ?>">
|
|
<input type="hidden" name="status" value="<?= Html::encode($statusFilter) ?>">
|
|
<input type="hidden" name="species" value="<?= Html::encode($speciesFilter) ?>">
|
|
<input type="hidden" name="sort" value="<?= Html::encode($sortKey) ?>">
|
|
<input type="hidden" name="direction" value="<?= Html::encode($sortDirection) ?>">
|
|
<?php foreach ($availableColumns as $columnKey => $columnLabel): ?>
|
|
<label style="margin:0 8px 0 0;">
|
|
<input type="checkbox" name="cols[]" value="<?= Html::encode($columnKey) ?>" <?= in_array($columnKey, $selectedColumns, true) ? 'checked' : '' ?> <?= $columnKey === 'name' ? 'disabled' : '' ?>>
|
|
<?= Html::encode($columnLabel) ?>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
<button type="submit" class="btn btn-default btn-sm"><?= Yii::t('AnimalManagementModule.base', 'Update Columns') ?></button>
|
|
</form>
|
|
</details>
|
|
<?php endif; ?>
|
|
|
|
<?php if (empty($animals)): ?>
|
|
<div class="alert alert-info" style="margin-bottom:0;">
|
|
<?= Yii::t('AnimalManagementModule.base', 'No animal profiles yet. Create the first intake record to begin tracking.') ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php if ($viewMode === 'tiles'): ?>
|
|
<div class="row">
|
|
<?php foreach ($animals as $animal): ?>
|
|
<?php $animalId = (int)$animal->id; ?>
|
|
<?php $lastMedical = $latestMedicalVisitByAnimal[$animalId] ?? null; ?>
|
|
<div class="col-sm-6 col-md-4" style="margin-bottom:16px;">
|
|
<?= $this->render('_tile', [
|
|
'animal' => $animal,
|
|
'contentContainer' => $space,
|
|
'lastMedical' => $lastMedical,
|
|
'imageUrl' => $animalImageUrls[$animalId] ?? '',
|
|
'tileFields' => $tileFieldOverrides[$animalId] ?? $tileFields,
|
|
'showMedicalIcon' => true,
|
|
]) ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<?php if (in_array('animal_uid', $selectedColumns, true)): ?>
|
|
<th><a href="<?= Html::encode($sortUrl('animal_uid')) ?>"><?= Yii::t('AnimalManagementModule.base', 'ID') ?></a></th>
|
|
<?php endif; ?>
|
|
<th><a href="<?= Html::encode($sortUrl('name')) ?>"><?= Yii::t('AnimalManagementModule.base', 'Name') ?></a></th>
|
|
<?php if (in_array('species', $selectedColumns, true)): ?>
|
|
<th><a href="<?= Html::encode($sortUrl('species')) ?>"><?= Yii::t('AnimalManagementModule.base', 'Species') ?></a></th>
|
|
<?php endif; ?>
|
|
<?php if (in_array('status', $selectedColumns, true)): ?>
|
|
<th><a href="<?= Html::encode($sortUrl('status')) ?>"><?= Yii::t('AnimalManagementModule.base', 'Status') ?></a></th>
|
|
<?php endif; ?>
|
|
<?php if (in_array('last_medical', $selectedColumns, true)): ?>
|
|
<th><a href="<?= Html::encode($sortUrl('last_medical')) ?>"><?= Yii::t('AnimalManagementModule.base', 'Last Medical Visit') ?></a></th>
|
|
<?php endif; ?>
|
|
<?php if (in_array('updated_at', $selectedColumns, true)): ?>
|
|
<th><a href="<?= Html::encode($sortUrl('updated_at')) ?>"><?= Yii::t('AnimalManagementModule.base', 'Updated') ?></a></th>
|
|
<?php endif; ?>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($animals as $animal): ?>
|
|
<?php $lastMedical = $latestMedicalVisitByAnimal[(int)$animal->id] ?? null; ?>
|
|
<tr>
|
|
<?php if (in_array('animal_uid', $selectedColumns, true)): ?>
|
|
<td><?= Html::encode($animal->animal_uid) ?></td>
|
|
<?php endif; ?>
|
|
<td>
|
|
<a href="<?= Html::encode($space->createUrl('/animal_management/animals/view', ['id' => $animal->id])) ?>">
|
|
<?= Html::encode($animal->getDisplayName()) ?>
|
|
</a>
|
|
</td>
|
|
<?php if (in_array('species', $selectedColumns, true)): ?>
|
|
<td><?= Html::encode((string)$animal->species) ?></td>
|
|
<?php endif; ?>
|
|
<?php if (in_array('status', $selectedColumns, true)): ?>
|
|
<td><?= Html::encode(Animal::statusOptions()[$animal->status] ?? $animal->status) ?></td>
|
|
<?php endif; ?>
|
|
<?php if (in_array('last_medical', $selectedColumns, true)): ?>
|
|
<td>
|
|
<?php if ($lastMedical instanceof AnimalMedicalVisit): ?>
|
|
<a href="<?= Html::encode($space->createUrl('/animal_management/animals/medical-visits', ['id' => $animal->id]) . '#medical-visit-' . (int)$lastMedical->id) ?>">
|
|
<?= Html::encode(DateDisplayHelper::format((string)$lastMedical->visit_at)) ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<span class="text-muted">-</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<?php endif; ?>
|
|
<?php if (in_array('updated_at', $selectedColumns, true)): ?>
|
|
<td><?= Html::encode(DateDisplayHelper::format((string)$animal->updated_at)) ?></td>
|
|
<?php endif; ?>
|
|
<td class="text-right" style="white-space:nowrap;">
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'View'))
|
|
->link($space->createUrl('/animal_management/animals/view', ['id' => $animal->id])) ?>
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Medical'))
|
|
->link($space->createUrl('/animal_management/animals/medical-visits', ['id' => $animal->id])) ?>
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Progress'))
|
|
->link($space->createUrl('/animal_management/animals/progress-updates', ['id' => $animal->id])) ?>
|
|
<?php if ($canManage): ?>
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Edit'))
|
|
->link($space->createUrl('/animal_management/animals/edit', ['id' => $animal->id])) ?>
|
|
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Transfer'))
|
|
->link($space->createUrl('/animal_management/animals/transfer', ['id' => $animal->id])) ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($canManage): ?>
|
|
<hr>
|
|
|
|
<h4 id="incoming-transfers" style="margin-top:0;"><?= Yii::t('AnimalManagementModule.base', 'Incoming Transfer Requests') ?></h4>
|
|
<?php if (empty($incomingTransfers)): ?>
|
|
<div class="text-muted" style="margin-bottom:12px;"><?= Yii::t('AnimalManagementModule.base', 'No incoming requests.') ?></div>
|
|
<?php else: ?>
|
|
<div class="row" style="margin-bottom:4px;">
|
|
<?php foreach ($incomingTransfers as $transfer): ?>
|
|
<?php
|
|
$fromSpace = $transfer->getFromSpace();
|
|
$toSpace = $transfer->getToSpace();
|
|
$animalLinkSpace = ($transfer->status === AnimalTransfer::STATUS_COMPLETED)
|
|
? ($toSpace ?: $fromSpace)
|
|
: ($fromSpace ?: $toSpace);
|
|
?>
|
|
<div class="col-sm-6" style="margin-bottom:14px;">
|
|
<?= $this->render('_transfer_tile', [
|
|
'transfer' => $transfer,
|
|
'space' => $space,
|
|
'otherRescueName' => $fromSpace ? $fromSpace->name : Yii::t('AnimalManagementModule.base', 'Unknown Rescue'),
|
|
'otherRescueUrl' => $fromSpace ? $fromSpace->createUrl('/space/space/home') : '',
|
|
'animalProfileUrl' => $animalLinkSpace ? $animalLinkSpace->createUrl('/animal_management/animals/view', ['id' => $transfer->animal_id]) : '',
|
|
'imageUrl' => trim((string)($transferAnimalImageUrls[(int)$transfer->animal_id] ?? '')),
|
|
'isIncoming' => true,
|
|
]) ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h4 id="outgoing-transfers"><?= Yii::t('AnimalManagementModule.base', 'Outgoing Transfer History') ?></h4>
|
|
<?php if (empty($outgoingTransfers)): ?>
|
|
<div class="text-muted"><?= Yii::t('AnimalManagementModule.base', 'No outgoing transfers yet.') ?></div>
|
|
<?php else: ?>
|
|
<div class="row" style="margin-bottom:0;">
|
|
<?php foreach ($outgoingTransfers as $transfer): ?>
|
|
<?php
|
|
$fromSpace = $transfer->getFromSpace();
|
|
$toSpace = $transfer->getToSpace();
|
|
$animalLinkSpace = ($transfer->status === AnimalTransfer::STATUS_COMPLETED)
|
|
? ($toSpace ?: $fromSpace)
|
|
: ($fromSpace ?: $toSpace);
|
|
?>
|
|
<div class="col-sm-6 col-md-4" style="margin-bottom:14px;">
|
|
<?= $this->render('_transfer_tile', [
|
|
'transfer' => $transfer,
|
|
'space' => $space,
|
|
'otherRescueName' => $toSpace ? $toSpace->name : Yii::t('AnimalManagementModule.base', 'Unknown Rescue'),
|
|
'otherRescueUrl' => $toSpace ? $toSpace->createUrl('/space/space/home') : '',
|
|
'animalProfileUrl' => $animalLinkSpace ? $animalLinkSpace->createUrl('/animal_management/animals/view', ['id' => $transfer->animal_id]) : '',
|
|
'imageUrl' => trim((string)($transferAnimalImageUrls[(int)$transfer->animal_id] ?? '')),
|
|
'isIncoming' => false,
|
|
]) ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|