user->isGuest) { $canManageTile = $contentContainer->permissionManager->can(new ManageAnimals()); } $showInlineAddControls = $canManageTile; $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]); $createInlineGoalUrl = $contentContainer->createUrl('/donations/settings/create-animal-goal-inline', [ 'animalId' => (int)$animal->id, ]); $toggleInputId = 'animal-donation-toggle-' . (int)$animal->id; $inlineFormId = 'animal-donation-inline-' . (int)$animal->id; $fileFieldId = 'animal-donation-image-file-' . (int)$animal->id; $previewId = 'animal-donation-image-preview-' . (int)$animal->id; $galleryItems = []; if (class_exists(AnimalGalleryItem::class)) { $galleryItems = $animal->getGalleryItems() ->orderBy(['id' => SORT_DESC]) ->limit(8) ->all(); } $galleryUrls = []; foreach ($galleryItems as $galleryItem) { if (!$galleryItem instanceof AnimalGalleryItem) { continue; } $url = trim((string)$galleryItem->getImageUrl()); if ($url === '') { continue; } $galleryUrls[] = $url; } $overlayStackId = 'animal-tile-overlay-stack-' . (int)$animal->id; $inlineMenuId = 'animal-tile-inline-menu-' . (int)$animal->id; $inlinePanelWrapId = 'animal-tile-inline-panel-wrap-' . (int)$animal->id; $tileUiGalleryId = 'animal-tile-gallery-' . (int)$animal->id; $inlinePanelRadioName = 'animal-tile-inline-panel-' . (int)$animal->id; $inlinePanelNoneId = 'animal-tile-inline-none-' . (int)$animal->id; $inlinePanelIds = [ 'gallery' => 'animal-tile-inline-gallery-' . (int)$animal->id, 'files' => 'animal-tile-inline-files-' . (int)$animal->id, 'medical-progress' => 'animal-tile-inline-medical-progress-' . (int)$animal->id, 'transfer' => 'animal-tile-inline-transfer-' . (int)$animal->id, ]; $galleryColsRadioName = 'animal-tile-gallery-cols-' . (int)$animal->id; $galleryCols2Id = 'animal-tile-gallery-cols-2-' . (int)$animal->id; $galleryCols3Id = 'animal-tile-gallery-cols-3-' . (int)$animal->id; $formModeRadioName = 'animal-tile-form-mode-' . (int)$animal->id; $formModeNoneId = 'animal-tile-form-none-' . (int)$animal->id; $formModeMedicalId = 'animal-tile-form-medical-' . (int)$animal->id; $formModeProgressId = 'animal-tile-form-progress-' . (int)$animal->id; $galleryAddToggleId = 'animal-tile-gallery-add-toggle-' . (int)$animal->id; $galleryFormWrapId = 'animal-tile-gallery-form-wrap-' . (int)$animal->id; $galleryListWrapId = 'animal-tile-gallery-list-' . (int)$animal->id; $transferAddToggleId = 'animal-tile-transfer-add-toggle-' . (int)$animal->id; $transferFormWrapId = 'animal-tile-transfer-form-wrap-' . (int)$animal->id; $transferHistoryWrapId = 'animal-tile-transfer-history-wrap-' . (int)$animal->id; $medicalFormWrapId = 'animal-tile-medical-form-wrap-' . (int)$animal->id; $progressFormWrapId = 'animal-tile-progress-form-wrap-' . (int)$animal->id; $donorHistoryToggleId = 'donation-goal-toggle-' . (int)$animal->id; $quickDonateToggleId = 'donation-goal-quick-toggle-' . (int)$animal->id; $goalCardId = 'donation-goal-card-' . (int)$animal->id; $donorPanelId = 'donation-goal-donors-panel-' . (int)$animal->id; $quickDonatePanelId = 'donation-goal-quick-panel-' . (int)$animal->id; $goalEditorToggleId = 'donation-goal-editor-toggle-' . (int)$animal->id; $cfilesEnabled = false; $cfilesBrowseUrl = ''; $recentMedicalVisits = []; $recentProgressUpdates = []; $recentTransferEvents = []; $recentTransfersById = []; $medicalAddInlineUrl = $contentContainer->createUrl('/animal_management/animals/add-medical-visit-inline', ['id' => (int)$animal->id, 'inline' => 1, 'returnTo' => 'medical-visits']); $progressAddInlineUrl = $contentContainer->createUrl('/animal_management/animals/add-progress-update-inline', ['id' => (int)$animal->id, 'inline' => 1, 'returnTo' => 'progress-updates']); $galleryAddInlineUrl = $contentContainer->createUrl('/animal_management/animals/add-gallery-images-inline', ['id' => (int)$animal->id, 'inline' => 1, 'returnTo' => 'view']); $transferAddInlineUrl = $contentContainer->createUrl('/animal_management/animals/transfer-inline', ['id' => (int)$animal->id, 'inline' => 1, 'returnTo' => 'view']); $donationHistoryRows = []; $existingGoalIdForHistory = is_object($existingDonationGoal) ? (int)($existingDonationGoal->id ?? 0) : 0; if ($tileLayoutMode === 'tablet') { if ($contentContainer instanceof Space) { $cfilesEnabled = $contentContainer->moduleManager->isEnabled('cfiles'); } if ($cfilesEnabled) { $cfilesBrowseUrl = $contentContainer->createUrl('/cfiles/browse'); } $recentMedicalVisits = $animal->getMedicalVisits() ->orderBy(['visit_at' => SORT_DESC, 'id' => SORT_DESC]) ->limit(6) ->all(); if (class_exists(AnimalProgressUpdate::class)) { $recentProgressUpdates = $animal->getProgressUpdates() ->orderBy(['update_at' => SORT_DESC, 'id' => SORT_DESC]) ->limit(6) ->all(); } if (class_exists(AnimalTransferEvent::class)) { $recentTransferEvents = $animal->getTransferEvents() ->orderBy(['id' => SORT_DESC]) ->limit(18) ->all(); $transferIds = []; foreach ($recentTransferEvents as $recentTransferEvent) { if ($recentTransferEvent instanceof AnimalTransferEvent) { $transferIds[] = (int)$recentTransferEvent->transfer_id; } } $transferIds = array_values(array_unique(array_filter($transferIds))); if (!empty($transferIds)) { $recentTransfersById = AnimalTransfer::find() ->where(['id' => $transferIds]) ->indexBy('id') ->all(); } } if ($existingGoalIdForHistory > 0) { $transactionClass = 'humhub\\modules\\donations\\models\\DonationTransaction'; if (class_exists($transactionClass) && Yii::$app->db->schema->getTableSchema($transactionClass::tableName(), true) !== null) { $transactions = $transactionClass::find() ->where([ 'contentcontainer_id' => (int)$contentContainer->contentcontainer_id, 'goal_id' => $existingGoalIdForHistory, 'status' => $transactionClass::STATUS_SUCCEEDED, ]) ->orderBy(['id' => SORT_DESC]) ->limit(120) ->all(); foreach ($transactions as $transaction) { $amount = max(0.0, (float)($transaction->amount ?? 0)); if ($amount <= 0) { continue; } $donorLabel = Yii::t('DonationsModule.base', 'Anonymous'); $donorUrl = ''; $donorAvatarUrl = ''; $createdAtRaw = trim((string)($transaction->created_at ?? '')); $createdAtTs = $createdAtRaw !== '' ? strtotime($createdAtRaw) : false; $whenText = $createdAtTs !== false ? date('m/d/y g:i A', $createdAtTs) : DateDisplayHelper::format($createdAtRaw); if ((int)($transaction->is_anonymous ?? 0) !== 1 && (int)($transaction->donor_user_id ?? 0) > 0) { $userClass = 'humhub\\modules\\user\\models\\User'; if (class_exists($userClass)) { $donor = $userClass::findOne(['id' => (int)$transaction->donor_user_id]); if ($donor !== null) { $donorLabel = (string)$donor->getDisplayName(); if (method_exists($donor, 'getUrl')) { $donorUrl = (string)$donor->getUrl(); } elseif (method_exists($donor, 'createUrl')) { $donorUrl = (string)$donor->createUrl('/user/profile'); } if (method_exists($donor, 'getProfileImage')) { $profileImage = $donor->getProfileImage(); if ($profileImage !== null && method_exists($profileImage, 'getUrl')) { $donorAvatarUrl = (string)$profileImage->getUrl(); } } } } } $donationHistoryRows[] = [ 'when' => $whenText, 'donor' => $donorLabel, 'donorUrl' => $donorUrl, 'avatarUrl' => $donorAvatarUrl, 'amount' => '$' . number_format($amount, 2), ]; } } } } $defaultGoalTitle = Yii::t('DonationsModule.base', '{animalName} Care Fund', [ 'animalName' => (string)$animal->getDisplayName(), ]); $existingGoalId = is_object($existingDonationGoal) ? (int)($existingDonationGoal->id ?? 0) : 0; $existingGoalTitle = trim((string)(is_object($existingDonationGoal) ? ($existingDonationGoal->title ?? '') : '')); $existingGoalTargetAmount = is_object($existingDonationGoal) ? (float)($existingDonationGoal->target_amount ?? 0) : 0.0; $existingGoalDescription = trim((string)(is_object($existingDonationGoal) ? ($existingDonationGoal->description ?? '') : '')); $existingGoalImage = trim((string)(is_object($existingDonationGoal) ? ($existingDonationGoal->image_path ?? '') : '')); $existingGoalActive = is_object($existingDonationGoal) ? (int)($existingDonationGoal->is_active ?? 1) : 1; if ($existingGoalTitle === '') { $existingGoalTitle = $defaultGoalTitle; } $tileRenderEvent = new AnimalTileRenderEvent([ 'animal' => $animal, 'contentContainer' => $contentContainer, 'existingDonationGoal' => $existingDonationGoal, 'showDonationSettingsButton' => $showDonationSettingsButton, 'donationToggleInputId' => $toggleInputId, 'donationInlineFormId' => $inlineFormId, ]); Event::trigger(AnimalTileRenderEvent::class, AnimalTileRenderEvent::EVENT_RENDER_OVERLAY, $tileRenderEvent); $tileOverlayAddonHtml = $tileRenderEvent->getHtml(); if ($tileLayoutMode === 'tablet' && $tileOverlayAddonHtml !== '') { $tabletQuickDonateExtrasHtml = trim((string)$this->render('_tablet_quick_donate_extras', [ 'donationHistoryRows' => $donationHistoryRows, 'showDonationSettingsButton' => $showDonationSettingsButton, 'goalEditorToggleId' => $goalEditorToggleId, 'existingGoalId' => $existingGoalId, 'createInlineGoalUrl' => $createInlineGoalUrl, 'existingGoalTitle' => $existingGoalTitle, 'existingGoalTargetAmount' => $existingGoalTargetAmount, 'existingGoalDescription' => $existingGoalDescription, 'existingGoalImage' => $existingGoalImage, 'galleryUrls' => $galleryUrls, 'animal' => $animal, 'existingGoalActive' => $existingGoalActive, 'fileFieldId' => $fileFieldId, 'previewId' => $previewId, 'quickDonateToggleId' => $quickDonateToggleId, 'quickDonatePanelId' => $quickDonatePanelId, ])); if ($tabletQuickDonateExtrasHtml !== '') { $quickPanelPattern = '/(