chore: sync module from working instance and add install guide

This commit is contained in:
Kelin Rescue Hub
2026-04-09 14:11:34 -04:00
parent 20adb1bd1e
commit 039c12233e
23 changed files with 4577 additions and 394 deletions

View File

@@ -7,15 +7,17 @@ use humhub\modules\animal_management\models\AnimalFieldValue;
use humhub\modules\animal_management\models\AnimalGalleryItem;
use humhub\modules\animal_management\models\AnimalMedicalVisit;
use humhub\modules\animal_management\models\forms\DisplaySettingsForm;
use humhub\modules\animal_management\permissions\ManageAnimals;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\rescue_foundation\models\RescueFieldDefinition;
use humhub\modules\space\models\Space;
use Yii;
use yii\base\Widget;
class SearchAnimalProfilesBlock extends Widget
{
public ContentContainerActiveRecord $contentContainer;
public int $limit = 10;
public int $limit = 4;
public function run()
{
@@ -25,29 +27,19 @@ class SearchAnimalProfilesBlock extends Widget
. '</div>';
}
$queryValue = trim((string)Yii::$app->request->get('q', ''));
$showAll = ((int)Yii::$app->request->get('animalFeedAll', 0)) === 1;
$countParam = (int)Yii::$app->request->get('animalFeedCount', $this->limit);
if ($countParam < $this->limit) {
$countParam = $this->limit;
}
if ($countParam > 200) {
$countParam = 200;
}
$query = Animal::find()->where(['contentcontainer_id' => $this->contentContainer->contentcontainer_id]);
if ($queryValue !== '') {
$query->andWhere([
'or',
['like', 'animal_uid', $queryValue],
['like', 'name', $queryValue],
['like', 'species', $queryValue],
]);
$totalCount = (int)$query->count();
$perPage = max(1, $this->limit);
$page = (int)Yii::$app->request->get('animalFeedPage', 1);
if ($page < 1) {
$page = 1;
}
$totalCount = (int)$query->count();
$displayCount = $showAll ? $totalCount : min($countParam, $totalCount);
$pageCount = max(1, (int)ceil($totalCount / $perPage));
if ($page > $pageCount) {
$page = $pageCount;
}
$offset = ($page - 1) * $perPage;
$settings = Yii::$app->getModule('animal_management')->settings->contentContainer($this->contentContainer);
$heading = trim((string)$settings->get('searchBlockHeading', DisplaySettingsForm::DEFAULT_SEARCH_BLOCK_HEADING));
@@ -60,7 +52,8 @@ class SearchAnimalProfilesBlock extends Widget
$animals = $query
->orderBy(['updated_at' => SORT_DESC, 'id' => SORT_DESC])
->limit($displayCount)
->offset($offset)
->limit($perPage)
->all();
$animalIds = array_map(static function (Animal $animal): int {
@@ -70,9 +63,14 @@ class SearchAnimalProfilesBlock extends Widget
$latestMedicalVisitByAnimal = $this->resolveLatestMedicalVisits($animalIds);
$animalImageUrls = $this->resolveAnimalImageUrls($animalIds, ['profile_image_url', 'profile_image', 'photo_url', 'image_url', 'photo'], false);
$tileFieldOverrides = $this->resolveDisplayFieldOverrides($animalIds, 'tile_display_fields');
$animalDonationGoalsByAnimal = $this->resolveAnimalDonationGoals($animalIds);
$hasMore = !$showAll && $displayCount < $totalCount;
$nextCount = min($displayCount + $this->limit, $totalCount);
$canManageAnimals = $this->contentContainer->can(ManageAnimals::class)
|| ($this->contentContainer instanceof Space && $this->contentContainer->isAdmin());
$showDonationSettingsButton = $canManageAnimals && $this->contentContainer->moduleManager->isEnabled('donations');
$hasPreviousPage = $page > 1;
$hasNextPage = $page < $pageCount;
$viewFile = $this->getViewPath() . '/searchAnimalProfilesBlock.php';
if (!is_file($viewFile)) {
@@ -84,20 +82,59 @@ class SearchAnimalProfilesBlock extends Widget
return $this->render('searchAnimalProfilesBlock', [
'animals' => $animals,
'contentContainer' => $this->contentContainer,
'queryValue' => $queryValue,
'heading' => $heading,
'tileFields' => $tileFields,
'tileFieldOverrides' => $tileFieldOverrides,
'latestMedicalVisitByAnimal' => $latestMedicalVisitByAnimal,
'animalImageUrls' => $animalImageUrls,
'animalDonationGoalsByAnimal' => $animalDonationGoalsByAnimal,
'showDonationSettingsButton' => $showDonationSettingsButton,
'totalCount' => $totalCount,
'displayCount' => $displayCount,
'hasMore' => $hasMore,
'nextCount' => $nextCount,
'showAll' => $showAll,
'page' => $page,
'pageCount' => $pageCount,
'hasPreviousPage' => $hasPreviousPage,
'hasNextPage' => $hasNextPage,
]);
}
private function resolveAnimalDonationGoals(array $animalIds): array
{
$animalIds = array_values(array_unique(array_map('intval', $animalIds)));
if (empty($animalIds)
|| !$this->contentContainer->moduleManager->isEnabled('donations')
) {
return [];
}
$donationGoalClass = 'humhub\\modules\\donations\\models\\DonationGoal';
if (!class_exists($donationGoalClass)
|| Yii::$app->db->schema->getTableSchema($donationGoalClass::tableName(), true) === null
) {
return [];
}
$goals = $donationGoalClass::find()
->where([
'contentcontainer_id' => $this->contentContainer->contentcontainer_id,
'goal_type' => $donationGoalClass::TYPE_ANIMAL,
])
->andWhere(['target_animal_id' => $animalIds])
->orderBy(['is_active' => SORT_DESC, 'id' => SORT_DESC])
->all();
$result = [];
foreach ($goals as $goal) {
$animalId = (int)$goal->target_animal_id;
if ($animalId <= 0 || isset($result[$animalId])) {
continue;
}
$result[$animalId] = $goal;
}
return $result;
}
private function normalizeDisplayFields($raw, array $default): array
{
if (is_string($raw)) {