diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ac40987f..827e50c1c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HumHub Changelog ----------------------- - Enh #6899: Fix a missed module config file - Fix #6913: Fix API tests +- Fix #6919: Fix saving of user profile country field value and enable a searching by country title 1.15.4 (March 20, 2024) ----------------------- diff --git a/protected/humhub/modules/content/components/AbstractActiveQueryContentContainer.php b/protected/humhub/modules/content/components/AbstractActiveQueryContentContainer.php index 39c0f19aee..9b1b8d5f73 100644 --- a/protected/humhub/modules/content/components/AbstractActiveQueryContentContainer.php +++ b/protected/humhub/modules/content/components/AbstractActiveQueryContentContainer.php @@ -44,6 +44,15 @@ abstract class AbstractActiveQueryContentContainer extends ActiveQuery */ abstract protected function getSearchableFields(): array; + /** + * Returns a list of fields with its associative array of values and titles. + * Only values of the fields are stored in DB, so we need to do a searching + * in titles which may be translatable, e.g. counties list. + * If additional tables are needed, they must be added via `joinWith`. + * + * @return array + */ + abstract protected function getSearchableFieldTitles(): array; /** * Performs a container text search @@ -98,6 +107,19 @@ abstract class AbstractActiveQueryContentContainer extends ActiveQuery $conditions[] = array_merge(['OR'], $subConditions); } + $fieldTitles = $this->getSearchableFieldTitles(); + foreach ($fieldTitles as $field => $titles) { + $valueKeys = []; + foreach ($titles as $key => $title) { + if (stripos($title, $keyword) === 0) { + $valueKeys[] = $key; + } + } + if ($valueKeys !== []) { + $conditions[] = ['IN', $field, $valueKeys]; + } + } + return $this->andWhere(array_merge(['OR'], $conditions)); } diff --git a/protected/humhub/modules/space/components/ActiveQuerySpace.php b/protected/humhub/modules/space/components/ActiveQuerySpace.php index 02fdf5a560..a68f234ef1 100644 --- a/protected/humhub/modules/space/components/ActiveQuerySpace.php +++ b/protected/humhub/modules/space/components/ActiveQuerySpace.php @@ -79,6 +79,14 @@ class ActiveQuerySpace extends AbstractActiveQueryContentContainer return ['space.name', 'space.description', 'contentcontainer.tags_cached']; } + /** + * @inerhitdoc + */ + protected function getSearchableFieldTitles(): array + { + return []; + } + /** * Exclude blocked spaces for the given $user or for the current User * diff --git a/protected/humhub/modules/user/components/ActiveQueryUser.php b/protected/humhub/modules/user/components/ActiveQueryUser.php index 5eb32f91c0..5f4fcf751e 100644 --- a/protected/humhub/modules/user/components/ActiveQueryUser.php +++ b/protected/humhub/modules/user/components/ActiveQueryUser.php @@ -12,6 +12,8 @@ use humhub\events\ActiveQueryEvent; use humhub\modules\admin\permissions\ManageUsers; use humhub\modules\content\components\AbstractActiveQueryContentContainer; use humhub\modules\user\models\fieldtype\BaseTypeVirtual; +use humhub\modules\user\models\fieldtype\CountrySelect; +use humhub\modules\user\models\fieldtype\Select; use humhub\modules\user\models\Group; use humhub\modules\user\models\GroupUser; use humhub\modules\user\models\ProfileField; @@ -130,6 +132,30 @@ class ActiveQueryUser extends AbstractActiveQueryContentContainer return $fields; } + /** + * @inerhitdoc + */ + protected function getSearchableFieldTitles(): array + { + $this->joinWith('profile')->joinWith('contentContainerRecord'); + + $fields = []; + + $profileFields = ProfileField::find() + ->where(['searchable' => 1]) + ->andWhere(['IN', 'field_type_class', [CountrySelect::class, Select::class]]); + + foreach ($profileFields->all() as $profileField) { + /* @var ProfileField $profileField */ + $fieldType = $profileField->getFieldType(); + if ($fieldType instanceof Select) { + $fields['profile.' . $profileField->internal_name] = $fieldType->getSelectItems(); + } + } + + return $fields; + } + /** * Limits the query to a specified user group * diff --git a/protected/humhub/modules/user/models/fieldtype/CountrySelect.php b/protected/humhub/modules/user/models/fieldtype/CountrySelect.php index 3ba847e1b4..7ab972673f 100644 --- a/protected/humhub/modules/user/models/fieldtype/CountrySelect.php +++ b/protected/humhub/modules/user/models/fieldtype/CountrySelect.php @@ -59,7 +59,7 @@ class CountrySelect extends Select $isoCodes = Iso3166Codes::$countries; foreach ($isoCodes as $code => $value) { - $items[Iso3166Codes::country($code)] = Iso3166Codes::country($code); + $items[$code] = Iso3166Codes::country($code); } } else { foreach (explode(",", $this->options) as $code) {