Initial import of animal_management module

This commit is contained in:
Kelin Rescue Hub
2026-04-04 13:13:00 -04:00
commit 20adb1bd1e
65 changed files with 14004 additions and 0 deletions

View File

@@ -0,0 +1,497 @@
<?php
use humhub\modules\animal_management\models\Animal;
use humhub\modules\animal_management\models\AnimalGalleryItem;
use humhub\modules\animal_management\models\AnimalMedicalVisit;
use humhub\modules\animal_management\models\forms\AnimalMedicalVisitForm;
use humhub\modules\space\models\Space;
use humhub\widgets\Button;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Json;
/* @var Space $space */
/* @var Animal $animal */
/* @var AnimalMedicalVisitForm $model */
/* @var AnimalMedicalVisit $medicalVisit */
/* @var string $returnTo */
/* @var AnimalGalleryItem[] $galleryItems */
/* @var bool $isInline */
$isInline = isset($isInline) ? (bool)$isInline : false;
$hiddenMedicalKeys = [
'second_physician_name',
'second_physician_business_name',
'second_physician_street_address',
'second_physician_city',
'second_physician_state',
'second_physician_zip',
'second_physician_cell_phone',
'second_physician_business_phone',
'second_physician_license_number',
'previous_physicians',
];
$renderCustomField = static function (string $fieldKey, AnimalMedicalVisitForm $formModel, array $definitions): string {
if (!isset($definitions[$fieldKey])) {
return '';
}
$definition = $definitions[$fieldKey];
$inputType = (string)$definition['input_type'];
$vitalLabelOverrides = [
'blood_pressure' => 'BP',
'oxygen' => 'O₂',
];
$label = (string)($vitalLabelOverrides[$fieldKey] ?? $definition['label']);
if ((int)$definition['required'] === 1) {
$label .= ' *';
}
$fieldName = "AnimalMedicalVisitForm[customFields][$fieldKey]";
$fieldValue = $formModel->customFields[$fieldKey] ?? '';
ob_start();
?>
<?php if ($inputType === 'textarea'): ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::textarea($fieldName, (string)$fieldValue, ['class' => 'form-control', 'rows' => 3, 'id' => "animalmedicalvisitform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'boolean'): ?>
<div class="checkbox" style="margin-bottom:10px;">
<label>
<?= Html::hiddenInput($fieldName, '0') ?>
<?= Html::checkbox($fieldName, !empty($fieldValue), ['value' => '1']) ?>
<?= Html::encode($label) ?>
</label>
</div>
<?php elseif ($inputType === 'select'): ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::dropDownList(
$fieldName,
(string)$fieldValue,
$formModel->getCustomFieldSelectOptions($fieldKey),
['class' => 'form-control', 'prompt' => Yii::t('AnimalManagementModule.base', 'Select...'), 'id' => "animalmedicalvisitform-customfields-$fieldKey"]
) ?>
</div>
<?php elseif ($inputType === 'number'): ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('number', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'step' => 'any', 'id' => "animalmedicalvisitform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'date'): ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('date', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalmedicalvisitform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'datetime'): ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('datetime-local', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalmedicalvisitform-customfields-$fieldKey"]) ?>
</div>
<?php else: ?>
<div class="form-group">
<label class="control-label" for="animalmedicalvisitform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::textInput($fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalmedicalvisitform-customfields-$fieldKey"]) ?>
</div>
<?php endif; ?>
<?php
return (string)ob_get_clean();
};
$customDefinitions = $model->getCustomFieldDefinitions();
$knownMedicalKeys = [
'weight',
'pulse',
'blood_pressure',
'oxygen',
'chronic_conditions',
'acute_conditions',
'special_needs',
'date_of_most_recent_medical_visit',
'physician_name',
'physician_business_name',
'physician_street_address',
'physician_city',
'physician_state',
'physician_zip',
'physician_cell_phone',
'physician_business_phone',
'physician_license_number',
'medical_media_reference',
'media_reference',
];
$remainingDefinitions = [];
foreach ($customDefinitions as $fieldKey => $definition) {
if (in_array($fieldKey, $knownMedicalKeys, true) || in_array($fieldKey, $hiddenMedicalKeys, true)) {
continue;
}
$remainingDefinitions[$fieldKey] = $definition;
}
$medicalMediaPath = trim((string)($model->customFields['medical_media_reference'] ?? $model->customFields['media_reference'] ?? ''));
$hasMedicalMedia = $medicalMediaPath !== '' && (preg_match('/^https?:\/\//i', $medicalMediaPath) || substr($medicalMediaPath, 0, 1) === '/');
$medicalGalleryModalId = 'edit-medical-media-gallery-modal';
$medicalFormId = 'edit-medical-visit-form';
$this->registerCss(<<<CSS
.inline-editor-shell.panel {
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 12px;
background: rgba(10, 18, 28, 0.36);
}
.inline-editor-shell > .panel-heading {
color: #eef5fb;
background: rgba(10, 18, 28, 0.42);
border-color: rgba(255, 255, 255, 0.2);
}
.inline-editor-shell > .panel-body {
background: rgba(10, 18, 28, 0.2);
}
.inline-editor-shell .panel.panel-default {
border-color: rgba(255, 255, 255, 0.2);
background: rgba(10, 18, 28, 0.34);
}
.inline-editor-shell .panel.panel-default > .panel-heading {
color: #eef5fb;
background: rgba(10, 18, 28, 0.42);
border-color: rgba(255, 255, 255, 0.2);
}
.inline-editor-shell,
.inline-editor-shell .panel-body,
.inline-editor-shell .control-label,
.inline-editor-shell .checkbox label,
.inline-editor-shell .radio label,
.inline-editor-shell .help-block {
color: #eef5fb;
}
.inline-editor-shell .text-muted {
color: rgba(233, 242, 250, 0.78) !important;
}
.inline-editor-shell .form-control {
background: rgba(10, 18, 28, 0.56);
border-color: rgba(255, 255, 255, 0.44);
color: #f3f8ff;
}
.inline-editor-shell .form-control::placeholder {
color: rgba(243, 248, 255, 0.72);
}
.inline-editor-shell .form-control[readonly],
.inline-editor-shell .form-control[disabled] {
background: rgba(10, 18, 28, 0.42);
color: rgba(243, 248, 255, 0.72);
}
.inline-editor-shell select.form-control option {
color: #0f1b2a;
}
CSS
);
if ($isInline) {
$this->registerCss(<<<CSS
html, body {
margin: 0 !important;
padding: 0 !important;
background: transparent !important;
}
body > .panel:first-child {
margin-top: 0 !important;
}
CSS
);
}
?>
<style>
.medical-media-select-thumb.is-selected {
border-color: #1f8dd6;
box-shadow: 0 0 0 2px rgba(31, 141, 214, 0.2);
}
</style>
<div class="panel panel-default inline-editor-shell">
<div class="panel-heading">
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;">
<span><?= Yii::t('AnimalManagementModule.base', '<strong>Edit</strong> Medical Visit') ?></span>
<?php if ($isInline): ?>
<span style="display:inline-flex;gap:8px;">
<?= Html::submitButton('<i class="fa fa-check"></i>', [
'class' => 'btn btn-default btn-sm',
'title' => Yii::t('AnimalManagementModule.base', 'Save Medical Visit'),
'form' => $medicalFormId,
]) ?>
<?= Html::button('<i class="fa fa-times"></i>', [
'type' => 'button',
'class' => 'btn btn-default btn-sm',
'id' => 'medical-inline-cancel-icon',
'title' => Yii::t('AnimalManagementModule.base', 'Cancel'),
]) ?>
</span>
<?php endif; ?>
</div>
</div>
<div class="panel-body">
<?php
$formOptions = ['id' => $medicalFormId, 'enctype' => 'multipart/form-data'];
if (!$isInline) {
$formOptions['target'] = '_top';
}
$form = ActiveForm::begin(['options' => $formOptions]);
?>
<?= Html::hiddenInput('returnTo', (string)($returnTo ?? 'view')) ?>
<?= Html::hiddenInput('medicalMediaGalleryPath', $medicalMediaPath, ['id' => 'medical-media-gallery-path']) ?>
<?= $form->errorSummary($model, ['showAllErrors' => true]) ?>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Visit') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<div class="row">
<div class="col-sm-6"><?= $form->field($model, 'visit_at')->input('datetime-local') ?></div>
<div class="col-sm-6"><?= $form->field($model, 'provider_name') ?></div>
</div>
<?= $form->field($model, 'notes')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'recommendations')->textarea(['rows' => 3]) ?>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Vitals') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<div class="row">
<div class="col-sm-3"><?= $renderCustomField('weight', $model, $customDefinitions) ?></div>
<div class="col-sm-3"><?= $renderCustomField('pulse', $model, $customDefinitions) ?></div>
<div class="col-sm-3"><?= $renderCustomField('blood_pressure', $model, $customDefinitions) ?></div>
<div class="col-sm-3"><?= $renderCustomField('oxygen', $model, $customDefinitions) ?></div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Conditions') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?= $renderCustomField('chronic_conditions', $model, $customDefinitions) ?>
<?= $renderCustomField('acute_conditions', $model, $customDefinitions) ?>
<?= $renderCustomField('special_needs', $model, $customDefinitions) ?>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Medical Visit Detail') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?= $renderCustomField('date_of_most_recent_medical_visit', $model, $customDefinitions) ?>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Media') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<div class="row">
<div class="col-sm-4" style="margin-bottom:8px;">
<div id="medical-media-preview" style="border-radius:8px;overflow:hidden;background:#f2f4f6;height:150px;display:flex;align-items:center;justify-content:center;">
<?php if ($hasMedicalMedia): ?>
<img src="<?= Html::encode($medicalMediaPath) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Selected medical media') ?>" style="width:100%;height:100%;object-fit:cover;">
<?php else: ?>
<i class="fa fa-image fa-2x" style="color:#a7b0b8;"></i>
<?php endif; ?>
</div>
</div>
<div class="col-sm-8">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#<?= Html::encode($medicalGalleryModalId) ?>" style="margin-bottom:8px;">
<i class="fa fa-photo"></i> <?= Yii::t('AnimalManagementModule.base', 'Choose from Gallery or Upload') ?>
</button>
<div class="checkbox" style="margin-top:0;">
<label>
<input type="checkbox" name="removeMedicalMedia" value="1">
<?= Yii::t('AnimalManagementModule.base', 'Remove selected media') ?>
</label>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Physician') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<div class="row">
<div class="col-sm-6"><?= $renderCustomField('physician_name', $model, $customDefinitions) ?></div>
<div class="col-sm-6"><?= $renderCustomField('physician_business_name', $model, $customDefinitions) ?></div>
<div class="col-sm-12"><?= $renderCustomField('physician_street_address', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_city', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_state', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_zip', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_cell_phone', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_business_phone', $model, $customDefinitions) ?></div>
<div class="col-sm-4"><?= $renderCustomField('physician_license_number', $model, $customDefinitions) ?></div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Social Post') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?= $form->field($model, 'post_to_space_feed')->checkbox() ?>
<?= $form->field($model, 'post_to_animal_feed')->checkbox() ?>
</div>
</div>
<?php if (!empty($remainingDefinitions)): ?>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Additional Details') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?php foreach ($remainingDefinitions as $fieldKey => $definition): ?>
<?= $renderCustomField($fieldKey, $model, $remainingDefinitions) ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?= Button::save(Yii::t('AnimalManagementModule.base', 'Save Medical Visit'))->submit() ?>
<?php if ($isInline): ?>
<?= Html::button(Yii::t('AnimalManagementModule.base', 'Cancel'), [
'type' => 'button',
'class' => 'btn btn-default',
'id' => 'medical-inline-cancel',
]) ?>
<?php else: ?>
<?= Button::asLink(Yii::t('AnimalManagementModule.base', 'Cancel'))
->link(($returnTo ?? 'view') === 'medical-visits'
? $space->createUrl('/animal_management/animals/medical-visits', ['id' => $animal->id])
: $space->createUrl('/animal_management/animals/view', ['id' => $animal->id])) ?>
<?php endif; ?>
<?php ActiveForm::end(); ?>
</div>
</div>
<div class="modal fade" id="<?= Html::encode($medicalGalleryModalId) ?>" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="<?= Yii::t('AnimalManagementModule.base', 'Close') ?>"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?= Yii::t('AnimalManagementModule.base', 'Select Medical Media from Gallery') ?></h4>
</div>
<div class="modal-body">
<?php if (empty($galleryItems)): ?>
<div class="text-muted" style="margin-bottom:10px;"><?= Yii::t('AnimalManagementModule.base', 'No gallery images available yet.') ?></div>
<?php else: ?>
<div class="row" style="max-height:280px;overflow:auto;margin-bottom:10px;">
<?php foreach ($galleryItems as $galleryItem): ?>
<?php $galleryUrl = trim((string)$galleryItem->getImageUrl()); ?>
<?php if ($galleryUrl === '') { continue; } ?>
<div class="col-xs-6 col-sm-4" style="margin-bottom:8px;">
<button type="button" class="btn btn-default medical-media-select-thumb<?= $medicalMediaPath === $galleryUrl ? ' is-selected' : '' ?>" data-media-url="<?= Html::encode($galleryUrl) ?>" style="width:100%;padding:3px;">
<img src="<?= Html::encode($galleryUrl) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Gallery image') ?>" style="width:100%;height:120px;object-fit:cover;display:block;">
</button>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="form-group" style="margin-bottom:0;">
<label class="control-label" for="medicalMediaUpload"><?= Yii::t('AnimalManagementModule.base', 'Upload New Image') ?></label>
<input type="file" class="form-control" id="medicalMediaUpload" name="medicalMediaUpload" form="<?= Html::encode($medicalFormId) ?>" accept="image/*">
</div>
</div>
</div>
</div>
</div>
<?php
$this->registerJs(<<<JS
(function(){
function renderMedicalPreview(source) {
var preview = $('#medical-media-preview');
if (!preview.length) {
return;
}
if (source) {
preview.html('<img src="' + source + '" alt="Selected medical media" style="width:100%;height:100%;object-fit:cover;">');
} else {
preview.html('<i class="fa fa-image fa-2x" style="color:#a7b0b8;"></i>');
}
}
function markSelectedMedicalThumb(value) {
$('.medical-media-select-thumb').removeClass('is-selected');
if (!value) {
return;
}
$('.medical-media-select-thumb').each(function() {
if ($(this).data('media-url') === value) {
$(this).addClass('is-selected');
}
});
}
$(document).on('click', '.medical-media-select-thumb', function() {
var mediaUrl = $(this).data('media-url');
$('#medical-media-gallery-path').val(mediaUrl);
markSelectedMedicalThumb(mediaUrl);
$('#medicalMediaUpload').val('');
$('input[name="removeMedicalMedia"]').prop('checked', false);
if (mediaUrl) {
renderMedicalPreview(mediaUrl);
}
$('#{$medicalGalleryModalId}').modal('hide');
});
$('#medicalMediaUpload').on('change', function() {
var file = this.files && this.files[0] ? this.files[0] : null;
if (!file) {
return;
}
$('#medical-media-gallery-path').val('');
markSelectedMedicalThumb('');
$('input[name="removeMedicalMedia"]').prop('checked', false);
var reader = new FileReader();
reader.onload = function(e) {
renderMedicalPreview(e.target.result);
$('#{$medicalGalleryModalId}').modal('hide');
};
reader.readAsDataURL(file);
});
$('#{$medicalGalleryModalId}').on('shown.bs.modal', function() {
markSelectedMedicalThumb($('#medical-media-gallery-path').val());
});
})();
JS
, \yii\web\View::POS_END);
if ($isInline) {
$cancelPayload = Json::htmlEncode([
'source' => 'animal-inline-editor',
'type' => 'cancel',
'collapseId' => 'medical-edit-inline-' . (int)$medicalVisit->id,
]);
$this->registerJs(<<<JS
$(document).on('click', '#medical-inline-cancel, #medical-inline-cancel-icon', function() {
if (window.parent && window.parent !== window) {
window.parent.postMessage($cancelPayload, '*');
}
});
JS
, \yii\web\View::POS_END);
}
?>