Initial import of animal_management module
This commit is contained in:
26
widgets/stream/AnimalStreamEntryWallEntry.php
Normal file
26
widgets/stream/AnimalStreamEntryWallEntry.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\animal_management\widgets\stream;
|
||||
|
||||
use humhub\modules\animal_management\models\AnimalStreamEntry;
|
||||
use humhub\modules\content\widgets\stream\WallStreamModuleEntryWidget;
|
||||
|
||||
class AnimalStreamEntryWallEntry extends WallStreamModuleEntryWidget
|
||||
{
|
||||
/**
|
||||
* @var AnimalStreamEntry
|
||||
*/
|
||||
public $model;
|
||||
|
||||
public function renderContent()
|
||||
{
|
||||
return $this->render('wall-entry', [
|
||||
'entry' => $this->model,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getTitle()
|
||||
{
|
||||
return $this->model->getContentDescription();
|
||||
}
|
||||
}
|
||||
228
widgets/stream/views/wall-entry.php
Normal file
228
widgets/stream/views/wall-entry.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
use humhub\modules\animal_management\helpers\DateDisplayHelper;
|
||||
use humhub\modules\animal_management\models\Animal;
|
||||
use humhub\modules\animal_management\models\AnimalMedicalVisit;
|
||||
use humhub\modules\animal_management\models\AnimalProgressUpdate;
|
||||
use humhub\modules\animal_management\models\AnimalStreamEntry;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var AnimalStreamEntry $entry */
|
||||
|
||||
$animal = $entry->animal;
|
||||
if (!$animal instanceof Animal) {
|
||||
return;
|
||||
}
|
||||
|
||||
$medicalVisit = $entry->medicalVisit;
|
||||
$progressUpdate = $entry->progressUpdate;
|
||||
$isMedical = (string)$entry->entry_type === AnimalStreamEntry::TYPE_MEDICAL && $medicalVisit instanceof AnimalMedicalVisit;
|
||||
$isProgress = (string)$entry->entry_type === AnimalStreamEntry::TYPE_PROGRESS && $progressUpdate instanceof AnimalProgressUpdate;
|
||||
|
||||
if (!$isMedical && !$isProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
$animalName = $animal->getDisplayName();
|
||||
|
||||
$mediaReference = '';
|
||||
$chipRows = [];
|
||||
$dateText = '';
|
||||
$detailRows = [];
|
||||
|
||||
if ($isProgress) {
|
||||
$customValues = $progressUpdate->getCustomFieldDisplayValues(true);
|
||||
$additionalFields = [];
|
||||
foreach ($customValues as $customField) {
|
||||
if ((string)($customField['field_key'] ?? '') === 'media_reference') {
|
||||
$mediaReference = trim((string)$customField['value']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$additionalFields[] = [
|
||||
'label' => (string)$customField['label'],
|
||||
'value' => (string)$customField['value'],
|
||||
];
|
||||
}
|
||||
|
||||
$dateText = DateDisplayHelper::format((string)$progressUpdate->update_at);
|
||||
if (trim((string)$progressUpdate->weight) !== '') {
|
||||
$chipRows[] = Yii::t('AnimalManagementModule.base', 'Weight') . ': ' . trim((string)$progressUpdate->weight);
|
||||
}
|
||||
if (trim((string)$progressUpdate->vitals) !== '') {
|
||||
$chipRows[] = Yii::t('AnimalManagementModule.base', 'Vitals');
|
||||
}
|
||||
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Animal'), 'value' => $animalName];
|
||||
if (!empty($progressUpdate->vitals)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Vitals'), 'value' => (string)$progressUpdate->vitals];
|
||||
}
|
||||
if (!empty($progressUpdate->behavior_notes)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Behavior'), 'value' => (string)$progressUpdate->behavior_notes];
|
||||
}
|
||||
if (!empty($progressUpdate->meal_plan_changes)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Meal Plan'), 'value' => (string)$progressUpdate->meal_plan_changes];
|
||||
}
|
||||
if (!empty($progressUpdate->housing_changes)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Housing'), 'value' => (string)$progressUpdate->housing_changes];
|
||||
}
|
||||
if (!empty($progressUpdate->medical_concerns)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Medical Concerns'), 'value' => (string)$progressUpdate->medical_concerns];
|
||||
}
|
||||
if (!empty($additionalFields)) {
|
||||
$text = '';
|
||||
foreach ($additionalFields as $field) {
|
||||
$text .= $field['label'] . ': ' . $field['value'] . "\n";
|
||||
}
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Additional Fields'), 'value' => trim($text)];
|
||||
}
|
||||
} elseif ($isMedical) {
|
||||
$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',
|
||||
];
|
||||
|
||||
$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',
|
||||
];
|
||||
|
||||
$vitalLabelOverrides = [
|
||||
'blood_pressure' => 'BP',
|
||||
'oxygen' => 'O₂',
|
||||
];
|
||||
|
||||
$fieldsByKey = [];
|
||||
$additionalFields = [];
|
||||
foreach ($medicalVisit->getCustomFieldDisplayValues(true) as $customField) {
|
||||
$fieldKey = (string)($customField['field_key'] ?? '');
|
||||
if (in_array($fieldKey, $hiddenMedicalKeys, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldValue = trim((string)($customField['value'] ?? ''));
|
||||
if ($fieldValue === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($fieldKey === 'medical_media_reference' || $fieldKey === 'media_reference') {
|
||||
$mediaReference = $fieldValue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($fieldKey, $knownMedicalKeys, true)) {
|
||||
$fieldsByKey[$fieldKey] = [
|
||||
'label' => (string)($vitalLabelOverrides[$fieldKey] ?? ($customField['label'] ?? $fieldKey)),
|
||||
'value' => $fieldValue,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$additionalFields[] = [
|
||||
'label' => (string)($customField['label'] ?? $fieldKey),
|
||||
'value' => $fieldValue,
|
||||
];
|
||||
}
|
||||
|
||||
$dateText = DateDisplayHelper::format((string)$medicalVisit->visit_at);
|
||||
foreach (['weight', 'pulse', 'blood_pressure', 'oxygen'] as $vitalKey) {
|
||||
if (!empty($fieldsByKey[$vitalKey]['value'])) {
|
||||
$chipRows[] = $fieldsByKey[$vitalKey]['label'] . ': ' . $fieldsByKey[$vitalKey]['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Animal'), 'value' => $animalName];
|
||||
if (!empty($medicalVisit->provider_name)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Provider'), 'value' => (string)$medicalVisit->provider_name];
|
||||
}
|
||||
if (!empty($medicalVisit->notes)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Clinical Notes'), 'value' => (string)$medicalVisit->notes];
|
||||
}
|
||||
if (!empty($medicalVisit->recommendations)) {
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Recommendations'), 'value' => (string)$medicalVisit->recommendations];
|
||||
}
|
||||
|
||||
foreach (['chronic_conditions', 'acute_conditions', 'special_needs'] as $conditionKey) {
|
||||
if (empty($fieldsByKey[$conditionKey]['value'])) {
|
||||
continue;
|
||||
}
|
||||
$detailRows[] = [
|
||||
'label' => (string)$fieldsByKey[$conditionKey]['label'],
|
||||
'value' => (string)$fieldsByKey[$conditionKey]['value'],
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($fieldsByKey['date_of_most_recent_medical_visit']['value'])) {
|
||||
$detailRows[] = [
|
||||
'label' => (string)$fieldsByKey['date_of_most_recent_medical_visit']['label'],
|
||||
'value' => DateDisplayHelper::format((string)$fieldsByKey['date_of_most_recent_medical_visit']['value']),
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($additionalFields)) {
|
||||
$text = '';
|
||||
foreach ($additionalFields as $field) {
|
||||
$text .= $field['label'] . ': ' . $field['value'] . "\n";
|
||||
}
|
||||
$detailRows[] = ['label' => Yii::t('AnimalManagementModule.base', 'Additional Fields'), 'value' => trim($text)];
|
||||
}
|
||||
}
|
||||
|
||||
$hasMediaImage = $mediaReference !== '' && (preg_match('/^https?:\/\//i', $mediaReference) || substr($mediaReference, 0, 1) === '/');
|
||||
?>
|
||||
|
||||
<div style="position:relative;overflow:hidden;border:1px solid #d5dfe8;border-radius:12px;background:#223446;margin:6px 0;min-height:240px;box-shadow:0 8px 22px rgba(12,24,36,0.16);">
|
||||
<?php if ($hasMediaImage): ?>
|
||||
<img src="<?= Html::encode($mediaReference) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Animal stream media') ?>" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block;">
|
||||
<?php endif; ?>
|
||||
<div style="position:absolute;inset:0;background:linear-gradient(110deg,rgba(10,18,28,0.28) 10%,rgba(10,18,28,0.55) 52%,rgba(10,18,28,0.75) 100%);"></div>
|
||||
<div style="position:relative;z-index:1;min-height:240px;padding:14px;display:flex;flex-direction:column;align-items:flex-end;gap:10px;">
|
||||
<div style="width:100%;display:flex;align-items:center;justify-content:space-between;gap:8px;">
|
||||
<span style="font-size:15px;font-weight:700;color:#ffffff;margin-right:auto;"><?= Html::encode($dateText) ?></span>
|
||||
<?php if (!empty($chipRows)): ?>
|
||||
<div style="display:flex;flex-wrap:wrap;gap:6px;margin-bottom:0;justify-content:flex-end;">
|
||||
<?php foreach ($chipRows as $chip): ?>
|
||||
<span style="display:inline-block;border-radius:999px;border:1px solid rgba(255,255,255,0.3);background:rgba(255,255,255,0.16);color:#ffffff;font-size:12px;padding:4px 10px;"><?= Html::encode($chip) ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div style="width:55%;max-width:55%;min-width:0;margin-left:auto;border-radius:10px;border:1px solid rgba(255,255,255,0.22);background:rgba(10,18,28,0.5);backdrop-filter:blur(2px);padding:12px;color:#ecf2f8;">
|
||||
<div style="color:#ffffff;font-size:13px;font-weight:700;margin-bottom:8px;">
|
||||
<?= Html::encode($isMedical
|
||||
? Yii::t('AnimalManagementModule.base', 'Medical Visit')
|
||||
: Yii::t('AnimalManagementModule.base', 'Progress Update')) ?>
|
||||
</div>
|
||||
<?php foreach ($detailRows as $row): ?>
|
||||
<div style="font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:rgba(231,241,249,0.78);margin-bottom:4px;"><?= Html::encode((string)$row['label']) ?></div>
|
||||
<div style="color:#eff5fb;margin-bottom:10px;"><?= nl2br(Html::encode((string)$row['value'])) ?></div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user